Dan Gohman | 84fbac5 | 2009-02-06 17:22:58 +0000 | [diff] [blame] | 1 | //===---- ScheduleDAGSDNodes.h - SDNode Scheduling --------------*- C++ -*-===// |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 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 | |
Dan Gohman | 84fbac5 | 2009-02-06 17:22:58 +0000 | [diff] [blame] | 15 | #ifndef SCHEDULEDAGSDNODES_H |
| 16 | #define SCHEDULEDAGSDNODES_H |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 17 | |
| 18 | #include "llvm/CodeGen/ScheduleDAG.h" |
| 19 | #include "llvm/CodeGen/SelectionDAG.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
Dan Gohman | 983bbba | 2008-12-22 21:06:20 +0000 | [diff] [blame] | 22 | /// ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs. |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 23 | /// |
Dan Gohman | 983bbba | 2008-12-22 21:06:20 +0000 | [diff] [blame] | 24 | /// Edges between SUnits are initially based on edges in the SelectionDAG, |
| 25 | /// and additional edges can be added by the schedulers as heuristics. |
| 26 | /// SDNodes such as Constants, Registers, and a few others that are not |
| 27 | /// interesting to schedulers are not allocated SUnits. |
| 28 | /// |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 29 | /// SDNodes with MVT::Glue operands are grouped along with the flagged |
Dan Gohman | 983bbba | 2008-12-22 21:06:20 +0000 | [diff] [blame] | 30 | /// nodes into a single SUnit so that they are scheduled together. |
| 31 | /// |
| 32 | /// SDNode-based scheduling graphs do not use SDep::Anti or SDep::Output |
| 33 | /// edges. Physical register dependence information is not carried in |
| 34 | /// the DAG and must be handled explicitly by schedulers. |
| 35 | /// |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 36 | class ScheduleDAGSDNodes : public ScheduleDAG { |
| 37 | public: |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 38 | SelectionDAG *DAG; // DAG of the current basic block |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 39 | const InstrItineraryData *InstrItins; |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 40 | |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 41 | explicit ScheduleDAGSDNodes(MachineFunction &mf); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 42 | |
| 43 | virtual ~ScheduleDAGSDNodes() {} |
| 44 | |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 45 | /// Run - perform scheduling. |
| 46 | /// |
| 47 | void Run(SelectionDAG *dag, MachineBasicBlock *bb, |
| 48 | MachineBasicBlock::iterator insertPos); |
| 49 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 50 | /// isPassiveNode - Return true if the node is a non-scheduled leaf. |
| 51 | /// |
| 52 | static bool isPassiveNode(SDNode *Node) { |
| 53 | if (isa<ConstantSDNode>(Node)) return true; |
| 54 | if (isa<ConstantFPSDNode>(Node)) return true; |
| 55 | if (isa<RegisterSDNode>(Node)) return true; |
Jakob Stoklund Olesen | 9cf37e8 | 2012-01-18 23:52:12 +0000 | [diff] [blame] | 56 | if (isa<RegisterMaskSDNode>(Node)) return true; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 57 | if (isa<GlobalAddressSDNode>(Node)) return true; |
| 58 | if (isa<BasicBlockSDNode>(Node)) return true; |
| 59 | if (isa<FrameIndexSDNode>(Node)) return true; |
| 60 | if (isa<ConstantPoolSDNode>(Node)) return true; |
| 61 | if (isa<JumpTableSDNode>(Node)) return true; |
| 62 | if (isa<ExternalSymbolSDNode>(Node)) return true; |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 63 | if (isa<BlockAddressSDNode>(Node)) return true; |
Chris Lattner | decc267 | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 64 | if (Node->getOpcode() == ISD::EntryToken || |
| 65 | isa<MDNodeSDNode>(Node)) return true; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 66 | return false; |
| 67 | } |
| 68 | |
| 69 | /// NewSUnit - Creates a new SUnit and return a ptr to it. |
| 70 | /// |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 71 | SUnit *NewSUnit(SDNode *N); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 72 | |
| 73 | /// Clone - Creates a clone of the specified SUnit. It does not copy the |
| 74 | /// predecessors / successors info nor the temporary scheduling states. |
| 75 | /// |
| 76 | SUnit *Clone(SUnit *N); |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 77 | |
Dan Gohman | c9a5b9e | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 78 | /// BuildSchedGraph - Build the SUnit graph from the selection dag that we |
| 79 | /// are input. This SUnit graph is similar to the SelectionDAG, but |
| 80 | /// excludes nodes that aren't interesting to scheduling, and represents |
| 81 | /// flagged together nodes with a single SUnit. |
Andrew Trick | 084e179 | 2012-03-07 00:18:12 +0000 | [diff] [blame] | 82 | void BuildSchedGraph(AliasAnalysis *AA); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 83 | |
Andrew Trick | 5469976 | 2011-04-07 19:54:57 +0000 | [diff] [blame] | 84 | /// InitVRegCycleFlag - Set isVRegCycle if this node's single use is |
| 85 | /// CopyToReg and its only active data operands are CopyFromReg within a |
| 86 | /// single block loop. |
| 87 | /// |
| 88 | void InitVRegCycleFlag(SUnit *SU); |
| 89 | |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 90 | /// InitNumRegDefsLeft - Determine the # of regs defined by this node. |
| 91 | /// |
| 92 | void InitNumRegDefsLeft(SUnit *SU); |
| 93 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 94 | /// ComputeLatency - Compute node latency. |
| 95 | /// |
| 96 | virtual void ComputeLatency(SUnit *SU); |
| 97 | |
Evan Cheng | 15a16de | 2010-05-20 06:13:19 +0000 | [diff] [blame] | 98 | /// ComputeOperandLatency - Override dependence edge latency using |
| 99 | /// operand use/def information |
| 100 | /// |
| 101 | virtual void ComputeOperandLatency(SUnit *Def, SUnit *Use, |
| 102 | SDep& dep) const { } |
| 103 | |
| 104 | virtual void ComputeOperandLatency(SDNode *Def, SDNode *Use, |
| 105 | unsigned OpIdx, SDep& dep) const; |
| 106 | |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 107 | virtual MachineBasicBlock *EmitSchedule(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 108 | |
| 109 | /// Schedule - Order nodes according to selected style, filling |
| 110 | /// in the Sequence member. |
| 111 | /// |
| 112 | virtual void Schedule() = 0; |
| 113 | |
| 114 | virtual void dumpNode(const SUnit *SU) const; |
| 115 | |
| 116 | virtual std::string getGraphNodeLabel(const SUnit *SU) const; |
| 117 | |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 118 | virtual std::string getDAGName() const; |
| 119 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 120 | virtual void getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const; |
| 121 | |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 122 | /// RegDefIter - In place iteration over the values defined by an |
| 123 | /// SUnit. This does not need copies of the iterator or any other STLisms. |
| 124 | /// The iterator creates itself, rather than being provided by the SchedDAG. |
| 125 | class RegDefIter { |
| 126 | const ScheduleDAGSDNodes *SchedDAG; |
| 127 | const SDNode *Node; |
| 128 | unsigned DefIdx; |
| 129 | unsigned NodeNumDefs; |
| 130 | EVT ValueType; |
| 131 | public: |
| 132 | RegDefIter(const SUnit *SU, const ScheduleDAGSDNodes *SD); |
| 133 | |
| 134 | bool IsValid() const { return Node != NULL; } |
| 135 | |
| 136 | EVT GetValue() const { |
| 137 | assert(IsValid() && "bad iterator"); |
| 138 | return ValueType; |
| 139 | } |
| 140 | |
Owen Anderson | 77b4b13 | 2011-06-15 23:35:18 +0000 | [diff] [blame] | 141 | const SDNode *GetNode() const { |
| 142 | return Node; |
| 143 | } |
| 144 | |
| 145 | unsigned GetIdx() const { |
Owen Anderson | 7021101 | 2011-06-27 18:34:12 +0000 | [diff] [blame] | 146 | return DefIdx-1; |
Owen Anderson | 77b4b13 | 2011-06-15 23:35:18 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Andrew Trick | 92e9466 | 2011-02-04 03:18:17 +0000 | [diff] [blame] | 149 | void Advance(); |
| 150 | private: |
| 151 | void InitNodeNumDefs(); |
| 152 | }; |
| 153 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 154 | private: |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 155 | /// ClusterNeighboringLoads - Cluster loads from "near" addresses into |
| 156 | /// combined SUnits. |
Evan Cheng | 302ef83 | 2010-06-10 02:09:31 +0000 | [diff] [blame] | 157 | void ClusterNeighboringLoads(SDNode *Node); |
| 158 | /// ClusterNodes - Cluster certain nodes which should be scheduled together. |
| 159 | /// |
| 160 | void ClusterNodes(); |
Evan Cheng | c589e03 | 2010-01-22 03:36:51 +0000 | [diff] [blame] | 161 | |
Dan Gohman | c9a5b9e | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 162 | /// BuildSchedUnits, AddSchedEdges - Helper functions for BuildSchedGraph. |
| 163 | void BuildSchedUnits(); |
| 164 | void AddSchedEdges(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 165 | }; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | #endif |