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