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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Returns a list of out-edges corresponding to a terminator | 93 // Returns a list of out-edges corresponding to a terminator |
94 // instruction, which is the last instruction of the block. | 94 // instruction, which is the last instruction of the block. |
95 virtual NodeList getTerminatorEdges() const { | 95 virtual NodeList getTerminatorEdges() const { |
96 // All valid terminator instructions override this method. For | 96 // All valid terminator instructions override this method. For |
97 // the default implementation, we assert in case some CfgNode | 97 // the default implementation, we assert in case some CfgNode |
98 // is constructed without a terminator instruction at the end. | 98 // is constructed without a terminator instruction at the end. |
99 llvm_unreachable( | 99 llvm_unreachable( |
100 "getTerminatorEdges() called on a non-terminator instruction"); | 100 "getTerminatorEdges() called on a non-terminator instruction"); |
101 return NodeList(); | 101 return NodeList(); |
102 } | 102 } |
| 103 virtual bool isUnconditionalBranch() const { return false; } |
| 104 // If the instruction is a branch-type instruction with OldNode as a |
| 105 // target, repoint it to NewNode and return true, otherwise return |
| 106 // false. Only repoint one instance, even if the instruction has |
| 107 // multiple instances of OldNode as a target. |
| 108 virtual bool repointEdge(CfgNode *OldNode, CfgNode *NewNode) { |
| 109 (void)OldNode; |
| 110 (void)NewNode; |
| 111 return false; |
| 112 } |
103 | 113 |
104 virtual bool isSimpleAssign() const { return false; } | 114 virtual bool isSimpleAssign() const { return false; } |
105 | 115 |
106 void livenessLightweight(Cfg *Func, LivenessBV &Live); | 116 void livenessLightweight(Cfg *Func, LivenessBV &Live); |
107 void liveness(InstNumberT InstNumber, LivenessBV &Live, Liveness *Liveness, | 117 // Calculates liveness for this instruction. Returns true if this |
| 118 // instruction is (tentatively) still live and should be retained, |
| 119 // and false if this instruction is (tentatively) dead and should be |
| 120 // deleted. The decision is tentative until the liveness dataflow |
| 121 // algorithm has converged, and then a separate pass permanently |
| 122 // deletes dead instructions. |
| 123 bool liveness(InstNumberT InstNumber, LivenessBV &Live, Liveness *Liveness, |
108 LiveBeginEndMap *LiveBegin, LiveBeginEndMap *LiveEnd); | 124 LiveBeginEndMap *LiveBegin, LiveBeginEndMap *LiveEnd); |
109 | 125 |
110 // Get the number of native instructions that this instruction | 126 // Get the number of native instructions that this instruction |
111 // ultimately emits. By default, high-level instructions don't | 127 // ultimately emits. By default, high-level instructions don't |
112 // result in any native instructions, and a target-specific | 128 // result in any native instructions, and a target-specific |
113 // instruction results in a single native instruction. | 129 // instruction results in a single native instruction. |
114 virtual uint32_t getEmitInstCount() const { return 0; } | 130 virtual uint32_t getEmitInstCount() const { return 0; } |
115 virtual void emit(const Cfg *Func) const = 0; | 131 virtual void emit(const Cfg *Func) const = 0; |
116 virtual void emitIAS(const Cfg *Func) const = 0; | 132 virtual void emitIAS(const Cfg *Func) const = 0; |
117 virtual void dump(const Cfg *Func) const; | 133 virtual void dump(const Cfg *Func) const; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 assert(!isUnconditional()); | 313 assert(!isUnconditional()); |
298 return getSrc(0); | 314 return getSrc(0); |
299 } | 315 } |
300 CfgNode *getTargetTrue() const { return TargetTrue; } | 316 CfgNode *getTargetTrue() const { return TargetTrue; } |
301 CfgNode *getTargetFalse() const { return TargetFalse; } | 317 CfgNode *getTargetFalse() const { return TargetFalse; } |
302 CfgNode *getTargetUnconditional() const { | 318 CfgNode *getTargetUnconditional() const { |
303 assert(isUnconditional()); | 319 assert(isUnconditional()); |
304 return getTargetFalse(); | 320 return getTargetFalse(); |
305 } | 321 } |
306 NodeList getTerminatorEdges() const override; | 322 NodeList getTerminatorEdges() const override; |
| 323 bool isUnconditionalBranch() const override { return isUnconditional(); } |
| 324 bool repointEdge(CfgNode *OldNode, CfgNode *NewNode) override; |
307 void dump(const Cfg *Func) const override; | 325 void dump(const Cfg *Func) const override; |
308 static bool classof(const Inst *Inst) { return Inst->getKind() == Br; } | 326 static bool classof(const Inst *Inst) { return Inst->getKind() == Br; } |
309 | 327 |
310 private: | 328 private: |
311 // Conditional branch | 329 // Conditional branch |
312 InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue, CfgNode *TargetFalse); | 330 InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue, CfgNode *TargetFalse); |
313 // Unconditional branch | 331 // Unconditional branch |
314 InstBr(Cfg *Func, CfgNode *Target); | 332 InstBr(Cfg *Func, CfgNode *Target); |
315 ~InstBr() override {} | 333 ~InstBr() override {} |
316 | 334 |
317 CfgNode *const TargetFalse; // Doubles as unconditional branch target | 335 CfgNode *TargetFalse; // Doubles as unconditional branch target |
318 CfgNode *const TargetTrue; // NULL if unconditional branch | 336 CfgNode *TargetTrue; // NULL if unconditional branch |
319 }; | 337 }; |
320 | 338 |
321 // Call instruction. The call target is captured as getSrc(0), and | 339 // Call instruction. The call target is captured as getSrc(0), and |
322 // arg I is captured as getSrc(I+1). | 340 // arg I is captured as getSrc(I+1). |
323 class InstCall : public InstHighLevel { | 341 class InstCall : public InstHighLevel { |
324 InstCall(const InstCall &) = delete; | 342 InstCall(const InstCall &) = delete; |
325 InstCall &operator=(const InstCall &) = delete; | 343 InstCall &operator=(const InstCall &) = delete; |
326 | 344 |
327 public: | 345 public: |
328 static InstCall *create(Cfg *Func, SizeT NumArgs, Variable *Dest, | 346 static InstCall *create(Cfg *Func, SizeT NumArgs, Variable *Dest, |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 uint64_t getValue(SizeT I) const { | 682 uint64_t getValue(SizeT I) const { |
665 assert(I < NumCases); | 683 assert(I < NumCases); |
666 return Values[I]; | 684 return Values[I]; |
667 } | 685 } |
668 CfgNode *getLabel(SizeT I) const { | 686 CfgNode *getLabel(SizeT I) const { |
669 assert(I < NumCases); | 687 assert(I < NumCases); |
670 return Labels[I]; | 688 return Labels[I]; |
671 } | 689 } |
672 void addBranch(SizeT CaseIndex, uint64_t Value, CfgNode *Label); | 690 void addBranch(SizeT CaseIndex, uint64_t Value, CfgNode *Label); |
673 NodeList getTerminatorEdges() const override; | 691 NodeList getTerminatorEdges() const override; |
| 692 bool repointEdge(CfgNode *OldNode, CfgNode *NewNode) override; |
674 void dump(const Cfg *Func) const override; | 693 void dump(const Cfg *Func) const override; |
675 static bool classof(const Inst *Inst) { return Inst->getKind() == Switch; } | 694 static bool classof(const Inst *Inst) { return Inst->getKind() == Switch; } |
676 | 695 |
677 private: | 696 private: |
678 InstSwitch(Cfg *Func, SizeT NumCases, Operand *Source, CfgNode *LabelDefault); | 697 InstSwitch(Cfg *Func, SizeT NumCases, Operand *Source, CfgNode *LabelDefault); |
679 void destroy(Cfg *Func) override { | 698 void destroy(Cfg *Func) override { |
680 Func->deallocateArrayOf<uint64_t>(Values); | 699 Func->deallocateArrayOf<uint64_t>(Values); |
681 Func->deallocateArrayOf<CfgNode *>(Labels); | 700 Func->deallocateArrayOf<CfgNode *>(Labels); |
682 Inst::destroy(Func); | 701 Inst::destroy(Func); |
683 } | 702 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 InstTarget(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) | 830 InstTarget(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) |
812 : Inst(Func, Kind, MaxSrcs, Dest) { | 831 : Inst(Func, Kind, MaxSrcs, Dest) { |
813 assert(Kind >= Target); | 832 assert(Kind >= Target); |
814 } | 833 } |
815 ~InstTarget() override {} | 834 ~InstTarget() override {} |
816 }; | 835 }; |
817 | 836 |
818 } // end of namespace Ice | 837 } // end of namespace Ice |
819 | 838 |
820 #endif // SUBZERO_SRC_ICEINST_H | 839 #endif // SUBZERO_SRC_ICEINST_H |
OLD | NEW |