X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FTargetSchedInfo.cpp;h=b2f66dbdee1864f48c46aee5b155784074893f56;hb=fd1f1ee0baf9c808fdee14bdbfe76d4a5e66210d;hp=a4a27e7103fe06592f036ea07a67926a50fe5d55;hpb=0e1c48b20995f4c6c304688ff2d06f26528baf1a;p=oota-llvm.git diff --git a/lib/Target/TargetSchedInfo.cpp b/lib/Target/TargetSchedInfo.cpp index a4a27e7103f..b2f66dbdee1 100644 --- a/lib/Target/TargetSchedInfo.cpp +++ b/lib/Target/TargetSchedInfo.cpp @@ -12,12 +12,29 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Config/alloca.h" #include "llvm/Target/TargetSchedInfo.h" #include "llvm/Target/TargetMachine.h" +#include +#include +using namespace llvm; -namespace llvm { +resourceId_t llvm::CPUResource::nextId = 0; +static std::vector *CPUResourceMap = 0; + +CPUResource::CPUResource(const std::string& resourceName, int maxUsers) + : rname(resourceName), rid(nextId++), maxNumUsers(maxUsers) { + if(!CPUResourceMap) + CPUResourceMap = new std::vector; + + //Put Resource in the map + CPUResourceMap->push_back(this); +} -resourceId_t CPUResource::nextId = 0; +///Get CPUResource if you only have the resource ID +CPUResource* CPUResource::getCPUResource(resourceId_t id) { + return (*CPUResourceMap)[id]; +} // Check if fromRVec and toRVec have *any* common entries. // Assume the vectors are sorted in increasing order. @@ -44,22 +61,22 @@ RUConflict(const std::vector& fromRVec, } -static cycles_t +static CycleCount_t ComputeMinGap(const InstrRUsage &fromRU, const InstrRUsage &toRU) { - cycles_t minGap = 0; + CycleCount_t minGap = 0; if (fromRU.numBubbles > 0) minGap = fromRU.numBubbles; if (minGap < fromRU.numCycles) { // only need to check from cycle `minGap' onwards - for (cycles_t gap=minGap; gap <= fromRU.numCycles-1; gap++) { + for (CycleCount_t gap=minGap; gap <= fromRU.numCycles-1; gap++) { // check if instr. #2 can start executing `gap' cycles after #1 // by checking for resource conflicts in each overlapping cycle - cycles_t numOverlap =std::min(fromRU.numCycles - gap, toRU.numCycles); - for (cycles_t c = 0; c <= numOverlap-1; c++) + CycleCount_t numOverlap =std::min(fromRU.numCycles - gap, toRU.numCycles); + for (CycleCount_t c = 0; c <= numOverlap-1; c++) if (RUConflict(fromRU.resourcesByCycle[gap + c], toRU.resourcesByCycle[c])) { // conflict found so minGap must be more than `gap' @@ -86,7 +103,7 @@ TargetSchedInfo::TargetSchedInfo(const TargetMachine& tgt, unsigned NumUsageDeltas, unsigned NumIssueDeltas) : target(tgt), - numSchedClasses(NumSchedClasses), mii(& tgt.getInstrInfo()), + numSchedClasses(NumSchedClasses), mii(tgt.getInstrInfo()), classRUsages(ClassRUsages), usageDeltas(UsageDeltas), issueDeltas(IssueDeltas), numUsageDeltas(NumUsageDeltas), numIssueDeltas(NumIssueDeltas) @@ -153,19 +170,17 @@ TargetSchedInfo::computeIssueGaps(const std::vector& issueGaps.resize(numOpCodes); conflictLists.resize(numOpCodes); - assert(numOpCodes < (1 << MAX_OPCODE_SIZE) - 1 - && "numOpCodes invalid for implementation of class OpCodePair!"); - // First, compute issue gaps between pairs of classes based on common // resources usages for each class, because most instruction pairs will // usually behave the same as their class. // - int classPairGaps[numSchedClasses][numSchedClasses]; + int* classPairGaps = + static_cast(alloca(sizeof(int) * numSchedClasses * numSchedClasses)); for (InstrSchedClass fromSC=0; fromSC < numSchedClasses; fromSC++) for (InstrSchedClass toSC=0; toSC < numSchedClasses; toSC++) { int classPairGap = ComputeMinGap(instrRUForClasses[fromSC], instrRUForClasses[toSC]); - classPairGaps[fromSC][toSC] = classPairGap; + classPairGaps[fromSC*numSchedClasses + toSC] = classPairGap; } // Now, for each pair of instructions, use the class pair gap if both @@ -178,7 +193,7 @@ TargetSchedInfo::computeIssueGaps(const std::vector& for (MachineOpCode toOp=0; toOp < numOpCodes; toOp++) { int instrPairGap = (instrRUsages[fromOp].sameAsClass && instrRUsages[toOp].sameAsClass) - ? classPairGaps[getSchedClass(fromOp)][getSchedClass(toOp)] + ? classPairGaps[getSchedClass(fromOp)*numSchedClasses + getSchedClass(toOp)] : ComputeMinGap(instrRUsages[fromOp], instrRUsages[toOp]); if (instrPairGap > 0) { @@ -213,7 +228,7 @@ void InstrRUsage::setTo(const InstrClassRUsage& classRU) { // Sort each resource usage vector by resourceId_t to speed up conflict // checking for (unsigned i=0; i < this->resourcesByCycle.size(); i++) - sort(resourcesByCycle[i].begin(), resourcesByCycle[i].end()); + std::sort(resourcesByCycle[i].begin(), resourcesByCycle[i].end()); } // Add the extra resource usage requirements specified in the delta. @@ -251,5 +266,3 @@ void InstrRUsage::addUsageDelta(const InstrRUsageDelta &delta) { assert(r >= 0 && "Resource to remove was unused in cycle c!"); } } - -} // End llvm namespace