Use higher level method
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / LiveRangeInfo.cpp
index 31bd134e1b0d95b24ff5808ff22a7ccd7386f613..f8e4b4f3a92d9b7c3caf3fb659313079b3a816da 100644 (file)
@@ -7,8 +7,9 @@
 #include "llvm/CodeGen/LiveRangeInfo.h"
 #include "llvm/CodeGen/RegAllocCommon.h"
 #include "llvm/CodeGen/RegClass.h"
+#include "llvm/CodeGen/IGNode.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/Function.h"
@@ -32,7 +33,7 @@ LiveRangeInfo::~LiveRangeInfo() {
       // live range. We have to make the other entries NULL when we delete
       // a live range.
 
-      for(LiveRange::iterator LI = LR->begin(); LI != LR->end(); ++LI)
+      for (LiveRange::iterator LI = LR->begin(); LI != LR->end(); ++LI)
         LiveRangeMap[*LI] = 0;
       
       delete LR;
@@ -110,7 +111,7 @@ LiveRangeInfo::createOrAddToLiveRange(const Value* Def, bool isCC /* = false*/)
 
   // check if the LR is already there (because of multiple defs)
   if (!DefRange) { 
-    DefRange = this->createNewLiveRange(Def, isCC);
+    DefRange = createNewLiveRange(Def, isCC);
   } else {                          // live range already exists
     DefRange->insert(Def);          // add the operand to the range
     LiveRangeMap[Def] = DefRange;   // make operand point to merged set
@@ -134,7 +135,7 @@ void LiveRangeInfo::constructLiveRanges() {
   // first find the live ranges for all incoming args of the function since
   // those LRs start from the start of the function
   for (Function::const_aiterator AI = Meth->abegin(); AI != Meth->aend(); ++AI)
-    this->createNewLiveRange(AI, /*isCC*/ false);
+    createNewLiveRange(AI, /*isCC*/ false);
 
   // Now suggest hardware registers for these function args 
   MRI.suggestRegs4MethodArgs(Meth, *this);
@@ -146,13 +147,13 @@ void LiveRangeInfo::constructLiveRanges() {
   // 
   // Also, find CALL and RETURN instructions, which need extra work.
   //
-  for (Function::const_iterator BBI=Meth->begin(); BBI != Meth->end(); ++BBI){
-    // get the vector of machine instructions for this basic block.
-    MachineBasicBlock& MIVec = MachineBasicBlock::get(BBI);
+  MachineFunction &MF = MachineFunction::get(Meth);
+  for (MachineFunction::iterator BBI = MF.begin(); BBI != MF.end(); ++BBI) {
+    MachineBasicBlock &MBB = *BBI;
 
     // iterate over all the machine instructions in BB
-    for(MachineBasicBlock::iterator MInstIterator = MIVec.begin();
-        MInstIterator != MIVec.end(); ++MInstIterator) {  
+    for(MachineBasicBlock::iterator MInstIterator = MBB.begin();
+        MInstIterator != MBB.end(); ++MInstIterator) {  
       MachineInstr *MInst = *MInstIterator; 
 
       // If the machine instruction is a  call/return instruction, add it to
@@ -160,7 +161,7 @@ void LiveRangeInfo::constructLiveRanges() {
       // 
       if(TM.getInstrInfo().isReturn(MInst->getOpCode()) ||
         TM.getInstrInfo().isCall(MInst->getOpCode()))
-       CallRetInstrList.push_back( MInst ); 
+       CallRetInstrList.push_back(MInst); 
  
       // iterate over explicit MI operands and create a new LR
       // for each operand that is defined by the instruction
@@ -168,9 +169,9 @@ void LiveRangeInfo::constructLiveRanges() {
              OpE = MInst->end(); OpI != OpE; ++OpI)
        if (OpI.isDef()) {     
          const Value *Def = *OpI;
-          bool isCC = (OpI.getMachineOperand().getOperandType()
+          bool isCC = (OpI.getMachineOperand().getType()
                        == MachineOperand::MO_CCRegister);
-          this->createOrAddToLiveRange(Def, isCC);
+          createOrAddToLiveRange(Def, isCC);
        }
 
       // iterate over implicit MI operands and create a new LR
@@ -178,7 +179,7 @@ void LiveRangeInfo::constructLiveRanges() {
       for (unsigned i = 0; i < MInst->getNumImplicitRefs(); ++i) 
        if (MInst->implicitRefIsDefined(i)) {     
          const Value *Def = MInst->getImplicitRef(i);
-          this->createOrAddToLiveRange(Def, /*isCC*/ false);
+          createOrAddToLiveRange(Def, /*isCC*/ false);
        }
 
     } // for all machine instructions in the BB
@@ -204,24 +205,19 @@ void LiveRangeInfo::constructLiveRanges() {
 //    1) suggest colors for call and return args. 
 //    2) create new LRs for implicit defs in machine instructions
 //---------------------------------------------------------------------------
-void LiveRangeInfo::suggestRegs4CallRets()
-{
-  CallRetInstrListType::iterator It =  CallRetInstrList.begin();
-  for( ; It !=  CallRetInstrList.end(); ++It ) {
-
+void LiveRangeInfo::suggestRegs4CallRets() {
+  std::vector<MachineInstr*>::iterator It = CallRetInstrList.begin();
+  for( ; It != CallRetInstrList.end(); ++It) {
     MachineInstr *MInst = *It;
-    MachineOpCode OpCode =  MInst->getOpCode();
+    MachineOpCode OpCode = MInst->getOpCode();
 
-    if( (TM.getInstrInfo()).isReturn(OpCode)  )
-      MRI.suggestReg4RetValue( MInst, *this);
-
-    else if( (TM.getInstrInfo()).isCall( OpCode ) )
-      MRI.suggestRegs4CallArgs( MInst, *this);
-    
+    if ((TM.getInstrInfo()).isReturn(OpCode))
+      MRI.suggestReg4RetValue(MInst, *this);
+    else if ((TM.getInstrInfo()).isCall(OpCode))
+      MRI.suggestRegs4CallArgs(MInst, *this);
     else 
-      assert( 0 && "Non call/ret instr in  CallRetInstrList" );
+      assert( 0 && "Non call/ret instr in CallRetInstrList" );
   }
-
 }
 
 
@@ -248,35 +244,30 @@ void LiveRangeInfo::coalesceLRs()
   if(DEBUG_RA >= RA_DEBUG_LiveRanges) 
     cerr << "\nCoalescing LRs ...\n";
 
-  for(Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
-      BBI != BBE; ++BBI) {
-
-    // get the iterator for machine instructions
-    const MachineBasicBlock& MIVec = MachineBasicBlock::get(BBI);
-    MachineBasicBlock::const_iterator MInstIterator = MIVec.begin();
+  MachineFunction &MF = MachineFunction::get(Meth);
+  for (MachineFunction::iterator BBI = MF.begin(); BBI != MF.end(); ++BBI) {
+    MachineBasicBlock &MBB = *BBI;
 
     // iterate over all the machine instructions in BB
-    for( ; MInstIterator != MIVec.end(); ++MInstIterator) {  
-      const MachineInstr * MInst = *MInstIterator; 
+    for(MachineBasicBlock::iterator MII = MBB.begin(); MII != MBB.end(); ++MII){
+      const MachineInstr *MI = *MII;
 
       if( DEBUG_RA >= RA_DEBUG_LiveRanges) {
        cerr << " *Iterating over machine instr ";
-       MInst->dump();
+       MI->dump();
        cerr << "\n";
       }
 
-
       // iterate over  MI operands to find defs
-      for(MachineInstr::const_val_op_iterator DefI = MInst->begin(),
-            DefE = MInst->end(); DefI != DefE; ++DefI) {
+      for(MachineInstr::const_val_op_iterator DefI = MI->begin(),
+            DefE = MI->end(); DefI != DefE; ++DefI) {
        if (DefI.isDef()) {            // iff this operand is a def
          LiveRange *LROfDef = getLiveRangeForValue( *DefI );
          RegClass *RCOfDef = LROfDef->getRegClass();
 
-         MachineInstr::const_val_op_iterator UseI = MInst->begin(),
-            UseE = MInst->end();
-         for( ; UseI != UseE; ++UseI){ // for all uses
-
+         MachineInstr::const_val_op_iterator UseI = MI->begin(),
+            UseE = MI->end();
+         for( ; UseI != UseE; ++UseI) { // for all uses
            LiveRange *LROfUse = getLiveRangeForValue( *UseI );
            if (!LROfUse) {             // if LR of use is not found
              //don't warn about labels