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 liveness(LivenessMode Mode, int32_t InstNumber, llvm::BitVector &Live, | |
96 Liveness *Liveness, const CfgNode *Node); | |
91 virtual void emit(const Cfg *Func) const; | 97 virtual void emit(const Cfg *Func) const; |
92 virtual void dump(const Cfg *Func) const; | 98 virtual void dump(const Cfg *Func) const; |
99 virtual void dumpExtras(const Cfg *Func) const; | |
93 void dumpDecorated(const Cfg *Func) const; | 100 void dumpDecorated(const Cfg *Func) const; |
94 void emitSources(const Cfg *Func) const; | 101 void emitSources(const Cfg *Func) const; |
95 void dumpSources(const Cfg *Func) const; | 102 void dumpSources(const Cfg *Func) const; |
96 void dumpDest(const Cfg *Func) const; | 103 void dumpDest(const Cfg *Func) const; |
97 virtual bool isRedundantAssign() const { return false; } | 104 virtual bool isRedundantAssign() const { return false; } |
98 | 105 |
99 virtual ~Inst() {} | 106 virtual ~Inst() {} |
100 | 107 |
101 protected: | 108 protected: |
102 Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest); | 109 Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest); |
103 void addSource(Operand *Src) { | 110 void addSource(Operand *Src) { |
104 assert(Src); | 111 assert(Src); |
105 assert(NumSrcs < MaxSrcs); | 112 assert(NumSrcs < MaxSrcs); |
106 Srcs[NumSrcs++] = Src; | 113 Srcs[NumSrcs++] = Src; |
107 } | 114 } |
115 void setLastUse(SizeT VarIndex) { | |
116 if (VarIndex < 8 * sizeof(LiveRangesEnded)) | |
JF
2014/05/25 22:50:50
s/8/CHAR_BIT/
Jim Stichnoth
2014/05/29 01:39:46
Done.
| |
117 LiveRangesEnded |= (1u << VarIndex); | |
JF
2014/05/25 22:50:50
Use a typedef for LiveRangesEnded, and cast 1u to
Jim Stichnoth
2014/05/29 01:39:46
Done.
| |
118 } | |
119 void resetLastUses() { LiveRangesEnded = 0; } | |
108 // The destroy() method lets the instruction cleanly release any | 120 // The destroy() method lets the instruction cleanly release any |
109 // memory that was allocated via the Cfg's allocator. | 121 // memory that was allocated via the Cfg's allocator. |
110 virtual void destroy(Cfg *Func) { Func->deallocateArrayOf<Operand *>(Srcs); } | 122 virtual void destroy(Cfg *Func) { Func->deallocateArrayOf<Operand *>(Srcs); } |
111 | 123 |
112 const InstKind Kind; | 124 const InstKind Kind; |
113 // Number is the instruction number for describing live ranges. | 125 // Number is the instruction number for describing live ranges. |
114 int32_t Number; | 126 int32_t Number; |
115 // Deleted means irrevocably deleted. | 127 // Deleted means irrevocably deleted. |
116 bool Deleted; | 128 bool Deleted; |
129 // Dead means pending deletion after liveness analysis converges. | |
130 bool Dead; | |
117 // HasSideEffects means the instruction is something like a function | 131 // HasSideEffects means the instruction is something like a function |
118 // call or a volatile load that can't be removed even if its Dest | 132 // call or a volatile load that can't be removed even if its Dest |
119 // variable is not live. | 133 // variable is not live. |
120 bool HasSideEffects; | 134 bool HasSideEffects; |
121 | 135 |
122 Variable *Dest; | 136 Variable *Dest; |
123 const SizeT MaxSrcs; // only used for assert | 137 const SizeT MaxSrcs; // only used for assert |
124 SizeT NumSrcs; | 138 SizeT NumSrcs; |
125 Operand **Srcs; | 139 Operand **Srcs; |
126 | 140 |
141 uint32_t LiveRangesEnded; // only first 32 src operands tracked, sorry | |
142 | |
127 private: | 143 private: |
128 Inst(const Inst &) LLVM_DELETED_FUNCTION; | 144 Inst(const Inst &) LLVM_DELETED_FUNCTION; |
129 Inst &operator=(const Inst &) LLVM_DELETED_FUNCTION; | 145 Inst &operator=(const Inst &) LLVM_DELETED_FUNCTION; |
130 }; | 146 }; |
131 | 147 |
132 // Alloca instruction. This captures the size in bytes as getSrc(0), | 148 // Alloca instruction. This captures the size in bytes as getSrc(0), |
133 // and the required alignment in bytes. The alignment must be either | 149 // and the required alignment in bytes. The alignment must be either |
134 // 0 (no alignment required) or a power of 2. | 150 // 0 (no alignment required) or a power of 2. |
135 class InstAlloca : public Inst { | 151 class InstAlloca : public Inst { |
136 public: | 152 public: |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 | 402 |
387 // Phi instruction. For incoming edge I, the node is Labels[I] and | 403 // Phi instruction. For incoming edge I, the node is Labels[I] and |
388 // the Phi source operand is getSrc(I). | 404 // the Phi source operand is getSrc(I). |
389 class InstPhi : public Inst { | 405 class InstPhi : public Inst { |
390 public: | 406 public: |
391 static InstPhi *create(Cfg *Func, SizeT MaxSrcs, Variable *Dest) { | 407 static InstPhi *create(Cfg *Func, SizeT MaxSrcs, Variable *Dest) { |
392 return new (Func->allocateInst<InstPhi>()) InstPhi(Func, MaxSrcs, Dest); | 408 return new (Func->allocateInst<InstPhi>()) InstPhi(Func, MaxSrcs, Dest); |
393 } | 409 } |
394 void addArgument(Operand *Source, CfgNode *Label); | 410 void addArgument(Operand *Source, CfgNode *Label); |
395 Operand *getOperandForTarget(CfgNode *Target) const; | 411 Operand *getOperandForTarget(CfgNode *Target) const; |
412 void livenessPhiOperand(llvm::BitVector &Live, CfgNode *Target, | |
413 Liveness *Liveness); | |
396 Inst *lower(Cfg *Func, CfgNode *Node); | 414 Inst *lower(Cfg *Func, CfgNode *Node); |
397 virtual void dump(const Cfg *Func) const; | 415 virtual void dump(const Cfg *Func) const; |
398 static bool classof(const Inst *Inst) { return Inst->getKind() == Phi; } | 416 static bool classof(const Inst *Inst) { return Inst->getKind() == Phi; } |
399 | 417 |
400 private: | 418 private: |
401 InstPhi(Cfg *Func, SizeT MaxSrcs, Variable *Dest); | 419 InstPhi(Cfg *Func, SizeT MaxSrcs, Variable *Dest); |
402 InstPhi(const InstPhi &) LLVM_DELETED_FUNCTION; | 420 InstPhi(const InstPhi &) LLVM_DELETED_FUNCTION; |
403 InstPhi &operator=(const InstPhi &) LLVM_DELETED_FUNCTION; | 421 InstPhi &operator=(const InstPhi &) LLVM_DELETED_FUNCTION; |
404 virtual void destroy(Cfg *Func) { | 422 virtual void destroy(Cfg *Func) { |
405 Func->deallocateArrayOf<CfgNode *>(Labels); | 423 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. | 637 // This instruction is ignored if Linked->isDeleted() is true. |
620 const Inst *Linked; | 638 const Inst *Linked; |
621 }; | 639 }; |
622 | 640 |
623 // The Target instruction is the base class for all target-specific | 641 // The Target instruction is the base class for all target-specific |
624 // instructions. | 642 // instructions. |
625 class InstTarget : public Inst { | 643 class InstTarget : public Inst { |
626 public: | 644 public: |
627 virtual void emit(const Cfg *Func) const = 0; | 645 virtual void emit(const Cfg *Func) const = 0; |
628 virtual void dump(const Cfg *Func) const; | 646 virtual void dump(const Cfg *Func) const; |
647 virtual void dumpExtras(const Cfg *Func) const; | |
629 static bool classof(const Inst *Inst) { return Inst->getKind() >= Target; } | 648 static bool classof(const Inst *Inst) { return Inst->getKind() >= Target; } |
630 | 649 |
631 protected: | 650 protected: |
632 InstTarget(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) | 651 InstTarget(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) |
633 : Inst(Func, Kind, MaxSrcs, Dest) { | 652 : Inst(Func, Kind, MaxSrcs, Dest) { |
634 assert(Kind >= Target); | 653 assert(Kind >= Target); |
635 } | 654 } |
636 InstTarget(const InstTarget &) LLVM_DELETED_FUNCTION; | 655 InstTarget(const InstTarget &) LLVM_DELETED_FUNCTION; |
637 InstTarget &operator=(const InstTarget &) LLVM_DELETED_FUNCTION; | 656 InstTarget &operator=(const InstTarget &) LLVM_DELETED_FUNCTION; |
638 virtual ~InstTarget() {} | 657 virtual ~InstTarget() {} |
639 }; | 658 }; |
640 | 659 |
641 } // end of namespace Ice | 660 } // end of namespace Ice |
642 | 661 |
643 #endif // SUBZERO_SRC_ICEINST_H | 662 #endif // SUBZERO_SRC_ICEINST_H |
OLD | NEW |