Allow emission of names that start with an underscore. This is needed to
[oota-llvm.git] / lib / Target / SparcV9 / InstrSched / InstrScheduling.cpp
index 1d4c18058f3dc9598d9d29428d7f85bc1da93a1e..a985680da3dd1dbce04b0c12d8c3cc162380edc5 100644 (file)
@@ -13,7 +13,6 @@
 #include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h" // FIXME: Remove when modularized better
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/BasicBlock.h"
-#include "llvm/Instruction.h"
 #include "Support/CommandLine.h"
 #include <algorithm>
 using std::cerr;
@@ -26,7 +25,6 @@ SDL_opt("dsched", cl::Hidden, cl::location(SchedDebugLevel),
         cl::desc("enable instruction scheduling debugging information"),
         cl::values(
  clEnumValN(Sched_NoDebugInfo,      "n", "disable debug output"),
- clEnumValN(Sched_Disable,        "off", "disable instruction scheduling"),
  clEnumValN(Sched_PrintMachineCode, "y", "print machine code after scheduling"),
  clEnumValN(Sched_PrintSchedTrace,  "t", "print trace of scheduling actions"),
  clEnumValN(Sched_PrintSchedGraphs, "g", "print scheduling graphs"),
@@ -79,7 +77,7 @@ private:
 //----------------------------------------------------------------------
 
 template<class _NodeType>
-class ScheduleIterator: public std::forward_iterator<_NodeType, ptrdiff_t> {
+class ScheduleIterator : public forward_iterator<_NodeType, ptrdiff_t> {
 private:
   unsigned cycleNum;
   unsigned slotNum;
@@ -352,18 +350,18 @@ private:
   unsigned int totalInstrCount;
   cycles_t curTime;
   cycles_t nextEarliestIssueTime;              // next cycle we can issue
-  vector<std::hash_set<const SchedGraphNode*> > choicesForSlot; // indexed by slot#
+  vector<hash_set<const SchedGraphNode*> > choicesForSlot; // indexed by slot#
   vector<const SchedGraphNode*> choiceVec;     // indexed by node ptr
   vector<int> numInClass;                      // indexed by sched class
   vector<cycles_t> nextEarliestStartTime;      // indexed by opCode
-  std::hash_map<const SchedGraphNode*, DelaySlotInfo*> delaySlotInfoForBranches;
+  hash_map<const SchedGraphNode*, DelaySlotInfo*> delaySlotInfoForBranches;
                                                // indexed by branch node ptr 
   
 public:
   SchedulingManager(const TargetMachine& _target, const SchedGraph* graph,
                     SchedPriorities& schedPrio);
   ~SchedulingManager() {
-    for (std::hash_map<const SchedGraphNode*,
+    for (hash_map<const SchedGraphNode*,
            DelaySlotInfo*>::iterator I = delaySlotInfoForBranches.begin(),
            E = delaySlotInfoForBranches.end(); I != E; ++I)
       delete I->second;
@@ -422,7 +420,7 @@ public:
     return choiceVec[i];
   }
   
-  inline std::hash_set<const SchedGraphNode*>& getChoicesForSlot(unsigned slotNum) {
+  inline hash_set<const SchedGraphNode*>& getChoicesForSlot(unsigned slotNum) {
     assert(slotNum < nslots);
     return choicesForSlot[slotNum];
   }
@@ -497,7 +495,7 @@ public:
   inline DelaySlotInfo* getDelaySlotInfoForInstr(const SchedGraphNode* bn,
                                                 bool createIfMissing=false)
   {
-    std::hash_map<const SchedGraphNode*, DelaySlotInfo*>::const_iterator
+    hash_map<const SchedGraphNode*, DelaySlotInfo*>::const_iterator
       I = delaySlotInfoForBranches.find(bn);
     if (I != delaySlotInfoForBranches.end())
       return I->second;
@@ -550,19 +548,17 @@ SchedulingManager::updateEarliestStartTimes(const SchedGraphNode* node,
                  curTime + 1 + schedInfo.numBubblesAfter(node->getOpCode()));
     }
   
-  const vector<MachineOpCode>*
+  const std::vector<MachineOpCode>&
     conflictVec = schedInfo.getConflictList(node->getOpCode());
   
-  if (conflictVec != NULL)
-    for (unsigned i=0; i < conflictVec->size(); i++)
-      {
-       MachineOpCode toOp = (*conflictVec)[i];
-       cycles_t est = schedTime + schedInfo.getMinIssueGap(node->getOpCode(),
-                                                           toOp);
-       assert(toOp < (int) nextEarliestStartTime.size());
-       if (nextEarliestStartTime[toOp] < est)
-         nextEarliestStartTime[toOp] = est;
-      }
+  for (unsigned i=0; i < conflictVec.size(); i++)
+    {
+      MachineOpCode toOp = conflictVec[i];
+      cycles_t est=schedTime + schedInfo.getMinIssueGap(node->getOpCode(),toOp);
+      assert(toOp < (int) nextEarliestStartTime.size());
+      if (nextEarliestStartTime[toOp] < est)
+        nextEarliestStartTime[toOp] = est;
+    }
 }
 
 //************************* Internal Functions *****************************/
@@ -1243,8 +1239,20 @@ ReplaceNopsWithUsefulInstr(SchedulingManager& S,
       if (sdelayNodeVec.size() < ndelays)
         sdelayNodeVec.push_back(graph->getGraphNodeForInstr(bbMvec[i]));
       else
-        nopNodeVec.push_back(graph->getGraphNodeForInstr(bbMvec[i]));
-  
+       {
+         nopNodeVec.push_back(graph->getGraphNodeForInstr(bbMvec[i]));
+         
+         //remove the MI from the Machine Code For Instruction
+         MachineCodeForInstruction& llvmMvec = 
+           MachineCodeForInstruction::get((Instruction *)
+                                          (node->getBB()->getTerminator()));
+         for(MachineCodeForInstruction::iterator mciI=llvmMvec.begin(), 
+               mciE=llvmMvec.end(); mciI!=mciE; ++mciI){
+           if(*mciI==bbMvec[i])
+             llvmMvec.erase(mciI);
+         }
+       }
+
   assert(sdelayNodeVec.size() >= ndelays);
   
   // If some delay slots were already filled, throw away that many new choices
@@ -1490,7 +1498,7 @@ namespace {
   
     // getAnalysisUsage - We use LiveVarInfo...
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired(FunctionLiveVarInfo::ID);
+      AU.addRequired<FunctionLiveVarInfo>();
     }
     
     bool runOnFunction(Function &F);
@@ -1500,9 +1508,6 @@ namespace {
 
 bool InstructionSchedulingWithSSA::runOnFunction(Function &F)
 {
-  if (SchedDebugLevel == Sched_Disable)
-    return false;
-  
   SchedGraphSet graphSet(&F, target);  
   
   if (SchedDebugLevel >= Sched_PrintSchedGraphs)