Remove using declarations
[oota-llvm.git] / lib / CodeGen / InstrSelection / InstrSelection.cpp
index 677bef7d04ad14741819d5fcdae80f1a810379f1..5e0fb8ec7259d238ff5d64432e9f267ac79d3c3b 100644 (file)
 #include "llvm/CodeGen/InstrForest.h"
 #include "llvm/CodeGen/MachineCodeForInstruction.h"
 #include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/Target/MachineRegInfo.h"
+#include "llvm/Target/TargetRegInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Function.h"
 #include "llvm/iPHINode.h"
 #include "llvm/Pass.h"
 #include "Support/CommandLine.h"
 #include "Support/LeakDetector.h"
-using std::cerr;
 using std::vector;
 
+std::vector<MachineInstr*>
+FixConstantOperandsForInstr(Instruction* vmInstr, MachineInstr* minstr,
+                            TargetMachine& target);
+
 namespace {
   //===--------------------------------------------------------------------===//
   // SelectDebugLevel - Allow command line control over debugging.
@@ -108,10 +111,10 @@ bool InstructionSelection::runOnFunction(Function &F)
   
   if (SelectDebugLevel >= Select_DebugInstTrees)
     {
-      cerr << "\n\n*** Input to instruction selection for function "
-          << F.getName() << "\n\n" << F
-           << "\n\n*** Instruction trees for function "
-          << F.getName() << "\n\n";
+      std::cerr << "\n\n*** Input to instruction selection for function "
+               << F.getName() << "\n\n" << F
+                << "\n\n*** Instruction trees for function "
+                << F.getName() << "\n\n";
       instrForest.dump();
     }
   
@@ -130,7 +133,7 @@ bool InstructionSelection::runOnFunction(Function &F)
       if (SelectDebugLevel >= Select_DebugBurgTrees)
        {
          printcover(basicNode, 1, 0);
-         cerr << "\nCover cost == " << treecost(basicNode, 1, 0) << "\n\n";
+         std::cerr << "\nCover cost == " << treecost(basicNode, 1, 0) <<"\n\n";
          printMatches(basicNode);
        }
       
@@ -159,7 +162,7 @@ bool InstructionSelection::runOnFunction(Function &F)
   
   if (SelectDebugLevel >= Select_PrintMachineCode)
     {
-      cerr << "\n*** Machine instructions after INSTRUCTION SELECTION\n";
+      std::cerr << "\n*** Machine instructions after INSTRUCTION SELECTION\n";
       MachineFunction::get(&F).dump();
     }
   
@@ -176,10 +179,10 @@ InstructionSelection::InsertCodeForPhis(Function &F)
 {
   // for all basic blocks in function
   //
-  for (Function::iterator BB = F.begin(); BB != F.end(); ++BB) {
-    BasicBlock::InstListType &InstList = BB->getInstList();
-    for (BasicBlock::iterator IIt = InstList.begin();
-         PHINode *PN = dyn_cast<PHINode>(&*IIt); ++IIt) {
+  MachineFunction &MF = MachineFunction::get(&F);
+  for (MachineFunction::iterator BB = MF.begin(); BB != MF.end(); ++BB) {
+    for (BasicBlock::iterator IIt = BB->getBasicBlock()->begin();
+         PHINode *PN = dyn_cast<PHINode>(IIt); ++IIt) {
       // FIXME: This is probably wrong...
       Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:");
 
@@ -208,11 +211,7 @@ InstructionSelection::InsertCodeForPhis(Function &F)
       
       vector<MachineInstr*> mvec;
       Target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec);
-      
-      // get an iterator to machine instructions in the BB
-      MachineBasicBlock& bbMvec = MachineBasicBlock::get(BB);
-      
-      bbMvec.insert(bbMvec.begin(), mvec.begin(), mvec.end());
+      BB->insert(BB->begin(), mvec.begin(), mvec.end());
     }  // for each Phi Instr in BB
   } // for all BBs in function
 }
@@ -224,26 +223,34 @@ InstructionSelection::InsertCodeForPhis(Function &F)
 
 void
 InstructionSelection::InsertPhiElimInstructions(BasicBlock *BB,
-                                                const vector<MachineInstr*>& CpVec)
+                                            const vector<MachineInstr*>& CpVec)
 { 
   Instruction *TermInst = (Instruction*)BB->getTerminator();
   MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
   MachineInstr *FirstMIOfTerm = MC4Term.front();
-  
   assert (FirstMIOfTerm && "No Machine Instrs for terminator");
-  
-  MachineBasicBlock &bbMvec = MachineBasicBlock::get(BB);
+
+  MachineFunction &MF = MachineFunction::get(BB->getParent());
+
+  // FIXME: if PHI instructions existed in the machine code, this would be
+  // unnecesary.
+  MachineBasicBlock *MBB = 0;
+  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
+    if (I->getBasicBlock() == BB) {
+      MBB = I;
+      break;
+    }
 
   // find the position of first machine instruction generated by the
   // terminator of this BB
   MachineBasicBlock::iterator MCIt =
-    std::find(bbMvec.begin(), bbMvec.end(), FirstMIOfTerm);
+    std::find(MBB->begin(), MBB->end(), FirstMIOfTerm);
 
-  assert( MCIt != bbMvec.end() && "Start inst of terminator not found");
+  assert(MCIt != MBB->end() && "Start inst of terminator not found");
   
   // insert the copy instructions just before the first machine instruction
   // generated for the terminator
-  bbMvec.insert(MCIt, CpVec.begin(), CpVec.end());
+  MBB->insert(MCIt, CpVec.begin(), CpVec.end());
 }
 
 
@@ -272,7 +279,7 @@ InstructionSelection::SelectInstructionsForTree(InstrTreeNode* treeRoot,
   int ruleForNode = burm_rule(treeRoot->state, goalnt);
   
   if (ruleForNode == 0) {
-    cerr << "Could not match instruction tree for instr selection\n";
+    std::cerr << "Could not match instruction tree for instr selection\n";
     abort();
   }
   
@@ -371,4 +378,3 @@ InstructionSelection::PostprocessMachineCodeForTree(InstructionNode* instrNode,
 Pass *createInstructionSelectionPass(TargetMachine &T) {
   return new InstructionSelection(T);
 }
-