2002-08-09 20:08:03 +00:00
|
|
|
//===-- SchedGraph.h - Scheduling Graph --------------------------*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// Scheduling graph based on SSA graph plus extra dependence edges
|
|
|
|
// capturing dependences due to machine resources (machine registers,
|
|
|
|
// CC registers, and any others).
|
|
|
|
//
|
|
|
|
// Strategy:
|
|
|
|
// This graph tries to leverage the SSA graph as much as possible,
|
|
|
|
// but captures the extra dependences through a common interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_SCHEDGRAPH_H
|
|
|
|
#define LLVM_CODEGEN_SCHEDGRAPH_H
|
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2001-11-27 00:03:19 +00:00
|
|
|
#include "Support/HashExtras.h"
|
|
|
|
#include "Support/GraphTraits.h"
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
class Value;
|
|
|
|
class Instruction;
|
2001-09-28 22:56:31 +00:00
|
|
|
class TerminatorInst;
|
2001-08-28 23:06:02 +00:00
|
|
|
class BasicBlock;
|
2002-03-23 22:51:58 +00:00
|
|
|
class Function;
|
2001-08-28 23:06:02 +00:00
|
|
|
class TargetMachine;
|
|
|
|
class SchedGraphEdge;
|
|
|
|
class SchedGraphNode;
|
|
|
|
class SchedGraph;
|
2001-09-30 23:37:26 +00:00
|
|
|
class RegToRefVecMap;
|
2001-11-05 04:04:23 +00:00
|
|
|
class ValueToDefVecMap;
|
|
|
|
class RefVec;
|
2001-09-14 17:55:51 +00:00
|
|
|
class MachineInstr;
|
2002-10-28 00:28:31 +00:00
|
|
|
class MachineBasicBlock;
|
2001-10-28 21:45:02 +00:00
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
/******************** Exported Data Types and Constants ********************/
|
|
|
|
|
|
|
|
typedef int ResourceId;
|
2001-10-28 21:45:02 +00:00
|
|
|
const ResourceId InvalidRID = -1;
|
|
|
|
const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
|
|
|
|
const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
|
|
|
|
const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
//*********************** Public Class Declarations ************************/
|
|
|
|
|
|
|
|
class SchedGraphEdge: public NonCopyable {
|
|
|
|
public:
|
|
|
|
enum SchedGraphEdgeDepType {
|
2001-11-12 18:53:43 +00:00
|
|
|
CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
|
2001-08-28 23:06:02 +00:00
|
|
|
};
|
|
|
|
enum DataDepOrderType {
|
2001-10-28 21:45:02 +00:00
|
|
|
TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
|
2001-08-28 23:06:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SchedGraphNode* src;
|
|
|
|
SchedGraphNode* sink;
|
|
|
|
SchedGraphEdgeDepType depType;
|
2001-10-28 21:45:02 +00:00
|
|
|
unsigned int depOrderType;
|
2001-08-28 23:06:02 +00:00
|
|
|
int minDelay; // cached latency (assumes fixed target arch)
|
|
|
|
|
|
|
|
union {
|
2001-09-30 23:37:26 +00:00
|
|
|
const Value* val;
|
|
|
|
int machineRegNum;
|
|
|
|
ResourceId resourceId;
|
2001-08-28 23:06:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
// For all constructors, if minDelay is unspecified, minDelay is
|
|
|
|
// set to _src->getLatency().
|
|
|
|
// constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
|
|
|
|
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
|
|
|
SchedGraphNode* _sink,
|
|
|
|
SchedGraphEdgeDepType _depType,
|
2001-11-12 18:53:43 +00:00
|
|
|
unsigned int _depOrderType,
|
2001-08-28 23:06:02 +00:00
|
|
|
int _minDelay = -1);
|
|
|
|
|
2001-11-12 18:53:43 +00:00
|
|
|
// constructor for explicit value dependence (may be true/anti/output)
|
2001-08-28 23:06:02 +00:00
|
|
|
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
|
|
|
SchedGraphNode* _sink,
|
2001-09-30 23:37:26 +00:00
|
|
|
const Value* _val,
|
2001-11-12 18:53:43 +00:00
|
|
|
unsigned int _depOrderType,
|
2001-08-28 23:06:02 +00:00
|
|
|
int _minDelay = -1);
|
|
|
|
|
|
|
|
// constructor for machine register dependence
|
|
|
|
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
|
|
|
SchedGraphNode* _sink,
|
|
|
|
unsigned int _regNum,
|
2001-11-12 18:53:43 +00:00
|
|
|
unsigned int _depOrderType,
|
2001-08-28 23:06:02 +00:00
|
|
|
int _minDelay = -1);
|
|
|
|
|
|
|
|
// constructor for any other machine resource dependences.
|
|
|
|
// DataDepOrderType is always NonDataDep. It it not an argument to
|
|
|
|
// avoid overloading ambiguity with previous constructor.
|
|
|
|
/*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
|
|
|
|
SchedGraphNode* _sink,
|
|
|
|
ResourceId _resourceId,
|
|
|
|
int _minDelay = -1);
|
|
|
|
|
2001-09-18 12:49:26 +00:00
|
|
|
/*dtor*/ ~SchedGraphEdge();
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
SchedGraphNode* getSrc () const { return src; }
|
|
|
|
SchedGraphNode* getSink () const { return sink; }
|
|
|
|
int getMinDelay () const { return minDelay; }
|
|
|
|
SchedGraphEdgeDepType getDepType () const { return depType; }
|
|
|
|
|
|
|
|
const Value* getValue () const {
|
2001-11-12 18:53:43 +00:00
|
|
|
assert(depType == ValueDep); return val;
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
|
|
|
int getMachineReg () const {
|
|
|
|
assert(depType == MachineRegister); return machineRegNum;
|
|
|
|
}
|
|
|
|
int getResourceId () const {
|
|
|
|
assert(depType == MachineResource); return resourceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// Debugging support
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-09-07 21:07:10 +00:00
|
|
|
void dump (int indent=0) const;
|
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
private:
|
|
|
|
// disable default ctor
|
|
|
|
/*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SchedGraphNode: public NonCopyable {
|
2002-10-28 18:50:08 +00:00
|
|
|
unsigned nodeId;
|
|
|
|
MachineBasicBlock *MBB;
|
2001-08-28 23:06:02 +00:00
|
|
|
const MachineInstr* minstr;
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<SchedGraphEdge*> inEdges;
|
|
|
|
std::vector<SchedGraphEdge*> outEdges;
|
2001-11-11 01:23:27 +00:00
|
|
|
int origIndexInBB; // original position of machine instr in BB
|
2001-08-28 23:06:02 +00:00
|
|
|
int latency;
|
|
|
|
|
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
typedef std::vector<SchedGraphEdge*>:: iterator iterator;
|
|
|
|
typedef std::vector<SchedGraphEdge*>::const_iterator const_iterator;
|
|
|
|
typedef std::vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
|
|
|
|
typedef std::vector<SchedGraphEdge*>::const_reverse_iterator const_reverse_iterator;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// Accessor methods
|
|
|
|
//
|
2002-10-28 18:50:08 +00:00
|
|
|
unsigned getNodeId () const { return nodeId; }
|
|
|
|
const MachineInstr* getMachineInstr () const { return minstr; }
|
|
|
|
const MachineOpCode getOpCode () const { return minstr->getOpCode(); }
|
|
|
|
int getLatency () const { return latency; }
|
|
|
|
unsigned getNumInEdges () const { return inEdges.size(); }
|
|
|
|
unsigned getNumOutEdges () const { return outEdges.size(); }
|
2001-08-28 23:06:02 +00:00
|
|
|
bool isDummyNode () const { return (minstr == NULL); }
|
2002-10-28 18:50:08 +00:00
|
|
|
MachineBasicBlock &getMachineBasicBlock() const { return *MBB; }
|
2001-11-11 01:23:27 +00:00
|
|
|
int getOrigIndexInBB() const { return origIndexInBB; }
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Iterators
|
|
|
|
//
|
|
|
|
iterator beginInEdges () { return inEdges.begin(); }
|
|
|
|
iterator endInEdges () { return inEdges.end(); }
|
|
|
|
iterator beginOutEdges () { return outEdges.begin(); }
|
|
|
|
iterator endOutEdges () { return outEdges.end(); }
|
|
|
|
|
|
|
|
const_iterator beginInEdges () const { return inEdges.begin(); }
|
|
|
|
const_iterator endInEdges () const { return inEdges.end(); }
|
|
|
|
const_iterator beginOutEdges () const { return outEdges.begin(); }
|
|
|
|
const_iterator endOutEdges () const { return outEdges.end(); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// Debugging support
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-09-07 21:07:10 +00:00
|
|
|
void dump (int indent=0) const;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SchedGraph; // give access for ctor and dtor
|
|
|
|
friend class SchedGraphEdge; // give access for adding edges
|
|
|
|
|
|
|
|
void addInEdge (SchedGraphEdge* edge);
|
|
|
|
void addOutEdge (SchedGraphEdge* edge);
|
|
|
|
|
|
|
|
void removeInEdge (const SchedGraphEdge* edge);
|
|
|
|
void removeOutEdge (const SchedGraphEdge* edge);
|
|
|
|
|
|
|
|
// disable default constructor and provide a ctor for single-block graphs
|
|
|
|
/*ctor*/ SchedGraphNode(); // DO NOT IMPLEMENT
|
2002-10-28 18:50:08 +00:00
|
|
|
/*ctor*/ SchedGraphNode (unsigned nodeId,
|
|
|
|
MachineBasicBlock *mbb,
|
2001-11-11 01:23:27 +00:00
|
|
|
int indexInBB,
|
2002-10-28 18:50:08 +00:00
|
|
|
const TargetMachine& Target);
|
2001-08-28 23:06:02 +00:00
|
|
|
/*dtor*/ ~SchedGraphNode ();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SchedGraph :
|
|
|
|
public NonCopyable,
|
2002-07-24 21:21:32 +00:00
|
|
|
private hash_map<const MachineInstr*, SchedGraphNode*>
|
2001-08-28 23:06:02 +00:00
|
|
|
{
|
2002-10-28 18:50:08 +00:00
|
|
|
MachineBasicBlock &MBB; // basic blocks for this graph
|
2001-08-28 23:06:02 +00:00
|
|
|
SchedGraphNode* graphRoot; // the root and leaf are not inserted
|
|
|
|
SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
|
|
|
|
|
2002-07-24 21:21:32 +00:00
|
|
|
typedef hash_map<const MachineInstr*, SchedGraphNode*> map_base;
|
2001-08-28 23:06:02 +00:00
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
using map_base::iterator;
|
|
|
|
using map_base::const_iterator;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// Accessor methods
|
|
|
|
//
|
2002-10-28 18:50:08 +00:00
|
|
|
MachineBasicBlock &getBasicBlock() const { return MBB; }
|
|
|
|
unsigned getNumNodes() const { return size()+2; }
|
2001-08-28 23:06:02 +00:00
|
|
|
SchedGraphNode* getRoot() const { return graphRoot; }
|
|
|
|
SchedGraphNode* getLeaf() const { return graphLeaf; }
|
|
|
|
|
|
|
|
SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
|
|
|
|
const_iterator onePair = this->find(minstr);
|
|
|
|
return (onePair != this->end())? (*onePair).second : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2001-09-18 12:49:26 +00:00
|
|
|
// Delete nodes or edges from the graph.
|
2001-08-28 23:06:02 +00:00
|
|
|
//
|
2001-09-18 12:49:26 +00:00
|
|
|
void eraseNode (SchedGraphNode* node);
|
|
|
|
|
|
|
|
void eraseIncomingEdges (SchedGraphNode* node,
|
|
|
|
bool addDummyEdges = true);
|
|
|
|
|
|
|
|
void eraseOutgoingEdges (SchedGraphNode* node,
|
|
|
|
bool addDummyEdges = true);
|
|
|
|
|
|
|
|
void eraseIncidentEdges (SchedGraphNode* node,
|
|
|
|
bool addDummyEdges = true);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Unordered iterators.
|
|
|
|
// Return values is pair<const MachineIntr*,SchedGraphNode*>.
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
using map_base::begin;
|
|
|
|
using map_base::end;
|
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
//
|
|
|
|
// Ordered iterators.
|
|
|
|
// Return values is pair<const MachineIntr*,SchedGraphNode*>.
|
|
|
|
//
|
|
|
|
// void postord_init();
|
|
|
|
// postorder_iterator postord_begin();
|
|
|
|
// postorder_iterator postord_end();
|
|
|
|
// const_postorder_iterator postord_begin() const;
|
|
|
|
// const_postorder_iterator postord_end() const;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Debugging support
|
|
|
|
//
|
|
|
|
void dump () const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SchedGraphSet; // give access to ctor
|
|
|
|
|
|
|
|
// disable default constructor and provide a ctor for single-block graphs
|
2002-10-28 18:50:08 +00:00
|
|
|
/*ctor*/ SchedGraph (MachineBasicBlock &bb,
|
2001-08-28 23:06:02 +00:00
|
|
|
const TargetMachine& target);
|
|
|
|
/*dtor*/ ~SchedGraph ();
|
|
|
|
|
|
|
|
inline void noteGraphNodeForInstr (const MachineInstr* minstr,
|
|
|
|
SchedGraphNode* node)
|
|
|
|
{
|
|
|
|
assert((*this)[minstr] == NULL);
|
|
|
|
(*this)[minstr] = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Graph builder
|
|
|
|
//
|
2001-10-28 21:45:02 +00:00
|
|
|
void buildGraph (const TargetMachine& target);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2002-10-28 18:50:08 +00:00
|
|
|
void buildNodesForBB (const TargetMachine& target,
|
|
|
|
MachineBasicBlock &MBB,
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<SchedGraphNode*>& memNod,
|
2001-11-05 04:04:23 +00:00
|
|
|
RegToRefVecMap& regToRefVecMap,
|
|
|
|
ValueToDefVecMap& valueToDefVecMap);
|
|
|
|
|
|
|
|
void findDefUseInfoAtInstr (const TargetMachine& target,
|
|
|
|
SchedGraphNode* node,
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<SchedGraphNode*>& memNode,
|
2001-11-05 04:04:23 +00:00
|
|
|
RegToRefVecMap& regToRefVecMap,
|
|
|
|
ValueToDefVecMap& valueToDefVecMap);
|
|
|
|
|
2001-11-08 05:20:23 +00:00
|
|
|
void addEdgesForInstruction(const MachineInstr& minstr,
|
2001-11-05 04:04:23 +00:00
|
|
|
const ValueToDefVecMap& valueToDefVecMap,
|
|
|
|
const TargetMachine& target);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
void addCDEdges (const TerminatorInst* term,
|
|
|
|
const TargetMachine& target);
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
void addMemEdges (const std::vector<SchedGraphNode*>& memNod,
|
2001-11-08 05:20:23 +00:00
|
|
|
const TargetMachine& target);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
void addCallCCEdges (const std::vector<SchedGraphNode*>& memNod,
|
2002-10-28 00:28:31 +00:00
|
|
|
MachineBasicBlock& bbMvec,
|
2001-11-08 05:20:23 +00:00
|
|
|
const TargetMachine& target);
|
2001-10-28 21:45:02 +00:00
|
|
|
|
2001-09-30 23:37:26 +00:00
|
|
|
void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
|
2001-08-28 23:06:02 +00:00
|
|
|
const TargetMachine& target);
|
|
|
|
|
2001-11-12 18:53:43 +00:00
|
|
|
void addEdgesForValue (SchedGraphNode* refNode,
|
2001-11-05 04:04:23 +00:00
|
|
|
const RefVec& defVec,
|
2001-10-17 23:55:16 +00:00
|
|
|
const Value* defValue,
|
2001-11-12 18:53:43 +00:00
|
|
|
bool refNodeIsDef,
|
2002-07-08 22:59:23 +00:00
|
|
|
bool refNodeIsDefAndUse,
|
2001-08-28 23:06:02 +00:00
|
|
|
const TargetMachine& target);
|
|
|
|
|
|
|
|
void addDummyEdges ();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SchedGraphSet :
|
|
|
|
public NonCopyable,
|
2002-03-24 03:53:03 +00:00
|
|
|
private std::vector<SchedGraph*>
|
2001-08-28 23:06:02 +00:00
|
|
|
{
|
|
|
|
private:
|
2002-03-23 22:51:58 +00:00
|
|
|
const Function* method;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
public:
|
2002-03-24 03:53:03 +00:00
|
|
|
typedef std::vector<SchedGraph*> baseVector;
|
|
|
|
using baseVector::iterator;
|
|
|
|
using baseVector::const_iterator;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
public:
|
2002-03-23 22:51:58 +00:00
|
|
|
/*ctor*/ SchedGraphSet (const Function * function,
|
2001-08-28 23:06:02 +00:00
|
|
|
const TargetMachine& target);
|
|
|
|
/*dtor*/ ~SchedGraphSet ();
|
|
|
|
|
|
|
|
// Iterators
|
2002-03-24 03:53:03 +00:00
|
|
|
using baseVector::begin;
|
|
|
|
using baseVector::end;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
// Debugging support
|
|
|
|
void dump () const;
|
|
|
|
|
|
|
|
private:
|
2002-03-24 03:53:03 +00:00
|
|
|
inline void addGraph(SchedGraph* graph) {
|
|
|
|
assert(graph != NULL);
|
|
|
|
this->push_back(graph);
|
2001-08-28 23:06:02 +00:00
|
|
|
}
|
2002-03-24 03:53:03 +00:00
|
|
|
|
2001-08-28 23:06:02 +00:00
|
|
|
// Graph builder
|
2002-03-23 22:51:58 +00:00
|
|
|
void buildGraphsForMethod (const Function *F,
|
2001-08-28 23:06:02 +00:00
|
|
|
const TargetMachine& target);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//********************** Sched Graph Iterators *****************************/
|
|
|
|
|
|
|
|
// Ok to make it a template because it shd get instantiated at most twice:
|
|
|
|
// for <SchedGraphNode, SchedGraphNode::iterator> and
|
|
|
|
// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
|
|
|
|
//
|
|
|
|
template <class _NodeType, class _EdgeType, class _EdgeIter>
|
2002-07-25 06:17:51 +00:00
|
|
|
class SGPredIterator: public bidirectional_iterator<_NodeType, ptrdiff_t> {
|
2001-08-28 23:06:02 +00:00
|
|
|
protected:
|
|
|
|
_EdgeIter oi;
|
|
|
|
public:
|
2002-02-12 22:39:50 +00:00
|
|
|
typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2002-02-12 22:39:50 +00:00
|
|
|
inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
inline bool operator==(const _Self& x) const { return oi == x.oi; }
|
|
|
|
inline bool operator!=(const _Self& x) const { return !operator==(x); }
|
|
|
|
|
|
|
|
// operator*() differs for pred or succ iterator
|
2001-09-07 21:07:10 +00:00
|
|
|
inline _NodeType* operator*() const { return (*oi)->getSrc(); }
|
2001-08-28 23:06:02 +00:00
|
|
|
inline _NodeType* operator->() const { return operator*(); }
|
|
|
|
|
|
|
|
inline _EdgeType* getEdge() const { return *(oi); }
|
|
|
|
|
2001-09-07 21:07:10 +00:00
|
|
|
inline _Self &operator++() { ++oi; return *this; } // Preincrement
|
|
|
|
inline _Self operator++(int) { // Postincrement
|
|
|
|
_Self tmp(*this); ++*this; return tmp;
|
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-09-07 21:07:10 +00:00
|
|
|
inline _Self &operator--() { --oi; return *this; } // Predecrement
|
|
|
|
inline _Self operator--(int) { // Postdecrement
|
|
|
|
_Self tmp = *this; --*this; return tmp;
|
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _NodeType, class _EdgeType, class _EdgeIter>
|
2002-07-25 06:17:51 +00:00
|
|
|
class SGSuccIterator : public bidirectional_iterator<_NodeType, ptrdiff_t> {
|
2001-09-07 21:07:10 +00:00
|
|
|
protected:
|
|
|
|
_EdgeIter oi;
|
2001-08-28 23:06:02 +00:00
|
|
|
public:
|
2002-02-12 22:39:50 +00:00
|
|
|
typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2002-02-12 22:39:50 +00:00
|
|
|
inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
|
2001-09-07 21:07:10 +00:00
|
|
|
|
|
|
|
inline bool operator==(const _Self& x) const { return oi == x.oi; }
|
|
|
|
inline bool operator!=(const _Self& x) const { return !operator==(x); }
|
|
|
|
|
|
|
|
inline _NodeType* operator*() const { return (*oi)->getSink(); }
|
|
|
|
inline _NodeType* operator->() const { return operator*(); }
|
2001-08-28 23:06:02 +00:00
|
|
|
|
2001-09-07 21:07:10 +00:00
|
|
|
inline _EdgeType* getEdge() const { return *(oi); }
|
|
|
|
|
|
|
|
inline _Self &operator++() { ++oi; return *this; } // Preincrement
|
|
|
|
inline _Self operator++(int) { // Postincrement
|
|
|
|
_Self tmp(*this); ++*this; return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline _Self &operator--() { --oi; return *this; } // Predecrement
|
|
|
|
inline _Self operator--(int) { // Postdecrement
|
|
|
|
_Self tmp = *this; --*this; return tmp;
|
|
|
|
}
|
2001-08-28 23:06:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// sg_pred_iterator
|
|
|
|
// sg_pred_const_iterator
|
|
|
|
//
|
2002-02-12 22:39:50 +00:00
|
|
|
typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
|
2001-08-28 23:06:02 +00:00
|
|
|
sg_pred_iterator;
|
2002-02-12 22:39:50 +00:00
|
|
|
typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
|
2001-08-28 23:06:02 +00:00
|
|
|
sg_pred_const_iterator;
|
|
|
|
|
|
|
|
inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
|
|
|
|
return sg_pred_iterator(N->beginInEdges());
|
|
|
|
}
|
|
|
|
inline sg_pred_iterator pred_end( SchedGraphNode *N) {
|
|
|
|
return sg_pred_iterator(N->endInEdges());
|
|
|
|
}
|
|
|
|
inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
|
|
|
|
return sg_pred_const_iterator(N->beginInEdges());
|
|
|
|
}
|
|
|
|
inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) {
|
|
|
|
return sg_pred_const_iterator(N->endInEdges());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// sg_succ_iterator
|
|
|
|
// sg_succ_const_iterator
|
|
|
|
//
|
2002-02-12 22:39:50 +00:00
|
|
|
typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
|
2001-08-28 23:06:02 +00:00
|
|
|
sg_succ_iterator;
|
2002-02-12 22:39:50 +00:00
|
|
|
typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
|
2001-08-28 23:06:02 +00:00
|
|
|
sg_succ_const_iterator;
|
|
|
|
|
|
|
|
inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
|
|
|
|
return sg_succ_iterator(N->beginOutEdges());
|
|
|
|
}
|
|
|
|
inline sg_succ_iterator succ_end( SchedGraphNode *N) {
|
|
|
|
return sg_succ_iterator(N->endOutEdges());
|
|
|
|
}
|
|
|
|
inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
|
|
|
|
return sg_succ_const_iterator(N->beginOutEdges());
|
|
|
|
}
|
|
|
|
inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) {
|
|
|
|
return sg_succ_const_iterator(N->endOutEdges());
|
|
|
|
}
|
|
|
|
|
2001-09-28 22:56:31 +00:00
|
|
|
// Provide specializations of GraphTraits to be able to use graph iterators on
|
|
|
|
// the scheduling graph!
|
2001-08-28 23:06:02 +00:00
|
|
|
//
|
2001-09-28 22:56:31 +00:00
|
|
|
template <> struct GraphTraits<SchedGraph*> {
|
|
|
|
typedef SchedGraphNode NodeType;
|
|
|
|
typedef sg_succ_iterator ChildIteratorType;
|
|
|
|
|
|
|
|
static inline NodeType *getEntryNode(SchedGraph *SG) { return SG->getRoot(); }
|
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
|
|
|
return succ_begin(N);
|
|
|
|
}
|
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
|
|
|
return succ_end(N);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct GraphTraits<const SchedGraph*> {
|
|
|
|
typedef const SchedGraphNode NodeType;
|
|
|
|
typedef sg_succ_const_iterator ChildIteratorType;
|
|
|
|
|
|
|
|
static inline NodeType *getEntryNode(const SchedGraph *SG) {
|
|
|
|
return SG->getRoot();
|
|
|
|
}
|
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
|
|
|
return succ_begin(N);
|
|
|
|
}
|
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
|
|
|
return succ_end(N);
|
|
|
|
}
|
|
|
|
};
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge);
|
|
|
|
std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node);
|
2001-08-28 23:06:02 +00:00
|
|
|
|
|
|
|
#endif
|