Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceDefs.h - Common Subzero declarations ------*- C++ -*-===// |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Declares various useful types and classes that have widespread use |
| 12 | /// across Subzero. |
| 13 | /// |
| 14 | /// Every Subzero source file is expected to include IceDefs.h. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 15 | /// |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #ifndef SUBZERO_SRC_ICEDEFS_H |
| 19 | #define SUBZERO_SRC_ICEDEFS_H |
| 20 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 21 | #include "IceBuildDefs.h" // TODO(stichnot): move into individual files |
| 22 | #include "IceTLS.h" |
| 23 | |
Jan Voung | b17f61d | 2014-08-28 16:00:53 -0700 | [diff] [blame] | 24 | #include "llvm/ADT/ArrayRef.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 25 | #include "llvm/ADT/BitVector.h" |
Jim Stichnoth | 607e9f0 | 2014-11-06 13:32:05 -0800 | [diff] [blame] | 26 | #include "llvm/ADT/ilist.h" |
| 27 | #include "llvm/ADT/ilist_node.h" |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 28 | #include "llvm/ADT/iterator_range.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 29 | #include "llvm/ADT/SmallBitVector.h" |
Jim Stichnoth | 586d4c2 | 2014-12-05 16:43:08 -0800 | [diff] [blame] | 30 | #include "llvm/ADT/SmallVector.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 31 | #include "llvm/ADT/STLExtras.h" |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 32 | #include "llvm/Support/Allocator.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 33 | #include "llvm/Support/Casting.h" |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 34 | #include "llvm/Support/ELF.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 36 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 37 | #include <cassert> |
| 38 | #include <cstdint> |
| 39 | #include <cstdio> // snprintf |
| 40 | #include <functional> // std::less |
| 41 | #include <limits> |
| 42 | #include <list> |
| 43 | #include <map> |
| 44 | #include <memory> |
| 45 | #include <mutex> |
| 46 | #include <string> |
| 47 | #include <system_error> |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 48 | #include <unordered_map> |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 49 | #include <vector> |
Jim Stichnoth | 7d53825 | 2015-01-23 10:22:56 -0800 | [diff] [blame] | 50 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 51 | namespace Ice { |
| 52 | |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 53 | class Assembler; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 54 | class Cfg; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 55 | class CfgNode; |
| 56 | class Constant; |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 57 | class ELFObjectWriter; |
| 58 | class ELFStreamer; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 59 | class FunctionDeclaration; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 60 | class GlobalContext; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 61 | class GlobalDeclaration; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 62 | class Inst; |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 63 | class InstAssign; |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 64 | class InstJumpTable; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 65 | class InstPhi; |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 66 | class InstSwitch; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 67 | class InstTarget; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 68 | class LiveRange; |
| 69 | class Liveness; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 70 | class Operand; |
Jan Voung | 72984d8 | 2015-01-29 14:42:38 -0800 | [diff] [blame] | 71 | class TargetDataLowering; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 72 | class TargetLowering; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 73 | class Variable; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 74 | class VariableDeclaration; |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 75 | class VariablesMetadata; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 76 | |
Jan Voung | 1d62cf0 | 2015-01-09 14:57:32 -0800 | [diff] [blame] | 77 | template <size_t SlabSize = 1024 * 1024> |
| 78 | using ArenaAllocator = |
| 79 | llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, SlabSize>; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 80 | |
Jan Voung | 1d62cf0 | 2015-01-09 14:57:32 -0800 | [diff] [blame] | 81 | ArenaAllocator<> *getCurrentCfgAllocator(); |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 82 | |
| 83 | template <typename T> struct CfgLocalAllocator { |
| 84 | using value_type = T; |
Jim Stichnoth | 91d1b80 | 2015-10-01 13:24:34 -0700 | [diff] [blame] | 85 | using pointer = T *; |
| 86 | using const_pointer = const T *; |
| 87 | using reference = T &; |
| 88 | using const_reference = const T &; |
| 89 | using size_type = std::size_t; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 90 | CfgLocalAllocator() = default; |
| 91 | template <class U> CfgLocalAllocator(const CfgLocalAllocator<U> &) {} |
Jim Stichnoth | 91d1b80 | 2015-10-01 13:24:34 -0700 | [diff] [blame] | 92 | pointer allocate(size_type Num) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 93 | return getCurrentCfgAllocator()->Allocate<T>(Num); |
| 94 | } |
Jim Stichnoth | 91d1b80 | 2015-10-01 13:24:34 -0700 | [diff] [blame] | 95 | void deallocate(pointer, size_type) {} |
| 96 | template <class U> struct rebind { typedef CfgLocalAllocator<U> other; }; |
| 97 | void construct(pointer P, const T &Val) { |
| 98 | new (static_cast<void *>(P)) T(Val); |
| 99 | } |
| 100 | void destroy(pointer P) { P->~T(); } |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 101 | }; |
| 102 | template <typename T, typename U> |
| 103 | inline bool operator==(const CfgLocalAllocator<T> &, |
| 104 | const CfgLocalAllocator<U> &) { |
| 105 | return true; |
| 106 | } |
| 107 | template <typename T, typename U> |
| 108 | inline bool operator!=(const CfgLocalAllocator<T> &, |
| 109 | const CfgLocalAllocator<U> &) { |
| 110 | return false; |
| 111 | } |
| 112 | |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 113 | // makeUnique should be used when memory is expected to be allocated from the |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 114 | // heap (as opposed to allocated from some Allocator.) It is intended to be |
| 115 | // used instead of new. |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 116 | // |
| 117 | // The expected usage is as follows |
| 118 | // |
| 119 | // class MyClass { |
| 120 | // public: |
| 121 | // static std::unique_ptr<MyClass> create(<ctor_args>) { |
| 122 | // return makeUnique<MyClass>(<ctor_args>); |
| 123 | // } |
| 124 | // |
| 125 | // private: |
| 126 | // ENABLE_MAKE_UNIQUE; |
| 127 | // |
| 128 | // MyClass(<ctor_args>) ... |
| 129 | // } |
| 130 | // |
| 131 | // ENABLE_MAKE_UNIQUE is a trick that is necessary if MyClass' ctor is private. |
| 132 | // Private ctors are highly encouraged when you're writing a class that you'd |
| 133 | // like to have allocated with makeUnique as it would prevent users from |
| 134 | // declaring stack allocated variables. |
| 135 | namespace Internal { |
| 136 | struct MakeUniqueEnabler { |
| 137 | template <class T, class... Args> |
| 138 | static std::unique_ptr<T> create(Args &&... TheArgs) { |
| 139 | std::unique_ptr<T> Unique(new T(std::forward<Args>(TheArgs)...)); |
| 140 | return Unique; |
| 141 | } |
| 142 | }; |
| 143 | } // end of namespace Internal |
| 144 | |
| 145 | template <class T, class... Args> |
| 146 | static std::unique_ptr<T> makeUnique(Args &&... TheArgs) { |
| 147 | return ::Ice::Internal::MakeUniqueEnabler::create<T>( |
| 148 | std::forward<Args>(TheArgs)...); |
| 149 | } |
| 150 | |
| 151 | #define ENABLE_MAKE_UNIQUE friend struct ::Ice::Internal::MakeUniqueEnabler |
| 152 | |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 153 | using IceString = std::string; |
| 154 | using InstList = llvm::ilist<Inst>; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 155 | // Ideally PhiList would be llvm::ilist<InstPhi>, and similar for AssignList, |
| 156 | // but this runs into issues with SFINAE. |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 157 | using PhiList = InstList; |
| 158 | using AssignList = InstList; |
Karl Schimpf | 209318a | 2015-08-20 13:24:02 -0700 | [diff] [blame] | 159 | |
Andrew Scull | 00741a0 | 2015-09-16 19:04:09 -0700 | [diff] [blame] | 160 | // Standard library containers with CfgLocalAllocator. |
| 161 | template <typename T> using CfgVector = std::vector<T, CfgLocalAllocator<T>>; |
| 162 | template <typename T> using CfgList = std::list<T, CfgLocalAllocator<T>>; |
| 163 | |
Karl Schimpf | 209318a | 2015-08-20 13:24:02 -0700 | [diff] [blame] | 164 | // Containers that are arena-allocated from the Cfg's allocator. |
Andrew Scull | 00741a0 | 2015-09-16 19:04:09 -0700 | [diff] [blame] | 165 | using OperandList = CfgVector<Operand *>; |
| 166 | using VarList = CfgVector<Variable *>; |
| 167 | using NodeList = CfgVector<CfgNode *>; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 168 | |
Karl Schimpf | 209318a | 2015-08-20 13:24:02 -0700 | [diff] [blame] | 169 | // Contains that use the default (global) allocator. |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 170 | using ConstantList = std::vector<Constant *>; |
| 171 | using FunctionDeclarationList = std::vector<FunctionDeclaration *>; |
| 172 | using VariableDeclarationList = std::vector<VariableDeclaration *>; |
Jan Voung | 72984d8 | 2015-01-29 14:42:38 -0800 | [diff] [blame] | 173 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 174 | /// SizeT is for holding small-ish limits like number of source operands in an |
| 175 | /// instruction. It is used instead of size_t (which may be 64-bits wide) when |
| 176 | /// we want to save space. |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 177 | using SizeT = uint32_t; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 178 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 179 | /// InstNumberT is for holding an instruction number. Instruction numbers are |
| 180 | /// used for representing Variable live ranges. |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 181 | using InstNumberT = int32_t; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 182 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 183 | /// A LiveBeginEndMapEntry maps a Variable::Number value to an Inst::Number |
| 184 | /// value, giving the instruction number that begins or ends a variable's live |
| 185 | /// range. |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 186 | using LiveBeginEndMapEntry = std::pair<SizeT, InstNumberT>; |
Andrew Scull | 00741a0 | 2015-09-16 19:04:09 -0700 | [diff] [blame] | 187 | using LiveBeginEndMap = CfgVector<LiveBeginEndMapEntry>; |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 188 | using LivenessBV = llvm::BitVector; |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 189 | |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 190 | using TimerStackIdT = uint32_t; |
| 191 | using TimerIdT = uint32_t; |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 192 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 193 | /// Use alignas(MaxCacheLineSize) to isolate variables/fields that might be |
| 194 | /// contended while multithreading. Assumes the maximum cache line size is 64. |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 195 | enum { MaxCacheLineSize = 64 }; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 196 | // Use ICE_CACHELINE_BOUNDARY to force the next field in a declaration |
| 197 | // list to be aligned to the next cache line. |
JF Bastien | 867684e | 2015-01-28 15:07:38 -0800 | [diff] [blame] | 198 | // Note: zero is added to work around the following GCC 4.8 bug (fixed in 4.9): |
| 199 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55382 |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 200 | #define ICE_CACHELINE_BOUNDARY \ |
JF Bastien | 867684e | 2015-01-28 15:07:38 -0800 | [diff] [blame] | 201 | __attribute__((aligned(MaxCacheLineSize + 0))) int : 0 |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 202 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 203 | /// PNaCl is ILP32, so theoretically we should only need 32-bit offsets. |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 204 | using RelocOffsetT = int32_t; |
Jan Voung | c0d965f | 2014-11-04 16:55:01 -0800 | [diff] [blame] | 205 | enum { RelocAddrSize = 4 }; |
Jan Voung | fe14fb8 | 2014-10-13 15:56:32 -0700 | [diff] [blame] | 206 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 207 | enum LivenessMode { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 208 | /// Basic version of live-range-end calculation. Marks the last uses of |
| 209 | /// variables based on dataflow analysis. Records the set of live-in and |
| 210 | /// live-out variables for each block. Identifies and deletes dead |
| 211 | /// instructions (primarily stores). |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 212 | Liveness_Basic, |
| 213 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 214 | /// In addition to Liveness_Basic, also calculate the complete live range for |
| 215 | /// each variable in a form suitable for interference calculation and register |
| 216 | /// allocation. |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 217 | Liveness_Intervals |
| 218 | }; |
| 219 | |
Jim Stichnoth | 70d0a05 | 2014-11-14 15:53:46 -0800 | [diff] [blame] | 220 | enum RegAllocKind { |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 221 | RAK_Unknown, |
Jim Stichnoth | 4001c93 | 2015-10-09 14:33:26 -0700 | [diff] [blame] | 222 | RAK_Global, /// full, global register allocation |
| 223 | RAK_SecondChance, /// second-chance bin-packing after full regalloc attempt |
| 224 | RAK_Phi, /// infinite-weight Variables with active spilling/filling |
| 225 | RAK_InfOnly /// allocation only for infinite-weight Variables |
Jim Stichnoth | 70d0a05 | 2014-11-14 15:53:46 -0800 | [diff] [blame] | 226 | }; |
| 227 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 228 | enum VerboseItem { |
| 229 | IceV_None = 0, |
| 230 | IceV_Instructions = 1 << 0, |
| 231 | IceV_Deleted = 1 << 1, |
| 232 | IceV_InstNumbers = 1 << 2, |
| 233 | IceV_Preds = 1 << 3, |
| 234 | IceV_Succs = 1 << 4, |
| 235 | IceV_Liveness = 1 << 5, |
Jim Stichnoth | 769be68 | 2015-01-15 09:05:08 -0800 | [diff] [blame] | 236 | IceV_RegOrigins = 1 << 6, |
| 237 | IceV_LinearScan = 1 << 7, |
| 238 | IceV_Frame = 1 << 8, |
| 239 | IceV_AddrOpt = 1 << 9, |
| 240 | IceV_Random = 1 << 10, |
Jim Stichnoth | a59ae6f | 2015-05-17 10:11:41 -0700 | [diff] [blame] | 241 | IceV_Folding = 1 << 11, |
Jim Stichnoth | e4f65d8 | 2015-06-17 22:16:02 -0700 | [diff] [blame] | 242 | IceV_RMW = 1 << 12, |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 243 | IceV_Loop = 1 << 13, |
Jim Stichnoth | a522965 | 2015-11-12 10:25:21 -0800 | [diff] [blame] | 244 | IceV_Status = 1 << 14, |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 245 | IceV_All = ~IceV_None, |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 246 | IceV_Most = IceV_All & ~IceV_LinearScan |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 247 | }; |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 248 | using VerboseMask = uint32_t; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 249 | |
Jim Stichnoth | d442e7e | 2015-02-12 14:01:48 -0800 | [diff] [blame] | 250 | enum FileType { |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 251 | FT_Elf, /// ELF .o file |
| 252 | FT_Asm, /// Assembly .s file |
| 253 | FT_Iasm /// "Integrated assembler" .byte-style .s file |
Jim Stichnoth | d442e7e | 2015-02-12 14:01:48 -0800 | [diff] [blame] | 254 | }; |
| 255 | |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 256 | using Ostream = llvm::raw_ostream; |
| 257 | using Fdstream = llvm::raw_fd_ostream; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 258 | |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 259 | using GlobalLockType = std::mutex; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 260 | |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 261 | enum ErrorCodes { EC_None = 0, EC_Args, EC_Bitcode, EC_Translation }; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 262 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 263 | /// Wrapper around std::error_code for allowing multiple errors to be folded |
| 264 | /// into one. The current implementation keeps track of the first error, which |
| 265 | /// is likely to be the most useful one, and this could be extended to e.g. |
| 266 | /// collect a vector of errors. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 267 | class ErrorCode : public std::error_code { |
| 268 | ErrorCode(const ErrorCode &) = delete; |
| 269 | ErrorCode &operator=(const ErrorCode &) = delete; |
| 270 | |
| 271 | public: |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 272 | ErrorCode() = default; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 273 | void assign(ErrorCodes Code) { |
| 274 | if (!HasError) { |
| 275 | HasError = true; |
| 276 | std::error_code::assign(Code, std::generic_category()); |
| 277 | } |
| 278 | } |
| 279 | void assign(int Code) { assign(static_cast<ErrorCodes>(Code)); } |
| 280 | |
| 281 | private: |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 282 | bool HasError = false; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 283 | }; |
| 284 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 285 | /// Reverse range adaptors written in terms of llvm::make_range(). |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 286 | template <typename T> |
| 287 | llvm::iterator_range<typename T::const_reverse_iterator> |
| 288 | reverse_range(const T &Container) { |
| 289 | return llvm::make_range(Container.rbegin(), Container.rend()); |
| 290 | } |
| 291 | template <typename T> |
| 292 | llvm::iterator_range<typename T::reverse_iterator> reverse_range(T &Container) { |
| 293 | return llvm::make_range(Container.rbegin(), Container.rend()); |
| 294 | } |
| 295 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 296 | /// Options for pooling and randomization of immediates. |
Qining Lu | 253dc8a | 2015-06-22 10:10:23 -0700 | [diff] [blame] | 297 | enum RandomizeAndPoolImmediatesEnum { RPI_None, RPI_Randomize, RPI_Pool }; |
| 298 | |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 299 | /// Salts for Random number generator for different randomization passes. |
| 300 | enum RandomizationPassesEnum { |
| 301 | RPE_BasicBlockReordering, |
| 302 | RPE_ConstantBlinding, |
| 303 | RPE_FunctionReordering, |
| 304 | RPE_GlobalVariableReordering, |
| 305 | RPE_NopInsertion, |
| 306 | RPE_PooledConstantReordering, |
| 307 | RPE_RegAllocRandomization, |
| 308 | RPE_num |
| 309 | }; |
| 310 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 311 | } // end of namespace Ice |
| 312 | |
| 313 | #endif // SUBZERO_SRC_ICEDEFS_H |