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