Revert "Use a simpler data structure to calculate the least recently used register...
[oota-llvm.git] / lib / CodeGen / SelectionDAG / SelectionDAGISel.cpp
index 7618166af6aea3cf7f40e4797313378cb1ddf9a7..9082fb6fbe92905261e178b3ad253bd2e66c9210 100644 (file)
@@ -195,7 +195,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
   assert((!EnableFastISelAbort || EnableFastISel) &&
          "-fast-isel-abort requires -fast-isel");
 
-  Function &Fn = *mf.getFunction();
+  const Function &Fn = *mf.getFunction();
   const TargetInstrInfo &TII = *TM.getInstrInfo();
   const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
 
@@ -237,7 +237,7 @@ static void SetDebugLoc(const Instruction *I, SelectionDAGBuilder *SDB,
     FastIS->setCurDebugLoc(DL);
 
   // If the function doesn't have a default debug location yet, set
-  // it. This is kind of a hack.
+  // it. This is a total hack.
   if (MF->getDefaultDebugLoc().isUnknown())
     MF->setDefaultDebugLoc(DL);
 }
@@ -256,15 +256,13 @@ void SelectionDAGISel::SelectBasicBlock(const BasicBlock *LLVMBB,
   SDB->setCurrentBasicBlock(BB);
 
   // Lower all of the non-terminator instructions. If a call is emitted
-  // as a tail call, cease emitting nodes for this block.
+  // as a tail call, cease emitting nodes for this block. Terminators
+  // are handled below.
   for (BasicBlock::const_iterator I = Begin;
-       I != End && !SDB->HasTailCall; ++I) {
+       I != End && !SDB->HasTailCall && !isa<TerminatorInst>(I);
+       ++I) {
     SetDebugLoc(I, SDB, 0, MF);
-
-    // Visit the instruction. Terminators are handled below.
-    if (!isa<TerminatorInst>(I))
-      SDB->visit(*I);
-
+    SDB->visit(*I);
     ResetDebugLoc(SDB, 0);
   }
 
@@ -836,7 +834,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
             BI->dump();
           }
 
-          if (!BI->getType()->isVoidTy()) {
+          if (!BI->getType()->isVoidTy() && !BI->use_empty()) {
             unsigned &R = FuncInfo->ValueMap[BI];
             if (!R)
               R = FuncInfo->CreateRegForValue(BI);
@@ -1881,6 +1879,7 @@ static unsigned IsPredicateKnownToFail(const unsigned char *Table,
   }
 }
 
+namespace {
 
 struct MatchScope {
   /// FailIndex - If this match fails, this is the index to continue with.
@@ -1902,6 +1901,8 @@ struct MatchScope {
   bool HasChainNodesMatched, HasFlagResultNodesMatched;
 };
 
+}
+
 SDNode *SelectionDAGISel::
 SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
                  unsigned TableSize) {