OLD | NEW |
1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// | 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- 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 /// \file | 10 /// \file |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 MDS_Unknown, | 617 MDS_Unknown, |
618 MDS_SingleDef, | 618 MDS_SingleDef, |
619 MDS_MultiDefSingleBlock, | 619 MDS_MultiDefSingleBlock, |
620 MDS_MultiDefMultiBlock | 620 MDS_MultiDefMultiBlock |
621 }; | 621 }; |
622 enum MultiBlockState { MBS_Unknown, MBS_SingleBlock, MBS_MultiBlock }; | 622 enum MultiBlockState { MBS_Unknown, MBS_SingleBlock, MBS_MultiBlock }; |
623 VariableTracking() = default; | 623 VariableTracking() = default; |
624 VariableTracking(const VariableTracking &) = default; | 624 VariableTracking(const VariableTracking &) = default; |
625 MultiDefState getMultiDef() const { return MultiDef; } | 625 MultiDefState getMultiDef() const { return MultiDef; } |
626 MultiBlockState getMultiBlock() const { return MultiBlock; } | 626 MultiBlockState getMultiBlock() const { return MultiBlock; } |
| 627 const Inst *getFirstDefinitionSingleBlock() const; |
| 628 const Inst *getSingleDefinition() const; |
627 const Inst *getFirstDefinition() const; | 629 const Inst *getFirstDefinition() const; |
628 const Inst *getSingleDefinition() const; | |
629 const InstDefList &getLatterDefinitions() const { return Definitions; } | 630 const InstDefList &getLatterDefinitions() const { return Definitions; } |
630 CfgNode *getNode() const { return SingleUseNode; } | 631 CfgNode *getNode() const { return SingleUseNode; } |
631 RegWeight getUseWeight() const { return UseWeight; } | 632 RegWeight getUseWeight() const { return UseWeight; } |
632 void markUse(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node, | 633 void markUse(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node, |
633 bool IsImplicit); | 634 bool IsImplicit); |
634 void markDef(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node); | 635 void markDef(MetadataKind TrackingKind, const Inst *Instr, CfgNode *Node); |
635 | 636 |
636 private: | 637 private: |
637 MultiDefState MultiDef = MDS_Unknown; | 638 MultiDefState MultiDef = MDS_Unknown; |
638 MultiBlockState MultiBlock = MBS_Unknown; | 639 MultiBlockState MultiBlock = MBS_Unknown; |
639 CfgNode *SingleUseNode = nullptr; | 640 CfgNode *SingleUseNode = nullptr; |
640 CfgNode *SingleDefNode = nullptr; | 641 CfgNode *SingleDefNode = nullptr; |
641 /// All definitions of the variable are collected here, in increasing | 642 /// All definitions of the variable are collected in Definitions[] (except for |
642 /// order of instruction number. | 643 /// the earliest definition), in increasing order of instruction number. |
643 InstDefList Definitions; /// Only used if Kind==VMK_All | 644 InstDefList Definitions; /// Only used if Kind==VMK_All |
644 const Inst *FirstOrSingleDefinition = | 645 const Inst *FirstOrSingleDefinition = nullptr; |
645 nullptr; /// Is a copy of Definitions[0] if Kind==VMK_All | |
646 RegWeight UseWeight; | 646 RegWeight UseWeight; |
647 }; | 647 }; |
648 | 648 |
649 /// VariablesMetadata analyzes and summarizes the metadata for the complete set | 649 /// VariablesMetadata analyzes and summarizes the metadata for the complete set |
650 /// of Variables. | 650 /// of Variables. |
651 class VariablesMetadata { | 651 class VariablesMetadata { |
652 VariablesMetadata() = delete; | 652 VariablesMetadata() = delete; |
653 VariablesMetadata(const VariablesMetadata &) = delete; | 653 VariablesMetadata(const VariablesMetadata &) = delete; |
654 VariablesMetadata &operator=(const VariablesMetadata &) = delete; | 654 VariablesMetadata &operator=(const VariablesMetadata &) = delete; |
655 | 655 |
656 public: | 656 public: |
657 explicit VariablesMetadata(const Cfg *Func) : Func(Func) {} | 657 explicit VariablesMetadata(const Cfg *Func) : Func(Func) {} |
658 /// Initialize the state by traversing all instructions/variables in the CFG. | 658 /// Initialize the state by traversing all instructions/variables in the CFG. |
659 void init(MetadataKind TrackingKind); | 659 void init(MetadataKind TrackingKind); |
660 /// Add a single node. This is called by init(), and can be called | 660 /// Add a single node. This is called by init(), and can be called |
661 /// incrementally from elsewhere, e.g. after edge-splitting. | 661 /// incrementally from elsewhere, e.g. after edge-splitting. |
662 void addNode(CfgNode *Node); | 662 void addNode(CfgNode *Node); |
| 663 MetadataKind getKind() const { return Kind; } |
663 /// Returns whether the given Variable is tracked in this object. It should | 664 /// Returns whether the given Variable is tracked in this object. It should |
664 /// only return false if changes were made to the CFG after running init(), in | 665 /// only return false if changes were made to the CFG after running init(), in |
665 /// which case the state is stale and the results shouldn't be trusted (but it | 666 /// which case the state is stale and the results shouldn't be trusted (but it |
666 /// may be OK e.g. for dumping). | 667 /// may be OK e.g. for dumping). |
667 bool isTracked(const Variable *Var) const { | 668 bool isTracked(const Variable *Var) const { |
668 return Var->getIndex() < Metadata.size(); | 669 return Var->getIndex() < Metadata.size(); |
669 } | 670 } |
670 | 671 |
671 /// Returns whether the given Variable has multiple definitions. | 672 /// Returns whether the given Variable has multiple definitions. |
672 bool isMultiDef(const Variable *Var) const; | 673 bool isMultiDef(const Variable *Var) const; |
673 /// Returns the first definition instruction of the given Variable. This is | 674 /// Returns the first definition instruction of the given Variable. This is |
674 /// only valid for variables whose definitions are all within the same block, | 675 /// only valid for variables whose definitions are all within the same block, |
675 /// e.g. T after the lowered sequence "T=B; T+=C; A=T", for which | 676 /// e.g. T after the lowered sequence "T=B; T+=C; A=T", for which |
676 /// getFirstDefinition(T) would return the "T=B" instruction. For variables | 677 /// getFirstDefinitionSingleBlock(T) would return the "T=B" instruction. For |
677 /// with definitions span multiple blocks, nullptr is returned. | 678 /// variables with definitions span multiple blocks, nullptr is returned. |
678 const Inst *getFirstDefinition(const Variable *Var) const; | 679 const Inst *getFirstDefinitionSingleBlock(const Variable *Var) const; |
679 /// Returns the definition instruction of the given Variable, when the | 680 /// Returns the definition instruction of the given Variable, when the |
680 /// variable has exactly one definition. Otherwise, nullptr is returned. | 681 /// variable has exactly one definition. Otherwise, nullptr is returned. |
681 const Inst *getSingleDefinition(const Variable *Var) const; | 682 const Inst *getSingleDefinition(const Variable *Var) const; |
682 /// Returns the list of all definition instructions of the given Variable. | 683 /// getFirstDefinition() and getLatterDefinitions() are used together to |
| 684 /// return the complete set of instructions that define the given Variable, |
| 685 /// regardless of whether the definitions are within the same block (in |
| 686 /// contrast to getFirstDefinitionSingleBlock). |
| 687 const Inst *getFirstDefinition(const Variable *Var) const; |
683 const InstDefList &getLatterDefinitions(const Variable *Var) const; | 688 const InstDefList &getLatterDefinitions(const Variable *Var) const; |
684 | 689 |
685 /// Returns whether the given Variable is live across multiple blocks. Mainly, | 690 /// Returns whether the given Variable is live across multiple blocks. Mainly, |
686 /// this is used to partition Variables into single-block versus multi-block | 691 /// this is used to partition Variables into single-block versus multi-block |
687 /// sets for leveraging sparsity in liveness analysis, and for implementing | 692 /// sets for leveraging sparsity in liveness analysis, and for implementing |
688 /// simple stack slot coalescing. As a special case, function arguments are | 693 /// simple stack slot coalescing. As a special case, function arguments are |
689 /// always considered multi-block because they are live coming into the entry | 694 /// always considered multi-block because they are live coming into the entry |
690 /// block. | 695 /// block. |
691 bool isMultiBlock(const Variable *Var) const; | 696 bool isMultiBlock(const Variable *Var) const; |
692 /// Returns the node that the given Variable is used in, assuming | 697 /// Returns the node that the given Variable is used in, assuming |
693 /// isMultiBlock() returns false. Otherwise, nullptr is returned. | 698 /// isMultiBlock() returns false. Otherwise, nullptr is returned. |
694 CfgNode *getLocalUseNode(const Variable *Var) const; | 699 CfgNode *getLocalUseNode(const Variable *Var) const; |
695 | 700 |
696 /// Returns the total use weight computed as the sum of uses multiplied by a | 701 /// Returns the total use weight computed as the sum of uses multiplied by a |
697 /// loop nest depth factor for each use. | 702 /// loop nest depth factor for each use. |
698 RegWeight getUseWeight(const Variable *Var) const; | 703 RegWeight getUseWeight(const Variable *Var) const; |
699 | 704 |
700 private: | 705 private: |
701 const Cfg *Func; | 706 const Cfg *Func; |
702 MetadataKind Kind; | 707 MetadataKind Kind; |
703 CfgVector<VariableTracking> Metadata; | 708 CfgVector<VariableTracking> Metadata; |
704 const static InstDefList NoDefinitions; | 709 const static InstDefList NoDefinitions; |
705 }; | 710 }; |
706 | 711 |
707 } // end of namespace Ice | 712 } // end of namespace Ice |
708 | 713 |
709 #endif // SUBZERO_SRC_ICEOPERAND_H | 714 #endif // SUBZERO_SRC_ICEOPERAND_H |
OLD | NEW |