Added LLVM project notice to the top of every C++ source file.
[oota-llvm.git] / lib / Target / SparcV9 / InstrSelection / InstrSelection.cpp
index 5e0fb8ec7259d238ff5d64432e9f267ac79d3c3b..32dc65e6e1e9196e0b558d4984784c789b463bba 100644 (file)
@@ -1,4 +1,11 @@
-//===- InstrSelection.cpp - Machine Independant Inst Selection Driver -----===//
+//===- InstrSelection.cpp - Machine Independent Inst Selection Driver -----===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // Machine-independent driver file for instruction selection.  This file
 // constructs a forest of BURG instruction trees and then uses the
@@ -71,16 +78,17 @@ 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
+  Operands.push_back(Use(s1, this));  // s1 must be non-null
   if (s2) {
     Operands.push_back(Use(s2, this));
   }
@@ -91,9 +99,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)); }
 
@@ -181,8 +193,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:");
 
@@ -201,7 +213,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());
         }
@@ -210,7 +222,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
@@ -233,7 +246,7 @@ InstructionSelection::InsertPhiElimInstructions(BasicBlock *BB,
   MachineFunction &MF = MachineFunction::get(BB->getParent());
 
   // FIXME: if PHI instructions existed in the machine code, this would be
-  // unnecesary.
+  // unnecessary.
   MachineBasicBlock *MBB = 0;
   for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
     if (I->getBasicBlock() == BB) {
@@ -336,7 +349,7 @@ InstructionSelection::SelectInstructionsForTree(InstrTreeNode* treeRoot,
        }
     }
   
-  // Finally, do any postprocessing on this node after its children
+  // Finally, do any post-processing on this node after its children
   // have been translated
   // 
   if (treeRoot->opLabel != VRegListOp)
@@ -375,6 +388,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);
 }