ScheduleDAGSDNodes.h revision 207618
1193323Sed//===---- ScheduleDAGSDNodes.h - SDNode Scheduling --------------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file implements the ScheduleDAGSDNodes class, which implements 11193323Sed// scheduling for an SDNode-based dependency graph. 12193323Sed// 13193323Sed//===----------------------------------------------------------------------===// 14193323Sed 15193323Sed#ifndef SCHEDULEDAGSDNODES_H 16193323Sed#define SCHEDULEDAGSDNODES_H 17193323Sed 18193323Sed#include "llvm/CodeGen/ScheduleDAG.h" 19193323Sed#include "llvm/CodeGen/SelectionDAG.h" 20193323Sed 21193323Sednamespace llvm { 22193323Sed /// ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs. 23193323Sed /// 24193323Sed /// Edges between SUnits are initially based on edges in the SelectionDAG, 25193323Sed /// and additional edges can be added by the schedulers as heuristics. 26193323Sed /// SDNodes such as Constants, Registers, and a few others that are not 27193323Sed /// interesting to schedulers are not allocated SUnits. 28193323Sed /// 29193323Sed /// SDNodes with MVT::Flag operands are grouped along with the flagged 30193323Sed /// nodes into a single SUnit so that they are scheduled together. 31193323Sed /// 32193323Sed /// SDNode-based scheduling graphs do not use SDep::Anti or SDep::Output 33193323Sed /// edges. Physical register dependence information is not carried in 34193323Sed /// the DAG and must be handled explicitly by schedulers. 35193323Sed /// 36193323Sed class ScheduleDAGSDNodes : public ScheduleDAG { 37193323Sed public: 38193323Sed SelectionDAG *DAG; // DAG of the current basic block 39193323Sed 40193323Sed explicit ScheduleDAGSDNodes(MachineFunction &mf); 41193323Sed 42193323Sed virtual ~ScheduleDAGSDNodes() {} 43193323Sed 44193323Sed /// Run - perform scheduling. 45193323Sed /// 46193323Sed void Run(SelectionDAG *dag, MachineBasicBlock *bb, 47193323Sed MachineBasicBlock::iterator insertPos); 48193323Sed 49193323Sed /// isPassiveNode - Return true if the node is a non-scheduled leaf. 50193323Sed /// 51193323Sed static bool isPassiveNode(SDNode *Node) { 52193323Sed if (isa<ConstantSDNode>(Node)) return true; 53193323Sed if (isa<ConstantFPSDNode>(Node)) return true; 54193323Sed if (isa<RegisterSDNode>(Node)) return true; 55193323Sed if (isa<GlobalAddressSDNode>(Node)) return true; 56193323Sed if (isa<BasicBlockSDNode>(Node)) return true; 57193323Sed if (isa<FrameIndexSDNode>(Node)) return true; 58193323Sed if (isa<ConstantPoolSDNode>(Node)) return true; 59193323Sed if (isa<JumpTableSDNode>(Node)) return true; 60193323Sed if (isa<ExternalSymbolSDNode>(Node)) return true; 61198892Srdivacky if (isa<BlockAddressSDNode>(Node)) return true; 62207618Srdivacky if (Node->getOpcode() == ISD::EntryToken || 63207618Srdivacky isa<MDNodeSDNode>(Node)) return true; 64193323Sed return false; 65193323Sed } 66193323Sed 67193323Sed /// NewSUnit - Creates a new SUnit and return a ptr to it. 68193323Sed /// 69193323Sed SUnit *NewSUnit(SDNode *N) { 70193323Sed#ifndef NDEBUG 71193323Sed const SUnit *Addr = 0; 72193323Sed if (!SUnits.empty()) 73193323Sed Addr = &SUnits[0]; 74193323Sed#endif 75193323Sed SUnits.push_back(SUnit(N, (unsigned)SUnits.size())); 76193323Sed assert((Addr == 0 || Addr == &SUnits[0]) && 77193323Sed "SUnits std::vector reallocated on the fly!"); 78193323Sed SUnits.back().OrigNode = &SUnits.back(); 79193323Sed return &SUnits.back(); 80193323Sed } 81193323Sed 82193323Sed /// Clone - Creates a clone of the specified SUnit. It does not copy the 83193323Sed /// predecessors / successors info nor the temporary scheduling states. 84193323Sed /// 85193323Sed SUnit *Clone(SUnit *N); 86193323Sed 87193323Sed /// BuildSchedGraph - Build the SUnit graph from the selection dag that we 88193323Sed /// are input. This SUnit graph is similar to the SelectionDAG, but 89193323Sed /// excludes nodes that aren't interesting to scheduling, and represents 90193323Sed /// flagged together nodes with a single SUnit. 91198090Srdivacky virtual void BuildSchedGraph(AliasAnalysis *AA); 92193323Sed 93193323Sed /// ComputeLatency - Compute node latency. 94193323Sed /// 95193323Sed virtual void ComputeLatency(SUnit *SU); 96193323Sed 97207618Srdivacky virtual MachineBasicBlock *EmitSchedule(); 98193323Sed 99193323Sed /// Schedule - Order nodes according to selected style, filling 100193323Sed /// in the Sequence member. 101193323Sed /// 102193323Sed virtual void Schedule() = 0; 103193323Sed 104193323Sed virtual void dumpNode(const SUnit *SU) const; 105193323Sed 106193323Sed virtual std::string getGraphNodeLabel(const SUnit *SU) const; 107193323Sed 108193323Sed virtual void getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const; 109193323Sed 110193323Sed private: 111202878Srdivacky /// ClusterNeighboringLoads - Cluster loads from "near" addresses into 112202878Srdivacky /// combined SUnits. 113202878Srdivacky void ClusterNeighboringLoads(); 114202878Srdivacky 115193323Sed /// BuildSchedUnits, AddSchedEdges - Helper functions for BuildSchedGraph. 116193323Sed void BuildSchedUnits(); 117193323Sed void AddSchedEdges(); 118193323Sed }; 119193323Sed} 120193323Sed 121193323Sed#endif 122