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