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