aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ModuloScheduling
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2003-04-09 21:51:34 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2003-04-09 21:51:34 +0000
commit8baa01c1d79d8cff13634a48339cf551e30eaf14 (patch)
tree260a487089bc25199315bfae696fcdbb448e1e58 /lib/CodeGen/ModuloScheduling
parent4bd8b244701feda01adf713eac0a16342c12021e (diff)
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
Diffstat (limited to 'lib/CodeGen/ModuloScheduling')
-rw-r--r--lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp1948
-rw-r--r--lib/CodeGen/ModuloScheduling/ModuloSchedGraph.h363
-rw-r--r--lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp1359
-rw-r--r--lib/CodeGen/ModuloScheduling/ModuloScheduling.h191
4 files changed, 1977 insertions, 1884 deletions
diff --git a/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp b/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp
index 34834826bc..31c99c1f40 100644
--- a/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp
+++ b/lib/CodeGen/ModuloScheduling/ModuloSchedGraph.cpp
@@ -1,31 +1,24 @@
-#include <math.h>
-#include "ModuloSchedGraph.h"
+//===- ModuloSchedGraph.cpp - Graph datastructure for Modulo Scheduling ---===//
+//
+//
+//===----------------------------------------------------------------------===//
+
#include "llvm/CodeGen/InstrSelection.h"
-#include "llvm/BasicBlock.h"
#include "llvm/Function.h"
-#include "llvm/iOther.h"
-#include "Support/StringExtras.h"
-#include "Support/STLExtras.h"
-#include <iostream>
-//#include <swig.h>
-#include "llvm/iOperators.h"
-#include "llvm/iOther.h"
-#include "llvm/iPHINode.h"
-#include "llvm/iTerminators.h"
-#include "llvm/iMemory.h"
+#include "llvm/Instructions.h"
#include "llvm/Type.h"
#include "llvm/CodeGen/MachineCodeForInstruction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Target/TargetSchedInfo.h"
+#include "Support/StringExtras.h"
+#include "Support/STLExtras.h"
+#include "ModuloSchedGraph.h"
+#include <algorithm>
+#include <math.h>
+//#include <swig.h>
#define UNIDELAY 1
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#define max(a, b) ((a) < (b) ? (b) : (a))
-using std::vector;
-using std::pair;
-//using std::hash_map;
-using std::cerr;
extern std::ostream modSched_os;
extern ModuloSchedDebugLevel_t ModuloSchedDebugLevel;
//*********************** Internal Data Structures *************************/
@@ -33,187 +26,177 @@ extern ModuloSchedDebugLevel_t ModuloSchedDebugLevel;
// The following two types need to be classes, not typedefs, so we can use
// opaque declarations in SchedGraph.h
//
-struct RefVec: public vector< pair<ModuloSchedGraphNode*, int> > {
- typedef vector< pair<ModuloSchedGraphNode*, int> >:: iterator iterator;
- typedef vector< pair<ModuloSchedGraphNode*, int> >::const_iterator const_iterator;
+struct RefVec:public std::vector < std::pair < ModuloSchedGraphNode *, int >> {
+ typedef std::vector<std::pair<ModuloSchedGraphNode*,
+ int> >::iterator iterator;
+ typedef std::vector<std::pair<ModuloSchedGraphNode*,
+ int> >::const_iterator const_iterator;
};
-struct RegToRefVecMap: public hash_map<int, RefVec> {
- typedef hash_map<int, RefVec>:: iterator iterator;
- typedef hash_map<int, RefVec>::const_iterator const_iterator;
+struct RegToRefVecMap:public std::hash_map < int, RefVec > {
+ typedef std::hash_map<int,RefVec>::iterator iterator;
+ typedef std::hash_map<int,RefVec>::const_iterator const_iterator;
};
-struct ValueToDefVecMap: public hash_map<const Instruction*, RefVec> {
- typedef hash_map<const Instruction*, RefVec>:: iterator iterator;
- typedef hash_map<const Instruction*, RefVec>::const_iterator const_iterator;
+struct ValueToDefVecMap:public std::hash_map < const Instruction *, RefVec > {
+ typedef std::hash_map<const Instruction*, RefVec>::iterator iterator;
+ typedef std::hash_map<const Instruction*,
+ RefVec>::const_iterator const_iterator;
};
-
-
// class Modulo SchedGraphNode
/*ctor*/
ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned int _nodeId,
- const BasicBlock* _bb,
- const Instruction* _inst,
- int indexInBB,
- const TargetMachine& target)
- :
- SchedGraphNodeCommon(_nodeId, _bb, indexInBB),
- inst(_inst)
+ const BasicBlock * _bb,
+ const Instruction * _inst,
+ int indexInBB,
+ const TargetMachine & target)
+:SchedGraphNodeCommon(_nodeId, _bb, indexInBB), inst(_inst)
{
- if(inst)
- {
- //FIXME: find the latency
- //currently setthe latency to zero
- latency =0;
- }
-
+ if (inst) {
+ //FIXME: find the latency
+ //currently setthe latency to zero
+ latency = 0;
+ }
}
-
-//class ModuloScheGraph
+//class ModuloScheGraph
-void
-ModuloSchedGraph::addDummyEdges()
+void ModuloSchedGraph::addDummyEdges()
{
assert(graphRoot->outEdges.size() == 0);
-
- for (const_iterator I=begin(); I != end(); ++I)
- {
- ModuloSchedGraphNode* node = (ModuloSchedGraphNode*)( (*I).second);
- assert(node != graphRoot && node != graphLeaf);
- if (node->beginInEdges() == node->endInEdges())
- (void) new SchedGraphEdge(graphRoot, node, SchedGraphEdge::CtrlDep,
- SchedGraphEdge::NonDataDep, 0);
- if (node->beginOutEdges() == node->endOutEdges())
- (void) new SchedGraphEdge(node, graphLeaf, SchedGraphEdge::CtrlDep,
- SchedGraphEdge::NonDataDep, 0);
- }
+
+ for (const_iterator I = begin(); I != end(); ++I) {
+ ModuloSchedGraphNode *node = (ModuloSchedGraphNode *) ((*I).second);
+ assert(node != graphRoot && node != graphLeaf);
+ if (node->beginInEdges() == node->endInEdges())
+ (void) new SchedGraphEdge(graphRoot, node, SchedGraphEdge::CtrlDep,
+ SchedGraphEdge::NonDataDep, 0);
+ if (node->beginOutEdges() == node->endOutEdges())
+ (void) new SchedGraphEdge(node, graphLeaf, SchedGraphEdge::CtrlDep,
+ SchedGraphEdge::NonDataDep, 0);
+ }
}
-bool isDefinition(const Instruction* I)
+bool isDefinition(const Instruction *I)
{
//if(TerminatorInst::classof(I)||FreeInst::classof(I) || StoreInst::classof(I) || CallInst::classof(I))
- if(!I->hasName())
+ if (!I->hasName())
return false;
else
return true;
}
-void ModuloSchedGraph::addDefUseEdges(const BasicBlock* bb)
+void ModuloSchedGraph::addDefUseEdges(const BasicBlock *bb)
{
//collect def instructions, store them in vector
// const TargetInstrInfo& mii = target.getInstrInfo();
- const TargetInstrInfo& mii = target.getInstrInfo();
-
- typedef std::vector<ModuloSchedGraphNode*> DefVec;
+ const TargetInstrInfo & mii = target.getInstrInfo();
+
+ typedef std::vector < ModuloSchedGraphNode * >DefVec;
DefVec defVec;
-
+
//find those def instructions
- for(BasicBlock::const_iterator I=bb->begin(), E=bb->end(); I !=E; I++)
- if(I->getType() != Type::VoidTy)
- {
- defVec.push_back(this->getGraphNodeForInst(I)) ;
- }
-
- for(unsigned int i=0; i < defVec.size();i++)
- for(Value::use_const_iterator I=defVec[i]->getInst()->use_begin();I !=defVec[i]->getInst()->use_end() ;I++)
+ for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E; ++I) {
+ if (I->getType() != Type::VoidTy) {
+ defVec.push_back(this->getGraphNodeForInst(I));
+ }
+ }
+
+ for (unsigned int i = 0; i < defVec.size(); i++) {
+ for (Value::use_const_iterator I = defVec[i]->getInst()->use_begin();
+ I != defVec[i]->getInst()->use_end(); I++) {
+ //for each use of a def, add a flow edge from the def instruction to the ref instruction
+
+
+ const Instruction *value = defVec[i]->getInst();
+ Instruction *inst = (Instruction *) (*I);
+ ModuloSchedGraphNode *node = NULL;
+
+ for (BasicBlock::const_iterator I = bb->begin(), E = bb->end();
+ I != E; ++I)
+ if ((const Instruction *) I == inst) {
+ node = (*this)[inst];
+ break;
+ }
+
+ assert(inst != NULL && " Use not an Instruction ?");
+
+ if (node == NULL) //inst is not an instruction in this block
{
- //for each use of a def, add a flow edge from the def instruction to the ref instruction
-
-
- const Instruction* value=defVec[i]->getInst();
- Instruction *inst=(Instruction*)(*I);
- ModuloSchedGraphNode* node=NULL;
-
- for(BasicBlock::const_iterator I=bb->begin(), E=bb->end(); I !=E; I++)
- if((const Instruction*)I == inst)
- {
- node=(*this)[inst];
- break;
- }
-
- assert(inst != NULL &&" Use not an Instruction ?" );
-
- if(node == NULL) //inst is not an instruction in this block
- {}
- else
- {
- //add a flow edge from the def instruction to the ref instruction
-
- //self loop will not happen in SSA form
- assert(defVec[i] != node && "same node?");
-
-
- //this is a true dependence, so the delay is equal to the delay of the pred node.
- int delay=0;
- MachineCodeForInstruction& tempMvec= MachineCodeForInstruction::get(value);
- for(unsigned j=0;j< tempMvec.size();j++)
- {
- MachineInstr* temp=tempMvec[j];
- //delay +=mii.minLatency(temp->getOpCode());
- delay = max(delay, mii.minLatency(temp->getOpCode()));
- }
-
- SchedGraphEdge* trueEdge=new SchedGraphEdge(defVec[i],node,value, SchedGraphEdge::TrueDep,delay);
-
- //if the ref instruction is before the def instrution
- //then the def instruction must be a phi instruction
- //add an anti-dependence edge to from the ref instruction to the def instruction
- if( node->getOrigIndexInBB() < defVec[i]->getOrigIndexInBB())
- {
- assert(PHINode::classof(inst) && "the ref instruction befre def is not PHINode?");
- trueEdge->setIteDiff(1);
- }
-
- }
-
- }
-}
+ } else {
+ // Add a flow edge from the def instruction to the ref instruction
+
+ // self loop will not happen in SSA form
+ assert(defVec[i] != node && "same node?");
+
+ // This is a true dependence, so the delay is equal to the delay of the
+ // pred node.
+ int delay = 0;
+ MachineCodeForInstruction & tempMvec =
+ MachineCodeForInstruction::get(value);
+ for (unsigned j = 0; j < tempMvec.size(); j++) {
+ MachineInstr *temp = tempMvec[j];
+ //delay +=mii.minLatency(temp->getOpCode());
+ delay = std::max(delay, mii.minLatency(temp->getOpCode()));
+ }
+
+ SchedGraphEdge *trueEdge =
+ new SchedGraphEdge(defVec[i], node, value,
+ SchedGraphEdge::TrueDep, delay);
+
+ // if the ref instruction is before the def instrution
+ // then the def instruction must be a phi instruction
+ // add an anti-dependence edge to from the ref instruction to the def
+ // instruction
+ if (node->getOrigIndexInBB() < defVec[i]->getOrigIndexInBB()) {
+ assert(PHINode::classof(inst)
+ && "the ref instruction befre def is not PHINode?");
+ trueEdge->setIteDiff(1);
+ }
-void ModuloSchedGraph::addCDEdges(const BasicBlock* bb)
-{
- //find the last instruction in the basic block
- //see if it is an branch instruction.
- //If yes, then add an edge from each node expcept the last node to the last node
-
- const Instruction* inst=&(bb->back());
- ModuloSchedGraphNode* lastNode=(*this)[inst];
- if( TerminatorInst::classof(inst))
- for(BasicBlock::const_iterator I=bb->begin(),E=bb->end(); I != E; I++)
- {
- if(inst != I)
- {
- ModuloSchedGraphNode* node = (*this)[I];
- //use latency of 0
- (void) new SchedGraphEdge(node,lastNode,SchedGraphEdge::CtrlDep,
- SchedGraphEdge::NonDataDep,0);
- }
-
}
-
-
-}
+ }
+ }
+}
+void ModuloSchedGraph::addCDEdges(const BasicBlock * bb) {
+ // find the last instruction in the basic block
+ // see if it is an branch instruction.
+ // If yes, then add an edge from each node expcept the last node to the last
+ // node
+ const Instruction *inst = &(bb->back());
+ ModuloSchedGraphNode *lastNode = (*this)[inst];
+ if (TerminatorInst::classof(inst))
+ for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E;
+ I++) {
+ if (inst != I) {
+ ModuloSchedGraphNode *node = (*this)[I];
+ //use latency of 0
+ (void) new SchedGraphEdge(node, lastNode, SchedGraphEdge::CtrlDep,
+ SchedGraphEdge::NonDataDep, 0);
+ }
+ }
+}
-static const int SG_LOAD_REF = 0;
+static const int SG_LOAD_REF = 0;
static const int SG_STORE_REF = 1;
-static const int SG_CALL_REF = 2;
+static const int SG_CALL_REF = 2;
static const unsigned int SG_DepOrderArray[][3] = {
- { SchedGraphEdge::NonDataDep,
- SchedGraphEdge::AntiDep,
- SchedGraphEdge::AntiDep },
- { SchedGraphEdge::TrueDep,
- SchedGraphEdge::OutputDep,
- SchedGraphEdge::TrueDep | SchedGraphEdge::OutputDep },
- { SchedGraphEdge::TrueDep,
- SchedGraphEdge::AntiDep | SchedGraphEdge::OutputDep,
- SchedGraphEdge::TrueDep | SchedGraphEdge::AntiDep
- | SchedGraphEdge::OutputDep }
+ {SchedGraphEdge::NonDataDep,
+ SchedGraphEdge::AntiDep,
+ SchedGraphEdge::AntiDep},
+ {SchedGraphEdge::TrueDep,
+ SchedGraphEdge::OutputDep,
+ SchedGraphEdge::TrueDep | SchedGraphEdge::OutputDep},
+ {SchedGraphEdge::TrueDep,
+ SchedGraphEdge::AntiDep | SchedGraphEdge::OutputDep,
+ SchedGraphEdge::TrueDep | SchedGraphEdge::AntiDep
+ | SchedGraphEdge::OutputDep}
};
@@ -222,616 +205,666 @@ static const unsigned int SG_DepOrderArray[][3] = {
// Use latency 1 just to ensure that memory operations are ordered;
// latency does not otherwise matter (true dependences enforce that).
//
-void
-ModuloSchedGraph::addMemEdges(const BasicBlock* bb)
-{
-
- vector<ModuloSchedGraphNode*> memNodeVec;
+void ModuloSchedGraph::addMemEdges(const BasicBlock * bb) {
+
+ std::vector<ModuloSchedGraphNode*> memNodeVec;
//construct the memNodeVec
-
- for( BasicBlock::const_iterator I=bb->begin(), E=bb->end();I != E; I++)
- if(LoadInst::classof(I) ||StoreInst::classof(I) || CallInst::classof(I))
- {
- ModuloSchedGraphNode* node =(*this)[(const Instruction*)I];
- memNodeVec.push_back(node);
- }
+ for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E; ++I) {
+ if (LoadInst::classof(I) || StoreInst::classof(I)
+ || CallInst::classof(I)) {
+ ModuloSchedGraphNode *node = (*this)[(const Instruction *) I];
+ memNodeVec.push_back(node);
+ }
+ }
+
// Instructions in memNodeVec are in execution order within the basic block,
// so simply look at all pairs <memNodeVec[i], memNodeVec[j: j > i]>.
//
- for (unsigned im=0, NM=memNodeVec.size(); im < NM; im++)
- {
- const Instruction* fromInst = memNodeVec[im]->getInst();
- int fromType = CallInst::classof(fromInst)? SG_CALL_REF
- : LoadInst::classof(fromInst)? SG_LOAD_REF
- : SG_STORE_REF;
- for (unsigned jm=im+1; jm < NM; jm++)
- {
- const Instruction* toInst=memNodeVec[jm]->getInst();
- int toType = CallInst::classof(toInst)? SG_CALL_REF
- : LoadInst::classof(toInst)? SG_LOAD_REF
- : SG_STORE_REF;
- if (fromType != SG_LOAD_REF || toType != SG_LOAD_REF)
- {
- (void) new SchedGraphEdge(memNodeVec[im], memNodeVec[jm],
- SchedGraphEdge::MemoryDep,
- SG_DepOrderArray[fromType][toType], 1);
-
- SchedGraphEdge* edge=new SchedGraphEdge(memNodeVec[jm],memNodeVec[im],
- SchedGraphEdge::MemoryDep,
- SG_DepOrderArray[toType][fromType],1);
- edge->setIteDiff(1);
-
- }
- }
+ for (unsigned im = 0, NM = memNodeVec.size(); im < NM; im++) {
+ const Instruction *fromInst = memNodeVec[im]->getInst();
+ int fromType = CallInst::classof(fromInst) ? SG_CALL_REF
+ : LoadInst::classof(fromInst) ? SG_LOAD_REF : SG_STORE_REF;
+ for (unsigned jm = im + 1; jm < NM; jm++) {
+ const Instruction *toInst = memNodeVec[jm]->getInst();
+ int toType = CallInst::classof(toInst) ? SG_CALL_REF
+ : LoadInst::classof(toInst) ? SG_LOAD_REF : SG_STORE_REF;
+ if (fromType != SG_LOAD_REF || toType != SG_LOAD_REF) {
+ (void) new SchedGraphEdge(memNodeVec[im], memNodeVec[jm],
+ SchedGraphEdge::MemoryDep,
+ SG_DepOrderArray[fromType][toType], 1);
+
+ SchedGraphEdge *edge =
+ new SchedGraphEdge(memNodeVec[jm], memNodeVec[im],
+ SchedGraphEdge::MemoryDep,
+ SG_DepOrderArray[toType][fromType], 1);
+ edge->setIteDiff(1);
+
+ }
}
-}
+ }
+}
-void ModuloSchedGraph::buildNodesforBB (const TargetMachine& target,
- const BasicBlock* bb,
- std::vector<ModuloSchedGraphNode*>& memNode,
- RegToRefVecMap& regToRefVecMap,
- ValueToDefVecMap& valueToDefVecMap)
+void ModuloSchedGraph::buildNodesforBB(const TargetMachine &target,
+ const BasicBlock *bb,
+ std::vector<ModuloSchedGraphNode*> &memNode,
+ RegToRefVecMap &regToRefVecMap,
+ ValueToDefVecMap &valueToDefVecMap)
{
//const TargetInstrInfo& mii=target.getInstrInfo();
-
+
//Build graph nodes for each LLVM instruction and gather def/use info.
//Do both together in a single pass over all machine instructions.
-
- int i=0;
- for(BasicBlock::const_iterator I=bb->begin(), E=bb->end(); I!=E; I++)
- {
- ModuloSchedGraphNode* node=new ModuloSchedGraphNode(getNumNodes(), bb,I,i, target);
- i++;
- this->noteModuloSchedGraphNodeForInst(I,node);
- }
-
- //this function finds some info about instruction in basic block for later use
- //findDefUseInfoAtInstr(target, node, memNode,regToRefVecMap,valueToDefVecMap);
+ int i = 0;
+ for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E;
+ ++I) {
+ ModuloSchedGraphNode *node =
+ new ModuloSchedGraphNode(getNumNodes(), bb, I, i, target);
+ i++;
+ this->noteModuloSchedGraphNodeForInst(I, node);
+ }
+ //this function finds some info about instruction in basic block for later use
+ //findDefUseInfoAtInstr(target, node,
+ //memNode,regToRefVecMap,valueToDefVecMap);
}
-bool ModuloSchedGraph::isLoop(const BasicBlock* bb)
-{
+bool ModuloSchedGraph::isLoop(const BasicBlock *bb) {
//only if the last instruction in the basicblock is branch instruction and
//there is at least an option to branch itself
-
- const Instruction* inst=&(bb->back());
- if( BranchInst::classof(inst))
- for(unsigned i=0;i < ((BranchInst*)inst)->getNumSuccessors();i++)
- {
- BasicBlock* sb=((BranchInst*)inst)->getSuccessor(i);
- if(sb ==bb) return true;
- }
-
+ const Instruction *inst = &(bb->back());
+ if (BranchInst::classof(inst)) {
+ for (unsigned i = 0; i < ((BranchInst *) inst)->getNumSuccessors();
+ i++) {
+ BasicBlock *sb = ((BranchInst *) inst)->getSuccessor(i);
+ if (sb == bb)
+ return true;
+ }
+ }
+
return false;
-
+
}
-bool ModuloSchedGraph::isLoop()
-{
+
+bool ModuloSchedGraph::isLoop() {
//only if the last instruction in the basicblock is branch instruction and
//there is at least an option to branch itself
-
- assert(bbVec.size() ==1 &&"only 1 basicblock in a graph");
- const BasicBlock* bb=bbVec[0];
- const Instruction* inst=&(bb->back());
- if( BranchInst::classof(inst))
- for(unsigned i=0;i < ((BranchInst*)inst)->getNumSuccessors();i++)
- {
- BasicBlock* sb=((BranchInst*)inst)->getSuccessor(i);
- if(sb ==bb) return true;
- }
-
+
+ assert(bbVec.size() == 1 && "only 1 basicblock in a graph");
+ const BasicBlock *bb = bbVec[0];
+ const Instruction *inst = &(bb->back());
+ if (BranchInst::classof(inst))
+ for (unsigned i = 0; i < ((BranchInst *) inst)->getNumSuccessors();
+ i++) {
+ BasicBlock *sb = ((BranchInst *) inst)->getSuccessor(i);
+ if (sb == bb)
+ return true;
+ }
+
return false;
-
+
}
-void ModuloSchedGraph::computeNodeASAP(const BasicBlock* bb)
-{
+void ModuloSchedGraph::computeNodeASAP(const BasicBlock *bb) {
- //FIXME: now assume the only backward edges come from the edges from other nodes to the phi Node
- //so i will ignore all edges to the phi node; after this, there shall be no recurrence.
-
- unsigned numNodes=bb->size();
- for(unsigned i=2;i < numNodes+2;i++)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->setPropertyComputed(false);
- }
+ //FIXME: now assume the only backward edges come from the edges from other
+ //nodes to the phi Node so i will ignore all edges to the phi node; after
+ //this, there shall be no recurrence.
+
+ unsigned numNodes = bb->size();
+ for (unsigned i = 2; i < numNodes + 2; i++) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->setPropertyComputed(false);
+ }
- for(unsigned i=2;i < numNodes+2; i++)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->ASAP=0;
- if(i==2 ||node->getNumInEdges() ==0)
- { node->setPropertyComputed(true);continue;}
- for(ModuloSchedGraphNode::const_iterator I=node->beginInEdges(), E=node->endInEdges();I !=E; I++)
- {
- SchedGraphEdge* edge=*I;
- ModuloSchedGraphNode* pred=(ModuloSchedGraphNode*)(edge->getSrc());
- assert(pred->getPropertyComputed()&&"pred node property is not computed!");
- int temp=pred->ASAP + edge->getMinDelay() - edge->getIteDiff()*this->MII;
- node->ASAP= max(node->ASAP,temp);
- }
+ for (unsigned i = 2; i < numNodes + 2; i++) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->ASAP = 0;
+ if (i == 2 || node->getNumInEdges() == 0) {
node->setPropertyComputed(true);
+ continue;
+ }
+ for (ModuloSchedGraphNode::const_iterator I = node->beginInEdges(), E =
+ node->endInEdges(); I != E; I++) {
+ SchedGraphEdge *edge = *I;
+ ModuloSchedGraphNode *pred =
+ (ModuloSchedGraphNode *) (edge->getSrc());
+ assert(pred->getPropertyComputed()
+ && "pred node property is not computed!");
+ int temp =
+ pred->ASAP + edge->getMinDelay() -
+ edge->getIteDiff() * this->MII;
+ node->ASAP = std::max(node->ASAP, temp);
}
+ node->setPropertyComputed(true);
+ }
}
-void ModuloSchedGraph::computeNodeALAP(const BasicBlock* bb)
-{
-
- unsigned numNodes=bb->size();
- int maxASAP=0;
- for(unsigned i=numNodes+1;i >= 2;i--)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->setPropertyComputed(false);
- //cerr<< " maxASAP= " <<maxASAP<<" node->ASAP= "<< node->ASAP<<"\n";
- maxASAP=max(maxASAP,node->ASAP);
- }
+void ModuloSchedGraph::computeNodeALAP(const BasicBlock *bb) {
+ unsigned numNodes = bb->size();
+ int maxASAP = 0;
+ for (unsigned i = numNodes + 1; i >= 2; i--) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->setPropertyComputed(false);
+ //cerr<< " maxASAP= " <<maxASAP<<" node->ASAP= "<< node->ASAP<<"\n";
+ maxASAP = std::max(maxASAP, node->ASAP);
+ }
//cerr<<"maxASAP is "<<maxASAP<<"\n";
-
- for(unsigned i=numNodes+1;i >= 2; i--)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->ALAP=maxASAP;
- for(ModuloSchedGraphNode::const_iterator I=node->beginOutEdges(), E=node->endOutEdges(); I!=E; I++)
- {
- SchedGraphEdge* edge= *I;
- ModuloSchedGraphNode* succ=(ModuloSchedGraphNode*) (edge->getSink());
- if(PHINode::classof(succ->getInst()))continue;
- assert(succ->getPropertyComputed()&&"succ node property is not computed!");
- int temp=succ->ALAP - edge->getMinDelay()+edge->getIteDiff()*this->MII;
- node->ALAP =min(node->ALAP,temp);
- }
- node->setPropertyComputed(true);
-
+
+ for (unsigned i = numNodes + 1; i >= 2; i--) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->ALAP = maxASAP;
+ for (ModuloSchedGraphNode::const_iterator I =
+ node->beginOutEdges(), E = node->endOutEdges(); I != E; I++) {
+ SchedGraphEdge *edge = *I;
+ ModuloSchedGraphNode *succ =
+ (ModuloSchedGraphNode *) (edge->getSink());
+ if (PHINode::classof(succ->getInst()))
+ continue;
+ assert(succ->getPropertyComputed()
+ && "succ node property is not computed!");
+ int temp =
+ succ->ALAP - edge->getMinDelay() +
+ edge->getIteDiff() * this->MII;
+ node->ALAP = std::min(node->ALAP, temp);
}
+ node->setPropertyComputed(true);
+ }
}
-void ModuloSchedGraph::computeNodeMov(const BasicBlock* bb)
+void ModuloSchedGraph::computeNodeMov(const BasicBlock *bb)
{
- unsigned numNodes=bb->size();
- for(unsigned i =2;i < numNodes +2 ;i++)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->mov=node->ALAP-node->ASAP;
- assert(node->mov >=0 &&"move freedom for this node is less than zero? ");
- }
+ unsigned numNodes = bb->size();
+ for (unsigned i = 2; i < numNodes + 2; i++) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->mov = node->ALAP - node->ASAP;
+ assert(node->mov >= 0
+ && "move freedom for this node is less than zero? ");
+ }
}
-void ModuloSchedGraph::computeNodeDepth(const BasicBlock* bb)
+void ModuloSchedGraph::computeNodeDepth(const BasicBlock * bb)
{
- unsigned numNodes=bb->size();
- for(unsigned i=2;i < numNodes+2;i++)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->setPropertyComputed(false);
- }
+ unsigned numNodes = bb->size();
+ for (unsigned i = 2; i < numNodes + 2; i++) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->setPropertyComputed(false);
+ }
- for(unsigned i=2;i < numNodes+2; i++)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->depth=0;
- if(i==2 ||node->getNumInEdges() ==0)
- { node->setPropertyComputed(true);continue;}
- for(ModuloSchedGraphNode::const_iterator I=node->beginInEdges(), E=node->endInEdges();I !=E; I++)
- {
- SchedGraphEdge* edge=*I;
- ModuloSchedGraphNode* pred=(ModuloSchedGraphNode*)(edge->getSrc());
- assert(pred->getPropertyComputed()&&"pred node property is not computed!");
- int temp=pred->depth + edge->getMinDelay();
- node->depth= max(node->depth,temp);
- }
+ for (unsigned i = 2; i < numNodes + 2; i++) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->depth = 0;
+ if (i == 2 || node->getNumInEdges() == 0) {
node->setPropertyComputed(true);
+ continue;
+ }
+ for (ModuloSchedGraphNode::const_iterator I = node->beginInEdges(), E =
+ node->endInEdges(); I != E; I++) {
+ SchedGraphEdge *edge = *I;
+ ModuloSchedGraphNode *pred =
+ (ModuloSchedGraphNode *) (edge->getSrc());
+ assert(pred->getPropertyComputed()
+ && "pred node property is not computed!");
+ int temp = pred->depth + edge->getMinDelay();
+ node->depth = std::max(node->depth, temp);
}
+ node->setPropertyComputed(true);
+ }
}
-void ModuloSchedGraph::computeNodeHeight(const BasicBlock* bb)
+void ModuloSchedGraph::computeNodeHeight(const BasicBlock *bb)
{
- unsigned numNodes=bb->size();
- for(unsigned i=numNodes+1;i >= 2;i--)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->setPropertyComputed(false);
- }
-
- for(unsigned i=numNodes+1;i >= 2; i--)
- {
- ModuloSchedGraphNode* node=getNode(i);
- node->height=0;
- for(ModuloSchedGraphNode::const_iterator I=node->beginOutEdges(), E=node->endOutEdges(); I!=E; I++)
- {
- SchedGraphEdge* edge= *I;
- ModuloSchedGraphNode* succ=(ModuloSchedGraphNode*)(edge->getSink());
- if(PHINode::classof(succ->getInst())) continue;
- assert(succ->getPropertyComputed()&&"succ node property is not computed!");
- node->height=max(node->height, succ->height+edge->getMinDelay());
-
- }
- node->setPropertyComputed(true);
-
+ unsigned numNodes = bb->size();
+ for (unsigned i = numNodes + 1; i >= 2; i--) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->setPropertyComputed(false);
+ }
+
+ for (unsigned i = numNodes + 1; i >= 2; i--) {
+ ModuloSchedGraphNode *node = getNode(i);
+ node->height = 0;
+ for (ModuloSchedGraphNode::const_iterator I =
+ node->beginOutEdges(), E = node->endOutEdges(); I != E; ++I) {
+ SchedGraphEdge *edge = *I;
+ ModuloSchedGraphNode *succ =
+ (ModuloSchedGraphNode *) (edge->getSink());
+ if (PHINode::classof(succ->getInst()))
+ continue;
+ assert(succ->getPropertyComputed()
+ && "succ node property is not computed!");
+ node->height = std::max(node->height, succ->height + edge->getMinDelay());
+
}
+ node->setPropertyComputed(true);
+
+ }
}
-void ModuloSchedGraph::computeNodeProperty(const BasicBlock* bb)
+void ModuloSchedGraph::computeNodeProperty(const BasicBlock * bb)
{
- //FIXME: now assume the only backward edges come from the edges from other nodes to the phi Node
- //so i will ignore all edges to the phi node; after this, there shall be no recurrence.
-
+ //FIXME: now assume the only backward edges come from the edges from other
+ //nodes to the phi Node so i will ignore all edges to the phi node; after
+ //this, there shall be no recurrence.
+
this->computeNodeASAP(bb);
this->computeNodeALAP(bb);
this->computeNodeMov(bb);
this->computeNodeDepth(bb);
- this->computeNodeHeight(bb);
+ this->computeNodeHeight(bb);
}
//do not consider the backedge in these two functions:
// i.e. don't consider the edge with destination in phi node
-std::vector<ModuloSchedGraphNode*> ModuloSchedGraph::predSet(std::vector<ModuloSchedGraphNode*> set, unsigned backEdgeSrc, unsigned backEdgeSink)
+std::vector<ModuloSchedGraphNode*>
+ModuloSchedGraph::predSet(std::vector<ModuloSchedGraphNode*> set,
+ unsigned backEdgeSrc,
+ unsigned
+ backEdgeSink)
{
std::vector<ModuloSchedGraphNode*> predS;
- for(unsigned i=0; i < set.size(); i++)
- {
- ModuloSchedGraphNode* node = set[i];
- for(ModuloSchedGraphNode::const_iterator I=node->beginInEdges(), E=node->endInEdges(); I !=E; I++)
- {
- SchedGraphEdge* edge= *I;
- if(edge->getSrc()->getNodeId() ==backEdgeSrc && edge->getSink()->getNodeId() == backEdgeSink) continue;
- ModuloSchedGraphNode* pred= (ModuloSchedGraphNode*)(edge->getSrc());
- //if pred is not in the predSet, push it in vector
- bool alreadyInset=false;
- for(unsigned j=0; j < predS.size(); j++)
- if(predS[j]->getNodeId() == pred->getNodeId() )
- {alreadyInset=true;break;}
-
- for(unsigned j=0; j < set.size(); j++)
- if(set[j]->getNodeId() == pred->getNodeId() )
- {alreadyInset=true; break;}
-
- if(! alreadyInset)
- predS.push_back(pred);
- }
+ for (unsigned i = 0; i < set.size(); i++) {
+ ModuloSchedGraphNode *node = set[i];
+ for (ModuloSchedGraphNode::const_iterator I = node->beginInEdges(), E =
+ node->endInEdges(); I != E; I++) {
+ SchedGraphEdge *edge = *I;
+ if (edge->getSrc()->getNodeId() == backEdgeSrc
+ && edge->getSink()->getNodeId() == backEdgeSink)
+ continue;
+ ModuloSchedGraphNode *pred =
+ (ModuloSchedGraphNode *) (edge->getSrc());
+ //if pred is not in the predSet, push it in vector
+ bool alreadyInset = false;
+ for (unsigned j = 0; j < predS.size(); ++j)
+ if (predS[j]->getNodeId() == pred->getNodeId()) {
+ alreadyInset = true;
+ break;
+ }
+
+ for (unsigned j = 0; j < set.size(); ++j)
+ if (set[j]->getNodeId() == pred->getNodeId()) {
+ alreadyInset = true;
+ break;
+ }
+
+ if (!alreadyInset)
+ predS.push_back(pred);
}
+ }
return predS;
}
ModuloSchedGraph::NodeVec ModuloSchedGraph::predSet(NodeVec set)
{
//node number increases from 2
- return predSet(set,0, 0);
+ return predSet(set, 0, 0);
}
-
-std::vector<ModuloSchedGraphNode*> ModuloSchedGraph::predSet(ModuloSchedGraphNode* _node, unsigned backEdgeSrc, unsigned backEdgeSink)
+std::vector <ModuloSchedGraphNode*>
+ModuloSchedGraph::predSet(ModuloSchedGraphNode *_node,
+ unsigned backEdgeSrc, unsigned backEdgeSink)
{
-
std::vector<ModuloSchedGraphNode*> set;
set.push_back(_node);
return predSet(set, backEdgeSrc, backEdgeSink);
-
}
-std::vector<ModuloSchedGraphNode*> ModuloSchedGraph::predSet(ModuloSchedGraphNode* _node)
+std::vector <ModuloSchedGraphNode*>
+ModuloSchedGraph::predSet(ModuloSchedGraphNode * _node)
{
- return predSet(_node,0,0);
+ return predSet(_node, 0, 0);
}
-std::vector<ModuloSchedGraphNode*> ModuloSchedGraph::succSet(std::vector<ModuloSchedGraphNode*> set,unsigned src, unsigned sink)
+std::vector<ModuloSchedGraphNode*>
+ModuloSchedGraph::succSet(std::vector<ModuloSchedGraphNode*> set,
+ unsigned src, unsigned sink)
{
- vector<ModuloSchedGraphNode*> succS;
- for(unsigned i=0; i < set.size(); i++)
- {
- ModuloSchedGraphNode* node = set[i];
- for(ModuloSchedGraphNode::const_iterator I=node->beginOutEdges(), E=node->endOutEdges(); I !=E; I++)
- {
- SchedGraphEdge* edge= *I;
- if(edge->getSrc()->getNodeId() == src && edge->getSink()->getNodeId() == sink) continue;
- ModuloSchedGraphNode* succ= (ModuloSchedGraphNode*)(edge->getSink());
- //if pred is not in the predSet, push it in vector
- bool alreadyInset=false;
- for(unsigned j=0; j < succS.size(); j++)
- if(succS[j]->