if (schedule[cycle].size() < numIssue) {
//Now check if all the resources in their respective cycles are available
if(resourcesFree(node, cycle)) {
- schedule[cycle].push_back(node);
+ //Insert to preserve dependencies
+ addToSchedule(cycle,node);
DEBUG(std::cerr << "Found spot in map, and there is an issue slot\n");
return false;
}
}
+void MSSchedule::addToSchedule(int cycle, MSchedGraphNode *node) {
+ std::vector<MSchedGraphNode*> nodesAtCycle = schedule[cycle];
+
+ std::map<unsigned, MSchedGraphNode*> indexMap;
+ for(unsigned i=0; i < nodesAtCycle.size(); ++i) {
+ indexMap[nodesAtCycle[i]->getIndex()] = nodesAtCycle[i];
+ }
+
+ indexMap[node->getIndex()] = node;
+
+ std::vector<MSchedGraphNode*> nodes;
+ for(std::map<unsigned, MSchedGraphNode*>::iterator I = indexMap.begin(), E = indexMap.end(); I != E; ++I)
+ nodes.push_back(I->second);
+
+ schedule[cycle] = nodes;
+}
+
+
bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
//Get Resource usage for this instruction
//Max stage count
int maxStage;
+ //add at the right spot in the schedule
+ void addToSchedule(int, MSchedGraphNode*);
+
public:
MSSchedule(int num) : numIssue(num) {}
MSSchedule() : numIssue(4) {}
using namespace llvm;
MSchedGraphNode::MSchedGraphNode(const MachineInstr* inst,
- MSchedGraph *graph,
+ MSchedGraph *graph, unsigned idx,
unsigned late, bool isBranch)
- : Inst(inst), Parent(graph), latency(late), isBranchInstr(isBranch) {
+ : Inst(inst), Parent(graph), index(idx), latency(late), isBranchInstr(isBranch) {
//Add to the graph
graph->addNode(inst, this);
//Save PHI instructions to deal with later
std::vector<const MachineInstr*> phiInstrs;
-
+ unsigned index = 0;
//Loop over instructions in MBB and add nodes and edges
for (MachineBasicBlock::const_iterator MI = BB->begin(), e = BB->end(); MI != e; ++MI) {
//Get each instruction of machine basic block, get the delay
isBranch = true;
//Node is created and added to the graph automatically
- MSchedGraphNode *node = new MSchedGraphNode(MI, this, delay, isBranch);
+ MSchedGraphNode *node = new MSchedGraphNode(MI, this, index, delay, isBranch);
DEBUG(std::cerr << "Created Node: " << *node << "\n");
}
}
}
+ ++index;
}
addMemEdges(memInstructions);
addMachRegEdges(regNumtoNodeMap);
const MachineInstr* Inst; //Machine Instruction
MSchedGraph* Parent; //Graph this node belongs to
+ unsigned index; //Index in BB
unsigned latency; //Latency of Instruction
bool isBranchInstr; //Is this node the branch instr or not
+
std::vector<MSchedGraphNode*> Predecessors; //Predecessor Nodes
std::vector<MSchedGraphEdge> Successors;
public:
MSchedGraphNode(const MachineInstr *inst, MSchedGraph *graph,
- unsigned late=0, bool isBranch=false);
+ unsigned index, unsigned late=0, bool isBranch=false);
//Iterators
typedef std::vector<MSchedGraphNode*>::iterator pred_iterator;
bool hasSuccessors() { return (Successors.size() > 0); }
unsigned getLatency() { return latency; }
unsigned getLatency() const { return latency; }
-
+ unsigned getIndex() { return index; }
MSchedGraphEdge getInEdge(MSchedGraphNode *pred);
unsigned getInEdgeNum(MSchedGraphNode *pred);