1 //===-- SchedGraphCommon.h - Scheduling Base Graph ---------------*- C++ -*---=//
3 // A common graph class that is based on the SSA graph. It includes
4 // extra dependencies that are caused by machine resources.
6 //===-------------------------------------------------------------------------=//
8 #ifndef LLVM_CODEGEN_SCHEDGRAPHCOMMON_H
9 #define LLVM_CODEGEN_SCHEDGRAPHCOMMON_H
13 #include "llvm/Value.h"
19 /******************** Exported Data Types and Constants ********************/
21 typedef int ResourceId;
22 const ResourceId InvalidRID = -1;
23 const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
24 const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
25 const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
27 //*********************** Public Class Declarations ************************/
29 class SchedGraphNodeCommon {
32 std::vector<SchedGraphEdge*> inEdges;
33 std::vector<SchedGraphEdge*> outEdges;
36 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
39 typedef std::vector<SchedGraphEdge*>:: iterator iterator;
40 typedef std::vector<SchedGraphEdge*>::const_iterator const_iterator;
41 typedef std::vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
42 typedef std::vector<SchedGraphEdge*>::const_reverse_iterator const_reverse_iterator;
45 unsigned getNodeId () const { return ID; }
46 int getLatency () const { return latency; }
47 unsigned getNumInEdges () const { return inEdges.size(); }
48 unsigned getNumOutEdges () const { return outEdges.size(); }
52 iterator beginInEdges () { return inEdges.begin(); }
53 iterator endInEdges () { return inEdges.end(); }
54 iterator beginOutEdges () { return outEdges.begin(); }
55 iterator endOutEdges () { return outEdges.end(); }
57 const_iterator beginInEdges () const { return inEdges.begin(); }
58 const_iterator endInEdges () const { return inEdges.end(); }
59 const_iterator beginOutEdges () const { return outEdges.begin(); }
60 const_iterator endOutEdges () const { return outEdges.end(); }
64 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNodeCommon& node);
66 void dump (int indent=0) const;
69 friend class SchedGraph;
70 friend class SchedGraphCommon;
71 friend class SchedGraphEdge; // give access for adding edges
72 //friend class ModuloSchedGraph;
74 void addInEdge (SchedGraphEdge* edge);
75 void addOutEdge (SchedGraphEdge* edge);
77 void removeInEdge (const SchedGraphEdge* edge);
78 void removeOutEdge (const SchedGraphEdge* edge);
80 // disable default constructor and provide a ctor for single-block graphs
81 SchedGraphNodeCommon(); // DO NOT IMPLEMENT
83 SchedGraphNodeCommon(unsigned Id);
85 virtual ~SchedGraphNodeCommon();
89 class SchedGraphEdge {
91 enum SchedGraphEdgeDepType {
92 CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
94 enum DataDepOrderType {
95 TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
99 SchedGraphNodeCommon* src;
100 SchedGraphNodeCommon* sink;
101 SchedGraphEdgeDepType depType;
102 unsigned int depOrderType;
103 int minDelay; // cached latency (assumes fixed target arch)
109 ResourceId resourceId;
113 // For all constructors, if minDelay is unspecified, minDelay is
114 // set to _src->getLatency().
115 // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
116 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
117 SchedGraphNodeCommon* _sink,
118 SchedGraphEdgeDepType _depType,
119 unsigned int _depOrderType,
122 // constructor for explicit value dependence (may be true/anti/output)
123 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
124 SchedGraphNodeCommon* _sink,
126 unsigned int _depOrderType,
129 // constructor for machine register dependence
130 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
131 SchedGraphNodeCommon* _sink,
132 unsigned int _regNum,
133 unsigned int _depOrderType,
136 // constructor for any other machine resource dependences.
137 // DataDepOrderType is always NonDataDep. It it not an argument to
138 // avoid overloading ambiguity with previous constructor.
139 /*ctor*/ SchedGraphEdge(SchedGraphNodeCommon* _src,
140 SchedGraphNodeCommon* _sink,
141 ResourceId _resourceId,
144 /*dtor*/ ~SchedGraphEdge();
146 SchedGraphNodeCommon* getSrc () const { return src; }
147 SchedGraphNodeCommon* getSink () const { return sink; }
148 int getMinDelay () const { return minDelay; }
149 SchedGraphEdgeDepType getDepType () const { return depType; }
151 const Value* getValue () const {
152 assert(depType == ValueDep); return val;
154 int getMachineReg () const {
155 assert(depType == MachineRegister); return machineRegNum;
157 int getResourceId () const {
158 assert(depType == MachineResource); return resourceId;
160 void setIteDiff (int _iteDiff) {
171 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
173 void dump (int indent=0) const;
176 // disable default ctor
177 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
181 class SchedGraphCommon {
184 SchedGraphNodeCommon* graphRoot; // the root and leaf are not inserted
185 SchedGraphNodeCommon* graphLeaf; // in the hash_map (see getNumNodes())
191 SchedGraphNodeCommon* getRoot() const { return graphRoot; }
192 SchedGraphNodeCommon* getLeaf() const { return graphLeaf; }
195 // Delete nodes or edges from the graph.
197 void eraseNode (SchedGraphNodeCommon* node);
199 void eraseIncomingEdges (SchedGraphNodeCommon* node,
200 bool addDummyEdges = true);
202 void eraseOutgoingEdges (SchedGraphNodeCommon* node,
203 bool addDummyEdges = true);
205 void eraseIncidentEdges (SchedGraphNodeCommon* node,
206 bool addDummyEdges = true);
208 /*ctor*/ SchedGraphCommon ();
209 /*dtor*/ ~SchedGraphCommon ();