mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-28 06:32:09 +00:00
Made the code readable:
* Lines must be wrapped at 80 chars. This is a hard limit. * Consistent style on functions, braces, if, for, etc. Code must be readable. No functional changes have been made, even though I added a new typedef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5768 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4bd8b24470
commit
8baa01c1d7
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
//===- ModuloSchedGraph.h - Represent a collection of data structures ----*- C++ -*-===//
|
||||
//===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===//
|
||||
//
|
||||
// This header defines the primative classes that make up a data structure
|
||||
// graph.
|
||||
@ -7,82 +7,111 @@
|
||||
|
||||
#ifndef LLVM_CODEGEN_MODULO_SCHED_GRAPH_H
|
||||
#define LLVM_CODEGEN_MODULO_SCHED_GRAPH_H
|
||||
|
||||
#include "Support/HashExtras.h"
|
||||
#include "Support/GraphTraits.h"
|
||||
#include "../InstrSched/SchedGraphCommon.h"
|
||||
|
||||
#include "llvm/Instruction.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetInstrInfo.h"
|
||||
#include "Support/HashExtras.h"
|
||||
#include "Support/GraphTraits.h"
|
||||
#include "../InstrSched/SchedGraphCommon.h"
|
||||
#include <iostream>
|
||||
using std::pair;
|
||||
|
||||
//for debug information selecton
|
||||
enum ModuloSchedDebugLevel_t{
|
||||
enum ModuloSchedDebugLevel_t {
|
||||
ModuloSched_NoDebugInfo,
|
||||
ModuloSched_Disable,
|
||||
ModuloSched_PrintSchedule,
|
||||
ModuloSched_PrintScheduleProcess,
|
||||
};
|
||||
|
||||
//===============------------------------------------------------------------------------
|
||||
///ModuloSchedGraphNode - Implement a data structure based on the SchedGraphNodeCommon
|
||||
///this class stores informtion needed later to order the nodes in modulo scheduling
|
||||
///
|
||||
class ModuloSchedGraphNode: public SchedGraphNodeCommon {
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ModuloSchedGraphNode - Implement a data structure based on the
|
||||
// SchedGraphNodeCommon this class stores informtion needed later to order the
|
||||
// nodes in modulo scheduling
|
||||
//
|
||||
class ModuloSchedGraphNode:public SchedGraphNodeCommon {
|
||||
private:
|
||||
//the corresponding instruction
|
||||
const Instruction* inst;
|
||||
// the corresponding instruction
|
||||
const Instruction *inst;
|
||||
|
||||
//whether this node's property(ASAP,ALAP, ...) has been computed
|
||||
// whether this node's property(ASAP,ALAP, ...) has been computed
|
||||
bool propertyComputed;
|
||||
|
||||
//ASAP: the earliest time the node could be scheduled
|
||||
//ALAP: the latest time the node couldbe scheduled
|
||||
//depth: the depth of the node
|
||||
//height: the height of the node
|
||||
//mov: the mobility function, computed as ALAP - ASAP
|
||||
//scheTime: the scheduled time if this node has been scheduled
|
||||
//earlyStart: the earliest time to be tried to schedule the node
|
||||
//lateStart: the latest time to be tried to schedule the node
|
||||
// ASAP: the earliest time the node could be scheduled
|
||||
// ALAP: the latest time the node couldbe scheduled
|
||||
// depth: the depth of the node
|
||||
// height: the height of the node
|
||||
// mov: the mobility function, computed as ALAP - ASAP
|
||||
// scheTime: the scheduled time if this node has been scheduled
|
||||
// earlyStart: the earliest time to be tried to schedule the node
|
||||
// lateStart: the latest time to be tried to schedule the node
|
||||
int ASAP, ALAP, depth, height, mov;
|
||||
int schTime;
|
||||
int earlyStart,lateStart;
|
||||
int earlyStart, lateStart;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
//get the instruction
|
||||
const Instruction* getInst() const { return inst;}
|
||||
|
||||
const Instruction *getInst() const {
|
||||
return inst;
|
||||
}
|
||||
//get the instruction op-code name
|
||||
const char* getInstOpcodeName() const{ return inst->getOpcodeName();}
|
||||
|
||||
//get the instruction op-code
|
||||
const unsigned getInstOpcode() const { return inst->getOpcode();}
|
||||
|
||||
const char *getInstOpcodeName() const {
|
||||
return inst->getOpcodeName();
|
||||
}
|
||||
//get the instruction op-code
|
||||
const unsigned getInstOpcode() const {
|
||||
return inst->getOpcode();
|
||||
}
|
||||
//return whether the node is NULL
|
||||
bool isNullNode() const{ return(inst== NULL);}
|
||||
|
||||
bool isNullNode() const {
|
||||
return (inst == NULL);
|
||||
}
|
||||
//return whether the property of the node has been computed
|
||||
bool getPropertyComputed() {return propertyComputed;}
|
||||
|
||||
bool getPropertyComputed() {
|
||||
return propertyComputed;
|
||||
}
|
||||
//set the propertyComputed
|
||||
void setPropertyComputed(bool _propertyComputed) {propertyComputed = _propertyComputed;}
|
||||
|
||||
void setPropertyComputed(bool _propertyComputed) {
|
||||
propertyComputed = _propertyComputed;
|
||||
}
|
||||
|
||||
//get the corresponding property
|
||||
int getASAP(){ return ASAP;}
|
||||
int getALAP(){ return ALAP;}
|
||||
int getMov() { return mov;}
|
||||
int getDepth(){return depth;}
|
||||
int getHeight(){return height;}
|
||||
int getSchTime(){return schTime;}
|
||||
int getEarlyStart(){return earlyStart;}
|
||||
int getLateStart() { return lateStart;}
|
||||
void setEarlyStart(int _earlyStart) {earlyStart= _earlyStart;}
|
||||
void setLateStart(int _lateStart) {lateStart= _lateStart;}
|
||||
void setSchTime(int _time){schTime=_time;}
|
||||
int getASAP() {
|
||||
return ASAP;
|
||||
}
|
||||
int getALAP() {
|
||||
return ALAP;
|
||||
}
|
||||
int getMov() {
|
||||
return mov;
|
||||
}
|
||||
int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
int getHeight() {
|
||||
return height;
|
||||
}
|
||||
int getSchTime() {
|
||||
return schTime;
|
||||
}
|
||||
int getEarlyStart() {
|
||||
return earlyStart;
|
||||
}
|
||||
int getLateStart() {
|
||||
return lateStart;
|
||||
}
|
||||
void setEarlyStart(int _earlyStart) {
|
||||
earlyStart = _earlyStart;
|
||||
}
|
||||
void setLateStart(int _lateStart) {
|
||||
lateStart = _lateStart;
|
||||
}
|
||||
void setSchTime(int _time) {
|
||||
schTime = _time;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
friend class ModuloSchedGraph;
|
||||
friend class SchedGraphNode;
|
||||
|
||||
@ -93,43 +122,34 @@ public:
|
||||
//indexInBB: the corresponding instruction's index in the BasicBlock
|
||||
//target: the targetMachine
|
||||
ModuloSchedGraphNode(unsigned int _nodeId,
|
||||
const BasicBlock* _bb,
|
||||
const Instruction* _inst,
|
||||
int indexInBB,
|
||||
const TargetMachine& target);
|
||||
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os,const ModuloSchedGraphNode& edge);
|
||||
|
||||
const BasicBlock * _bb,
|
||||
const Instruction * _inst,
|
||||
int indexInBB, const TargetMachine &target);
|
||||
|
||||
|
||||
friend std::ostream & operator<<(std::ostream & os,
|
||||
const ModuloSchedGraphNode & edge);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//FIXME: these two value should not be used
|
||||
#define MAXNODE 100
|
||||
#define MAXCC 100
|
||||
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// ModuloSchedGraph- the data structure to store dependence between nodes
|
||||
/// it catches data dependence and constrol dependence
|
||||
///
|
||||
///
|
||||
|
||||
class ModuloSchedGraph:
|
||||
class ModuloSchedGraph :
|
||||
public SchedGraphCommon,
|
||||
protected hash_map<const Instruction*, ModuloSchedGraphNode*>
|
||||
{
|
||||
|
||||
private:
|
||||
protected hash_map<const Instruction*,ModuloSchedGraphNode*> {
|
||||
|
||||
private:
|
||||
//iteration Interval
|
||||
int MII;
|
||||
|
||||
|
||||
//target machine
|
||||
const TargetMachine& target;
|
||||
const TargetMachine & target;
|
||||
|
||||
//the circuits in the dependence graph
|
||||
unsigned circuits[MAXCC][MAXNODE];
|
||||
@ -140,20 +160,20 @@ private:
|
||||
typedef std::vector<ModuloSchedGraphNode*> NodeVec;
|
||||
|
||||
//the function to compute properties
|
||||
void computeNodeASAP(const BasicBlock* bb);
|
||||
void computeNodeALAP(const BasicBlock* bb);
|
||||
void computeNodeMov(const BasicBlock* bb);
|
||||
void computeNodeDepth(const BasicBlock* bb);
|
||||
void computeNodeHeight(const BasicBlock* bb);
|
||||
void computeNodeASAP(const BasicBlock * bb);
|
||||
void computeNodeALAP(const BasicBlock * bb);
|
||||
void computeNodeMov(const BasicBlock * bb);
|
||||
void computeNodeDepth(const BasicBlock * bb);
|
||||
void computeNodeHeight(const BasicBlock * bb);
|
||||
|
||||
//the function to compute node property
|
||||
void computeNodeProperty(const BasicBlock* bb);
|
||||
void computeNodeProperty(const BasicBlock * bb);
|
||||
|
||||
//the function to sort nodes
|
||||
void orderNodes();
|
||||
|
||||
|
||||
//add the resource usage
|
||||
void addResourceUsage(std::vector<pair<int,int> >&, int);
|
||||
void addResourceUsage(std::vector<pair<int,int>>&, int);
|
||||
|
||||
//debug functions:
|
||||
//dump circuits
|
||||
@ -161,13 +181,13 @@ private:
|
||||
//dump the input set of nodes
|
||||
void dumpSet(std::vector<ModuloSchedGraphNode*> set);
|
||||
//dump the input resource usage table
|
||||
void dumpResourceUsage(std::vector<pair<int,int> >&);
|
||||
|
||||
public:
|
||||
void dumpResourceUsage(std::vector<pair<int,int>> &);
|
||||
|
||||
public:
|
||||
//help functions
|
||||
|
||||
|
||||
//get the maxium the delay between two nodes
|
||||
SchedGraphEdge* getMaxDelayEdge(unsigned srcId, unsigned sinkId);
|
||||
SchedGraphEdge *getMaxDelayEdge(unsigned srcId, unsigned sinkId);
|
||||
|
||||
//FIXME:
|
||||
//get the predessor Set of the set
|
||||
@ -175,174 +195,171 @@ private:
|
||||
NodeVec predSet(NodeVec set);
|
||||
|
||||
//get the predessor set of the node
|
||||
NodeVec predSet(ModuloSchedGraphNode* node, unsigned,unsigned);
|
||||
NodeVec predSet(ModuloSchedGraphNode* node);
|
||||
NodeVec predSet(ModuloSchedGraphNode * node, unsigned, unsigned);
|
||||
NodeVec predSet(ModuloSchedGraphNode * node);
|
||||
|
||||
//get the successor set of the set
|
||||
NodeVec succSet(NodeVec set, unsigned, unsigned);
|
||||
NodeVec succSet(NodeVec set);
|
||||
|
||||
|
||||
//get the succssor set of the node
|
||||
NodeVec succSet(ModuloSchedGraphNode* node,unsigned, unsigned);
|
||||
NodeVec succSet(ModuloSchedGraphNode* node);
|
||||
NodeVec succSet(ModuloSchedGraphNode * node, unsigned, unsigned);
|
||||
NodeVec succSet(ModuloSchedGraphNode * node);
|
||||
|
||||
//return the uniton of the two vectors
|
||||
NodeVec vectorUnion(NodeVec set1,NodeVec set2 );
|
||||
NodeVec vectorUnion(NodeVec set1, NodeVec set2);
|
||||
|
||||
//return the consjuction of the two vectors
|
||||
NodeVec vectorConj(NodeVec set1,NodeVec set2 );
|
||||
|
||||
NodeVec vectorConj(NodeVec set1, NodeVec set2);
|
||||
|
||||
//return all nodes in set1 but not set2
|
||||
NodeVec vectorSub(NodeVec set1, NodeVec set2);
|
||||
|
||||
typedef hash_map<const Instruction*, ModuloSchedGraphNode*> map_base;
|
||||
typedef hash_map<const Instruction*,ModuloSchedGraphNode*> map_base;
|
||||
|
||||
public:
|
||||
using map_base::iterator;
|
||||
using map_base::const_iterator;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//get target machine
|
||||
const TargetMachine& getTarget(){return target;}
|
||||
|
||||
const TargetMachine & getTarget() {
|
||||
return target;
|
||||
}
|
||||
//get the iteration interval
|
||||
const int getMII(){return MII;}
|
||||
const int getMII() {
|
||||
return MII;
|
||||
}
|
||||
|
||||
//get the ordered nodes
|
||||
const NodeVec& getONodes(){return oNodes;}
|
||||
const NodeVec & getONodes() {
|
||||
return oNodes;
|
||||
}
|
||||
|
||||
//get the number of nodes (including the root and leaf)
|
||||
//note: actually root and leaf is not used
|
||||
const unsigned int getNumNodes() const {return size()+2;}
|
||||
|
||||
const unsigned int getNumNodes() const {
|
||||
return size() + 2;
|
||||
}
|
||||
//return wether the BasicBlock 'bb' contains a loop
|
||||
bool isLoop (const BasicBlock* bb);
|
||||
bool isLoop(const BasicBlock * bb);
|
||||
|
||||
//return this basibBlock contains a loop
|
||||
bool isLoop ();
|
||||
|
||||
bool isLoop();
|
||||
|
||||
|
||||
//return the node for the input instruction
|
||||
ModuloSchedGraphNode* getGraphNodeForInst(const Instruction* inst) const{
|
||||
ModuloSchedGraphNode *getGraphNodeForInst(const Instruction * inst) const {
|
||||
const_iterator onePair = this->find(inst);
|
||||
return (onePair != this->end())?(*onePair).second: NULL;
|
||||
return (onePair != this->end()) ? (*onePair).second : NULL;
|
||||
}
|
||||
|
||||
//Debugging support
|
||||
//dump the graph
|
||||
void dump() const;
|
||||
//Debugging support//dump the graph void dump() const;
|
||||
//dump the basicBlock
|
||||
void dump(const BasicBlock* bb);
|
||||
void dump(const BasicBlock * bb);
|
||||
//dump the basicBlock into 'os' stream
|
||||
void dump(const BasicBlock* bb, std::ostream& os);
|
||||
void dump(const BasicBlock * bb, std::ostream & os);
|
||||
//dump the node property
|
||||
void dumpNodeProperty() const ;
|
||||
|
||||
private:
|
||||
friend class ModuloSchedGraphSet; //give access to ctor
|
||||
void dumpNodeProperty() const;
|
||||
|
||||
public:
|
||||
/*ctr*/
|
||||
ModuloSchedGraph(const BasicBlock* bb, const TargetMachine& _target)
|
||||
:SchedGraphCommon(bb), target(_target){
|
||||
private:
|
||||
friend class ModuloSchedGraphSet; //give access to ctor
|
||||
|
||||
public:
|
||||
ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &_target)
|
||||
:SchedGraphCommon(bb), target(_target) {
|
||||
buildGraph(target);
|
||||
}
|
||||
|
||||
/*dtr*/
|
||||
~ModuloSchedGraph(){
|
||||
for(const_iterator I=begin(); I!=end(); ++I)
|
||||
~ModuloSchedGraph() {
|
||||
for (const_iterator I = begin(); I != end(); ++I)
|
||||
delete I->second;
|
||||
}
|
||||
|
||||
|
||||
//unorder iterators
|
||||
//return values are pair<const Instruction*, ModuloSchedGraphNode*>
|
||||
using map_base::begin;
|
||||
using map_base::end;
|
||||
|
||||
void noteModuloSchedGraphNodeForInst(const Instruction *inst,
|
||||
ModuloSchedGraphNode *node)
|
||||
{
|
||||
assert((*this)[inst] == NULL);
|
||||
(*this)[inst] = node;
|
||||
}
|
||||
|
||||
|
||||
inline void noteModuloSchedGraphNodeForInst(const Instruction* inst,
|
||||
ModuloSchedGraphNode* node)
|
||||
{
|
||||
assert((*this)[inst] ==NULL);
|
||||
(*this)[inst]=node;
|
||||
}
|
||||
|
||||
//Graph builder
|
||||
|
||||
ModuloSchedGraphNode* getNode (const unsigned nodeId) const;
|
||||
|
||||
ModuloSchedGraphNode *getNode(const unsigned nodeId) const;
|
||||
|
||||
//build the graph from the basicBlock
|
||||
void buildGraph (const TargetMachine& target);
|
||||
void buildGraph(const TargetMachine & target);
|
||||
|
||||
//Build nodes for BasicBlock
|
||||
void buildNodesforBB (const TargetMachine& target,
|
||||
const BasicBlock* bb,
|
||||
NodeVec& memNode,
|
||||
RegToRefVecMap& regToRefVecMap,
|
||||
ValueToDefVecMap& valueToDefVecMap);
|
||||
void buildNodesforBB(const TargetMachine &target,
|
||||
const BasicBlock *bb,
|
||||
NodeVec &memNode,
|
||||
RegToRefVecMap ®ToRefVecMap,
|
||||
ValueToDefVecMap &valueToDefVecMap);
|
||||
|
||||
//find definitiona and use information for all nodes
|
||||
void findDefUseInfoAtInstr (const TargetMachine& target,
|
||||
ModuloSchedGraphNode* node,
|
||||
NodeVec& memNode,
|
||||
RegToRefVecMap& regToRefVecMap,
|
||||
ValueToDefVecMap& valueToDefVecMap);
|
||||
void findDefUseInfoAtInstr(const TargetMachine &target,
|
||||
ModuloSchedGraphNode *node,
|
||||
NodeVec &memNode,
|
||||
RegToRefVecMap ®ToRefVecMap,
|
||||
ValueToDefVecMap &valueToDefVecMap);
|
||||
|
||||
//add def-use edge
|
||||
void addDefUseEdges (const BasicBlock* bb);
|
||||
void addDefUseEdges(const BasicBlock *bb);
|
||||
|
||||
//add control dependence edges
|
||||
void addCDEdges (const BasicBlock* bb);
|
||||
void addCDEdges(const BasicBlock *bb);
|
||||
|
||||
//add memory dependence dges
|
||||
void addMemEdges (const BasicBlock* bb);
|
||||
void addMemEdges(const BasicBlock *bb);
|
||||
|
||||
//add dummy edges
|
||||
void addDummyEdges();
|
||||
|
||||
//computer source restrictoin II
|
||||
int computeResII (const BasicBlock* bb);
|
||||
int computeResII(const BasicBlock *bb);
|
||||
|
||||
//computer recurrence II
|
||||
int computeRecII (const BasicBlock* bb);
|
||||
int computeRecII(const BasicBlock *bb);
|
||||
};
|
||||
|
||||
///==================================-
|
||||
//gragh set
|
||||
//==================================-
|
||||
// Graph set
|
||||
|
||||
class ModuloSchedGraphSet:
|
||||
public std::vector<ModuloSchedGraph*>
|
||||
{
|
||||
class ModuloSchedGraphSet : public std::vector<ModuloSchedGraph*> {
|
||||
private:
|
||||
const Function* method;
|
||||
|
||||
const Function *method;
|
||||
|
||||
public:
|
||||
typedef std::vector<ModuloSchedGraph*> baseVector;
|
||||
using baseVector::iterator;
|
||||
using baseVector::const_iterator;
|
||||
|
||||
|
||||
public:
|
||||
/*ctor*/ ModuloSchedGraphSet (const Function* function, const TargetMachine& target);
|
||||
|
||||
/*dtor*/ ~ModuloSchedGraphSet ();
|
||||
|
||||
//iterators
|
||||
ModuloSchedGraphSet(const Function *function, const TargetMachine &target);
|
||||
~ModuloSchedGraphSet();
|
||||
|
||||
// Iterators
|
||||
using baseVector::begin;
|
||||
using baseVector::end;
|
||||
|
||||
// Debugging support
|
||||
void dump() const;
|
||||
|
||||
//Debugging support
|
||||
void dump() const;
|
||||
|
||||
private:
|
||||
inline void addGraph(ModuloSchedGraph* graph){
|
||||
assert(graph !=NULL);
|
||||
void addGraph(ModuloSchedGraph *graph) {
|
||||
assert(graph != NULL);
|
||||
this->push_back(graph);
|
||||
}
|
||||
|
||||
//Graph builder
|
||||
void buildGraphsForMethod (const Function *F, const TargetMachine& target);
|
||||
};
|
||||
|
||||
#endif
|
||||
// Graph builder
|
||||
void buildGraphsForMethod(const Function *F,
|
||||
const TargetMachine &target);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
//// - head file for the classes ModuloScheduling and ModuloScheduling ----*- C++ -*-===//
|
||||
// ModuloScheduling.h -------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This header defines the the classes ModuloScheduling and ModuloSchedulingSet 's structure
|
||||
//
|
||||
// This header defines the the classes ModuloScheduling and
|
||||
// ModuloSchedulingSet's structure
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@ -13,151 +13,148 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
class ModuloScheduling: NonCopyable {
|
||||
private:
|
||||
|
||||
class ModuloScheduling:NonCopyable {
|
||||
private:
|
||||
typedef std::vector<ModuloSchedGraphNode*> NodeVec;
|
||||
|
||||
/// the graph to feed in
|
||||
ModuloSchedGraph& graph;
|
||||
const TargetMachine& target;
|
||||
|
||||
//the BasicBlock to be scheduled
|
||||
BasicBlock* bb;
|
||||
typedef std::vector<std::vector<unsigned> > Resources;
|
||||
|
||||
///Iteration Intervel
|
||||
///FIXME: II may be a better name for its meaning
|
||||
// The graph to feed in
|
||||
ModuloSchedGraph &graph;
|
||||
const TargetMachine ⌖
|
||||
|
||||
// The BasicBlock to be scheduled
|
||||
BasicBlock *bb;
|
||||
|
||||
// Iteration Interval
|
||||
// FIXME: II may be a better name for its meaning
|
||||
unsigned II;
|
||||
|
||||
//the vector containing the nodes which have been scheduled
|
||||
// The vector containing the nodes which have been scheduled
|
||||
NodeVec nodeScheduled;
|
||||
|
||||
///the remaining unscheduled nodes
|
||||
const NodeVec& oNodes;
|
||||
|
||||
///the machine resource table
|
||||
std::vector< std::vector<pair<int,int> > > resourceTable ;
|
||||
|
||||
|
||||
// The remaining unscheduled nodes
|
||||
const NodeVec &oNodes;
|
||||
|
||||
// The machine resource table
|
||||
std::vector<std::vector<std::pair<int,int> > > resourceTable;
|
||||
|
||||
///the schedule( with many schedule stage)
|
||||
std::vector<std::vector<ModuloSchedGraphNode*> > schedule;
|
||||
|
||||
|
||||
///the kernel(core) schedule(length = II)
|
||||
std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule;
|
||||
|
||||
typedef BasicBlock::InstListType InstListType;
|
||||
typedef std::vector <std::vector<ModuloSchedGraphNode*> > vvNodeType;
|
||||
|
||||
|
||||
typedef BasicBlock::InstListType InstListType;
|
||||
typedef std::vector<std::vector<ModuloSchedGraphNode*> > vvNodeType;
|
||||
|
||||
public:
|
||||
|
||||
///constructor
|
||||
ModuloScheduling(ModuloSchedGraph& _graph):
|
||||
graph(_graph),
|
||||
target(graph.getTarget()),
|
||||
oNodes(graph.getONodes())
|
||||
{
|
||||
II = graph.getMII();
|
||||
bb=(BasicBlock*)graph.getBasicBlocks()[0];
|
||||
|
||||
instrScheduling();
|
||||
};
|
||||
ModuloScheduling(ModuloSchedGraph & _graph):
|
||||
graph(_graph), target(graph.getTarget()), oNodes(graph.getONodes())
|
||||
{
|
||||
II = graph.getMII();
|
||||
bb = (BasicBlock *) graph.getBasicBlocks()[0];
|
||||
instrScheduling();
|
||||
};
|
||||
|
||||
///destructor
|
||||
~ModuloScheduling(){};
|
||||
~ModuloScheduling() {};
|
||||
|
||||
///the method to compute schedule and instert epilogue and prologue
|
||||
void instrScheduling();
|
||||
|
||||
///debug functions:
|
||||
///dump the schedule and core schedule
|
||||
void dumpScheduling();
|
||||
|
||||
void
|
||||
dumpScheduling();
|
||||
|
||||
///dump the input vector of nodes
|
||||
//sch: the input vector of nodes
|
||||
void dumpSchedule( std::vector<std::vector<ModuloSchedGraphNode*> > sch);
|
||||
void dumpSchedule(std::vector<std::vector<ModuloSchedGraphNode*>> sch);
|
||||
|
||||
///dump the resource usage table
|
||||
void dumpResourceUsageTable();
|
||||
|
||||
|
||||
//*******************internel functions*******************************
|
||||
//*******************internal functions*******************************
|
||||
private:
|
||||
//clear memory from the last round and initialize if necessary
|
||||
void clearInitMem(const TargetSchedInfo& );
|
||||
void clearInitMem(const TargetSchedInfo&);
|
||||
|
||||
//compute schedule and coreSchedule with the current II
|
||||
bool computeSchedule();
|
||||
|
||||
BasicBlock* getSuccBB(BasicBlock*);
|
||||
BasicBlock* getPredBB(BasicBlock*);
|
||||
void constructPrologue(BasicBlock* prologue);
|
||||
void constructKernel(BasicBlock* prologue,BasicBlock* kernel,BasicBlock* epilogue);
|
||||
void constructEpilogue(BasicBlock* epilogue,BasicBlock* succ_bb);
|
||||
BasicBlock *getSuccBB(BasicBlock *);
|
||||
BasicBlock *getPredBB(BasicBlock *);
|
||||
void constructPrologue(BasicBlock *prologue);
|
||||
void constructKernel(BasicBlock *prologue,
|
||||
BasicBlock *kernel,
|
||||
BasicBlock *epilogue);
|
||||
void constructEpilogue(BasicBlock *epilogue, BasicBlock *succ_bb);
|
||||
|
||||
///update the resource table at the startCycle
|
||||
//vec: the resouce usage
|
||||
//startCycle: the start cycle the resouce usage is
|
||||
void updateResourceTable(std::vector<vector<unsigned int> > vec,int startCycle);
|
||||
// update the resource table at the startCycle
|
||||
// vec: the resouce usage
|
||||
// startCycle: the start cycle the resouce usage is
|
||||
void updateResourceTable(std::vector<std::vector<unsigned int>> vec,
|
||||
int startCycle);
|
||||
|
||||
///un-do the update in the resource table in the startCycle
|
||||
//vec: the resouce usage
|
||||
//startCycle: the start cycle the resouce usage is
|
||||
void undoUpdateResourceTable(std::vector<vector<unsigned int> > vec,int startCycle);
|
||||
// un-do the update in the resource table in the startCycle
|
||||
// vec: the resouce usage
|
||||
// startCycle: the start cycle the resouce usage is
|
||||
void undoUpdateResourceTable(std::vector<vector<unsigned int>> vec,
|
||||
int startCycle);
|
||||
|
||||
///return whether the resourcetable has negative element
|
||||
///this function is called after updateResouceTable() to determine whether a node can
|
||||
/// be scheduled at certain cycle
|
||||
// return whether the resourcetable has negative element
|
||||
// this function is called after updateResouceTable() to determine whether a
|
||||
// node can be scheduled at certain cycle
|
||||
bool resourceTableNegative();
|
||||
|
||||
|
||||
///try to Schedule the node starting from start to end cycle(inclusive)
|
||||
//if it can be scheduled, put it in the schedule and update nodeScheduled
|
||||
//node: the node to be scheduled
|
||||
//start: start cycle
|
||||
//end : end cycle
|
||||
//nodeScheduled: a vector storing nodes which has been scheduled
|
||||
bool ScheduleNode(ModuloSchedGraphNode* node,unsigned start, unsigned end, NodeVec& nodeScheduled);
|
||||
// try to Schedule the node starting from start to end cycle(inclusive)
|
||||
// if it can be scheduled, put it in the schedule and update nodeScheduled
|
||||
// node: the node to be scheduled
|
||||
// start: start cycle
|
||||
// end : end cycle
|
||||
// nodeScheduled: a vector storing nodes which has been scheduled
|
||||
bool ScheduleNode(ModuloSchedGraphNode * node, unsigned start,
|
||||
unsigned end, NodeVec &nodeScheduled);
|
||||
|
||||
//each instruction has a memory of the latest clone instruction
|
||||
//the clone instruction can be get using getClone()
|
||||
//this function clears the memory, i.e. getClone() after calling this function returns null
|
||||
//this function clears the memory, i.e. getClone() after calling this function
|
||||
//returns null
|
||||
void clearCloneMemory();
|
||||
|
||||
//this fuction make a clone of this input Instruction and update the clone memory
|
||||
//this fuction make a clone of this input Instruction and update the clone
|
||||
//memory
|
||||
//inst: the instrution to be cloned
|
||||
Instruction* cloneInstSetMemory(Instruction* inst);
|
||||
Instruction *cloneInstSetMemory(Instruction *inst);
|
||||
|
||||
//this function update each instrutions which uses ist as its operand
|
||||
//after update, each instruction will use ist's clone as its operand
|
||||
void updateUseWithClone(Instruction* ist);
|
||||
void updateUseWithClone(Instruction * ist);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ModuloSchedulingSet:NonCopyable{
|
||||
private:
|
||||
|
||||
class ModuloSchedulingSet:
|
||||
NonCopyable {
|
||||
private:
|
||||
|
||||
//the graphSet to feed in
|
||||
ModuloSchedGraphSet& graphSet;
|
||||
public:
|
||||
ModuloSchedGraphSet & graphSet;
|
||||
|
||||
public:
|
||||
|
||||
//constructor
|
||||
//Scheduling graph one by one
|
||||
ModuloSchedulingSet(ModuloSchedGraphSet _graphSet):graphSet(_graphSet){
|
||||
for(unsigned i=0;i<graphSet.size();i++){
|
||||
ModuloSchedGraph& graph=*(graphSet[i]);
|
||||
if(graph.isLoop())ModuloScheduling ModuloScheduling(graph);
|
||||
ModuloSchedulingSet(ModuloSchedGraphSet _graphSet): graphSet(_graphSet) {
|
||||
for (unsigned i = 0; i < graphSet.size(); i++) {
|
||||
ModuloSchedGraph & graph = *(graphSet[i]);
|
||||
if (graph.isLoop())
|
||||
ModuloScheduling ModuloScheduling(graph);
|
||||
}
|
||||
};
|
||||
|
||||
//destructor
|
||||
~ModuloSchedulingSet(){};
|
||||
|
||||
~ModuloSchedulingSet() {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
//===- ModuloSchedGraph.h - Represent a collection of data structures ----*- C++ -*-===//
|
||||
//===- ModuloSchedGraph.h - Modulo Scheduling Graph and Set -*- C++ -*-----===//
|
||||
//
|
||||
// This header defines the primative classes that make up a data structure
|
||||
// graph.
|
||||
@ -7,82 +7,111 @@
|
||||
|
||||
#ifndef LLVM_CODEGEN_MODULO_SCHED_GRAPH_H
|
||||
#define LLVM_CODEGEN_MODULO_SCHED_GRAPH_H
|
||||
|
||||
#include "Support/HashExtras.h"
|
||||
#include "Support/GraphTraits.h"
|
||||
#include "../InstrSched/SchedGraphCommon.h"
|
||||
|
||||
#include "llvm/Instruction.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetInstrInfo.h"
|
||||
#include "Support/HashExtras.h"
|
||||
#include "Support/GraphTraits.h"
|
||||
#include "../InstrSched/SchedGraphCommon.h"
|
||||
#include <iostream>
|
||||
using std::pair;
|
||||
|
||||
//for debug information selecton
|
||||
enum ModuloSchedDebugLevel_t{
|
||||
enum ModuloSchedDebugLevel_t {
|
||||
ModuloSched_NoDebugInfo,
|
||||
ModuloSched_Disable,
|
||||
ModuloSched_PrintSchedule,
|
||||
ModuloSched_PrintScheduleProcess,
|
||||
};
|
||||
|
||||
//===============------------------------------------------------------------------------
|
||||
///ModuloSchedGraphNode - Implement a data structure based on the SchedGraphNodeCommon
|
||||
///this class stores informtion needed later to order the nodes in modulo scheduling
|
||||
///
|
||||
class ModuloSchedGraphNode: public SchedGraphNodeCommon {
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ModuloSchedGraphNode - Implement a data structure based on the
|
||||
// SchedGraphNodeCommon this class stores informtion needed later to order the
|
||||
// nodes in modulo scheduling
|
||||
//
|
||||
class ModuloSchedGraphNode:public SchedGraphNodeCommon {
|
||||
private:
|
||||
//the corresponding instruction
|
||||
const Instruction* inst;
|
||||
// the corresponding instruction
|
||||
const Instruction *inst;
|
||||
|
||||
//whether this node's property(ASAP,ALAP, ...) has been computed
|
||||
// whether this node's property(ASAP,ALAP, ...) has been computed
|
||||
bool propertyComputed;
|
||||
|
||||
//ASAP: the earliest time the node could be scheduled
|
||||
//ALAP: the latest time the node couldbe scheduled
|
||||
//depth: the depth of the node
|
||||
//height: the height of the node
|
||||
//mov: the mobility function, computed as ALAP - ASAP
|
||||
//scheTime: the scheduled time if this node has been scheduled
|
||||
//earlyStart: the earliest time to be tried to schedule the node
|
||||
//lateStart: the latest time to be tried to schedule the node
|
||||
// ASAP: the earliest time the node could be scheduled
|
||||
// ALAP: the latest time the node couldbe scheduled
|
||||
// depth: the depth of the node
|
||||
// height: the height of the node
|
||||
// mov: the mobility function, computed as ALAP - ASAP
|
||||
// scheTime: the scheduled time if this node has been scheduled
|
||||
// earlyStart: the earliest time to be tried to schedule the node
|
||||
// lateStart: the latest time to be tried to schedule the node
|
||||
int ASAP, ALAP, depth, height, mov;
|
||||
int schTime;
|
||||
int earlyStart,lateStart;
|
||||
int earlyStart, lateStart;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
//get the instruction
|
||||
const Instruction* getInst() const { return inst;}
|
||||
|
||||
const Instruction *getInst() const {
|
||||
return inst;
|
||||
}
|
||||
//get the instruction op-code name
|
||||
const char* getInstOpcodeName() const{ return inst->getOpcodeName();}
|
||||
|
||||
//get the instruction op-code
|
||||
const unsigned getInstOpcode() const { return inst->getOpcode();}
|
||||
|
||||
const char *getInstOpcodeName() const {
|
||||
return inst->getOpcodeName();
|
||||
}
|
||||
//get the instruction op-code
|
||||
const unsigned getInstOpcode() const {
|
||||
return inst->getOpcode();
|
||||
}
|
||||
//return whether the node is NULL
|
||||
bool isNullNode() const{ return(inst== NULL);}
|
||||
|
||||
bool isNullNode() const {
|
||||
return (inst == NULL);
|
||||
}
|
||||
//return whether the property of the node has been computed
|
||||
bool getPropertyComputed() {return propertyComputed;}
|
||||
|
||||
bool getPropertyComputed() {
|
||||
return propertyComputed;
|
||||
}
|
||||
//set the propertyComputed
|
||||
void setPropertyComputed(bool _propertyComputed) {propertyComputed = _propertyComputed;}
|
||||
|
||||
void setPropertyComputed(bool _propertyComputed) {
|
||||
propertyComputed = _propertyComputed;
|
||||
}
|
||||
|
||||
//get the corresponding property
|
||||
int getASAP(){ return ASAP;}
|
||||
int getALAP(){ return ALAP;}
|
||||
int getMov() { return mov;}
|
||||
int getDepth(){return depth;}
|
||||
int getHeight(){return height;}
|
||||
int getSchTime(){return schTime;}
|
||||
int getEarlyStart(){return earlyStart;}
|
||||
int getLateStart() { return lateStart;}
|
||||
void setEarlyStart(int _earlyStart) {earlyStart= _earlyStart;}
|
||||
void setLateStart(int _lateStart) {lateStart= _lateStart;}
|
||||
void setSchTime(int _time){schTime=_time;}
|
||||
int getASAP() {
|
||||
return ASAP;
|
||||
}
|
||||
int getALAP() {
|
||||
return ALAP;
|
||||
}
|
||||
int getMov() {
|
||||
return mov;
|
||||
}
|
||||
int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
int getHeight() {
|
||||
return height;
|
||||
}
|
||||
int getSchTime() {
|
||||
return schTime;
|
||||
}
|
||||
int getEarlyStart() {
|
||||
return earlyStart;
|
||||
}
|
||||
int getLateStart() {
|
||||
return lateStart;
|
||||
}
|
||||
void setEarlyStart(int _earlyStart) {
|
||||
earlyStart = _earlyStart;
|
||||
}
|
||||
void setLateStart(int _lateStart) {
|
||||
lateStart = _lateStart;
|
||||
}
|
||||
void setSchTime(int _time) {
|
||||
schTime = _time;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
friend class ModuloSchedGraph;
|
||||
friend class SchedGraphNode;
|
||||
|
||||
@ -93,43 +122,34 @@ public:
|
||||
//indexInBB: the corresponding instruction's index in the BasicBlock
|
||||
//target: the targetMachine
|
||||
ModuloSchedGraphNode(unsigned int _nodeId,
|
||||
const BasicBlock* _bb,
|
||||
const Instruction* _inst,
|
||||
int indexInBB,
|
||||
const TargetMachine& target);
|
||||
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os,const ModuloSchedGraphNode& edge);
|
||||
|
||||
const BasicBlock * _bb,
|
||||
const Instruction * _inst,
|
||||
int indexInBB, const TargetMachine &target);
|
||||
|
||||
|
||||
friend std::ostream & operator<<(std::ostream & os,
|
||||
const ModuloSchedGraphNode & edge);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//FIXME: these two value should not be used
|
||||
#define MAXNODE 100
|
||||
#define MAXCC 100
|
||||
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// ModuloSchedGraph- the data structure to store dependence between nodes
|
||||
/// it catches data dependence and constrol dependence
|
||||
///
|
||||
///
|
||||
|
||||
class ModuloSchedGraph:
|
||||
class ModuloSchedGraph :
|
||||
public SchedGraphCommon,
|
||||
protected hash_map<const Instruction*, ModuloSchedGraphNode*>
|
||||
{
|
||||
|
||||
private:
|
||||
protected hash_map<const Instruction*,ModuloSchedGraphNode*> {
|
||||
|
||||
private:
|
||||
//iteration Interval
|
||||
int MII;
|
||||
|
||||
|
||||
//target machine
|
||||
const TargetMachine& target;
|
||||
const TargetMachine & target;
|
||||
|
||||
//the circuits in the dependence graph
|
||||
unsigned circuits[MAXCC][MAXNODE];
|
||||
@ -140,20 +160,20 @@ private:
|
||||
typedef std::vector<ModuloSchedGraphNode*> NodeVec;
|
||||
|
||||
//the function to compute properties
|
||||
void computeNodeASAP(const BasicBlock* bb);
|
||||
void computeNodeALAP(const BasicBlock* bb);
|
||||
void computeNodeMov(const BasicBlock* bb);
|
||||
void computeNodeDepth(const BasicBlock* bb);
|
||||
void computeNodeHeight(const BasicBlock* bb);
|
||||
void computeNodeASAP(const BasicBlock * bb);
|
||||
void computeNodeALAP(const BasicBlock * bb);
|
||||
void computeNodeMov(const BasicBlock * bb);
|
||||
void computeNodeDepth(const BasicBlock * bb);
|
||||
void computeNodeHeight(const BasicBlock * bb);
|
||||
|
||||
//the function to compute node property
|
||||
void computeNodeProperty(const BasicBlock* bb);
|
||||
void computeNodeProperty(const BasicBlock * bb);
|
||||
|
||||
//the function to sort nodes
|
||||
void orderNodes();
|
||||
|
||||
|
||||
//add the resource usage
|
||||
void addResourceUsage(std::vector<pair<int,int> >&, int);
|
||||
void addResourceUsage(std::vector<pair<int,int>>&, int);
|
||||
|
||||
//debug functions:
|
||||
//dump circuits
|
||||
@ -161,13 +181,13 @@ private:
|
||||
//dump the input set of nodes
|
||||
void dumpSet(std::vector<ModuloSchedGraphNode*> set);
|
||||
//dump the input resource usage table
|
||||
void dumpResourceUsage(std::vector<pair<int,int> >&);
|
||||
|
||||
public:
|
||||
void dumpResourceUsage(std::vector<pair<int,int>> &);
|
||||
|
||||
public:
|
||||
//help functions
|
||||
|
||||
|
||||
//get the maxium the delay between two nodes
|
||||
SchedGraphEdge* getMaxDelayEdge(unsigned srcId, unsigned sinkId);
|
||||
SchedGraphEdge *getMaxDelayEdge(unsigned srcId, unsigned sinkId);
|
||||
|
||||
//FIXME:
|
||||
//get the predessor Set of the set
|
||||
@ -175,174 +195,171 @@ private:
|
||||
NodeVec predSet(NodeVec set);
|
||||
|
||||
//get the predessor set of the node
|
||||
NodeVec predSet(ModuloSchedGraphNode* node, unsigned,unsigned);
|
||||
NodeVec predSet(ModuloSchedGraphNode* node);
|
||||
NodeVec predSet(ModuloSchedGraphNode * node, unsigned, unsigned);
|
||||
NodeVec predSet(ModuloSchedGraphNode * node);
|
||||
|
||||
//get the successor set of the set
|
||||
NodeVec succSet(NodeVec set, unsigned, unsigned);
|
||||
NodeVec succSet(NodeVec set);
|
||||
|
||||
|
||||
//get the succssor set of the node
|
||||
NodeVec succSet(ModuloSchedGraphNode* node,unsigned, unsigned);
|
||||
NodeVec succSet(ModuloSchedGraphNode* node);
|
||||
NodeVec succSet(ModuloSchedGraphNode * node, unsigned, unsigned);
|
||||
NodeVec succSet(ModuloSchedGraphNode * node);
|
||||
|
||||
//return the uniton of the two vectors
|
||||
NodeVec vectorUnion(NodeVec set1,NodeVec set2 );
|
||||
NodeVec vectorUnion(NodeVec set1, NodeVec set2);
|
||||
|
||||
//return the consjuction of the two vectors
|
||||
NodeVec vectorConj(NodeVec set1,NodeVec set2 );
|
||||
|
||||
NodeVec vectorConj(NodeVec set1, NodeVec set2);
|
||||
|
||||
//return all nodes in set1 but not set2
|
||||
NodeVec vectorSub(NodeVec set1, NodeVec set2);
|
||||
|
||||
typedef hash_map<const Instruction*, ModuloSchedGraphNode*> map_base;
|
||||
typedef hash_map<const Instruction*,ModuloSchedGraphNode*> map_base;
|
||||
|
||||
public:
|
||||
using map_base::iterator;
|
||||
using map_base::const_iterator;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//get target machine
|
||||
const TargetMachine& getTarget(){return target;}
|
||||
|
||||
const TargetMachine & getTarget() {
|
||||
return target;
|
||||
}
|
||||
//get the iteration interval
|
||||
const int getMII(){return MII;}
|
||||
const int getMII() {
|
||||
return MII;
|
||||
}
|
||||
|
||||
//get the ordered nodes
|
||||
const NodeVec& getONodes(){return oNodes;}
|
||||
const NodeVec & getONodes() {
|
||||
return oNodes;
|
||||
}
|
||||
|
||||
//get the number of nodes (including the root and leaf)
|
||||
//note: actually root and leaf is not used
|
||||
const unsigned int getNumNodes() const {return size()+2;}
|
||||
|
||||
const unsigned int getNumNodes() const {
|
||||
return size() + 2;
|
||||
}
|
||||
//return wether the BasicBlock 'bb' contains a loop
|
||||
bool isLoop (const BasicBlock* bb);
|
||||
bool isLoop(const BasicBlock * bb);
|
||||
|
||||
//return this basibBlock contains a loop
|
||||
bool isLoop ();
|
||||
|
||||
bool isLoop();
|
||||
|
||||
|
||||
//return the node for the input instruction
|
||||
ModuloSchedGraphNode* getGraphNodeForInst(const Instruction* inst) const{
|
||||
ModuloSchedGraphNode *getGraphNodeForInst(const Instruction * inst) const {
|
||||
const_iterator onePair = this->find(inst);
|
||||
return (onePair != this->end())?(*onePair).second: NULL;
|
||||
return (onePair != this->end()) ? (*onePair).second : NULL;
|
||||
}
|
||||
|
||||
//Debugging support
|
||||
//dump the graph
|
||||
void dump() const;
|
||||
//Debugging support//dump the graph void dump() const;
|
||||
//dump the basicBlock
|
||||
void dump(const BasicBlock* bb);
|
||||
void dump(const BasicBlock * bb);
|
||||
//dump the basicBlock into 'os' stream
|
||||
void dump(const BasicBlock* bb, std::ostream& os);
|
||||
void dump(const BasicBlock * bb, std::ostream & os);
|
||||
//dump the node property
|
||||
void dumpNodeProperty() const ;
|
||||
|
||||
private:
|
||||
friend class ModuloSchedGraphSet; //give access to ctor
|
||||
void dumpNodeProperty() const;
|
||||
|
||||
public:
|
||||
/*ctr*/
|
||||
ModuloSchedGraph(const BasicBlock* bb, const TargetMachine& _target)
|
||||
:SchedGraphCommon(bb), target(_target){
|
||||
private:
|
||||
friend class ModuloSchedGraphSet; //give access to ctor
|
||||
|
||||
public:
|
||||
ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &_target)
|
||||
:SchedGraphCommon(bb), target(_target) {
|
||||
buildGraph(target);
|
||||
}
|
||||
|
||||
/*dtr*/
|
||||
~ModuloSchedGraph(){
|
||||
for(const_iterator I=begin(); I!=end(); ++I)
|
||||
~ModuloSchedGraph() {
|
||||
for (const_iterator I = begin(); I != end(); ++I)
|
||||
delete I->second;
|
||||
}
|
||||
|
||||
|
||||
//unorder iterators
|
||||
//return values are pair<const Instruction*, ModuloSchedGraphNode*>
|
||||
using map_base::begin;
|
||||
using map_base::end;
|
||||
|
||||
void noteModuloSchedGraphNodeForInst(const Instruction *inst,
|
||||
ModuloSchedGraphNode *node)
|
||||
{
|
||||
assert((*this)[inst] == NULL);
|
||||
(*this)[inst] = node;
|
||||
}
|
||||
|
||||
|
||||
inline void noteModuloSchedGraphNodeForInst(const Instruction* inst,
|
||||
ModuloSchedGraphNode* node)
|
||||
{
|
||||
assert((*this)[inst] ==NULL);
|
||||
(*this)[inst]=node;
|
||||
}
|
||||
|
||||
//Graph builder
|
||||
|
||||
ModuloSchedGraphNode* getNode (const unsigned nodeId) const;
|
||||
|
||||
ModuloSchedGraphNode *getNode(const unsigned nodeId) const;
|
||||
|
||||
//build the graph from the basicBlock
|
||||
void buildGraph (const TargetMachine& target);
|
||||
void buildGraph(const TargetMachine & target);
|
||||
|
||||
//Build nodes for BasicBlock
|
||||
void buildNodesforBB (const TargetMachine& target,
|
||||
const BasicBlock* bb,
|
||||
NodeVec& memNode,
|
||||
RegToRefVecMap& regToRefVecMap,
|
||||
ValueToDefVecMap& valueToDefVecMap);
|
||||
void buildNodesforBB(const TargetMachine &target,
|
||||
const BasicBlock *bb,
|
||||
NodeVec &memNode,
|
||||
RegToRefVecMap ®ToRefVecMap,
|
||||
ValueToDefVecMap &valueToDefVecMap);
|
||||
|
||||
//find definitiona and use information for all nodes
|
||||
void findDefUseInfoAtInstr (const TargetMachine& target,
|
||||
ModuloSchedGraphNode* node,
|
||||
NodeVec& memNode,
|
||||
RegToRefVecMap& regToRefVecMap,
|
||||
ValueToDefVecMap& valueToDefVecMap);
|
||||
void findDefUseInfoAtInstr(const TargetMachine &target,
|
||||
ModuloSchedGraphNode *node,
|
||||
NodeVec &memNode,
|
||||
RegToRefVecMap ®ToRefVecMap,
|
||||
ValueToDefVecMap &valueToDefVecMap);
|
||||
|
||||
//add def-use edge
|
||||
void addDefUseEdges (const BasicBlock* bb);
|
||||
void addDefUseEdges(const BasicBlock *bb);
|
||||
|
||||
//add control dependence edges
|
||||
void addCDEdges (const BasicBlock* bb);
|
||||
void addCDEdges(const BasicBlock *bb);
|
||||
|
||||
//add memory dependence dges
|
||||
void addMemEdges (const BasicBlock* bb);
|
||||
void addMemEdges(const BasicBlock *bb);
|
||||
|
||||
//add dummy edges
|
||||
void addDummyEdges();
|
||||
|
||||
//computer source restrictoin II
|
||||
int computeResII (const BasicBlock* bb);
|
||||
int computeResII(const BasicBlock *bb);
|
||||
|
||||
//computer recurrence II
|
||||
int computeRecII (const BasicBlock* bb);
|
||||
int computeRecII(const BasicBlock *bb);
|
||||
};
|
||||
|
||||
///==================================-
|
||||
//gragh set
|
||||
//==================================-
|
||||
// Graph set
|
||||
|
||||
class ModuloSchedGraphSet:
|
||||
public std::vector<ModuloSchedGraph*>
|
||||
{
|
||||
class ModuloSchedGraphSet : public std::vector<ModuloSchedGraph*> {
|
||||
private:
|
||||
const Function* method;
|
||||
|
||||
const Function *method;
|
||||
|
||||
public:
|
||||
typedef std::vector<ModuloSchedGraph*> baseVector;
|
||||
using baseVector::iterator;
|
||||
using baseVector::const_iterator;
|
||||
|
||||
|
||||
public:
|
||||
/*ctor*/ ModuloSchedGraphSet (const Function* function, const TargetMachine& target);
|
||||
|
||||
/*dtor*/ ~ModuloSchedGraphSet ();
|
||||
|
||||
//iterators
|
||||
ModuloSchedGraphSet(const Function *function, const TargetMachine &target);
|
||||
~ModuloSchedGraphSet();
|
||||
|
||||
// Iterators
|
||||
using baseVector::begin;
|
||||
using baseVector::end;
|
||||
|
||||
// Debugging support
|
||||
void dump() const;
|
||||
|
||||
//Debugging support
|
||||
void dump() const;
|
||||
|
||||
private:
|
||||
inline void addGraph(ModuloSchedGraph* graph){
|
||||
assert(graph !=NULL);
|
||||
void addGraph(ModuloSchedGraph *graph) {
|
||||
assert(graph != NULL);
|
||||
this->push_back(graph);
|
||||
}
|
||||
|
||||
//Graph builder
|
||||
void buildGraphsForMethod (const Function *F, const TargetMachine& target);
|
||||
};
|
||||
|
||||
#endif
|
||||
// Graph builder
|
||||
void buildGraphsForMethod(const Function *F,
|
||||
const TargetMachine &target);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
//// - head file for the classes ModuloScheduling and ModuloScheduling ----*- C++ -*-===//
|
||||
// ModuloScheduling.h -------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// This header defines the the classes ModuloScheduling and ModuloSchedulingSet 's structure
|
||||
//
|
||||
// This header defines the the classes ModuloScheduling and
|
||||
// ModuloSchedulingSet's structure
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@ -13,151 +13,148 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
class ModuloScheduling: NonCopyable {
|
||||
private:
|
||||
|
||||
class ModuloScheduling:NonCopyable {
|
||||
private:
|
||||
typedef std::vector<ModuloSchedGraphNode*> NodeVec;
|
||||
|
||||
/// the graph to feed in
|
||||
ModuloSchedGraph& graph;
|
||||
const TargetMachine& target;
|
||||
|
||||
//the BasicBlock to be scheduled
|
||||
BasicBlock* bb;
|
||||
typedef std::vector<std::vector<unsigned> > Resources;
|
||||
|
||||
///Iteration Intervel
|
||||
///FIXME: II may be a better name for its meaning
|
||||
// The graph to feed in
|
||||
ModuloSchedGraph &graph;
|
||||
const TargetMachine ⌖
|
||||
|
||||
// The BasicBlock to be scheduled
|
||||
BasicBlock *bb;
|
||||
|
||||
// Iteration Interval
|
||||
// FIXME: II may be a better name for its meaning
|
||||
unsigned II;
|
||||
|
||||
//the vector containing the nodes which have been scheduled
|
||||
// The vector containing the nodes which have been scheduled
|
||||
NodeVec nodeScheduled;
|
||||
|
||||
///the remaining unscheduled nodes
|
||||
const NodeVec& oNodes;
|
||||
|
||||
///the machine resource table
|
||||
std::vector< std::vector<pair<int,int> > > resourceTable ;
|
||||
|
||||
|
||||
// The remaining unscheduled nodes
|
||||
const NodeVec &oNodes;
|
||||
|
||||
// The machine resource table
|
||||
std::vector<std::vector<std::pair<int,int> > > resourceTable;
|
||||
|
||||
///the schedule( with many schedule stage)
|
||||
std::vector<std::vector<ModuloSchedGraphNode*> > schedule;
|
||||
|
||||
|
||||
///the kernel(core) schedule(length = II)
|
||||
std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule;
|
||||
|
||||
typedef BasicBlock::InstListType InstListType;
|
||||
typedef std::vector <std::vector<ModuloSchedGraphNode*> > vvNodeType;
|
||||
|
||||
|
||||
typedef BasicBlock::InstListType InstListType;
|
||||
typedef std::vector<std::vector<ModuloSchedGraphNode*> > vvNodeType;
|
||||
|
||||
public:
|
||||
|
||||
///constructor
|
||||
ModuloScheduling(ModuloSchedGraph& _graph):
|
||||
graph(_graph),
|
||||
target(graph.getTarget()),
|
||||
oNodes(graph.getONodes())
|
||||
{
|
||||
II = graph.getMII();
|
||||
bb=(BasicBlock*)graph.getBasicBlocks()[0];
|
||||
|
||||
instrScheduling();
|
||||
};
|
||||
ModuloScheduling(ModuloSchedGraph & _graph):
|
||||
graph(_graph), target(graph.getTarget()), oNodes(graph.getONodes())
|
||||
{
|
||||
II = graph.getMII();
|
||||
bb = (BasicBlock *) graph.getBasicBlocks()[0];
|
||||
instrScheduling();
|
||||
};
|
||||
|
||||
///destructor
|
||||
~ModuloScheduling(){};
|
||||
~ModuloScheduling() {};
|
||||
|
||||
///the method to compute schedule and instert epilogue and prologue
|
||||
void instrScheduling();
|
||||
|
||||
///debug functions:
|
||||
///dump the schedule and core schedule
|
||||
void dumpScheduling();
|
||||
|
||||
void
|
||||
dumpScheduling();
|
||||
|
||||
///dump the input vector of nodes
|
||||
//sch: the input vector of nodes
|
||||
void dumpSchedule( std::vector<std::vector<ModuloSchedGraphNode*> > sch);
|
||||
void dumpSchedule(std::vector<std::vector<ModuloSchedGraphNode*>> sch);
|
||||
|
||||
///dump the resource usage table
|
||||
void dumpResourceUsageTable();
|
||||
|
||||
|
||||
//*******************internel functions*******************************
|
||||
//*******************internal functions*******************************
|
||||
private:
|
||||
//clear memory from the last round and initialize if necessary
|
||||
void clearInitMem(const TargetSchedInfo& );
|
||||
void clearInitMem(const TargetSchedInfo&);
|
||||
|
||||
//compute schedule and coreSchedule with the current II
|
||||
bool computeSchedule();
|
||||
|
||||
BasicBlock* getSuccBB(BasicBlock*);
|
||||
BasicBlock* getPredBB(BasicBlock*);
|
||||
void constructPrologue(BasicBlock* prologue);
|
||||
void constructKernel(BasicBlock* prologue,BasicBlock* kernel,BasicBlock* epilogue);
|
||||
void constructEpilogue(BasicBlock* epilogue,BasicBlock* succ_bb);
|
||||
BasicBlock *getSuccBB(BasicBlock *);
|
||||
BasicBlock *getPredBB(BasicBlock *);
|
||||
void constructPrologue(BasicBlock *prologue);
|
||||
void constructKernel(BasicBlock *prologue,
|
||||
BasicBlock *kernel,
|
||||
BasicBlock *epilogue);
|
||||
void constructEpilogue(BasicBlock *epilogue, BasicBlock *succ_bb);
|
||||
|
||||
///update the resource table at the startCycle
|
||||
//vec: the resouce usage
|
||||
//startCycle: the start cycle the resouce usage is
|
||||
void updateResourceTable(std::vector<vector<unsigned int> > vec,int startCycle);
|
||||
// update the resource table at the startCycle
|
||||
// vec: the resouce usage
|
||||
// startCycle: the start cycle the resouce usage is
|
||||
void updateResourceTable(std::vector<std::vector<unsigned int>> vec,
|
||||
int startCycle);
|
||||
|
||||
///un-do the update in the resource table in the startCycle
|
||||
//vec: the resouce usage
|
||||
//startCycle: the start cycle the resouce usage is
|
||||
void undoUpdateResourceTable(std::vector<vector<unsigned int> > vec,int startCycle);
|
||||
// un-do the update in the resource table in the startCycle
|
||||
// vec: the resouce usage
|
||||
// startCycle: the start cycle the resouce usage is
|
||||
void undoUpdateResourceTable(std::vector<vector<unsigned int>> vec,
|
||||
int startCycle);
|
||||
|
||||
///return whether the resourcetable has negative element
|
||||
///this function is called after updateResouceTable() to determine whether a node can
|
||||
/// be scheduled at certain cycle
|
||||
// return whether the resourcetable has negative element
|
||||
// this function is called after updateResouceTable() to determine whether a
|
||||
// node can be scheduled at certain cycle
|
||||
bool resourceTableNegative();
|
||||
|
||||
|
||||
///try to Schedule the node starting from start to end cycle(inclusive)
|
||||
//if it can be scheduled, put it in the schedule and update nodeScheduled
|
||||
//node: the node to be scheduled
|
||||
//start: start cycle
|
||||
//end : end cycle
|
||||
//nodeScheduled: a vector storing nodes which has been scheduled
|
||||
bool ScheduleNode(ModuloSchedGraphNode* node,unsigned start, unsigned end, NodeVec& nodeScheduled);
|
||||
// try to Schedule the node starting from start to end cycle(inclusive)
|
||||
// if it can be scheduled, put it in the schedule and update nodeScheduled
|
||||
// node: the node to be scheduled
|
||||
// start: start cycle
|
||||
// end : end cycle
|
||||
// nodeScheduled: a vector storing nodes which has been scheduled
|
||||
bool ScheduleNode(ModuloSchedGraphNode * node, unsigned start,
|
||||
unsigned end, NodeVec &nodeScheduled);
|
||||
|
||||
//each instruction has a memory of the latest clone instruction
|
||||
//the clone instruction can be get using getClone()
|
||||
//this function clears the memory, i.e. getClone() after calling this function returns null
|
||||
//this function clears the memory, i.e. getClone() after calling this function
|
||||
//returns null
|
||||
void clearCloneMemory();
|
||||
|
||||
//this fuction make a clone of this input Instruction and update the clone memory
|
||||
//this fuction make a clone of this input Instruction and update the clone
|
||||
//memory
|
||||
//inst: the instrution to be cloned
|
||||
Instruction* cloneInstSetMemory(Instruction* inst);
|
||||
Instruction *cloneInstSetMemory(Instruction *inst);
|
||||
|
||||
//this function update each instrutions which uses ist as its operand
|
||||
//after update, each instruction will use ist's clone as its operand
|
||||
void updateUseWithClone(Instruction* ist);
|
||||
void updateUseWithClone(Instruction * ist);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ModuloSchedulingSet:NonCopyable{
|
||||
private:
|
||||
|
||||
class ModuloSchedulingSet:
|
||||
NonCopyable {
|
||||
private:
|
||||
|
||||
//the graphSet to feed in
|
||||
ModuloSchedGraphSet& graphSet;
|
||||
public:
|
||||
ModuloSchedGraphSet & graphSet;
|
||||
|
||||
public:
|
||||
|
||||
//constructor
|
||||
//Scheduling graph one by one
|
||||
ModuloSchedulingSet(ModuloSchedGraphSet _graphSet):graphSet(_graphSet){
|
||||
for(unsigned i=0;i<graphSet.size();i++){
|
||||
ModuloSchedGraph& graph=*(graphSet[i]);
|
||||
if(graph.isLoop())ModuloScheduling ModuloScheduling(graph);
|
||||
ModuloSchedulingSet(ModuloSchedGraphSet _graphSet): graphSet(_graphSet) {
|
||||
for (unsigned i = 0; i < graphSet.size(); i++) {
|
||||
ModuloSchedGraph & graph = *(graphSet[i]);
|
||||
if (graph.isLoop())
|
||||
ModuloScheduling ModuloScheduling(graph);
|
||||
}
|
||||
};
|
||||
|
||||
//destructor
|
||||
~ModuloSchedulingSet(){};
|
||||
|
||||
~ModuloSchedulingSet() {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user