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