ScheduleDAGSDNodes.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //===---- ScheduleDAGSDNodes.h - SDNode Scheduling --------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  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 implements the ScheduleDAGSDNodes class, which implements
  11. // scheduling for an SDNode-based dependency graph.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SCHEDULEDAGSDNODES_H
  15. #define LLVM_LIB_CODEGEN_SELECTIONDAG_SCHEDULEDAGSDNODES_H
  16. #include "llvm/CodeGen/MachineBasicBlock.h"
  17. #include "llvm/CodeGen/ScheduleDAG.h"
  18. namespace llvm {
  19. /// ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs.
  20. ///
  21. /// Edges between SUnits are initially based on edges in the SelectionDAG,
  22. /// and additional edges can be added by the schedulers as heuristics.
  23. /// SDNodes such as Constants, Registers, and a few others that are not
  24. /// interesting to schedulers are not allocated SUnits.
  25. ///
  26. /// SDNodes with MVT::Glue operands are grouped along with the flagged
  27. /// nodes into a single SUnit so that they are scheduled together.
  28. ///
  29. /// SDNode-based scheduling graphs do not use SDep::Anti or SDep::Output
  30. /// edges. Physical register dependence information is not carried in
  31. /// the DAG and must be handled explicitly by schedulers.
  32. ///
  33. class ScheduleDAGSDNodes : public ScheduleDAG {
  34. public:
  35. MachineBasicBlock *BB;
  36. SelectionDAG *DAG; // DAG of the current basic block
  37. const InstrItineraryData *InstrItins;
  38. /// The schedule. Null SUnit*'s represent noop instructions.
  39. std::vector<SUnit*> Sequence;
  40. explicit ScheduleDAGSDNodes(MachineFunction &mf);
  41. ~ScheduleDAGSDNodes() override {}
  42. /// Run - perform scheduling.
  43. ///
  44. void Run(SelectionDAG *dag, MachineBasicBlock *bb);
  45. /// isPassiveNode - Return true if the node is a non-scheduled leaf.
  46. ///
  47. static bool isPassiveNode(SDNode *Node) {
  48. if (isa<ConstantSDNode>(Node)) return true;
  49. if (isa<ConstantFPSDNode>(Node)) return true;
  50. if (isa<RegisterSDNode>(Node)) return true;
  51. if (isa<RegisterMaskSDNode>(Node)) return true;
  52. if (isa<GlobalAddressSDNode>(Node)) return true;
  53. if (isa<BasicBlockSDNode>(Node)) return true;
  54. if (isa<FrameIndexSDNode>(Node)) return true;
  55. if (isa<ConstantPoolSDNode>(Node)) return true;
  56. if (isa<TargetIndexSDNode>(Node)) return true;
  57. if (isa<JumpTableSDNode>(Node)) return true;
  58. if (isa<ExternalSymbolSDNode>(Node)) return true;
  59. if (isa<MCSymbolSDNode>(Node)) return true;
  60. if (isa<BlockAddressSDNode>(Node)) return true;
  61. if (Node->getOpcode() == ISD::EntryToken ||
  62. isa<MDNodeSDNode>(Node)) return true;
  63. return false;
  64. }
  65. /// NewSUnit - Creates a new SUnit and return a ptr to it.
  66. ///
  67. SUnit *newSUnit(SDNode *N);
  68. /// Clone - Creates a clone of the specified SUnit. It does not copy the
  69. /// predecessors / successors info nor the temporary scheduling states.
  70. ///
  71. SUnit *Clone(SUnit *N);
  72. /// BuildSchedGraph - Build the SUnit graph from the selection dag that we
  73. /// are input. This SUnit graph is similar to the SelectionDAG, but
  74. /// excludes nodes that aren't interesting to scheduling, and represents
  75. /// flagged together nodes with a single SUnit.
  76. void BuildSchedGraph(AliasAnalysis *AA);
  77. /// InitVRegCycleFlag - Set isVRegCycle if this node's single use is
  78. /// CopyToReg and its only active data operands are CopyFromReg within a
  79. /// single block loop.
  80. ///
  81. void InitVRegCycleFlag(SUnit *SU);
  82. /// InitNumRegDefsLeft - Determine the # of regs defined by this node.
  83. ///
  84. void InitNumRegDefsLeft(SUnit *SU);
  85. /// computeLatency - Compute node latency.
  86. ///
  87. virtual void computeLatency(SUnit *SU);
  88. virtual void computeOperandLatency(SDNode *Def, SDNode *Use,
  89. unsigned OpIdx, SDep& dep) const;
  90. /// Schedule - Order nodes according to selected style, filling
  91. /// in the Sequence member.
  92. ///
  93. virtual void Schedule() = 0;
  94. /// VerifyScheduledSequence - Verify that all SUnits are scheduled and
  95. /// consistent with the Sequence of scheduled instructions.
  96. void VerifyScheduledSequence(bool isBottomUp);
  97. /// EmitSchedule - Insert MachineInstrs into the MachineBasicBlock
  98. /// according to the order specified in Sequence.
  99. ///
  100. virtual MachineBasicBlock*
  101. EmitSchedule(MachineBasicBlock::iterator &InsertPos);
  102. void dumpNode(const SUnit *SU) const override;
  103. void dumpSchedule() const;
  104. std::string getGraphNodeLabel(const SUnit *SU) const override;
  105. std::string getDAGName() const override;
  106. virtual void getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const;
  107. /// RegDefIter - In place iteration over the values defined by an
  108. /// SUnit. This does not need copies of the iterator or any other STLisms.
  109. /// The iterator creates itself, rather than being provided by the SchedDAG.
  110. class RegDefIter {
  111. const ScheduleDAGSDNodes *SchedDAG;
  112. const SDNode *Node;
  113. unsigned DefIdx;
  114. unsigned NodeNumDefs;
  115. MVT ValueType;
  116. public:
  117. RegDefIter(const SUnit *SU, const ScheduleDAGSDNodes *SD);
  118. bool IsValid() const { return Node != nullptr; }
  119. MVT GetValue() const {
  120. assert(IsValid() && "bad iterator");
  121. return ValueType;
  122. }
  123. const SDNode *GetNode() const {
  124. return Node;
  125. }
  126. unsigned GetIdx() const {
  127. return DefIdx-1;
  128. }
  129. void Advance();
  130. private:
  131. void InitNodeNumDefs();
  132. };
  133. protected:
  134. /// ForceUnitLatencies - Return true if all scheduling edges should be given
  135. /// a latency value of one. The default is to return false; schedulers may
  136. /// override this as needed.
  137. virtual bool forceUnitLatencies() const { return false; }
  138. private:
  139. /// ClusterNeighboringLoads - Cluster loads from "near" addresses into
  140. /// combined SUnits.
  141. void ClusterNeighboringLoads(SDNode *Node);
  142. /// ClusterNodes - Cluster certain nodes which should be scheduled together.
  143. ///
  144. void ClusterNodes();
  145. /// BuildSchedUnits, AddSchedEdges - Helper functions for BuildSchedGraph.
  146. void BuildSchedUnits();
  147. void AddSchedEdges();
  148. void EmitPhysRegCopy(SUnit *SU, DenseMap<SUnit*, unsigned> &VRBaseMap,
  149. MachineBasicBlock::iterator InsertPos);
  150. };
  151. }
  152. #endif