diff options
author | Misha Brukman <brukman+llvm@gmail.com> | 2005-04-21 23:30:14 +0000 |
---|---|---|
committer | Misha Brukman <brukman+llvm@gmail.com> | 2005-04-21 23:30:14 +0000 |
commit | b5f662fa0314f7e7e690aae8ebff7136cc3a5ab0 (patch) | |
tree | e7c0cbff032351446ce38058e84f6f6f9fd2300d /lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp | |
parent | 4633f1cde84b1dbb05dfbdce17ca6b483596cee7 (diff) |
Remove trailing whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21425 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp')
-rw-r--r-- | lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp | 636 |
1 files changed, 318 insertions, 318 deletions
diff --git a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp index f5faae5e31..4c0e449513 100644 --- a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp +++ b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp @@ -6,10 +6,10 @@ // the University of Illinois Open Source License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This ModuloScheduling pass is based on the Swing Modulo Scheduling -// algorithm. -// +// +// This ModuloScheduling pass is based on the Swing Modulo Scheduling +// algorithm. +// //===----------------------------------------------------------------------===// #define DEBUG_TYPE "ModuloSched" @@ -44,7 +44,7 @@ using namespace llvm; /// FunctionPass *llvm::createModuloSchedulingPass(TargetMachine & targ) { DEBUG(std::cerr << "Created ModuloSchedulingPass\n"); - return new ModuloSchedulingPass(targ); + return new ModuloSchedulingPass(targ); } @@ -55,7 +55,7 @@ static void WriteGraphToFile(std::ostream &O, const std::string &GraphName, std::string Filename = GraphName + ".dot"; O << "Writing '" << Filename << "'..."; std::ofstream F(Filename.c_str()); - + if (F.good()) WriteGraph(F, GT); else @@ -86,7 +86,7 @@ namespace llvm { static std::string getGraphName(MSchedGraph *F) { return "Dependence Graph"; } - + static std::string getNodeLabel(MSchedGraphNode *Node, MSchedGraph *Graph) { if (Node->getInst()) { std::stringstream ss; @@ -102,15 +102,15 @@ namespace llvm { std::string edgelabel = ""; switch (I.getEdge().getDepOrderType()) { - case MSchedGraphEdge::TrueDep: + case MSchedGraphEdge::TrueDep: edgelabel = "True"; break; - - case MSchedGraphEdge::AntiDep: + + case MSchedGraphEdge::AntiDep: edgelabel = "Anti"; break; - case MSchedGraphEdge::OutputDep: + case MSchedGraphEdge::OutputDep: edgelabel = "Output"; break; @@ -140,37 +140,37 @@ namespace llvm { /// 1) Computation and Analysis of the dependence graph /// 2) Ordering of the nodes /// 3) Scheduling -/// +/// bool ModuloSchedulingPass::runOnFunction(Function &F) { alarm(300); bool Changed = false; int numMS = 0; - + DEBUG(std::cerr << "Creating ModuloSchedGraph for each valid BasicBlock in " + F.getName() + "\n"); - + //Get MachineFunction MachineFunction &MF = MachineFunction::get(&F); - + DependenceAnalyzer &DA = getAnalysis<DependenceAnalyzer>(); - + //Worklist std::vector<MachineBasicBlock*> Worklist; - + //Iterate over BasicBlocks and put them into our worklist if they are valid for (MachineFunction::iterator BI = MF.begin(); BI != MF.end(); ++BI) - if(MachineBBisValid(BI)) { + if(MachineBBisValid(BI)) { Worklist.push_back(&*BI); ++ValidLoops; } - + defaultInst = 0; DEBUG(if(Worklist.size() == 0) std::cerr << "No single basic block loops in function to ModuloSchedule\n"); //Iterate over the worklist and perform scheduling - for(std::vector<MachineBasicBlock*>::iterator BI = Worklist.begin(), + for(std::vector<MachineBasicBlock*>::iterator BI = Worklist.begin(), BE = Worklist.end(); BI != BE; ++BI) { //Print out BB for debugging @@ -192,71 +192,71 @@ bool ModuloSchedulingPass::runOnFunction(Function &F) { } MSchedGraph *MSG = new MSchedGraph(*BI, target, indVarInstrs[*BI], DA, machineTollvm[*BI]); - + //Write Graph out to file DEBUG(WriteGraphToFile(std::cerr, F.getName(), MSG)); - + //Calculate Resource II int ResMII = calculateResMII(*BI); - + //Calculate Recurrence II int RecMII = calculateRecMII(MSG, ResMII); DEBUG(std::cerr << "Number of reccurrences found: " << recurrenceList.size() << "\n"); - - + + //Our starting initiation interval is the maximum of RecMII and ResMII II = std::max(RecMII, ResMII); - + //Print out II, RecMII, and ResMII DEBUG(std::cerr << "II starts out as " << II << " ( RecMII=" << RecMII << " and ResMII=" << ResMII << ")\n"); - + //Dump node properties if in debug mode - DEBUG(for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), + DEBUG(for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), E = nodeToAttributesMap.end(); I !=E; ++I) { - std::cerr << "Node: " << *(I->first) << " ASAP: " << I->second.ASAP << " ALAP: " - << I->second.ALAP << " MOB: " << I->second.MOB << " Depth: " << I->second.depth + std::cerr << "Node: " << *(I->first) << " ASAP: " << I->second.ASAP << " ALAP: " + << I->second.ALAP << " MOB: " << I->second.MOB << " Depth: " << I->second.depth << " Height: " << I->second.height << "\n"; }); //Calculate Node Properties calculateNodeAttributes(MSG, ResMII); - + //Dump node properties if in debug mode - DEBUG(for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), + DEBUG(for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), E = nodeToAttributesMap.end(); I !=E; ++I) { - std::cerr << "Node: " << *(I->first) << " ASAP: " << I->second.ASAP << " ALAP: " - << I->second.ALAP << " MOB: " << I->second.MOB << " Depth: " << I->second.depth + std::cerr << "Node: " << *(I->first) << " ASAP: " << I->second.ASAP << " ALAP: " + << I->second.ALAP << " MOB: " << I->second.MOB << " Depth: " << I->second.depth << " Height: " << I->second.height << "\n"; }); - + //Put nodes in order to schedule them computePartialOrder(); - + //Dump out partial order - DEBUG(for(std::vector<std::set<MSchedGraphNode*> >::iterator I = partialOrder.begin(), + DEBUG(for(std::vector<std::set<MSchedGraphNode*> >::iterator I = partialOrder.begin(), E = partialOrder.end(); I !=E; ++I) { std::cerr << "Start set in PO\n"; for(std::set<MSchedGraphNode*>::iterator J = I->begin(), JE = I->end(); J != JE; ++J) std::cerr << "PO:" << **J << "\n"; }); - + //Place nodes in final order orderNodes(); - + //Dump out order of nodes DEBUG(for(std::vector<MSchedGraphNode*>::iterator I = FinalNodeOrder.begin(), E = FinalNodeOrder.end(); I != E; ++I) { std::cerr << "FO:" << **I << "\n"; }); - + //Finally schedule nodes bool haveSched = computeSchedule(*BI); - + //Print out final schedule DEBUG(schedule.print(std::cerr)); - + //Final scheduling step is to reconstruct the loop only if we actual have //stage > 0 if(haveSched) { @@ -269,7 +269,7 @@ bool ModuloSchedulingPass::runOnFunction(Function &F) { } else ++NoSched; - + //Clear out our maps for the next basic block that is processed nodeToAttributesMap.clear(); partialOrder.clear(); @@ -283,12 +283,12 @@ bool ModuloSchedulingPass::runOnFunction(Function &F) { //Should't std::find work?? //parent->getBasicBlockList().erase(std::find(parent->getBasicBlockList().begin(), parent->getBasicBlockList().end(), *llvmBB)); //parent->getBasicBlockList().erase(llvmBB); - + //delete(llvmBB); //delete(*BI); } - alarm(0); + alarm(0); return Changed; } @@ -300,12 +300,12 @@ bool ModuloSchedulingPass::CreateDefMap(MachineBasicBlock *BI) { const MachineOperand &mOp = I->getOperand(opNum); if(mOp.getType() == MachineOperand::MO_VirtualRegister && mOp.isDef()) { //assert if this is the second def we have seen - //DEBUG(std::cerr << "Putting " << *(mOp.getVRegValue()) << " into map\n"); + //DEBUG(std::cerr << "Putting " << *(mOp.getVRegValue()) << " into map\n"); assert(!defMap.count(mOp.getVRegValue()) && "Def already in the map"); defMap[mOp.getVRegValue()] = &*I; } - + //See if we can use this Value* as our defaultInst if(!defaultInst && mOp.getType() == MachineOperand::MO_VirtualRegister) { Value *V = mOp.getVRegValue(); @@ -314,12 +314,12 @@ bool ModuloSchedulingPass::CreateDefMap(MachineBasicBlock *BI) { } } } - + if(!defaultInst) return false; - + return true; - + } /// This function checks if a Machine Basic Block is valid for modulo /// scheduling. This means that it has no control flow (if/else or @@ -328,14 +328,14 @@ bool ModuloSchedulingPass::CreateDefMap(MachineBasicBlock *BI) { bool ModuloSchedulingPass::MachineBBisValid(const MachineBasicBlock *BI) { bool isLoop = false; - + //Check first if its a valid loop - for(succ_const_iterator I = succ_begin(BI->getBasicBlock()), + for(succ_const_iterator I = succ_begin(BI->getBasicBlock()), E = succ_end(BI->getBasicBlock()); I != E; ++I) { if (*I == BI->getBasicBlock()) // has single block loop isLoop = true; } - + if(!isLoop) return false; @@ -353,7 +353,7 @@ bool ModuloSchedulingPass::MachineBBisValid(const MachineBasicBlock *BI) { //Get Target machine instruction info const TargetInstrInfo *TMI = target.getInstrInfo(); - + //Check each instruction and look for calls, keep map to get index later std::map<const MachineInstr*, unsigned> indexMap; @@ -361,21 +361,21 @@ bool ModuloSchedulingPass::MachineBBisValid(const MachineBasicBlock *BI) { for(MachineBasicBlock::const_iterator I = BI->begin(), E = BI->end(); I != E; ++I) { //Get opcode to check instruction type MachineOpCode OC = I->getOpcode(); - + //Look for calls if(TMI->isCall(OC)) return false; - + //Look for conditional move - if(OC == V9::MOVRZr || OC == V9::MOVRZi || OC == V9::MOVRLEZr || OC == V9::MOVRLEZi + if(OC == V9::MOVRZr || OC == V9::MOVRZi || OC == V9::MOVRLEZr || OC == V9::MOVRLEZi || OC == V9::MOVRLZr || OC == V9::MOVRLZi || OC == V9::MOVRNZr || OC == V9::MOVRNZi - || OC == V9::MOVRGZr || OC == V9::MOVRGZi || OC == V9::MOVRGEZr + || OC == V9::MOVRGZr || OC == V9::MOVRGZi || OC == V9::MOVRGEZr || OC == V9::MOVRGEZi || OC == V9::MOVLEr || OC == V9::MOVLEi || OC == V9::MOVLEUr || OC == V9::MOVLEUi || OC == V9::MOVFLEr || OC == V9::MOVFLEi || OC == V9::MOVNEr || OC == V9::MOVNEi || OC == V9::MOVNEGr || OC == V9::MOVNEGi || OC == V9::MOVFNEr || OC == V9::MOVFNEi) return false; - + indexMap[I] = count; if(TMI->isNop(OC)) @@ -435,7 +435,7 @@ bool ModuloSchedulingPass::MachineBBisValid(const MachineBasicBlock *BI) { //Convert list of LLVM Instructions to list of Machine instructions std::map<const MachineInstr*, unsigned> mIndVar; for(std::set<Instruction*>::iterator N = indVar.begin(), NE = indVar.end(); N != NE; ++N) { - + //If we have a load, we can't handle this loop because there is no way to preserve dependences //between loads and stores if(isa<LoadInst>(*N)) @@ -463,7 +463,7 @@ bool ModuloSchedulingPass::MachineBBisValid(const MachineBasicBlock *BI) { return true; } -bool ModuloSchedulingPass::assocIndVar(Instruction *I, std::set<Instruction*> &indVar, +bool ModuloSchedulingPass::assocIndVar(Instruction *I, std::set<Instruction*> &indVar, std::vector<Instruction*> &stack, BasicBlock *BB) { stack.push_back(I); @@ -503,14 +503,14 @@ bool ModuloSchedulingPass::assocIndVar(Instruction *I, std::set<Instruction*> &i //FIXME: In future there should be a way to get alternative resources //for each instruction int ModuloSchedulingPass::calculateResMII(const MachineBasicBlock *BI) { - + TIME_REGION(X, "calculateResMII"); const TargetInstrInfo *mii = target.getInstrInfo(); const TargetSchedInfo *msi = target.getSchedInfo(); int ResMII = 0; - + //Map to keep track of usage count of each resource std::map<unsigned, unsigned> resourceUsageCount; @@ -533,18 +533,18 @@ int ModuloSchedulingPass::calculateResMII(const MachineBasicBlock *BI) { } //Find maximum usage count - + //Get max number of instructions that can be issued at once. (FIXME) int issueSlots = msi->maxNumIssueTotal; for(std::map<unsigned,unsigned>::iterator RB = resourceUsageCount.begin(), RE = resourceUsageCount.end(); RB != RE; ++RB) { - + //Get the total number of the resources in our cpu int resourceNum = CPUResource::getCPUResource(RB->first)->maxNumUsers; - + //Get total usage count for this resources unsigned usageCount = RB->second; - + //Divide the usage count by either the max number we can issue or the number of //resources (whichever is its upper bound) double finalUsageCount; @@ -552,8 +552,8 @@ int ModuloSchedulingPass::calculateResMII(const MachineBasicBlock *BI) { finalUsageCount = ceil(1.0 * usageCount / resourceNum); else finalUsageCount = ceil(1.0 * usageCount / issueSlots); - - + + //Only keep track of the max ResMII = std::max( (int) finalUsageCount, ResMII); @@ -572,16 +572,16 @@ int ModuloSchedulingPass::calculateRecMII(MSchedGraph *graph, int MII) { findAllReccurrences(I->second, vNodes, MII); vNodes.clear(); }*/ - + TIME_REGION(X, "calculateRecMII"); findAllCircuits(graph, MII); int RecMII = 0; - + for(std::set<std::pair<int, std::vector<MSchedGraphNode*> > >::iterator I = recurrenceList.begin(), E=recurrenceList.end(); I !=E; ++I) { RecMII = std::max(RecMII, I->first); } - + return MII; } @@ -602,20 +602,20 @@ void ModuloSchedulingPass::calculateNodeAttributes(MSchedGraph *graph, int MII) //Assert if its already in the map assert(nodeToAttributesMap.count(I->second) == 0 && "Node attributes are already in the map"); - + //Put into the map with default attribute values nodeToAttributesMap[I->second] = MSNodeAttributes(); } //Create set to deal with reccurrences std::set<MSchedGraphNode*> visitedNodes; - + //Now Loop over map and calculate the node attributes for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), E = nodeToAttributesMap.end(); I != E; ++I) { calculateASAP(I->first, MII, (MSchedGraphNode*) 0); visitedNodes.clear(); } - + int maxASAP = findMaxASAP(); //Calculate ALAP which depends on ASAP being totally calculated for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), E = nodeToAttributesMap.end(); I != E; ++I) { @@ -626,7 +626,7 @@ void ModuloSchedulingPass::calculateNodeAttributes(MSchedGraph *graph, int MII) //Calculate MOB which depends on ASAP being totally calculated, also do depth and height for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), E = nodeToAttributesMap.end(); I != E; ++I) { (I->second).MOB = std::max(0,(I->second).ALAP - (I->second).ASAP); - + DEBUG(std::cerr << "MOB: " << (I->second).MOB << " (" << *(I->first) << ")\n"); calculateDepth(I->first, (MSchedGraphNode*) 0); calculateHeight(I->first, (MSchedGraphNode*) 0); @@ -639,18 +639,18 @@ void ModuloSchedulingPass::calculateNodeAttributes(MSchedGraph *graph, int MII) bool ModuloSchedulingPass::ignoreEdge(MSchedGraphNode *srcNode, MSchedGraphNode *destNode) { if(destNode == 0 || srcNode ==0) return false; - + bool findEdge = edgesToIgnore.count(std::make_pair(srcNode, destNode->getInEdgeNum(srcNode))); - + DEBUG(std::cerr << "Ignoring edge? from: " << *srcNode << " to " << *destNode << "\n"); return findEdge; } -/// calculateASAP - Calculates the +/// calculateASAP - Calculates the int ModuloSchedulingPass::calculateASAP(MSchedGraphNode *node, int MII, MSchedGraphNode *destNode) { - + DEBUG(std::cerr << "Calculating ASAP for " << *node << "\n"); //Get current node attributes @@ -658,46 +658,46 @@ int ModuloSchedulingPass::calculateASAP(MSchedGraphNode *node, int MII, MSchedG if(attributes.ASAP != -1) return attributes.ASAP; - + int maxPredValue = 0; - + //Iterate over all of the predecessors and find max for(MSchedGraphNode::pred_iterator P = node->pred_begin(), E = node->pred_end(); P != E; ++P) { - + //Only process if we are not ignoring the edge if(!ignoreEdge(*P, node)) { int predASAP = -1; predASAP = calculateASAP(*P, MII, node); - + assert(predASAP != -1 && "ASAP has not been calculated"); int iteDiff = node->getInEdge(*P).getIteDiff(); - + int currentPredValue = predASAP + (*P)->getLatency() - (iteDiff * MII); DEBUG(std::cerr << "pred ASAP: " << predASAP << ", iteDiff: " << iteDiff << ", PredLatency: " << (*P)->getLatency() << ", Current ASAP pred: " << currentPredValue << "\n"); maxPredValue = std::max(maxPredValue, currentPredValue); } } - + attributes.ASAP = maxPredValue; DEBUG(std::cerr << "ASAP: " << attributes.ASAP << " (" << *node << ")\n"); - + return maxPredValue; } -int ModuloSchedulingPass::calculateALAP(MSchedGraphNode *node, int MII, +int ModuloSchedulingPass::calculateALAP(MSchedGraphNode *node, int MII, int maxASAP, MSchedGraphNode *srcNode) { - + DEBUG(std::cerr << "Calculating ALAP for " << *node << "\n"); - + MSNodeAttributes &attributes = nodeToAttributesMap.find(node)->second; - + if(attributes.ALAP != -1) return attributes.ALAP; - + if(node->hasSuccessors()) { - + //Trying to deal with the issue where the node has successors, but //we are ignoring all of the edges to them. So this is my hack for //now.. there is probably a more elegant way of doing this (FIXME) @@ -705,11 +705,11 @@ int ModuloSchedulingPass::calculateALAP(MSchedGraphNode *node, int MII, //FIXME, set to something high to start int minSuccValue = 9999999; - + //Iterate over all of the predecessors and fine max - for(MSchedGraphNode::succ_iterator P = node->succ_begin(), + for(MSchedGraphNode::succ_iterator P = node->succ_begin(), E = node->succ_end(); P != E; ++P) { - + //Only process if we are not ignoring the edge if(!ignoreEdge(node, *P)) { processedOneEdge = true; @@ -727,10 +727,10 @@ int ModuloSchedulingPass::calculateALAP(MSchedGraphNode *node, int MII, minSuccValue = std::min(minSuccValue, currentSuccValue); } } - + if(processedOneEdge) attributes.ALAP = minSuccValue; - + else attributes.ALAP = maxASAP; } @@ -756,19 +756,19 @@ int ModuloSchedulingPass::findMaxASAP() { int ModuloSchedulingPass::calculateHeight(MSchedGraphNode *node,MSchedGraphNode *srcNode) { - + MSNodeAttributes &attributes = nodeToAttributesMap.find(node)->second; if(attributes.height != -1) return attributes.height; int maxHeight = 0; - + //Iterate over all of the predecessors and find max - for(MSchedGraphNode::succ_iterator P = node->succ_begin(), + for(MSchedGraphNode::succ_iterator P = node->succ_begin(), E = node->succ_end(); P != E; ++P) { - - + + if(!ignoreEdge(node, *P)) { int succHeight = calculateHeight(*P, node); @@ -784,7 +784,7 @@ int ModuloSchedulingPass::calculateHeight(MSchedGraphNode *node,MSchedGraphNode } -int ModuloSchedulingPass::calculateDepth(MSchedGraphNode *node, +int ModuloSchedulingPass::calculateDepth(MSchedGraphNode *node, MSchedGraphNode *destNode) { MSNodeAttributes &attributes = nodeToAttributesMap.find(node)->second; @@ -793,14 +793,14 @@ int ModuloSchedulingPass::calculateDepth(MSchedGraphNode *node, return attributes.depth; int maxDepth = 0; - + //Iterate over all of the predecessors and fine max for(MSchedGraphNode::pred_iterator P = node->pred_begin(), E = node->pred_end(); P != E; ++P) { if(!ignoreEdge(*P, node)) { int predDepth = -1; predDepth = calculateDepth(*P, node); - + assert(predDepth != -1 && "Predecessors ASAP should have been caclulated"); int currentDepth = predDepth + (*P)->getLatency(); @@ -808,7 +808,7 @@ int ModuloSchedulingPass::calculateDepth(MSchedGraphNode *node, } } attributes.depth = maxDepth; - + DEBUG(std::cerr << "Depth: " << attributes.depth << " (" << *node << "*)\n"); return maxDepth; } @@ -822,11 +822,11 @@ void ModuloSchedulingPass::addReccurrence(std::vector<MSchedGraphNode*> &recurre //Loop over all recurrences already in our list for(std::set<std::pair<int, std::vector<MSchedGraphNode*> > >::iterator R = recurrenceList.begin(), RE = recurrenceList.end(); R != RE; ++R) { - + bool all_same = true; //First compare size if(R->second.size() == recurrence.size()) { - + for(std::vector<MSchedGraphNode*>::const_iterator node = R->second.begin(), end = R->second.end(); node != end; ++node) { if(std::find(recurrence.begin(), recurrence.end(), *node) == recurrence.end()) { all_same = all_same && false; @@ -841,30 +841,30 @@ void ModuloSchedulingPass::addReccurrence(std::vector<MSchedGraphNode*> &recurre } } } - + if(!same) { srcBENode = recurrence.back(); destBENode = recurrence.front(); - + //FIXME if(destBENode->getInEdge(srcBENode).getIteDiff() == 0) { //DEBUG(std::cerr << "NOT A BACKEDGE\n"); - //find actual backedge HACK HACK + //find actual backedge HACK HACK for(unsigned i=0; i< recurrence.size()-1; ++i) { if(recurrence[i+1]->getInEdge(recurrence[i]).getIteDiff() == 1) { srcBENode = recurrence[i]; destBENode = recurrence[i+1]; break; } - + } - + } DEBUG(std::cerr << "Back Edge to Remove: " << *srcBENode << " to " << *destBENode << "\n"); edgesToIgnore.insert(std::make_pair(srcBENode, destBENode->getInEdgeNum(srcBENode))); recurrenceList.insert(std::make_pair(II, recurrence)); } - + } int CircCount; @@ -888,12 +888,12 @@ void ModuloSchedulingPass::unblock(MSchedGraphNode *u, std::set<MSchedGraphNode* } -bool ModuloSchedulingPass::circuit(MSchedGraphNode *v, std::vector<MSchedGraphNode*> &stack, - std::set<MSchedGraphNode*> &blocked, std::vector<MSchedGraphNode*> &SCC, - MSchedGraphNode *s, std::map<MSchedGraphNode*, std::set<MSchedGraphNode*> > &B, +bool ModuloSchedulingPass::circuit(MSchedGraphNode *v, std::vector<MSchedGraphNode*> &stack, + std::set<MSchedGraphNode*> &blocked, std::vector<MSchedGraphNode*> &SCC, + MSchedGraphNode *s, std::map<MSchedGraphNode*, std::set<MSchedGraphNode*> > &B, int II, std::map<MSchedGraphNode*, MSchedGraphNode*> &newNodes) { bool f = false; - + DEBUG(std::cerr << "Finding Circuits Starting with: ( " << v << ")"<< *v << "\n"); //Push node onto the stack @@ -913,7 +913,7 @@ bool ModuloSchedulingPass::circuit(MSchedGraphNode *v, std::vector<MSchedGraphNo for(std::set<MSchedGraphNode*>::iterator I = AkV.begin(), E = AkV.end(); I != E; ++I) { if(*I == s) { //We have a circuit, so add it to our list - + std::vector<MSchedGraphNode*> recc; //Dump recurrence for now DEBUG(std::cerr << "Starting Recc\n"); @@ -966,7 +966,7 @@ bool ModuloSchedulingPass::circuit(MSchedGraphNode *v, std::vector<MSchedGraphNo int value = totalDelay-(RecMII * totalDistance); int lastII = II; while(value <= 0) { - + lastII = RecMII; RecMII--; value = totalDelay-(RecMII * totalDistance); @@ -988,7 +988,7 @@ bool ModuloSchedulingPass::circuit(MSchedGraphNode *v, std::vector<MSchedGraphNo unblock(v, blocked, B); } else { - for(std::set<MSchedGraphNode*>::iterator I = AkV.begin(), E = AkV.end(); I != E; ++I) + for(std::set<MSchedGraphNode*>::iterator I = AkV.begin(), E = AkV.end(); I != E; ++I) B[*I].insert(v); } @@ -1004,7 +1004,7 @@ void ModuloSchedulingPass::findAllCircuits(MSchedGraph *g, int II) { CircCount = 0; - //Keep old to new node mapping information + //Keep old to new node mapping information std::map<MSchedGraphNode*, MSchedGraphNode*> newNodes; //copy the graph @@ -1027,7 +1027,7 @@ void ModuloSchedulingPass::findAllCircuits(MSchedGraph *g, int II) { //Iterate over the graph until its down to one node or empty while(MSG->size() > 1) { - + //Write Graph out to file //WriteGraphToFile(std::cerr, "Graph" + utostr(MSG->size()), MSG); @@ -1070,13 +1070,13 @@ void ModuloSchedulingPass::findAllCircuits(MSchedGraph *g, int II) { } } } - - + + //Process SCC DEBUG(for(std::vector<MSchedGraphNode*>::iterator N = Vk.begin(), NE = Vk.end(); N != NE; ++N) { std::cerr << *((*N)->getInst()); }); - + //Iterate over all nodes in this scc for(std::vector<MSchedGraphNode*>::iterator N = Vk.begin(), NE = Vk.end(); N != NE; ++N) { @@ -1085,7 +1085,7 @@ void ModuloSchedulingPass::findAllCircuits(MSchedGraph *g, int II) { } if(Vk.size() > 1) { circuit(s, stack, blocked, Vk, s, B, II, newNodes); - + //Find all nodes up to s and delete them std::vector<MSchedGraphNode*> nodesToRemove; nodesToRemove.push_back(s); @@ -1105,10 +1105,10 @@ void ModuloSchedulingPass::findAllCircuits(MSchedGraph *g, int II) { } -void ModuloSchedulingPass::findAllReccurrences(MSchedGraphNode *node, +void ModuloSchedulingPass::findAllReccurrences(MSchedGraphNode *node, std::vector<MSchedGraphNode*> &visitedNodes, int II) { - + if(std::find(visitedNodes.begin(), visitedNodes.end(), node) != visitedNodes.end()) { std::vector<MSchedGraphNode*> recurrence; @@ -1119,13 +1119,13 @@ void ModuloSchedulingPass::findAllReccurrences(MSchedGraphNode *node, MSchedGraphNode *last = node; MSchedGraphNode *srcBackEdge = 0; MSchedGraphNode *destBackEdge = 0; - + for(std::vector<MSchedGraphNode*>::iterator I = visitedNodes.begin(), E = visitedNodes.end(); I !=E; ++I) { - if(*I == node) + if(*I == node) first = false; if(first) continue; @@ -1146,23 +1146,23 @@ void ModuloSchedulingPass::findAllReccurrences(MSchedGraphNode *node, } - + //Get final distance calc distance += node->getInEdge(last).getIteDiff(); DEBUG(std::cerr << "Reccurrence Distance: " << distance << "\n"); //Adjust II until we get close to the inequality delay - II*distance <= 0 - + int value = delay-(RecMII * distance); int lastII = II; while(value <= 0) { - + lastII = RecMII; RecMII--; value = delay-(RecMII * distance); } - - + + DEBUG(std::cerr << "Final II for this recurrence: " << lastII << "\n"); addReccurrence(recurrence, lastII, srcBackEdge, destBackEdge); assert(distance != 0 && "Recurrence distance should not be zero"); @@ -1179,23 +1179,23 @@ void ModuloSchedulingPass::findAllReccurrences(MSchedGraphNode *node, } } -void ModuloSchedulingPass::searchPath(MSchedGraphNode *node, +void ModuloSchedulingPass::searchPath(MSchedGraphNode *node, std::vector<MSchedGraphNode*> &path, std::set<MSchedGraphNode*> &nodesToAdd) { //Push node onto the path path.push_back(node); - //Loop over all successors and see if there is a path from this node to + //Loop over all successors and see if there is a path from this node to //a recurrence in the partial order, if so.. add all nodes to be added to recc - for(MSchedGraphNode::succ_iterator S = node->succ_begin(), SE = node->succ_end(); S != SE; + for(MSchedGraphNode::succ_iterator S = node->succ_begin(), SE = node->succ_end(); S != SE; ++S) { //If this node exists in a recurrence already in the partial order, then add all //nodes in the path to the set of nodes to add //Check if its already in our partial order, if not add it to the final vector - for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), + for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), PE = partialOrder.end(); PO != PE; ++PO) { - + //Check if we should ignore this edge first if(ignoreEdge(node,*S)) continue; @@ -1208,12 +1208,12 @@ void ModuloSchedulingPass::searchPath(MSchedGraphNode *node, searchPath(*S, path, nodesToAdd); } } - + //Pop Node off the path path.pop_back(); } -void ModuloSchedulingPass::pathToRecc(MSchedGraphNode *node, +void ModuloSchedulingPass::pathToRecc(MSchedGraphNode *node, std::vector<MSchedGraphNode*> &path, std::set<MSchedGraphNode*> &poSet, std::set<MSchedGraphNode*> &lastNodes) { @@ -1222,15 +1222,15 @@ void ModuloSchedulingPass::pathToRecc(MSchedGraphNode *node, DEBUG(std::cerr << "Current node: " << *node << "\n"); - //Loop over all successors and see if there is a path from this node to + //Loop over all successors and see if there is a path from this node to //a recurrence in the partial order, if so.. add all nodes to be added to recc - for(MSchedGraphNode::succ_iterator S = node->succ_begin(), SE = node->succ_end(); S != SE; + for(MSchedGraphNode::succ_iterator S = node->succ_begin(), SE = node->succ_end(); S != SE; ++S) { DEBUG(std::cerr << "Succ:" << **S << "\n"); //Check if we should ignore this edge first if(ignoreEdge(node,*S)) continue; - + if(poSet.count(*S)) { DEBUG(std::cerr << "Found path to recc from no pred\n"); //Loop over path, if it exists in lastNodes, then add to poset, and remove from lastNodes @@ -1245,7 +1245,7 @@ void ModuloSchedulingPass::pathToRecc(MSchedGraphNode *node, else pathToRecc(*S, path, poSet, lastNodes); } - + //Pop Node off the path path.pop_back(); } @@ -1253,27 +1253,27 @@ void ModuloSchedulingPass::pathToRecc(MSchedGraphNode *node, void ModuloSchedulingPass::computePartialOrder() { TIME_REGION(X, "calculatePartialOrder"); - + //Only push BA branches onto the final node order, we put other branches after it //FIXME: Should we really be pushing branches on it a specific order instead of relying //on BA being there? std::vector<MSchedGraphNode*> branches; - + //Steps to add a recurrence to the partial order // 1) Find reccurrence with the highest RecMII. Add it to the partial order. // 2) For each recurrence with decreasing RecMII, add it to the partial order along with // any nodes that connect this recurrence to recurrences already in the partial order - for(std::set<std::pair<int, std::vector<MSchedGraphNode*> > >::reverse_iterator + for(std::set<std::pair<int, std::vector<MSchedGraphNode*> > >::reverse_iterator I = recurrenceList.rbegin(), E=recurrenceList.rend(); I !=E; ++I) { std::set<MSchedGraphNode*> new_recurrence; //Loop through recurrence and remove any nodes already in the partial order - for(std::vector<MSchedGraphNode*>::const_iterator N = I->second.begin(), + for(std::vector<MSchedGraphNode*>::const_iterator N = I->second.begin(), NE = I->second.end(); N != NE; ++N) { bool found = false; - for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), + for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), PE = partialOrder.end(); PO != PE; ++PO) { if(PO->count(*N)) found = true; @@ -1289,10 +1289,10 @@ void ModuloSchedulingPass::computePartialOrder() { } } - + if(new_recurrence.size() > 0) { - + std::vector<MSchedGraphNode*> path; std::set<MSchedGraphNode*> nodesToAdd; @@ -1300,12 +1300,12 @@ void ModuloSchedulingPass::computePartialOrder() { for(std::set<MSchedGraphNode*>::iterator N = new_recurrence.begin(), NE = new_recurrence.end(); N != NE; ++N) searchPath(*N, path, nodesToAdd); - + //Add nodes to this recurrence if they are not already in the partial order for(std::set<MSchedGraphNode*>::iterator N = nodesToAdd.begin(), NE = nodesToAdd.end(); N != NE; ++N) { bool found = false; - for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), + for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), PE = partialOrder.end(); PO != PE; ++PO) { if(PO->count(*N)) found = true; @@ -1320,18 +1320,18 @@ void ModuloSchedulingPass::computePartialOrder() { } } - + //Add any nodes that are not already in the partial order //Add them in a set, one set per connected component std::set<MSchedGraphNode*> lastNodes; std::set<MSchedGraphNode*> noPredNodes; - for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), + for(std::map<MSchedGraphNode*, MSNodeAttributes>::iterator I = nodeToAttributesMap.begin(), E = nodeToAttributesMap.end(); I != E; ++I) { - + bool found = false; - + //Check if its already in our partial order, if not add it to the final vector - for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), + for(std::vector<std::set<MSchedGraphNode*> >::iterator PO = partialOrder.begin(), PE = partialOrder.end(); PO != PE; ++PO) { if(PO-> |