summaryrefslogtreecommitdiff
path: root/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2004-11-24 01:49:10 +0000
committerTanya Lattner <tonic@nondot.org>2004-11-24 01:49:10 +0000
commita6ec8f5548d5f60a93a436fc3e5bdd20bdc047cf (patch)
tree15397aa0dc4214ec5bfd1a294ce45a6c0c551a29 /lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
parent8599d385a2f1fbafaaead903ea5be5a9b33a6509 (diff)
downloadllvm-a6ec8f5548d5f60a93a436fc3e5bdd20bdc047cf.tar.gz
llvm-a6ec8f5548d5f60a93a436fc3e5bdd20bdc047cf.tar.bz2
llvm-a6ec8f5548d5f60a93a436fc3e5bdd20bdc047cf.tar.xz
Forced branches to be first to be scheduled.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18195 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp')
-rw-r--r--lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp107
1 files changed, 54 insertions, 53 deletions
diff --git a/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp b/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
index 25bd55f314..7ee77510f0 100644
--- a/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
+++ b/lib/Target/SparcV9/ModuloScheduling/MSSchedule.cpp
@@ -23,7 +23,9 @@ bool MSSchedule::insert(MSchedGraphNode *node, int cycle) {
//First, check if the cycle has a spot free to start
if(schedule.find(cycle) != schedule.end()) {
+ //Check if we have a free issue slot at this cycle
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);
DEBUG(std::cerr << "Found spot in map, and there is an issue slot\n");
@@ -44,45 +46,43 @@ bool MSSchedule::insert(MSchedGraphNode *node, int cycle) {
DEBUG(std::cerr << "All issue slots taken\n");
return true;
-
+
}
bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
-
+
//Get Resource usage for this instruction
const TargetSchedInfo *msi = node->getParent()->getTarget()->getSchedInfo();
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;
-
- //Loop over resources in each cycle and increments their usage count
- for(unsigned i=0; i < resources.size(); ++i) {
- for(unsigned j=0; j < resources[i].size(); ++j) {
- int resourceNum = resources[i][j];
-
- DEBUG(std::cerr << "Attempting to schedule Resource Num: " << resourceNum << " in cycle: " << currentCycle << "\n");
-
+
+ //Get resource usage for this instruction
+ InstrRUsage rUsage = msi->getInstrRUsage(node->getInst()->getOpcode());
+ std::vector<std::vector<resourceId_t> > resources = rUsage.resourcesByCycle;
+
+ //Loop over resources in each cycle and increments their usage count
+ for(unsigned i=0; i < resources.size(); ++i) {
+ for(unsigned j=0; j < resources[i].size(); ++j) {
+
+ //Get Resource to check its availability
+ int resourceNum = resources[i][j];
+
+ DEBUG(std::cerr << "Attempting to schedule Resource Num: " << resourceNum << " in cycle: " << currentCycle << "\n");
+
//Check if this resource is available for this cycle
std::map<int, std::map<int,int> >::iterator resourcesForCycle = resourceNumPerCycle.find(currentCycle);
- //First check map of resources for this cycle
+ //First check if map exists for this cycle
if(resourcesForCycle != resourceNumPerCycle.end()) {
//A map exists for this cycle, so lets check for the resource
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 {
+ DEBUG(std::cerr << "No resource num " << resourceNum << " available for cycle " << currentCycle << "\n");
success = false;
}
}
@@ -96,50 +96,51 @@ bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
std::map<int, int> resourceMap;
resourceMap[resourceNum] = 1;
resourceNumPerCycle[currentCycle] = resourceMap;
-
}
if(!success)
break;
}
if(!success)
break;
- //Increase cycle
- currentCycle++;
- }
-
- if(!success) {
- int oldCycle = cycle;
- DEBUG(std::cerr << "Backtrack\n");
- //Get resource usage for this instruction
- InstrRUsage rUsage = msi->getInstrRUsage(node->getInst()->getOpcode());
- std::vector<std::vector<resourceId_t> > resources = rUsage.resourcesByCycle;
+
- //Loop over resources in each cycle and increments their usage count
- for(unsigned i=0; i < resources.size(); ++i) {
- if(oldCycle < currentCycle) {
-
- //Check if this resource is available for this cycle
- std::map<int, std::map<int,int> >::iterator resourcesForCycle = resourceNumPerCycle.find(oldCycle);
- if(resourcesForCycle != resourceNumPerCycle.end()) {
- for(unsigned j=0; j < resources[i].size(); ++j) {
- int resourceNum = resources[i][j];
- //remove from map
- std::map<int, int>::iterator resourceUse = resourcesForCycle->second.find(resourceNum);
- //assert if not in the map.. since it should be!
- //assert(resourceUse != resourcesForCycle.end() && "Resource should be in map!");
- --resourceUse->second;
- }
+ //Increase cycle
+ currentCycle++;
+ }
+
+ if(!success) {
+ int oldCycle = cycle;
+ DEBUG(std::cerr << "Backtrack\n");
+ //Get resource usage for this instruction
+ InstrRUsage rUsage = msi->getInstrRUsage(node->getInst()->getOpcode());
+ std::vector<std::vector<resourceId_t> > resources = rUsage.resourcesByCycle;
+
+ //Loop over resources in each cycle and increments their usage count
+ for(unsigned i=0; i < resources.size(); ++i) {
+ if(oldCycle < currentCycle) {
+
+ //Check if this resource is available for this cycle
+ std::map<int, std::map<int,int> >::iterator resourcesForCycle = resourceNumPerCycle.find(oldCycle);
+ if(resourcesForCycle != resourceNumPerCycle.end()) {
+ for(unsigned j=0; j < resources[i].size(); ++j) {
+ int resourceNum = resources[i][j];
+ //remove from map
+ std::map<int, int>::iterator resourceUse = resourcesForCycle->second.find(resourceNum);
+ //assert if not in the map.. since it should be!
+ //assert(resourceUse != resourcesForCycle.end() && "Resource should be in map!");
+ --resourceUse->second;
}
}
- else
- break;
- oldCycle++;
}
- return false;
-
+ else
+ break;
+ oldCycle++;
}
+ return false;
+
+ }
- return true;
+ return true;
}