aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2004-11-22 20:41:24 +0000
committerTanya Lattner <tonic@nondot.org>2004-11-22 20:41:24 +0000
commite1df212fb3eb651a85ee1e0f493a9f27033901cb (patch)
tree9b82ba9a96fcc94797f41b234fa29c48f3709cff
parent54a4d6a3cd25f94d1dd2e2908ad6be2c153fbcc4 (diff)
downloadexternal_llvm-e1df212fb3eb651a85ee1e0f493a9f27033901cb.zip
external_llvm-e1df212fb3eb651a85ee1e0f493a9f27033901cb.tar.gz
external_llvm-e1df212fb3eb651a85ee1e0f493a9f27033901cb.tar.bz2
Fixed a bug where I was trying to ModuloSchedule a loop with no instructions but a terminator.
Fixed a bug in the schedule generation that was always using the start cycle. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18123 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp11
-rw-r--r--lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp29
-rw-r--r--lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.h1
3 files changed, 32 insertions, 9 deletions
diff --git a/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp b/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
index 02cd8b7..25bd55f 100644
--- a/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
+++ b/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
@@ -54,6 +54,9 @@ bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
int currentCycle = cycle;
bool success = true;
+ //map for easy backtracking, resource num at a certain cycle
+ //std::map<int, int> backtrackMap;
+
//Get resource usage for this instruction
InstrRUsage rUsage = msi->getInstrRUsage(node->getInst()->getOpcode());
std::vector<std::vector<resourceId_t> > resources = rUsage.resourcesByCycle;
@@ -74,8 +77,11 @@ bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
std::map<int, int>::iterator resourceUse = resourcesForCycle->second.find(resourceNum);
if(resourceUse != resourcesForCycle->second.end()) {
//Check if there are enough of this resource and if so, increase count and move on
- if(resourceUse->second < CPUResource::getCPUResource(resourceNum)->maxNumUsers)
+ if(resourceUse->second < CPUResource::getCPUResource(resourceNum)->maxNumUsers) {
++resourceUse->second;
+ //Document that we increased the usage count for this resource at this cycle
+
+ }
else {
success = false;
}
@@ -89,7 +95,8 @@ bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
//Create a new map and put in our resource
std::map<int, int> resourceMap;
resourceMap[resourceNum] = 1;
- resourceNumPerCycle[cycle] = resourceMap;
+ resourceNumPerCycle[currentCycle] = resourceMap;
+
}
if(!success)
break;
diff --git a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp
index 01598c3..eb73a3b 100644
--- a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp
+++ b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.cpp
@@ -1,4 +1,3 @@
-
//===-- ModuloScheduling.cpp - ModuloScheduling ----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
@@ -25,6 +24,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Statistic.h"
#include <cmath>
#include <algorithm>
#include <fstream>
@@ -62,6 +62,9 @@ static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
//Graph Traits for printing out the dependence graph
namespace llvm {
+ Statistic<> ValidLoops("modulosched-validLoops", "Number of candidate loops modulo-scheduled");
+ Statistic<> MSLoops("modulosched-schedLoops", "Number of loops successfully modulo-scheduled");
+ Statistic<> IncreasedII("modulosched-increasedII", "Number of times we had to increase II");
template<>
struct DOTGraphTraits<MSchedGraph*> : public DefaultDOTGraphTraits {
@@ -136,8 +139,10 @@ bool ModuloSchedulingPass::runOnFunction(Function &F) {
//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;
@@ -217,7 +222,7 @@ bool ModuloSchedulingPass::runOnFunction(Function &F) {
//stage > 0
if(schedule.getMaxStage() != 0) {
reconstructLoop(*BI);
- numMS++;
+ ++MSLoops;
Changed = true;
}
else
@@ -241,9 +246,6 @@ bool ModuloSchedulingPass::runOnFunction(Function &F) {
//delete(*BI);
}
-
- DEBUG(std::cerr << "Number of Loop Candidates: " << Worklist.size() << "\n Number ModuloScheduled: " << numMS << "\n");
-
return Changed;
}
@@ -254,6 +256,10 @@ void ModuloSchedulingPass::CreateDefMap(MachineBasicBlock *BI) {
for(unsigned opNum = 0; opNum < I->getNumOperands(); ++opNum) {
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");
+ assert(!defMap.count(mOp.getVRegValue()) && "Def already in the map");
+
defMap[mOp.getVRegValue()] = &*I;
}
@@ -265,6 +271,7 @@ void ModuloSchedulingPass::CreateDefMap(MachineBasicBlock *BI) {
}
}
}
+
assert(defaultInst && "We must have a default instruction to use as our main point to add to machine code for instruction\n");
}
@@ -286,6 +293,10 @@ bool ModuloSchedulingPass::MachineBBisValid(const MachineBasicBlock *BI) {
if(!isLoop)
return false;
+ //Check size of our basic block.. make sure we have more then just the terminator in it
+ if(BI->getBasicBlock()->size() == 1)
+ return false;
+
//Get Target machine instruction info
const TargetInstrInfo *TMI = target.getInstrInfo();
@@ -705,7 +716,7 @@ 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
@@ -1187,6 +1198,7 @@ void ModuloSchedulingPass::computeSchedule() {
success = scheduleNode(*I, EarlyStart, EarlyStart + II - 1);
if(!success) {
+ ++IncreasedII;
++II;
schedule.clear();
break;
@@ -1199,6 +1211,7 @@ void ModuloSchedulingPass::computeSchedule() {
success = schedule.constructKernel(II);
DEBUG(std::cerr << "Done Constructing Schedule Kernel\n");
if(!success) {
+ ++IncreasedII;
++II;
schedule.clear();
}
@@ -1267,6 +1280,8 @@ void ModuloSchedulingPass::writePrologues(std::vector<MachineBasicBlock *> &prol
MSchedGraphNode *branch = 0;
MSchedGraphNode *BAbranch = 0;
+ schedule.print(std::cerr);
+
for(MSSchedule::kernel_iterator I = schedule.kernel_begin(), E = schedule.kernel_end(); I != E; ++I) {
maxStageCount = std::max(maxStageCount, I->second);
diff --git a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.h b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.h
index 7f16096..5ed8986 100644
--- a/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.h
+++ b/lib/Target/SparcV9/ModuloScheduling/ModuloScheduling.h
@@ -113,6 +113,7 @@ namespace llvm {
public:
ModuloSchedulingPass(TargetMachine &targ) : target(targ) {}
virtual bool runOnFunction(Function &F);
+ virtual const char* getPassName() const { return "ModuloScheduling"; }
};
}