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