Factory methods for function passes now return type FunctionPass *.
[oota-llvm.git] / lib / CodeGen / InstrSelection / InstrSelection.cpp
index 294ecc681338983283f0cddf2ea6206163c0487c..835169aeeb8b01add074ac00737a67dcd85b2aae 100644 (file)
 #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.
@@ -68,15 +71,16 @@ namespace {
     }
     
     bool runOnFunction(Function &F);
+    virtual const char *getPassName() const { return "Instruction Selection"; }
   };
 }
 
-// Register the pass...
-static RegisterLLC<InstructionSelection>
-X("instselect", "Instruction Selection", createInstructionSelectionPass);
+TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
+                               Value *s1, Value *s2, const std::string &name)
+  : Instruction(s1->getType(), Instruction::UserOp1, name)
+{
+  mcfi.addTemp(this);
 
-TmpInstruction::TmpInstruction(Value *s1, Value *s2, const std::string &name)
-  : Instruction(s1->getType(), Instruction::UserOp1, name) {
   Operands.push_back(Use(s1, this));  // s1 must be nonnull
   if (s2) {
     Operands.push_back(Use(s2, this));
@@ -88,9 +92,13 @@ TmpInstruction::TmpInstruction(Value *s1, Value *s2, const std::string &name)
   
 // Constructor that requires the type of the temporary to be specified.
 // Both S1 and S2 may be NULL.(
-TmpInstruction::TmpInstruction(const Type *Ty, Value *s1, Value* s2,
+TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
+                               const Type *Ty, Value *s1, Value* s2,
                                const std::string &name)
-  : Instruction(Ty, Instruction::UserOp1, name) {
+  : Instruction(Ty, Instruction::UserOp1, name)
+{
+  mcfi.addTemp(this);
+
   if (s1) { Operands.push_back(Use(s1, this)); }
   if (s2) { Operands.push_back(Use(s2, this)); }
 
@@ -108,10 +116,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 +138,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 +167,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();
     }
   
@@ -178,8 +186,8 @@ InstructionSelection::InsertCodeForPhis(Function &F)
   //
   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) {
+    for (BasicBlock::const_iterator IIt = BB->getBasicBlock()->begin();
+         const PHINode *PN = dyn_cast<PHINode>(IIt); ++IIt) {
       // FIXME: This is probably wrong...
       Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:");
 
@@ -198,7 +206,7 @@ InstructionSelection::InsertCodeForPhis(Function &F)
         for (vector<MachineInstr*>::iterator MI=mvec.begin();
              MI != mvec.end(); ++MI) {
           vector<MachineInstr*> CpVec2 =
-            FixConstantOperandsForInstr(PN, *MI, Target);
+            FixConstantOperandsForInstr(const_cast<PHINode*>(PN), *MI, Target);
           CpVec2.push_back(*MI);
           CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end());
         }
@@ -207,7 +215,8 @@ InstructionSelection::InsertCodeForPhis(Function &F)
       }
       
       vector<MachineInstr*> mvec;
-      Target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec);
+      Target.getRegInfo().cpValue2Value(PhiCpRes, const_cast<PHINode*>(PN),
+                                        mvec);
       BB->insert(BB->begin(), mvec.begin(), mvec.end());
     }  // for each Phi Instr in BB
   } // for all BBs in function
@@ -276,7 +285,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();
   }
   
@@ -372,7 +381,6 @@ InstructionSelection::PostprocessMachineCodeForTree(InstructionNode* instrNode,
 // createInstructionSelectionPass - Public entrypoint for instruction selection
 // and this file as a whole...
 //
-Pass *createInstructionSelectionPass(TargetMachine &T) {
+FunctionPass *createInstructionSelectionPass(TargetMachine &T) {
   return new InstructionSelection(T);
 }
-