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