Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceInst.h - High-level instructions ----------*- 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 the Inst class and its target-independent |
| 11 | // subclasses, which represent the high-level Vanilla ICE instructions |
| 12 | // and map roughly 1:1 to LLVM instructions. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICEINST_H |
| 17 | #define SUBZERO_SRC_ICEINST_H |
| 18 | |
| 19 | #include "IceDefs.h" |
| 20 | #include "IceInst.def" |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 21 | #include "IceIntrinsics.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 22 | #include "IceTypes.h" |
| 23 | |
| 24 | // TODO: The Cfg structure, and instructions in particular, need to be |
| 25 | // validated for things like valid operand types, valid branch |
| 26 | // targets, proper ordering of Phi and non-Phi instructions, etc. |
| 27 | // Most of the validity checking will be done in the bitcode reader. |
| 28 | // We need a list of everything that should be validated, and tests |
| 29 | // for each. |
| 30 | |
| 31 | namespace Ice { |
| 32 | |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 33 | // Base instruction class for ICE. Inst has two subclasses: |
| 34 | // InstHighLevel and InstTarget. High-level ICE instructions inherit |
| 35 | // from InstHighLevel, and low-level (target-specific) ICE |
| 36 | // instructions inherit from InstTarget. |
Jim Stichnoth | 607e9f0 | 2014-11-06 13:32:05 -0800 | [diff] [blame] | 37 | class Inst : public llvm::ilist_node<Inst> { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 38 | Inst(const Inst &) = delete; |
| 39 | Inst &operator=(const Inst &) = delete; |
| 40 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 41 | public: |
| 42 | enum InstKind { |
| 43 | // Arbitrary (alphabetical) order, except put Unreachable first. |
| 44 | Unreachable, |
| 45 | Alloca, |
| 46 | Arithmetic, |
| 47 | Assign, // not part of LLVM/PNaCl bitcode |
| 48 | Br, |
| 49 | Call, |
| 50 | Cast, |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 51 | ExtractElement, |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 52 | Fcmp, |
| 53 | Icmp, |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 54 | IntrinsicCall, |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 55 | InsertElement, |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 56 | Load, |
| 57 | Phi, |
| 58 | Ret, |
| 59 | Select, |
| 60 | Store, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 61 | Switch, |
| 62 | FakeDef, // not part of LLVM/PNaCl bitcode |
| 63 | FakeUse, // not part of LLVM/PNaCl bitcode |
| 64 | FakeKill, // not part of LLVM/PNaCl bitcode |
| 65 | Target // target-specific low-level ICE |
| 66 | // Anything >= Target is an InstTarget subclass. |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 67 | }; |
| 68 | InstKind getKind() const { return Kind; } |
| 69 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 70 | InstNumberT getNumber() const { return Number; } |
| 71 | void renumber(Cfg *Func); |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 72 | enum { |
| 73 | NumberDeleted = -1, |
| 74 | NumberSentinel = 0, |
| 75 | NumberInitial = 2, |
| 76 | NumberExtended = NumberInitial - 1 |
| 77 | }; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 78 | |
| 79 | bool isDeleted() const { return Deleted; } |
| 80 | void setDeleted() { Deleted = true; } |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 81 | void deleteIfDead(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 82 | |
| 83 | bool hasSideEffects() const { return HasSideEffects; } |
| 84 | |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 85 | bool isDestNonKillable() const { return IsDestNonKillable; } |
| 86 | void setDestNonKillable() { IsDestNonKillable = true; } |
| 87 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 88 | Variable *getDest() const { return Dest; } |
| 89 | |
| 90 | SizeT getSrcSize() const { return NumSrcs; } |
| 91 | Operand *getSrc(SizeT I) const { |
| 92 | assert(I < getSrcSize()); |
| 93 | return Srcs[I]; |
| 94 | } |
| 95 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 96 | bool isLastUse(const Operand *Src) const; |
| 97 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 98 | // Returns a list of out-edges corresponding to a terminator |
| 99 | // instruction, which is the last instruction of the block. |
| 100 | virtual NodeList getTerminatorEdges() const { |
| 101 | // All valid terminator instructions override this method. For |
| 102 | // the default implementation, we assert in case some CfgNode |
| 103 | // is constructed without a terminator instruction at the end. |
| 104 | llvm_unreachable( |
| 105 | "getTerminatorEdges() called on a non-terminator instruction"); |
| 106 | return NodeList(); |
| 107 | } |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 108 | virtual bool isUnconditionalBranch() const { return false; } |
| 109 | // If the instruction is a branch-type instruction with OldNode as a |
| 110 | // target, repoint it to NewNode and return true, otherwise return |
| 111 | // false. Only repoint one instance, even if the instruction has |
| 112 | // multiple instances of OldNode as a target. |
| 113 | virtual bool repointEdge(CfgNode *OldNode, CfgNode *NewNode) { |
| 114 | (void)OldNode; |
| 115 | (void)NewNode; |
| 116 | return false; |
| 117 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 118 | |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 119 | virtual bool isSimpleAssign() const { return false; } |
| 120 | |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 121 | void livenessLightweight(Cfg *Func, LivenessBV &Live); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 122 | // Calculates liveness for this instruction. Returns true if this |
| 123 | // instruction is (tentatively) still live and should be retained, |
| 124 | // and false if this instruction is (tentatively) dead and should be |
| 125 | // deleted. The decision is tentative until the liveness dataflow |
| 126 | // algorithm has converged, and then a separate pass permanently |
| 127 | // deletes dead instructions. |
| 128 | bool liveness(InstNumberT InstNumber, LivenessBV &Live, Liveness *Liveness, |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 129 | LiveBeginEndMap *LiveBegin, LiveBeginEndMap *LiveEnd); |
Jim Stichnoth | 1873560 | 2014-09-16 19:59:35 -0700 | [diff] [blame] | 130 | |
| 131 | // Get the number of native instructions that this instruction |
| 132 | // ultimately emits. By default, high-level instructions don't |
| 133 | // result in any native instructions, and a target-specific |
| 134 | // instruction results in a single native instruction. |
| 135 | virtual uint32_t getEmitInstCount() const { return 0; } |
Jim Stichnoth | dddaf9c | 2014-12-04 14:09:21 -0800 | [diff] [blame] | 136 | // TODO(stichnot): Change Inst back to abstract once the g++ build |
| 137 | // issue is fixed. llvm::ilist<Ice::Inst> doesn't work under g++ |
| 138 | // because the resize(size_t, Ice::Inst) method is incorrectly |
| 139 | // declared and thus doesn't allow the abstract class Ice::Inst. |
| 140 | // The method should be declared resize(size_t, const Ice::Inst &). |
| 141 | // virtual void emit(const Cfg *Func) const = 0; |
| 142 | // virtual void emitIAS(const Cfg *Func) const = 0; |
| 143 | virtual void emit(const Cfg *) const { |
| 144 | llvm_unreachable("emit on abstract class"); |
| 145 | } |
| 146 | virtual void emitIAS(const Cfg *Func) const { emit(Func); } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 147 | virtual void dump(const Cfg *Func) const; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 148 | virtual void dumpExtras(const Cfg *Func) const; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 149 | void dumpDecorated(const Cfg *Func) const; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 150 | void emitSources(const Cfg *Func) const; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 151 | void dumpSources(const Cfg *Func) const; |
| 152 | void dumpDest(const Cfg *Func) const; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 153 | virtual bool isRedundantAssign() const { return false; } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 154 | |
| 155 | virtual ~Inst() {} |
| 156 | |
| 157 | protected: |
| 158 | Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest); |
| 159 | void addSource(Operand *Src) { |
| 160 | assert(Src); |
| 161 | assert(NumSrcs < MaxSrcs); |
| 162 | Srcs[NumSrcs++] = Src; |
| 163 | } |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 164 | void setLastUse(SizeT VarIndex) { |
| 165 | if (VarIndex < CHAR_BIT * sizeof(LiveRangesEnded)) |
| 166 | LiveRangesEnded |= (((LREndedBits)1u) << VarIndex); |
| 167 | } |
| 168 | void resetLastUses() { LiveRangesEnded = 0; } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 169 | // The destroy() method lets the instruction cleanly release any |
| 170 | // memory that was allocated via the Cfg's allocator. |
| 171 | virtual void destroy(Cfg *Func) { Func->deallocateArrayOf<Operand *>(Srcs); } |
| 172 | |
| 173 | const InstKind Kind; |
| 174 | // Number is the instruction number for describing live ranges. |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 175 | InstNumberT Number; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 176 | // Deleted means irrevocably deleted. |
| 177 | bool Deleted; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 178 | // Dead means pending deletion after liveness analysis converges. |
| 179 | bool Dead; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 180 | // HasSideEffects means the instruction is something like a function |
| 181 | // call or a volatile load that can't be removed even if its Dest |
| 182 | // variable is not live. |
| 183 | bool HasSideEffects; |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 184 | // IsDestNonKillable means that liveness analysis shouldn't consider |
| 185 | // this instruction to kill the Dest variable. This is used when |
| 186 | // lowering produces two assignments to the same variable. |
| 187 | bool IsDestNonKillable; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 188 | |
| 189 | Variable *Dest; |
| 190 | const SizeT MaxSrcs; // only used for assert |
| 191 | SizeT NumSrcs; |
| 192 | Operand **Srcs; |
| 193 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 194 | // LiveRangesEnded marks which Variables' live ranges end in this |
| 195 | // instruction. An instruction can have an arbitrary number of |
| 196 | // source operands (e.g. a call instruction), and each source |
| 197 | // operand can contain 0 or 1 Variable (and target-specific operands |
| 198 | // could contain more than 1 Variable). All the variables in an |
| 199 | // instruction are conceptually flattened and each variable is |
| 200 | // mapped to one bit position of the LiveRangesEnded bit vector. |
| 201 | // Only the first CHAR_BIT * sizeof(LREndedBits) variables are |
| 202 | // tracked this way. |
| 203 | typedef uint32_t LREndedBits; // only first 32 src operands tracked, sorry |
| 204 | LREndedBits LiveRangesEnded; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 207 | class InstHighLevel : public Inst { |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 208 | InstHighLevel(const InstHighLevel &) = delete; |
| 209 | InstHighLevel &operator=(const InstHighLevel &) = delete; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 210 | |
| 211 | protected: |
| 212 | InstHighLevel(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) |
| 213 | : Inst(Func, Kind, MaxSrcs, Dest) {} |
| 214 | void emit(const Cfg * /*Func*/) const override { |
| 215 | llvm_unreachable("emit() called on a non-lowered instruction"); |
| 216 | } |
| 217 | void emitIAS(const Cfg * /*Func*/) const override { |
| 218 | llvm_unreachable("emitIAS() called on a non-lowered instruction"); |
| 219 | } |
| 220 | ~InstHighLevel() override {} |
| 221 | }; |
| 222 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 223 | // Alloca instruction. This captures the size in bytes as getSrc(0), |
| 224 | // and the required alignment in bytes. The alignment must be either |
| 225 | // 0 (no alignment required) or a power of 2. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 226 | class InstAlloca : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 227 | InstAlloca(const InstAlloca &) = delete; |
| 228 | InstAlloca &operator=(const InstAlloca &) = delete; |
| 229 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 230 | public: |
| 231 | static InstAlloca *create(Cfg *Func, Operand *ByteCount, |
| 232 | uint32_t AlignInBytes, Variable *Dest) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 233 | return new (Func->allocate<InstAlloca>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 234 | InstAlloca(Func, ByteCount, AlignInBytes, Dest); |
| 235 | } |
| 236 | uint32_t getAlignInBytes() const { return AlignInBytes; } |
| 237 | Operand *getSizeInBytes() const { return getSrc(0); } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 238 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 239 | static bool classof(const Inst *Inst) { return Inst->getKind() == Alloca; } |
| 240 | |
| 241 | private: |
| 242 | InstAlloca(Cfg *Func, Operand *ByteCount, uint32_t AlignInBytes, |
| 243 | Variable *Dest); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 244 | ~InstAlloca() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 245 | const uint32_t AlignInBytes; |
| 246 | }; |
| 247 | |
| 248 | // Binary arithmetic instruction. The source operands are captured in |
| 249 | // getSrc(0) and getSrc(1). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 250 | class InstArithmetic : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 251 | InstArithmetic(const InstArithmetic &) = delete; |
| 252 | InstArithmetic &operator=(const InstArithmetic &) = delete; |
| 253 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 254 | public: |
| 255 | enum OpKind { |
| 256 | #define X(tag, str, commutative) tag, |
| 257 | ICEINSTARITHMETIC_TABLE |
| 258 | #undef X |
Jim Stichnoth | 4376d29 | 2014-05-23 13:39:02 -0700 | [diff] [blame] | 259 | _num |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 260 | }; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 261 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 262 | static InstArithmetic *create(Cfg *Func, OpKind Op, Variable *Dest, |
| 263 | Operand *Source1, Operand *Source2) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 264 | return new (Func->allocate<InstArithmetic>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 265 | InstArithmetic(Func, Op, Dest, Source1, Source2); |
| 266 | } |
| 267 | OpKind getOp() const { return Op; } |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 268 | static const char *getOpName(OpKind Op); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 269 | bool isCommutative() const; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 270 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 271 | static bool classof(const Inst *Inst) { |
| 272 | return Inst->getKind() == Arithmetic; |
| 273 | } |
| 274 | |
| 275 | private: |
| 276 | InstArithmetic(Cfg *Func, OpKind Op, Variable *Dest, Operand *Source1, |
| 277 | Operand *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 278 | ~InstArithmetic() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 279 | |
| 280 | const OpKind Op; |
| 281 | }; |
| 282 | |
| 283 | // Assignment instruction. The source operand is captured in |
| 284 | // getSrc(0). This is not part of the LLVM bitcode, but is a useful |
| 285 | // abstraction for some of the lowering. E.g., if Phi instruction |
| 286 | // lowering happens before target lowering, or for representing an |
| 287 | // Inttoptr instruction, or as an intermediate step for lowering a |
| 288 | // Load instruction. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 289 | class InstAssign : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 290 | InstAssign(const InstAssign &) = delete; |
| 291 | InstAssign &operator=(const InstAssign &) = delete; |
| 292 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 293 | public: |
| 294 | static InstAssign *create(Cfg *Func, Variable *Dest, Operand *Source) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 295 | return new (Func->allocate<InstAssign>()) InstAssign(Func, Dest, Source); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 296 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 297 | bool isSimpleAssign() const override { return true; } |
| 298 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 299 | static bool classof(const Inst *Inst) { return Inst->getKind() == Assign; } |
| 300 | |
| 301 | private: |
| 302 | InstAssign(Cfg *Func, Variable *Dest, Operand *Source); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 303 | ~InstAssign() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | // Branch instruction. This represents both conditional and |
| 307 | // unconditional branches. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 308 | class InstBr : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 309 | InstBr(const InstBr &) = delete; |
| 310 | InstBr &operator=(const InstBr &) = delete; |
| 311 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 312 | public: |
| 313 | // Create a conditional branch. If TargetTrue==TargetFalse, it is |
| 314 | // optimized to an unconditional branch. |
| 315 | static InstBr *create(Cfg *Func, Operand *Source, CfgNode *TargetTrue, |
| 316 | CfgNode *TargetFalse) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 317 | return new (Func->allocate<InstBr>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 318 | InstBr(Func, Source, TargetTrue, TargetFalse); |
| 319 | } |
| 320 | // Create an unconditional branch. |
| 321 | static InstBr *create(Cfg *Func, CfgNode *Target) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 322 | return new (Func->allocate<InstBr>()) InstBr(Func, Target); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 323 | } |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 324 | bool isUnconditional() const { return getTargetTrue() == nullptr; } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 325 | Operand *getCondition() const { |
| 326 | assert(!isUnconditional()); |
| 327 | return getSrc(0); |
| 328 | } |
| 329 | CfgNode *getTargetTrue() const { return TargetTrue; } |
| 330 | CfgNode *getTargetFalse() const { return TargetFalse; } |
| 331 | CfgNode *getTargetUnconditional() const { |
| 332 | assert(isUnconditional()); |
| 333 | return getTargetFalse(); |
| 334 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 335 | NodeList getTerminatorEdges() const override; |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 336 | bool isUnconditionalBranch() const override { return isUnconditional(); } |
| 337 | bool repointEdge(CfgNode *OldNode, CfgNode *NewNode) override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 338 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 339 | static bool classof(const Inst *Inst) { return Inst->getKind() == Br; } |
| 340 | |
| 341 | private: |
| 342 | // Conditional branch |
| 343 | InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue, CfgNode *TargetFalse); |
| 344 | // Unconditional branch |
| 345 | InstBr(Cfg *Func, CfgNode *Target); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 346 | ~InstBr() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 347 | |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 348 | CfgNode *TargetFalse; // Doubles as unconditional branch target |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 349 | CfgNode *TargetTrue; // nullptr if unconditional branch |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | // Call instruction. The call target is captured as getSrc(0), and |
| 353 | // arg I is captured as getSrc(I+1). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 354 | class InstCall : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 355 | InstCall(const InstCall &) = delete; |
| 356 | InstCall &operator=(const InstCall &) = delete; |
| 357 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 358 | public: |
| 359 | static InstCall *create(Cfg *Func, SizeT NumArgs, Variable *Dest, |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 360 | Operand *CallTarget, bool HasTailCall) { |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 361 | // Set HasSideEffects to true so that the call instruction can't be |
| 362 | // dead-code eliminated. IntrinsicCalls can override this if the |
| 363 | // particular intrinsic is deletable and has no side-effects. |
| 364 | const bool HasSideEffects = true; |
| 365 | const InstKind Kind = Inst::Call; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 366 | return new (Func->allocate<InstCall>()) InstCall( |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 367 | Func, NumArgs, Dest, CallTarget, HasTailCall, HasSideEffects, Kind); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 368 | } |
| 369 | void addArg(Operand *Arg) { addSource(Arg); } |
| 370 | Operand *getCallTarget() const { return getSrc(0); } |
| 371 | Operand *getArg(SizeT I) const { return getSrc(I + 1); } |
| 372 | SizeT getNumArgs() const { return getSrcSize() - 1; } |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 373 | bool isTailcall() const { return HasTailCall; } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 374 | void dump(const Cfg *Func) const; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 375 | static bool classof(const Inst *Inst) { return Inst->getKind() == Call; } |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 376 | Type getReturnType() const; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 377 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 378 | protected: |
| 379 | InstCall(Cfg *Func, SizeT NumArgs, Variable *Dest, Operand *CallTarget, |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 380 | bool HasTailCall, bool HasSideEff, InstKind Kind) |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 381 | : InstHighLevel(Func, Kind, NumArgs + 1, Dest), HasTailCall(HasTailCall) { |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 382 | HasSideEffects = HasSideEff; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 383 | addSource(CallTarget); |
| 384 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 385 | ~InstCall() override {} |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 386 | |
| 387 | private: |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 388 | bool HasTailCall; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | // Cast instruction (a.k.a. conversion operation). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 392 | class InstCast : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 393 | InstCast(const InstCast &) = delete; |
| 394 | InstCast &operator=(const InstCast &) = delete; |
| 395 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 396 | public: |
| 397 | enum OpKind { |
| 398 | #define X(tag, str) tag, |
| 399 | ICEINSTCAST_TABLE |
| 400 | #undef X |
Jim Stichnoth | 4376d29 | 2014-05-23 13:39:02 -0700 | [diff] [blame] | 401 | _num |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 402 | }; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 403 | |
Karl Schimpf | bf17037 | 2014-12-15 10:16:31 -0800 | [diff] [blame] | 404 | static const char *getCastName(OpKind Kind); |
| 405 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 406 | static InstCast *create(Cfg *Func, OpKind CastKind, Variable *Dest, |
| 407 | Operand *Source) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 408 | return new (Func->allocate<InstCast>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 409 | InstCast(Func, CastKind, Dest, Source); |
| 410 | } |
| 411 | OpKind getCastKind() const { return CastKind; } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 412 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 413 | static bool classof(const Inst *Inst) { return Inst->getKind() == Cast; } |
| 414 | |
| 415 | private: |
| 416 | InstCast(Cfg *Func, OpKind CastKind, Variable *Dest, Operand *Source); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 417 | ~InstCast() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 418 | const OpKind CastKind; |
| 419 | }; |
| 420 | |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 421 | // ExtractElement instruction. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 422 | class InstExtractElement : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 423 | InstExtractElement(const InstExtractElement &) = delete; |
| 424 | InstExtractElement &operator=(const InstExtractElement &) = delete; |
| 425 | |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 426 | public: |
| 427 | static InstExtractElement *create(Cfg *Func, Variable *Dest, Operand *Source1, |
| 428 | Operand *Source2) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 429 | return new (Func->allocate<InstExtractElement>()) |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 430 | InstExtractElement(Func, Dest, Source1, Source2); |
| 431 | } |
| 432 | |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 433 | void dump(const Cfg *Func) const override; |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 434 | static bool classof(const Inst *Inst) { |
| 435 | return Inst->getKind() == ExtractElement; |
| 436 | } |
| 437 | |
| 438 | private: |
| 439 | InstExtractElement(Cfg *Func, Variable *Dest, Operand *Source1, |
| 440 | Operand *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 441 | ~InstExtractElement() override {} |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 442 | }; |
| 443 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 444 | // Floating-point comparison instruction. The source operands are |
| 445 | // captured in getSrc(0) and getSrc(1). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 446 | class InstFcmp : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 447 | InstFcmp(const InstFcmp &) = delete; |
| 448 | InstFcmp &operator=(const InstFcmp &) = delete; |
| 449 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 450 | public: |
| 451 | enum FCond { |
| 452 | #define X(tag, str) tag, |
| 453 | ICEINSTFCMP_TABLE |
| 454 | #undef X |
Jim Stichnoth | 4376d29 | 2014-05-23 13:39:02 -0700 | [diff] [blame] | 455 | _num |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 456 | }; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 457 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 458 | static InstFcmp *create(Cfg *Func, FCond Condition, Variable *Dest, |
| 459 | Operand *Source1, Operand *Source2) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 460 | return new (Func->allocate<InstFcmp>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 461 | InstFcmp(Func, Condition, Dest, Source1, Source2); |
| 462 | } |
| 463 | FCond getCondition() const { return Condition; } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 464 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 465 | static bool classof(const Inst *Inst) { return Inst->getKind() == Fcmp; } |
| 466 | |
| 467 | private: |
| 468 | InstFcmp(Cfg *Func, FCond Condition, Variable *Dest, Operand *Source1, |
| 469 | Operand *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 470 | ~InstFcmp() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 471 | const FCond Condition; |
| 472 | }; |
| 473 | |
| 474 | // Integer comparison instruction. The source operands are captured |
| 475 | // in getSrc(0) and getSrc(1). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 476 | class InstIcmp : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 477 | InstIcmp(const InstIcmp &) = delete; |
| 478 | InstIcmp &operator=(const InstIcmp &) = delete; |
| 479 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 480 | public: |
| 481 | enum ICond { |
| 482 | #define X(tag, str) tag, |
| 483 | ICEINSTICMP_TABLE |
| 484 | #undef X |
Jim Stichnoth | 4376d29 | 2014-05-23 13:39:02 -0700 | [diff] [blame] | 485 | _num |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 486 | }; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 487 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 488 | static InstIcmp *create(Cfg *Func, ICond Condition, Variable *Dest, |
| 489 | Operand *Source1, Operand *Source2) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 490 | return new (Func->allocate<InstIcmp>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 491 | InstIcmp(Func, Condition, Dest, Source1, Source2); |
| 492 | } |
| 493 | ICond getCondition() const { return Condition; } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 494 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 495 | static bool classof(const Inst *Inst) { return Inst->getKind() == Icmp; } |
| 496 | |
| 497 | private: |
| 498 | InstIcmp(Cfg *Func, ICond Condition, Variable *Dest, Operand *Source1, |
| 499 | Operand *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 500 | ~InstIcmp() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 501 | const ICond Condition; |
| 502 | }; |
| 503 | |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 504 | // InsertElement instruction. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 505 | class InstInsertElement : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 506 | InstInsertElement(const InstInsertElement &) = delete; |
| 507 | InstInsertElement &operator=(const InstInsertElement &) = delete; |
| 508 | |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 509 | public: |
| 510 | static InstInsertElement *create(Cfg *Func, Variable *Dest, Operand *Source1, |
| 511 | Operand *Source2, Operand *Source3) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 512 | return new (Func->allocate<InstInsertElement>()) |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 513 | InstInsertElement(Func, Dest, Source1, Source2, Source3); |
| 514 | } |
| 515 | |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 516 | void dump(const Cfg *Func) const override; |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 517 | static bool classof(const Inst *Inst) { |
| 518 | return Inst->getKind() == InsertElement; |
| 519 | } |
| 520 | |
| 521 | private: |
| 522 | InstInsertElement(Cfg *Func, Variable *Dest, Operand *Source1, |
| 523 | Operand *Source2, Operand *Source3); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 524 | ~InstInsertElement() override {} |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 525 | }; |
| 526 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 527 | // Call to an intrinsic function. The call target is captured as getSrc(0), |
| 528 | // and arg I is captured as getSrc(I+1). |
| 529 | class InstIntrinsicCall : public InstCall { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 530 | InstIntrinsicCall(const InstIntrinsicCall &) = delete; |
| 531 | InstIntrinsicCall &operator=(const InstIntrinsicCall &) = delete; |
| 532 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 533 | public: |
| 534 | static InstIntrinsicCall *create(Cfg *Func, SizeT NumArgs, Variable *Dest, |
| 535 | Operand *CallTarget, |
| 536 | const Intrinsics::IntrinsicInfo &Info) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 537 | return new (Func->allocate<InstIntrinsicCall>()) |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 538 | InstIntrinsicCall(Func, NumArgs, Dest, CallTarget, Info); |
| 539 | } |
| 540 | static bool classof(const Inst *Inst) { |
| 541 | return Inst->getKind() == IntrinsicCall; |
| 542 | } |
| 543 | |
| 544 | Intrinsics::IntrinsicInfo getIntrinsicInfo() const { return Info; } |
| 545 | |
| 546 | private: |
| 547 | InstIntrinsicCall(Cfg *Func, SizeT NumArgs, Variable *Dest, |
| 548 | Operand *CallTarget, const Intrinsics::IntrinsicInfo &Info) |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 549 | : InstCall(Func, NumArgs, Dest, CallTarget, false, Info.HasSideEffects, |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 550 | Inst::IntrinsicCall), |
| 551 | Info(Info) {} |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 552 | ~InstIntrinsicCall() override {} |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 553 | const Intrinsics::IntrinsicInfo Info; |
| 554 | }; |
| 555 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 556 | // Load instruction. The source address is captured in getSrc(0). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 557 | class InstLoad : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 558 | InstLoad(const InstLoad &) = delete; |
| 559 | InstLoad &operator=(const InstLoad &) = delete; |
| 560 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 561 | public: |
Karl Schimpf | 41689df | 2014-09-10 14:36:07 -0700 | [diff] [blame] | 562 | static InstLoad *create(Cfg *Func, Variable *Dest, Operand *SourceAddr, |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 563 | uint32_t Align = 1) { |
Karl Schimpf | 41689df | 2014-09-10 14:36:07 -0700 | [diff] [blame] | 564 | // TODO(kschimpf) Stop ignoring alignment specification. |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 565 | (void)Align; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 566 | return new (Func->allocate<InstLoad>()) InstLoad(Func, Dest, SourceAddr); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 567 | } |
| 568 | Operand *getSourceAddress() const { return getSrc(0); } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 569 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 570 | static bool classof(const Inst *Inst) { return Inst->getKind() == Load; } |
| 571 | |
| 572 | private: |
| 573 | InstLoad(Cfg *Func, Variable *Dest, Operand *SourceAddr); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 574 | ~InstLoad() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 575 | }; |
| 576 | |
| 577 | // Phi instruction. For incoming edge I, the node is Labels[I] and |
| 578 | // the Phi source operand is getSrc(I). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 579 | class InstPhi : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 580 | InstPhi(const InstPhi &) = delete; |
| 581 | InstPhi &operator=(const InstPhi &) = delete; |
| 582 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 583 | public: |
| 584 | static InstPhi *create(Cfg *Func, SizeT MaxSrcs, Variable *Dest) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 585 | return new (Func->allocate<InstPhi>()) InstPhi(Func, MaxSrcs, Dest); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 586 | } |
| 587 | void addArgument(Operand *Source, CfgNode *Label); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 588 | Operand *getOperandForTarget(CfgNode *Target) const; |
Jim Stichnoth | 98712a3 | 2014-10-24 10:59:02 -0700 | [diff] [blame] | 589 | CfgNode *getLabel(SizeT Index) const { return Labels[Index]; } |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 590 | void livenessPhiOperand(LivenessBV &Live, CfgNode *Target, |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 591 | Liveness *Liveness); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 592 | Inst *lower(Cfg *Func); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 593 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 594 | static bool classof(const Inst *Inst) { return Inst->getKind() == Phi; } |
| 595 | |
| 596 | private: |
| 597 | InstPhi(Cfg *Func, SizeT MaxSrcs, Variable *Dest); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 598 | void destroy(Cfg *Func) override { |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 599 | Func->deallocateArrayOf<CfgNode *>(Labels); |
| 600 | Inst::destroy(Func); |
| 601 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 602 | ~InstPhi() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 603 | |
| 604 | // Labels[] duplicates the InEdges[] information in the enclosing |
| 605 | // CfgNode, but the Phi instruction is created before InEdges[] |
| 606 | // is available, so it's more complicated to share the list. |
| 607 | CfgNode **Labels; |
| 608 | }; |
| 609 | |
| 610 | // Ret instruction. The return value is captured in getSrc(0), but if |
| 611 | // there is no return value (void-type function), then |
| 612 | // getSrcSize()==0 and hasRetValue()==false. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 613 | class InstRet : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 614 | InstRet(const InstRet &) = delete; |
| 615 | InstRet &operator=(const InstRet &) = delete; |
| 616 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 617 | public: |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 618 | static InstRet *create(Cfg *Func, Operand *RetValue = nullptr) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 619 | return new (Func->allocate<InstRet>()) InstRet(Func, RetValue); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 620 | } |
| 621 | bool hasRetValue() const { return getSrcSize(); } |
| 622 | Operand *getRetValue() const { |
| 623 | assert(hasRetValue()); |
| 624 | return getSrc(0); |
| 625 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 626 | NodeList getTerminatorEdges() const override { return NodeList(); } |
| 627 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 628 | static bool classof(const Inst *Inst) { return Inst->getKind() == Ret; } |
| 629 | |
| 630 | private: |
| 631 | InstRet(Cfg *Func, Operand *RetValue); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 632 | ~InstRet() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 633 | }; |
| 634 | |
| 635 | // Select instruction. The condition, true, and false operands are captured. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 636 | class InstSelect : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 637 | InstSelect(const InstSelect &) = delete; |
| 638 | InstSelect &operator=(const InstSelect &) = delete; |
| 639 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 640 | public: |
| 641 | static InstSelect *create(Cfg *Func, Variable *Dest, Operand *Condition, |
| 642 | Operand *SourceTrue, Operand *SourceFalse) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 643 | return new (Func->allocate<InstSelect>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 644 | InstSelect(Func, Dest, Condition, SourceTrue, SourceFalse); |
| 645 | } |
| 646 | Operand *getCondition() const { return getSrc(0); } |
| 647 | Operand *getTrueOperand() const { return getSrc(1); } |
| 648 | Operand *getFalseOperand() const { return getSrc(2); } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 649 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 650 | static bool classof(const Inst *Inst) { return Inst->getKind() == Select; } |
| 651 | |
| 652 | private: |
| 653 | InstSelect(Cfg *Func, Variable *Dest, Operand *Condition, Operand *Source1, |
| 654 | Operand *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 655 | ~InstSelect() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 656 | }; |
| 657 | |
| 658 | // Store instruction. The address operand is captured, along with the |
| 659 | // data operand to be stored into the address. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 660 | class InstStore : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 661 | InstStore(const InstStore &) = delete; |
| 662 | InstStore &operator=(const InstStore &) = delete; |
| 663 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 664 | public: |
Karl Schimpf | 41689df | 2014-09-10 14:36:07 -0700 | [diff] [blame] | 665 | static InstStore *create(Cfg *Func, Operand *Data, Operand *Addr, |
| 666 | uint32_t align = 1) { |
| 667 | // TODO(kschimpf) Stop ignoring alignment specification. |
| 668 | (void)align; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 669 | return new (Func->allocate<InstStore>()) InstStore(Func, Data, Addr); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 670 | } |
| 671 | Operand *getAddr() const { return getSrc(1); } |
| 672 | Operand *getData() const { return getSrc(0); } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 673 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 674 | static bool classof(const Inst *Inst) { return Inst->getKind() == Store; } |
| 675 | |
| 676 | private: |
| 677 | InstStore(Cfg *Func, Operand *Data, Operand *Addr); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 678 | ~InstStore() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | // Switch instruction. The single source operand is captured as |
| 682 | // getSrc(0). |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 683 | class InstSwitch : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 684 | InstSwitch(const InstSwitch &) = delete; |
| 685 | InstSwitch &operator=(const InstSwitch &) = delete; |
| 686 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 687 | public: |
| 688 | static InstSwitch *create(Cfg *Func, SizeT NumCases, Operand *Source, |
| 689 | CfgNode *LabelDefault) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 690 | return new (Func->allocate<InstSwitch>()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 691 | InstSwitch(Func, NumCases, Source, LabelDefault); |
| 692 | } |
| 693 | Operand *getComparison() const { return getSrc(0); } |
| 694 | CfgNode *getLabelDefault() const { return LabelDefault; } |
| 695 | SizeT getNumCases() const { return NumCases; } |
| 696 | uint64_t getValue(SizeT I) const { |
| 697 | assert(I < NumCases); |
| 698 | return Values[I]; |
| 699 | } |
| 700 | CfgNode *getLabel(SizeT I) const { |
| 701 | assert(I < NumCases); |
| 702 | return Labels[I]; |
| 703 | } |
| 704 | void addBranch(SizeT CaseIndex, uint64_t Value, CfgNode *Label); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 705 | NodeList getTerminatorEdges() const override; |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 706 | bool repointEdge(CfgNode *OldNode, CfgNode *NewNode) override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 707 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 708 | static bool classof(const Inst *Inst) { return Inst->getKind() == Switch; } |
| 709 | |
| 710 | private: |
| 711 | InstSwitch(Cfg *Func, SizeT NumCases, Operand *Source, CfgNode *LabelDefault); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 712 | void destroy(Cfg *Func) override { |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 713 | Func->deallocateArrayOf<uint64_t>(Values); |
| 714 | Func->deallocateArrayOf<CfgNode *>(Labels); |
| 715 | Inst::destroy(Func); |
| 716 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 717 | ~InstSwitch() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 718 | |
| 719 | CfgNode *LabelDefault; |
| 720 | SizeT NumCases; // not including the default case |
| 721 | uint64_t *Values; // size is NumCases |
| 722 | CfgNode **Labels; // size is NumCases |
| 723 | }; |
| 724 | |
| 725 | // Unreachable instruction. This is a terminator instruction with no |
| 726 | // operands. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 727 | class InstUnreachable : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 728 | InstUnreachable(const InstUnreachable &) = delete; |
| 729 | InstUnreachable &operator=(const InstUnreachable &) = delete; |
| 730 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 731 | public: |
| 732 | static InstUnreachable *create(Cfg *Func) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 733 | return new (Func->allocate<InstUnreachable>()) InstUnreachable(Func); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 734 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 735 | NodeList getTerminatorEdges() const override { return NodeList(); } |
| 736 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 737 | static bool classof(const Inst *Inst) { |
| 738 | return Inst->getKind() == Unreachable; |
| 739 | } |
| 740 | |
| 741 | private: |
| 742 | InstUnreachable(Cfg *Func); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 743 | ~InstUnreachable() override {} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 744 | }; |
| 745 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 746 | // FakeDef instruction. This creates a fake definition of a variable, |
| 747 | // which is how we represent the case when an instruction produces |
| 748 | // multiple results. This doesn't happen with high-level ICE |
| 749 | // instructions, but might with lowered instructions. For example, |
| 750 | // this would be a way to represent condition flags being modified by |
| 751 | // an instruction. |
| 752 | // |
| 753 | // It's generally useful to set the optional source operand to be the |
| 754 | // dest variable of the instruction that actually produces the FakeDef |
| 755 | // dest. Otherwise, the original instruction could be dead-code |
| 756 | // eliminated if its dest operand is unused, and therefore the FakeDef |
| 757 | // dest wouldn't be properly initialized. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 758 | class InstFakeDef : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 759 | InstFakeDef(const InstFakeDef &) = delete; |
| 760 | InstFakeDef &operator=(const InstFakeDef &) = delete; |
| 761 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 762 | public: |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 763 | static InstFakeDef *create(Cfg *Func, Variable *Dest, |
| 764 | Variable *Src = nullptr) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 765 | return new (Func->allocate<InstFakeDef>()) InstFakeDef(Func, Dest, Src); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 766 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 767 | void emit(const Cfg *Func) const override; |
Jan Voung | 198b294 | 2014-10-16 09:40:02 -0700 | [diff] [blame] | 768 | void emitIAS(const Cfg * /* Func */) const override {} |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 769 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 770 | static bool classof(const Inst *Inst) { return Inst->getKind() == FakeDef; } |
| 771 | |
| 772 | private: |
| 773 | InstFakeDef(Cfg *Func, Variable *Dest, Variable *Src); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 774 | ~InstFakeDef() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 775 | }; |
| 776 | |
| 777 | // FakeUse instruction. This creates a fake use of a variable, to |
| 778 | // keep the instruction that produces that variable from being |
| 779 | // dead-code eliminated. This is useful in a variety of lowering |
| 780 | // situations. The FakeUse instruction has no dest, so it can itself |
| 781 | // never be dead-code eliminated. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 782 | class InstFakeUse : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 783 | InstFakeUse(const InstFakeUse &) = delete; |
| 784 | InstFakeUse &operator=(const InstFakeUse &) = delete; |
| 785 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 786 | public: |
| 787 | static InstFakeUse *create(Cfg *Func, Variable *Src) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 788 | return new (Func->allocate<InstFakeUse>()) InstFakeUse(Func, Src); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 789 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 790 | void emit(const Cfg *Func) const override; |
Jan Voung | 198b294 | 2014-10-16 09:40:02 -0700 | [diff] [blame] | 791 | void emitIAS(const Cfg * /* Func */) const override {} |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 792 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 793 | static bool classof(const Inst *Inst) { return Inst->getKind() == FakeUse; } |
| 794 | |
| 795 | private: |
| 796 | InstFakeUse(Cfg *Func, Variable *Src); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 797 | ~InstFakeUse() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 798 | }; |
| 799 | |
Jim Stichnoth | 87ff3a1 | 2014-11-14 10:27:29 -0800 | [diff] [blame] | 800 | // FakeKill instruction. This "kills" a set of variables by modeling |
| 801 | // a trivial live range at this instruction for each (implicit) |
| 802 | // variable. The primary use is to indicate that scratch registers |
| 803 | // are killed after a call, so that the register allocator won't |
| 804 | // assign a scratch register to a variable whose live range spans a |
| 805 | // call. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 806 | // |
| 807 | // The FakeKill instruction also holds a pointer to the instruction |
| 808 | // that kills the set of variables, so that if that linked instruction |
| 809 | // gets dead-code eliminated, the FakeKill instruction will as well. |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 810 | class InstFakeKill : public InstHighLevel { |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 811 | InstFakeKill(const InstFakeKill &) = delete; |
| 812 | InstFakeKill &operator=(const InstFakeKill &) = delete; |
| 813 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 814 | public: |
Jim Stichnoth | 87ff3a1 | 2014-11-14 10:27:29 -0800 | [diff] [blame] | 815 | static InstFakeKill *create(Cfg *Func, const Inst *Linked) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 816 | return new (Func->allocate<InstFakeKill>()) InstFakeKill(Func, Linked); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 817 | } |
| 818 | const Inst *getLinked() const { return Linked; } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 819 | void emit(const Cfg *Func) const override; |
Jan Voung | 198b294 | 2014-10-16 09:40:02 -0700 | [diff] [blame] | 820 | void emitIAS(const Cfg * /* Func */) const override {} |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 821 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 822 | static bool classof(const Inst *Inst) { return Inst->getKind() == FakeKill; } |
| 823 | |
| 824 | private: |
Jim Stichnoth | 87ff3a1 | 2014-11-14 10:27:29 -0800 | [diff] [blame] | 825 | InstFakeKill(Cfg *Func, const Inst *Linked); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 826 | ~InstFakeKill() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 827 | |
| 828 | // This instruction is ignored if Linked->isDeleted() is true. |
| 829 | const Inst *Linked; |
| 830 | }; |
| 831 | |
| 832 | // The Target instruction is the base class for all target-specific |
| 833 | // instructions. |
| 834 | class InstTarget : public Inst { |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 835 | InstTarget(const InstTarget &) = delete; |
| 836 | InstTarget &operator=(const InstTarget &) = delete; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 837 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 838 | public: |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 839 | uint32_t getEmitInstCount() const override { return 1; } |
| 840 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 841 | static bool classof(const Inst *Inst) { return Inst->getKind() >= Target; } |
| 842 | |
| 843 | protected: |
| 844 | InstTarget(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) |
| 845 | : Inst(Func, Kind, MaxSrcs, Dest) { |
| 846 | assert(Kind >= Target); |
| 847 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 848 | ~InstTarget() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 849 | }; |
| 850 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 851 | } // end of namespace Ice |
| 852 | |
Jim Stichnoth | dddaf9c | 2014-12-04 14:09:21 -0800 | [diff] [blame] | 853 | namespace llvm { |
| 854 | |
Jim Stichnoth | 607e9f0 | 2014-11-06 13:32:05 -0800 | [diff] [blame] | 855 | // Override the default ilist traits so that Inst's private ctor and |
| 856 | // deleted dtor aren't invoked. |
| 857 | template <> |
Jim Stichnoth | dddaf9c | 2014-12-04 14:09:21 -0800 | [diff] [blame] | 858 | struct ilist_traits<Ice::Inst> : public ilist_default_traits<Ice::Inst> { |
Jim Stichnoth | 607e9f0 | 2014-11-06 13:32:05 -0800 | [diff] [blame] | 859 | Ice::Inst *createSentinel() const { |
| 860 | return static_cast<Ice::Inst *>(&Sentinel); |
| 861 | } |
| 862 | static void destroySentinel(Ice::Inst *) {} |
| 863 | Ice::Inst *provideInitialHead() const { return createSentinel(); } |
| 864 | Ice::Inst *ensureHead(Ice::Inst *) const { return createSentinel(); } |
| 865 | static void noteHead(Ice::Inst *, Ice::Inst *) {} |
| 866 | void deleteNode(Ice::Inst *) {} |
| 867 | |
| 868 | private: |
| 869 | mutable ilist_half_node<Ice::Inst> Sentinel; |
| 870 | }; |
| 871 | |
Jim Stichnoth | dddaf9c | 2014-12-04 14:09:21 -0800 | [diff] [blame] | 872 | } // end of namespace llvm |
| 873 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 874 | #endif // SUBZERO_SRC_ICEINST_H |