LLVM API Documentation
00001 //===---- llvm/CodeGen/ScheduleDAGSDNodes.h - SDNode Scheduling -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the ScheduleDAGSDNodes class, which implements 00011 // scheduling for an SDNode-based dependency graph. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CODEGEN_SCHEDULEDAGSDNODES_H 00016 #define LLVM_CODEGEN_SCHEDULEDAGSDNODES_H 00017 00018 #include "llvm/CodeGen/ScheduleDAG.h" 00019 #include "llvm/CodeGen/SelectionDAG.h" 00020 00021 namespace llvm { 00022 /// ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs. 00023 /// 00024 /// Edges between SUnits are initially based on edges in the SelectionDAG, 00025 /// and additional edges can be added by the schedulers as heuristics. 00026 /// SDNodes such as Constants, Registers, and a few others that are not 00027 /// interesting to schedulers are not allocated SUnits. 00028 /// 00029 /// SDNodes with MVT::Flag operands are grouped along with the flagged 00030 /// nodes into a single SUnit so that they are scheduled together. 00031 /// 00032 /// SDNode-based scheduling graphs do not use SDep::Anti or SDep::Output 00033 /// edges. Physical register dependence information is not carried in 00034 /// the DAG and must be handled explicitly by schedulers. 00035 /// 00036 class ScheduleDAGSDNodes : public ScheduleDAG { 00037 public: 00038 explicit ScheduleDAGSDNodes(MachineFunction &mf); 00039 00040 virtual ~ScheduleDAGSDNodes() {} 00041 00042 /// isPassiveNode - Return true if the node is a non-scheduled leaf. 00043 /// 00044 static bool isPassiveNode(SDNode *Node) { 00045 if (isa<ConstantSDNode>(Node)) return true; 00046 if (isa<ConstantFPSDNode>(Node)) return true; 00047 if (isa<RegisterSDNode>(Node)) return true; 00048 if (isa<GlobalAddressSDNode>(Node)) return true; 00049 if (isa<BasicBlockSDNode>(Node)) return true; 00050 if (isa<FrameIndexSDNode>(Node)) return true; 00051 if (isa<ConstantPoolSDNode>(Node)) return true; 00052 if (isa<JumpTableSDNode>(Node)) return true; 00053 if (isa<ExternalSymbolSDNode>(Node)) return true; 00054 if (isa<MemOperandSDNode>(Node)) return true; 00055 if (Node->getOpcode() == ISD::EntryToken) return true; 00056 return false; 00057 } 00058 00059 /// NewSUnit - Creates a new SUnit and return a ptr to it. 00060 /// 00061 SUnit *NewSUnit(SDNode *N) { 00062 #ifndef NDEBUG 00063 const SUnit *Addr = 0; 00064 if (!SUnits.empty()) 00065 Addr = &SUnits[0]; 00066 #endif 00067 SUnits.push_back(SUnit(N, (unsigned)SUnits.size())); 00068 assert((Addr == 0 || Addr == &SUnits[0]) && 00069 "SUnits std::vector reallocated on the fly!"); 00070 SUnits.back().OrigNode = &SUnits.back(); 00071 return &SUnits.back(); 00072 } 00073 00074 /// Clone - Creates a clone of the specified SUnit. It does not copy the 00075 /// predecessors / successors info nor the temporary scheduling states. 00076 /// 00077 SUnit *Clone(SUnit *N); 00078 00079 virtual SelectionDAG *getDAG() { return DAG; } 00080 00081 /// BuildSchedGraph - Build the SUnit graph from the selection dag that we 00082 /// are input. This SUnit graph is similar to the SelectionDAG, but 00083 /// excludes nodes that aren't interesting to scheduling, and represents 00084 /// flagged together nodes with a single SUnit. 00085 virtual void BuildSchedGraph(); 00086 00087 /// ComputeLatency - Compute node latency. 00088 /// 00089 virtual void ComputeLatency(SUnit *SU); 00090 00091 /// CountResults - The results of target nodes have register or immediate 00092 /// operands first, then an optional chain, and optional flag operands 00093 /// (which do not go into the machine instrs.) 00094 static unsigned CountResults(SDNode *Node); 00095 00096 /// CountOperands - The inputs to target nodes have any actual inputs first, 00097 /// followed by special operands that describe memory references, then an 00098 /// optional chain operand, then flag operands. Compute the number of 00099 /// actual operands that will go into the resulting MachineInstr. 00100 static unsigned CountOperands(SDNode *Node); 00101 00102 /// ComputeMemOperandsEnd - Find the index one past the last 00103 /// MemOperandSDNode operand 00104 static unsigned ComputeMemOperandsEnd(SDNode *Node); 00105 00106 /// EmitNode - Generate machine code for an node and needed dependencies. 00107 /// VRBaseMap contains, for each already emitted node, the first virtual 00108 /// register number for the results of the node. 00109 /// 00110 void EmitNode(SDNode *Node, bool IsClone, bool HasClone, 00111 DenseMap<SDValue, unsigned> &VRBaseMap); 00112 00113 virtual MachineBasicBlock *EmitSchedule(); 00114 00115 /// Schedule - Order nodes according to selected style, filling 00116 /// in the Sequence member. 00117 /// 00118 virtual void Schedule() = 0; 00119 00120 virtual void dumpNode(const SUnit *SU) const; 00121 00122 virtual std::string getGraphNodeLabel(const SUnit *SU) const; 00123 00124 virtual void getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const; 00125 00126 private: 00127 /// EmitSubregNode - Generate machine code for subreg nodes. 00128 /// 00129 void EmitSubregNode(SDNode *Node, 00130 DenseMap<SDValue, unsigned> &VRBaseMap); 00131 00132 /// getVR - Return the virtual register corresponding to the specified result 00133 /// of the specified node. 00134 unsigned getVR(SDValue Op, DenseMap<SDValue, unsigned> &VRBaseMap); 00135 00136 /// getDstOfCopyToRegUse - If the only use of the specified result number of 00137 /// node is a CopyToReg, return its destination register. Return 0 otherwise. 00138 unsigned getDstOfOnlyCopyToRegUse(SDNode *Node, unsigned ResNo) const; 00139 00140 void AddOperand(MachineInstr *MI, SDValue Op, unsigned IIOpNum, 00141 const TargetInstrDesc *II, 00142 DenseMap<SDValue, unsigned> &VRBaseMap); 00143 00144 /// EmitCopyFromReg - Generate machine code for an CopyFromReg node or an 00145 /// implicit physical register output. 00146 void EmitCopyFromReg(SDNode *Node, unsigned ResNo, bool IsClone, 00147 bool IsCloned, unsigned SrcReg, 00148 DenseMap<SDValue, unsigned> &VRBaseMap); 00149 00150 void CreateVirtualRegisters(SDNode *Node, MachineInstr *MI, 00151 const TargetInstrDesc &II, bool IsClone, 00152 bool IsCloned, 00153 DenseMap<SDValue, unsigned> &VRBaseMap); 00154 00155 /// BuildSchedUnits, AddSchedEdges - Helper functions for BuildSchedGraph. 00156 void BuildSchedUnits(); 00157 void AddSchedEdges(); 00158 }; 00159 } 00160 00161 #endif