Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceDefs.h - Common Subzero declaraions -------*- C++ -*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares various useful types and classes that have |
| 11 | // widespread use across Subzero. Every Subzero source file is |
| 12 | // expected to include IceDefs.h. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICEDEFS_H |
| 17 | #define SUBZERO_SRC_ICEDEFS_H |
| 18 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 19 | #include <cassert> |
Jim Stichnoth | a18cc9c | 2014-09-30 19:10:22 -0700 | [diff] [blame] | 20 | #include <cstdint> |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 21 | #include <cstdio> // snprintf |
| 22 | #include <functional> // std::less |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame] | 23 | #include <limits> |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 24 | #include <list> |
| 25 | #include <map> |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 26 | #include <string> |
| 27 | #include <vector> |
Jan Voung | b17f61d | 2014-08-28 16:00:53 -0700 | [diff] [blame] | 28 | #include "llvm/ADT/ArrayRef.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 29 | #include "llvm/ADT/BitVector.h" |
Jim Stichnoth | 607e9f0 | 2014-11-06 13:32:05 -0800 | [diff] [blame] | 30 | #include "llvm/ADT/ilist.h" |
| 31 | #include "llvm/ADT/ilist_node.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 32 | #include "llvm/ADT/SmallBitVector.h" |
Jim Stichnoth | 586d4c2 | 2014-12-05 16:43:08 -0800 | [diff] [blame] | 33 | #include "llvm/ADT/SmallVector.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 34 | #include "llvm/ADT/STLExtras.h" |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 35 | #include "llvm/Support/Allocator.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 36 | #include "llvm/Support/Casting.h" |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 37 | #include "llvm/Support/ELF.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 38 | #include "llvm/Support/raw_ostream.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 39 | |
| 40 | namespace Ice { |
| 41 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 42 | class Cfg; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 43 | class CfgNode; |
| 44 | class Constant; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 45 | class FunctionDeclaration; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 46 | class GlobalContext; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 47 | class GlobalDeclaration; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 48 | class Inst; |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 49 | class InstAssign; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 50 | class InstPhi; |
| 51 | class InstTarget; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 52 | class LiveRange; |
| 53 | class Liveness; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 54 | class Operand; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 55 | class TargetLowering; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 56 | class Variable; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 57 | class VariableDeclaration; |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 58 | class VariablesMetadata; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 59 | |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 60 | typedef llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 1024 * 1024> |
| 61 | ArenaAllocator; |
| 62 | |
| 63 | ArenaAllocator *getCurrentCfgAllocator(); |
| 64 | |
| 65 | template <typename T> struct CfgLocalAllocator { |
| 66 | using value_type = T; |
| 67 | CfgLocalAllocator() = default; |
| 68 | template <class U> CfgLocalAllocator(const CfgLocalAllocator<U> &) {} |
| 69 | T *allocate(std::size_t Num) { |
| 70 | return getCurrentCfgAllocator()->Allocate<T>(Num); |
| 71 | } |
| 72 | void deallocate(T *, std::size_t) {} |
| 73 | }; |
| 74 | template <typename T, typename U> |
| 75 | inline bool operator==(const CfgLocalAllocator<T> &, |
| 76 | const CfgLocalAllocator<U> &) { |
| 77 | return true; |
| 78 | } |
| 79 | template <typename T, typename U> |
| 80 | inline bool operator!=(const CfgLocalAllocator<T> &, |
| 81 | const CfgLocalAllocator<U> &) { |
| 82 | return false; |
| 83 | } |
| 84 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 85 | typedef std::string IceString; |
Jim Stichnoth | 607e9f0 | 2014-11-06 13:32:05 -0800 | [diff] [blame] | 86 | typedef llvm::ilist<Inst> InstList; |
Jim Stichnoth | 1502e59 | 2014-12-11 09:22:45 -0800 | [diff] [blame] | 87 | // Ideally PhiList would be llvm::ilist<InstPhi>, and similar for |
| 88 | // AssignList, but this runs into issues with SFINAE. |
| 89 | typedef InstList PhiList; |
| 90 | typedef InstList AssignList; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 91 | // VarList and NodeList are arena-allocated from the Cfg's allocator. |
| 92 | typedef std::vector<Variable *, CfgLocalAllocator<Variable *>> VarList; |
| 93 | typedef std::vector<CfgNode *, CfgLocalAllocator<CfgNode *>> NodeList; |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 94 | typedef std::vector<Constant *> ConstantList; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 95 | |
| 96 | // SizeT is for holding small-ish limits like number of source |
| 97 | // operands in an instruction. It is used instead of size_t (which |
| 98 | // may be 64-bits wide) when we want to save space. |
| 99 | typedef uint32_t SizeT; |
| 100 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 101 | // InstNumberT is for holding an instruction number. Instruction |
| 102 | // numbers are used for representing Variable live ranges. |
| 103 | typedef int32_t InstNumberT; |
| 104 | |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 105 | // A LiveBeginEndMapEntry maps a Variable::Number value to an |
| 106 | // Inst::Number value, giving the instruction number that begins or |
| 107 | // ends a variable's live range. |
| 108 | typedef std::pair<SizeT, InstNumberT> LiveBeginEndMapEntry; |
Jim Stichnoth | c599e46 | 2015-01-08 16:56:49 -0800 | [diff] [blame^] | 109 | typedef std::vector<LiveBeginEndMapEntry, |
| 110 | CfgLocalAllocator<LiveBeginEndMapEntry> > LiveBeginEndMap; |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 111 | typedef llvm::BitVector LivenessBV; |
| 112 | |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 113 | typedef uint32_t TimerStackIdT; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 114 | typedef uint32_t TimerIdT; |
| 115 | |
Jan Voung | fe14fb8 | 2014-10-13 15:56:32 -0700 | [diff] [blame] | 116 | // PNaCl is ILP32, so theoretically we should only need 32-bit offsets. |
| 117 | typedef int32_t RelocOffsetT; |
Jan Voung | c0d965f | 2014-11-04 16:55:01 -0800 | [diff] [blame] | 118 | enum { RelocAddrSize = 4 }; |
Jan Voung | fe14fb8 | 2014-10-13 15:56:32 -0700 | [diff] [blame] | 119 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 120 | enum LivenessMode { |
| 121 | // Basic version of live-range-end calculation. Marks the last uses |
| 122 | // of variables based on dataflow analysis. Records the set of |
| 123 | // live-in and live-out variables for each block. Identifies and |
| 124 | // deletes dead instructions (primarily stores). |
| 125 | Liveness_Basic, |
| 126 | |
| 127 | // In addition to Liveness_Basic, also calculate the complete |
| 128 | // live range for each variable in a form suitable for interference |
| 129 | // calculation and register allocation. |
| 130 | Liveness_Intervals |
| 131 | }; |
| 132 | |
Jim Stichnoth | 70d0a05 | 2014-11-14 15:53:46 -0800 | [diff] [blame] | 133 | enum RegAllocKind { |
| 134 | RAK_Global, // full, global register allocation |
| 135 | RAK_InfOnly // allocation only for infinite-weight Variables |
| 136 | }; |
| 137 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 138 | enum VerboseItem { |
| 139 | IceV_None = 0, |
| 140 | IceV_Instructions = 1 << 0, |
| 141 | IceV_Deleted = 1 << 1, |
| 142 | IceV_InstNumbers = 1 << 2, |
| 143 | IceV_Preds = 1 << 3, |
| 144 | IceV_Succs = 1 << 4, |
| 145 | IceV_Liveness = 1 << 5, |
| 146 | IceV_RegManager = 1 << 6, |
| 147 | IceV_RegOrigins = 1 << 7, |
| 148 | IceV_LinearScan = 1 << 8, |
| 149 | IceV_Frame = 1 << 9, |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 150 | IceV_AddrOpt = 1 << 10, |
Jim Stichnoth | e6d2478 | 2014-12-19 05:42:24 -0800 | [diff] [blame] | 151 | IceV_Random = 1 << 11, |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 152 | IceV_All = ~IceV_None, |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 153 | IceV_Most = IceV_All & ~IceV_LinearScan |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 154 | }; |
| 155 | typedef uint32_t VerboseMask; |
| 156 | |
Jim Stichnoth | 78282f6 | 2014-07-27 23:14:00 -0700 | [diff] [blame] | 157 | typedef llvm::raw_ostream Ostream; |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 158 | typedef llvm::raw_fd_ostream Fdstream; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 159 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 160 | } // end of namespace Ice |
| 161 | |
| 162 | #endif // SUBZERO_SRC_ICEDEFS_H |