Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceInst.h - High-level instructions ----------*- C++ -*-===// | 1 //===- subzero/src/IceInst.h - High-level instructions ----------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file declares the Inst class and its target-independent | 10 // This file declares the Inst class and its target-independent |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 Switch, | 50 Switch, |
| 51 FakeDef, // not part of LLVM/PNaCl bitcode | 51 FakeDef, // not part of LLVM/PNaCl bitcode |
| 52 FakeUse, // not part of LLVM/PNaCl bitcode | 52 FakeUse, // not part of LLVM/PNaCl bitcode |
| 53 FakeKill, // not part of LLVM/PNaCl bitcode | 53 FakeKill, // not part of LLVM/PNaCl bitcode |
| 54 Target // target-specific low-level ICE | 54 Target // target-specific low-level ICE |
| 55 // Anything >= Target is an InstTarget subclass. | 55 // Anything >= Target is an InstTarget subclass. |
| 56 }; | 56 }; |
| 57 InstKind getKind() const { return Kind; } | 57 InstKind getKind() const { return Kind; } |
| 58 | 58 |
| 59 int32_t getNumber() const { return Number; } | 59 int32_t getNumber() const { return Number; } |
| 60 void renumber(Cfg *Func); | |
| 60 | 61 |
| 61 bool isDeleted() const { return Deleted; } | 62 bool isDeleted() const { return Deleted; } |
| 62 void setDeleted() { Deleted = true; } | 63 void setDeleted() { Deleted = true; } |
| 64 void deleteIfDead(); | |
| 63 | 65 |
| 64 bool hasSideEffects() const { return HasSideEffects; } | 66 bool hasSideEffects() const { return HasSideEffects; } |
| 65 | 67 |
| 66 Variable *getDest() const { return Dest; } | 68 Variable *getDest() const { return Dest; } |
| 67 | 69 |
| 68 SizeT getSrcSize() const { return NumSrcs; } | 70 SizeT getSrcSize() const { return NumSrcs; } |
| 69 Operand *getSrc(SizeT I) const { | 71 Operand *getSrc(SizeT I) const { |
| 70 assert(I < getSrcSize()); | 72 assert(I < getSrcSize()); |
| 71 return Srcs[I]; | 73 return Srcs[I]; |
| 72 } | 74 } |
| 73 | 75 |
| 76 bool isLastUse(const Operand *Src) const; | |
| 77 | |
| 74 // Returns a list of out-edges corresponding to a terminator | 78 // Returns a list of out-edges corresponding to a terminator |
| 75 // instruction, which is the last instruction of the block. | 79 // instruction, which is the last instruction of the block. |
| 76 virtual NodeList getTerminatorEdges() const { | 80 virtual NodeList getTerminatorEdges() const { |
| 77 // All valid terminator instructions override this method. For | 81 // All valid terminator instructions override this method. For |
| 78 // the default implementation, we assert in case some CfgNode | 82 // the default implementation, we assert in case some CfgNode |
| 79 // is constructed without a terminator instruction at the end. | 83 // is constructed without a terminator instruction at the end. |
| 80 llvm_unreachable( | 84 llvm_unreachable( |
| 81 "getTerminatorEdges() called on a non-terminator instruction"); | 85 "getTerminatorEdges() called on a non-terminator instruction"); |
| 82 return NodeList(); | 86 return NodeList(); |
| 83 } | 87 } |
| 84 | 88 |
| 85 // Updates the status of the Variables contained within the | 89 // Updates the status of the Variables contained within the |
| 86 // instruction. In particular, it marks where the Dest variable is | 90 // instruction. In particular, it marks where the Dest variable is |
| 87 // first assigned, and it tracks whether variables are live across | 91 // first assigned, and it tracks whether variables are live across |
| 88 // basic blocks, i.e. used in a different block from their definition. | 92 // basic blocks, i.e. used in a different block from their definition. |
| 89 void updateVars(CfgNode *Node); | 93 void updateVars(CfgNode *Node); |
| 90 | 94 |
| 95 void livenessLightweight(llvm::BitVector &Live); | |
| 96 void liveness(int32_t InstNumber, llvm::BitVector &Live, Liveness *Liveness, | |
| 97 const CfgNode *Node); | |
| 91 virtual void emit(const Cfg *Func) const; | 98 virtual void emit(const Cfg *Func) const; |
| 92 virtual void dump(const Cfg *Func) const; | 99 virtual void dump(const Cfg *Func) const; |
| 100 virtual void dumpExtras(const Cfg *Func) const; | |
| 93 void dumpDecorated(const Cfg *Func) const; | 101 void dumpDecorated(const Cfg *Func) const; |
| 94 void emitSources(const Cfg *Func) const; | 102 void emitSources(const Cfg *Func) const; |
| 95 void dumpSources(const Cfg *Func) const; | 103 void dumpSources(const Cfg *Func) const; |
| 96 void dumpDest(const Cfg *Func) const; | 104 void dumpDest(const Cfg *Func) const; |
| 97 virtual bool isRedundantAssign() const { return false; } | 105 virtual bool isRedundantAssign() const { return false; } |
| 98 | 106 |
| 99 virtual ~Inst() {} | 107 virtual ~Inst() {} |
| 100 | 108 |
| 101 protected: | 109 protected: |
| 102 Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest); | 110 Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest); |
| 103 void addSource(Operand *Src) { | 111 void addSource(Operand *Src) { |
| 104 assert(Src); | 112 assert(Src); |
| 105 assert(NumSrcs < MaxSrcs); | 113 assert(NumSrcs < MaxSrcs); |
| 106 Srcs[NumSrcs++] = Src; | 114 Srcs[NumSrcs++] = Src; |
| 107 } | 115 } |
| 116 void setLastUse(SizeT VarIndex) { | |
| 117 if (VarIndex < CHAR_BIT * sizeof(LiveRangesEnded)) | |
| 118 LiveRangesEnded |= (((LREndedBits)1u) << VarIndex); | |
| 119 } | |
| 120 void resetLastUses() { LiveRangesEnded = 0; } | |
| 108 // The destroy() method lets the instruction cleanly release any | 121 // The destroy() method lets the instruction cleanly release any |
| 109 // memory that was allocated via the Cfg's allocator. | 122 // memory that was allocated via the Cfg's allocator. |
| 110 virtual void destroy(Cfg *Func) { Func->deallocateArrayOf<Operand *>(Srcs); } | 123 virtual void destroy(Cfg *Func) { Func->deallocateArrayOf<Operand *>(Srcs); } |
| 111 | 124 |
| 112 const InstKind Kind; | 125 const InstKind Kind; |
| 113 // Number is the instruction number for describing live ranges. | 126 // Number is the instruction number for describing live ranges. |
|
jvoung (off chromium)
2014/05/30 15:41:31
Could be worth documenting somewhere numbers that
Jim Stichnoth
2014/05/30 23:06:18
Done -- Inst::NumberDeleted=-1 and Inst::NumberSen
| |
| 114 int32_t Number; | 127 int32_t Number; |
| 115 // Deleted means irrevocably deleted. | 128 // Deleted means irrevocably deleted. |
| 116 bool Deleted; | 129 bool Deleted; |
| 130 // Dead means pending deletion after liveness analysis converges. | |
| 131 bool Dead; | |
| 117 // HasSideEffects means the instruction is something like a function | 132 // HasSideEffects means the instruction is something like a function |
| 118 // call or a volatile load that can't be removed even if its Dest | 133 // call or a volatile load that can't be removed even if its Dest |
| 119 // variable is not live. | 134 // variable is not live. |
| 120 bool HasSideEffects; | 135 bool HasSideEffects; |
| 121 | 136 |
| 122 Variable *Dest; | 137 Variable *Dest; |
| 123 const SizeT MaxSrcs; // only used for assert | 138 const SizeT MaxSrcs; // only used for assert |
| 124 SizeT NumSrcs; | 139 SizeT NumSrcs; |
| 125 Operand **Srcs; | 140 Operand **Srcs; |
| 126 | 141 |
| 142 // LiveRangesEnded marks which Variables' live ranges end in this | |
| 143 // instruction. An instruction can have an arbitrary number of | |
| 144 // source operands (e.g. a call instruction), and each source | |
| 145 // operand can contain 0 or 1 Variable (and target-specific operands | |
| 146 // could contain more than 1 Variable). All the variables in an | |
| 147 // instruction are conceptually flattened and each variable is | |
| 148 // mapped to one bit position of the LiveRangesEnded bit vector. | |
| 149 // Only the first CHAR_BIT * sizeof(LREndedBits) variables are | |
| 150 // tracked this way. | |
| 151 typedef uint32_t LREndedBits; // only first 32 src operands tracked, sorry | |
| 152 LREndedBits LiveRangesEnded; | |
| 153 | |
| 127 private: | 154 private: |
| 128 Inst(const Inst &) LLVM_DELETED_FUNCTION; | 155 Inst(const Inst &) LLVM_DELETED_FUNCTION; |
| 129 Inst &operator=(const Inst &) LLVM_DELETED_FUNCTION; | 156 Inst &operator=(const Inst &) LLVM_DELETED_FUNCTION; |
| 130 }; | 157 }; |
| 131 | 158 |
| 132 // Alloca instruction. This captures the size in bytes as getSrc(0), | 159 // Alloca instruction. This captures the size in bytes as getSrc(0), |
| 133 // and the required alignment in bytes. The alignment must be either | 160 // and the required alignment in bytes. The alignment must be either |
| 134 // 0 (no alignment required) or a power of 2. | 161 // 0 (no alignment required) or a power of 2. |
| 135 class InstAlloca : public Inst { | 162 class InstAlloca : public Inst { |
| 136 public: | 163 public: |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 | 413 |
| 387 // Phi instruction. For incoming edge I, the node is Labels[I] and | 414 // Phi instruction. For incoming edge I, the node is Labels[I] and |
| 388 // the Phi source operand is getSrc(I). | 415 // the Phi source operand is getSrc(I). |
| 389 class InstPhi : public Inst { | 416 class InstPhi : public Inst { |
| 390 public: | 417 public: |
| 391 static InstPhi *create(Cfg *Func, SizeT MaxSrcs, Variable *Dest) { | 418 static InstPhi *create(Cfg *Func, SizeT MaxSrcs, Variable *Dest) { |
| 392 return new (Func->allocateInst<InstPhi>()) InstPhi(Func, MaxSrcs, Dest); | 419 return new (Func->allocateInst<InstPhi>()) InstPhi(Func, MaxSrcs, Dest); |
| 393 } | 420 } |
| 394 void addArgument(Operand *Source, CfgNode *Label); | 421 void addArgument(Operand *Source, CfgNode *Label); |
| 395 Operand *getOperandForTarget(CfgNode *Target) const; | 422 Operand *getOperandForTarget(CfgNode *Target) const; |
| 423 void livenessPhiOperand(llvm::BitVector &Live, CfgNode *Target, | |
| 424 Liveness *Liveness); | |
| 396 Inst *lower(Cfg *Func, CfgNode *Node); | 425 Inst *lower(Cfg *Func, CfgNode *Node); |
| 397 virtual void dump(const Cfg *Func) const; | 426 virtual void dump(const Cfg *Func) const; |
| 398 static bool classof(const Inst *Inst) { return Inst->getKind() == Phi; } | 427 static bool classof(const Inst *Inst) { return Inst->getKind() == Phi; } |
| 399 | 428 |
| 400 private: | 429 private: |
| 401 InstPhi(Cfg *Func, SizeT MaxSrcs, Variable *Dest); | 430 InstPhi(Cfg *Func, SizeT MaxSrcs, Variable *Dest); |
| 402 InstPhi(const InstPhi &) LLVM_DELETED_FUNCTION; | 431 InstPhi(const InstPhi &) LLVM_DELETED_FUNCTION; |
| 403 InstPhi &operator=(const InstPhi &) LLVM_DELETED_FUNCTION; | 432 InstPhi &operator=(const InstPhi &) LLVM_DELETED_FUNCTION; |
| 404 virtual void destroy(Cfg *Func) { | 433 virtual void destroy(Cfg *Func) { |
| 405 Func->deallocateArrayOf<CfgNode *>(Labels); | 434 Func->deallocateArrayOf<CfgNode *>(Labels); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 // This instruction is ignored if Linked->isDeleted() is true. | 648 // This instruction is ignored if Linked->isDeleted() is true. |
| 620 const Inst *Linked; | 649 const Inst *Linked; |
| 621 }; | 650 }; |
| 622 | 651 |
| 623 // The Target instruction is the base class for all target-specific | 652 // The Target instruction is the base class for all target-specific |
| 624 // instructions. | 653 // instructions. |
| 625 class InstTarget : public Inst { | 654 class InstTarget : public Inst { |
| 626 public: | 655 public: |
| 627 virtual void emit(const Cfg *Func) const = 0; | 656 virtual void emit(const Cfg *Func) const = 0; |
| 628 virtual void dump(const Cfg *Func) const; | 657 virtual void dump(const Cfg *Func) const; |
| 658 virtual void dumpExtras(const Cfg *Func) const; | |
| 629 static bool classof(const Inst *Inst) { return Inst->getKind() >= Target; } | 659 static bool classof(const Inst *Inst) { return Inst->getKind() >= Target; } |
| 630 | 660 |
| 631 protected: | 661 protected: |
| 632 InstTarget(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) | 662 InstTarget(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) |
| 633 : Inst(Func, Kind, MaxSrcs, Dest) { | 663 : Inst(Func, Kind, MaxSrcs, Dest) { |
| 634 assert(Kind >= Target); | 664 assert(Kind >= Target); |
| 635 } | 665 } |
| 636 InstTarget(const InstTarget &) LLVM_DELETED_FUNCTION; | 666 InstTarget(const InstTarget &) LLVM_DELETED_FUNCTION; |
| 637 InstTarget &operator=(const InstTarget &) LLVM_DELETED_FUNCTION; | 667 InstTarget &operator=(const InstTarget &) LLVM_DELETED_FUNCTION; |
| 638 virtual ~InstTarget() {} | 668 virtual ~InstTarget() {} |
| 639 }; | 669 }; |
| 640 | 670 |
| 641 } // end of namespace Ice | 671 } // end of namespace Ice |
| 642 | 672 |
| 643 #endif // SUBZERO_SRC_ICEINST_H | 673 #endif // SUBZERO_SRC_ICEINST_H |
| OLD | NEW |