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