changed mem_fun to std::mem_fun
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / PhyRegAlloc.cpp
index 4ad98d917fd592f85cf17df0d1c67d4dc571ca02..ef4156147cb1ccc95cb393331a1f612282d56db7 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 //***************************************************************************
 // File:
 //     PhyRegAlloc.cpp
@@ -13,6 +12,8 @@
 #include "llvm/CodeGen/RegisterAllocation.h"
 #include "llvm/CodeGen/PhyRegAlloc.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineInstrAnnot.h"
+#include "llvm/CodeGen/MachineCodeForBasicBlock.h"
 #include "llvm/CodeGen/MachineCodeForMethod.h"
 #include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Function.h"
 #include "llvm/Type.h"
+#include "llvm/iOther.h"
+#include "llvm/CodeGen/RegAllocCommon.h"
+#include "Support/CommandLine.h"
+#include "Support/STLExtras.h"
 #include <iostream>
 #include <math.h>
 using std::cerr;
+using std::vector;
 
-
-// ***TODO: There are several places we add instructions. Validate the order
-//          of adding these instructions.
-
-cl::Enum<RegAllocDebugLevel_t> DEBUG_RA("dregalloc", cl::NoFlags,
+RegAllocDebugLevel_t DEBUG_RA;
+static cl::Enum<RegAllocDebugLevel_t> DEBUG_RA_c(DEBUG_RA, "dregalloc",
+                                                 cl::Hidden,
   "enable register allocation debugging information",
   clEnumValN(RA_DEBUG_None   , "n", "disable debug output"),
   clEnumValN(RA_DEBUG_Normal , "y", "enable debug output"),
@@ -44,13 +48,14 @@ namespace {
     TargetMachine &Target;
   public:
     inline RegisterAllocator(TargetMachine &T) : Target(T) {}
+
+    const char *getPassName() const { return "Register Allocation"; }
     
-    bool runOnFunction(Function *F) {
+    bool runOnFunction(Function &F) {
       if (DEBUG_RA)
-        cerr << "\n******************** Function "<< F->getName()
-             << " ********************\n";
+        cerr << "\n********* Function "<< F.getName() << " ***********\n";
       
-      PhyRegAlloc PRA(F, Target, &getAnalysis<FunctionLiveVarInfo>(),
+      PhyRegAlloc PRA(&F, Target, &getAnalysis<FunctionLiveVarInfo>(),
                       &getAnalysis<LoopInfo>());
       PRA.allocateRegisters();
       
@@ -83,7 +88,7 @@ PhyRegAlloc::PhyRegAlloc(Function *F, const TargetMachine& tm,
 
   // create each RegisterClass and put in RegClassList
   //
-  for(unsigned int rc=0; rc < NumOfRegClasses; rc++)  
+  for (unsigned rc=0; rc < NumOfRegClasses; rc++)  
     RegClassList.push_back(new RegClass(F, MRI.getMachineRegClass(rc),
                                         &ResColList));
 }
@@ -93,7 +98,7 @@ PhyRegAlloc::PhyRegAlloc(Function *F, const TargetMachine& tm,
 // Destructor: Deletes register classes
 //----------------------------------------------------------------------------
 PhyRegAlloc::~PhyRegAlloc() { 
-  for( unsigned int rc=0; rc < NumOfRegClasses; rc++)
+  for ( unsigned rc=0; rc < NumOfRegClasses; rc++)
     delete RegClassList[rc];
 
   AddedInstrMap.clear();
@@ -116,7 +121,7 @@ void PhyRegAlloc::createIGNodeListsAndIGs() {
     if (HMI->first) { 
       LiveRange *L = HMI->second;   // get the LiveRange
       if (!L) { 
-        ifDEBUG_RA) {
+        if (DEBUG_RA) {
           cerr << "\n*?!?Warning: Null liver range found for: "
                << RAV(HMI->first) << "\n";
         }
@@ -124,7 +129,7 @@ void PhyRegAlloc::createIGNodeListsAndIGs() {
       }
                                         // if the Value * is not null, and LR  
                                         // is not yet written to the IGNodeList
-      if!(L->getUserIGNode())  ) {  
+      if (!(L->getUserIGNode())  ) {  
         RegClass *const RC =           // RegClass of first value in the LR
           RegClassList[ L->getRegClass()->getID() ];
         
@@ -134,10 +139,10 @@ void PhyRegAlloc::createIGNodeListsAndIGs() {
   }
     
   // init RegClassList
-  for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)  
+  for ( unsigned rc=0; rc < NumOfRegClasses ; rc++)  
     RegClassList[rc]->createInterferenceGraph();
 
-  ifDEBUG_RA)
+  if (DEBUG_RA)
     cerr << "LRLists Created!\n";
 }
 
@@ -167,9 +172,9 @@ void PhyRegAlloc::addInterference(const Value *Def,
 
   // for each live var in live variable set
   //
-  for( ; LIt != LVSet->end(); ++LIt) {
+  for ( ; LIt != LVSet->end(); ++LIt) {
 
-    if (DEBUG_RA > 1)
+    if (DEBUG_RA >= RA_DEBUG_Verbose)
       cerr << "< Def=" << RAV(Def) << ", Lvar=" << RAV(*LIt) << "> ";
 
     //  get the live range corresponding to live var
@@ -180,14 +185,14 @@ void PhyRegAlloc::addInterference(const Value *Def,
     // doesn't have a dominating def - see Assumptions above
     //
     if (LROfVar) {  
-      if(LROfDef == LROfVar)            // do not set interf for same LR
+      if (LROfDef == LROfVar)            // do not set interf for same LR
        continue;
 
       // if 2 reg classes are the same set interference
       //
       if (RCOfDef == LROfVar->getRegClass()) {
        RCOfDef->setInterference( LROfDef, LROfVar);  
-      } else if (DEBUG_RA > 1)  { 
+      } else if (DEBUG_RA >= RA_DEBUG_Verbose)  { 
         // we will not have LRs for values not explicitly allocated in the
         // instruction stream (e.g., constants)
         cerr << " warning: no live range for " << RAV(*LIt) << "\n";
@@ -208,20 +213,20 @@ void PhyRegAlloc::addInterference(const Value *Def,
 void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, 
                                       const ValueSet *LVSetAft) {
 
-  ifDEBUG_RA)
+  if (DEBUG_RA)
     cerr << "\n For call inst: " << *MInst;
 
   ValueSet::const_iterator LIt = LVSetAft->begin();
 
   // for each live var in live variable set after machine inst
   //
-  for( ; LIt != LVSetAft->end(); ++LIt) {
+  for ( ; LIt != LVSetAft->end(); ++LIt) {
 
     //  get the live range corresponding to live var
     //
     LiveRange *const LR = LRI.getLiveRangeForValue(*LIt ); 
 
-    ifLR && DEBUG_RA) {
+    if (LR && DEBUG_RA) {
       cerr << "\n\tLR Aft Call: ";
       printSet(*LR);
     }
@@ -229,9 +234,9 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst,
     // LR can be null if it is a const since a const 
     // doesn't have a dominating def - see Assumptions above
     //
-    ifLR )   {  
+    if (LR )   {  
       LR->setCallInterference();
-      ifDEBUG_RA) {
+      if (DEBUG_RA) {
        cerr << "\n  ++Added call interf for LR: " ;
        printSet(*LR);
       }
@@ -245,7 +250,9 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst,
   // of the call is live in this set - but it does not interfere with call
   // (i.e., we can allocate a volatile register to the return value)
   //
-  if( const Value *RetVal = MRI.getCallInstRetVal( MInst )) {
+  CallArgsDescriptor* argDesc = CallArgsDescriptor::get(MInst);
+  
+  if (const Value *RetVal = argDesc->getReturnValue()) {
     LiveRange *RetValLR = LRI.getLiveRangeForValue( RetVal );
     assert( RetValLR && "No LR for RetValue of call");
     RetValLR->clearCallInterference();
@@ -253,7 +260,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst,
 
   // If the CALL is an indirect call, find the LR of the function pointer.
   // That has a call interference because it conflicts with outgoing args.
-  if( const Value *AddrVal = MRI.getCallInstIndirectAddrVal( MInst )) {
+  if (const Value *AddrVal = argDesc->getIndirectFuncPtr()) {
     LiveRange *AddrValLR = LRI.getLiveRangeForValue( AddrVal );
     assert( AddrValLR && "No LR for indirect addr val of call");
     AddrValLR->setCallInterference();
@@ -272,7 +279,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst,
 void PhyRegAlloc::buildInterferenceGraphs()
 {
 
-  if(DEBUG_RA) cerr << "Creating interference graphs ...\n";
+  if (DEBUG_RA) cerr << "Creating interference graphs ...\n";
 
   unsigned BBLoopDepthCost;
   for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
@@ -280,26 +287,26 @@ void PhyRegAlloc::buildInterferenceGraphs()
 
     // find the 10^(loop_depth) of this BB 
     //
-    BBLoopDepthCost = (unsigned) pow(10.0, LoopDepthCalc->getLoopDepth(*BBI));
+    BBLoopDepthCost = (unsigned)pow(10.0, LoopDepthCalc->getLoopDepth(BBI));
 
     // get the iterator for machine instructions
     //
-    const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
+    const MachineCodeForBasicBlock& MIVec = MachineCodeForBasicBlock::get(BBI);
     MachineCodeForBasicBlock::const_iterator MII = MIVec.begin();
 
     // iterate over all the machine instructions in BB
     //
-    for( ; MII != MIVec.end(); ++MII) {  
+    for ( ; MII != MIVec.end(); ++MII) {  
 
       const MachineInstr *MInst = *MII; 
 
       // get the LV set after the instruction
       //
-      const ValueSet &LVSetAI = LVI->getLiveVarSetAfterMInst(MInst, *BBI);
+      const ValueSet &LVSetAI = LVI->getLiveVarSetAfterMInst(MInst, BBI);
     
       const bool isCallInst = TM.getInstrInfo().isCall(MInst->getOpCode());
 
-      ifisCallInst ) {
+      if (isCallInst ) {
        // set the isCallInterference flag of each live range wich extends
        // accross this call instruction. This information is used by graph
        // coloring algo to avoid allocating volatile colors to live ranges
@@ -333,9 +340,9 @@ void PhyRegAlloc::buildInterferenceGraphs()
       // instr (currently, only calls have this).
       //
       unsigned NumOfImpRefs =  MInst->getNumImplicitRefs();
-      if NumOfImpRefs > 0 ) {
-       for(unsigned z=0; z < NumOfImpRefs; z++) 
-         ifMInst->implicitRefIsDefined(z) )
+      if ( NumOfImpRefs > 0 ) {
+       for (unsigned z=0; z < NumOfImpRefs; z++) 
+         if (MInst->implicitRefIsDefined(z) )
            addInterference( MInst->getImplicitRef(z), &LVSetAI, isCallInst );
       }
 
@@ -349,7 +356,7 @@ void PhyRegAlloc::buildInterferenceGraphs()
   //  
   addInterferencesForArgs();          
 
-  ifDEBUG_RA)
+  if (DEBUG_RA)
     cerr << "Interference graphs calculted!\n";
 
 }
@@ -374,14 +381,14 @@ void PhyRegAlloc::addInterf4PseudoInstr(const MachineInstr *MInst) {
     assert((LROfOp1 || !It1.isDef()) && "No LR for Def in PSEUDO insruction");
 
     MachineInstr::const_val_op_iterator It2 = It1;
-    for(++It2; It2 != ItE; ++It2) {
+    for (++It2; It2 != ItE; ++It2) {
       const LiveRange *LROfOp2 = LRI.getLiveRangeForValue(*It2); 
 
       if (LROfOp2) {
        RegClass *RCOfOp1 = LROfOp1->getRegClass(); 
        RegClass *RCOfOp2 = LROfOp2->getRegClass(); 
  
-       ifRCOfOp1 == RCOfOp2 ){ 
+       if (RCOfOp1 == RCOfOp2 ){ 
          RCOfOp1->setInterference( LROfOp1, LROfOp2 );  
          setInterf = true;
        }
@@ -403,21 +410,14 @@ void PhyRegAlloc::addInterf4PseudoInstr(const MachineInstr *MInst) {
 //----------------------------------------------------------------------------
 void PhyRegAlloc::addInterferencesForArgs() {
   // get the InSet of root BB
-  const ValueSet &InSet = LVI->getInSetOfBB(Meth->front());  
-
-  // get the argument list
-  const Function::ArgumentListType &ArgList = Meth->getArgumentList();  
-
-  // get an iterator to arg list
-  Function::ArgumentListType::const_iterator ArgIt = ArgList.begin();          
-
+  const ValueSet &InSet = LVI->getInSetOfBB(&Meth->front());  
 
-  for( ; ArgIt != ArgList.end() ; ++ArgIt) {  // for each argument
-    addInterference((Value*)*ArgIt, &InSet, false);// add interferences between 
-                                              // args and LVars at start
-    if( DEBUG_RA > 1)
-      cerr << " - %% adding interference for  argument "
-           << RAV((const Value *)*ArgIt) << "\n";
+  for (Function::const_aiterator AI = Meth->abegin(); AI != Meth->aend(); ++AI) {
+    // add interferences between args and LVars at start 
+    addInterference(AI, &InSet, false);
+    
+    if (DEBUG_RA >= RA_DEBUG_Verbose)
+      cerr << " - %% adding interference for  argument " << RAV(AI) << "\n";
   }
 }
 
@@ -435,7 +435,7 @@ void PhyRegAlloc::addInterferencesForArgs() {
 // Utility functions used below
 //-----------------------------
 inline void
-PrependInstructions(std::deque<MachineInstr *> &IBef,
+PrependInstructions(vector<MachineInstr *> &IBef,
                     MachineCodeForBasicBlock& MIVec,
                     MachineCodeForBasicBlock::iterator& MII,
                     const std::string& msg)
@@ -443,7 +443,7 @@ PrependInstructions(std::deque<MachineInstr *> &IBef,
   if (!IBef.empty())
     {
       MachineInstr* OrigMI = *MII;
-      std::deque<MachineInstr *>::iterator AdIt; 
+      std::vector<MachineInstr *>::iterator AdIt; 
       for (AdIt = IBef.begin(); AdIt != IBef.end() ; ++AdIt)
         {
           if (DEBUG_RA) {
@@ -457,7 +457,7 @@ PrependInstructions(std::deque<MachineInstr *> &IBef,
 }
 
 inline void
-AppendInstructions(std::deque<MachineInstr *> &IAft,
+AppendInstructions(std::vector<MachineInstr *> &IAft,
                    MachineCodeForBasicBlock& MIVec,
                    MachineCodeForBasicBlock::iterator& MII,
                    const std::string& msg)
@@ -465,10 +465,10 @@ AppendInstructions(std::deque<MachineInstr *> &IAft,
   if (!IAft.empty())
     {
       MachineInstr* OrigMI = *MII;
-      std::deque<MachineInstr *>::iterator AdIt; 
-      for( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt )
+      std::vector<MachineInstr *>::iterator AdIt; 
+      for ( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt )
         {
-          if(DEBUG_RA) {
+          if (DEBUG_RA) {
             if (OrigMI) cerr << "For MInst: " << *OrigMI;
             cerr << msg << " APPENDed instr: "  << **AdIt << "\n";
           }
@@ -481,25 +481,22 @@ AppendInstructions(std::deque<MachineInstr *> &IAft,
 
 void PhyRegAlloc::updateMachineCode()
 {
-  const BasicBlock* entryBB = Meth->getEntryNode();
-  if (entryBB) {
-    MachineCodeForBasicBlock& MIVec = entryBB->getMachineInstrVec();
-    MachineCodeForBasicBlock::iterator MII = MIVec.begin();
+  MachineCodeForBasicBlock& MIVec = MachineCodeForBasicBlock::get(&Meth->getEntryNode());
     
-    // Insert any instructions needed at method entry
-    PrependInstructions(AddedInstrAtEntry.InstrnsBefore, MIVec, MII,
-                        "At function entry: \n");
-    assert(AddedInstrAtEntry.InstrnsAfter.empty() &&
-           "InstrsAfter should be unnecessary since we are just inserting at "
-           "the function entry point here.");
-  }
+  // Insert any instructions needed at method entry
+  MachineCodeForBasicBlock::iterator MII = MIVec.begin();
+  PrependInstructions(AddedInstrAtEntry.InstrnsBefore, MIVec, MII,
+                      "At function entry: \n");
+  assert(AddedInstrAtEntry.InstrnsAfter.empty() &&
+         "InstrsAfter should be unnecessary since we are just inserting at "
+         "the function entry point here.");
   
   for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
        BBI != BBE; ++BBI) {
     
     // iterate over all the machine instructions in BB
-    MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
-    for(MachineCodeForBasicBlock::iterator MII = MIVec.begin();
+    MachineCodeForBasicBlock &MIVec = MachineCodeForBasicBlock::get(BBI);
+    for (MachineCodeForBasicBlock::iterator MII = MIVec.begin();
         MII != MIVec.end(); ++MII) {  
       
       MachineInstr *MInst = *MII; 
@@ -510,6 +507,9 @@ void PhyRegAlloc::updateMachineCode()
       if (TM.getInstrInfo().isDummyPhiInstr(Opcode))
        continue;
 
+      // Reset tmp stack positions so they can be reused for each machine instr.
+      mcInfo.popAllTempValues(TM);  
+       
       // Now insert speical instructions (if necessary) for call/return
       // instructions. 
       //
@@ -518,94 +518,44 @@ void PhyRegAlloc::updateMachineCode()
 
        AddedInstrns &AI = AddedInstrMap[MInst];
        
-       // Tmp stack poistions are needed by some calls that have spilled args
-       // So reset it before we call each such method
-       //
-       mcInfo.popAllTempValues(TM);  
-       
        if (TM.getInstrInfo().isCall(Opcode))
-         MRI.colorCallArgs(MInst, LRI, &AI, *this, *BBI);
+         MRI.colorCallArgs(MInst, LRI, &AI, *this, BBI);
        else if (TM.getInstrInfo().isReturn(Opcode))
          MRI.colorRetValue(MInst, LRI, &AI);
       }
       
-
-      /* -- Using above code instead of this
-
-      // if this machine instr is call, insert caller saving code
-
-      if( (TM.getInstrInfo()).isCall( MInst->getOpCode()) )
-       MRI.insertCallerSavingCode(MInst,  *BBI, *this );
-       
-      */
-
+      // Set the registers for operands in the machine instruction
+      // if a register was successfully allocated.  If not, insert
+      // code to spill the register value.
+      // 
+      for (unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum)
+        {
+          MachineOperand& Op = MInst->getOperand(OpNum);
+          if (Op.getOperandType() ==  MachineOperand::MO_VirtualRegister || 
+              Op.getOperandType() ==  MachineOperand::MO_CCRegister)
+            {
+              const Value *const Val =  Op.getVRegValue();
+          
+              LiveRange *const LR = LRI.getLiveRangeForValue(Val);
+              if (!LR)              // consts or labels will have no live range
+                {
+                  // if register is not allocated, mark register as invalid
+                  if (Op.getAllocatedRegNum() == -1)
+                    MInst->SetRegForOperand(OpNum, MRI.getInvalidRegNum()); 
+                  continue;
+                }
+          
+              if (LR->hasColor() )
+                MInst->SetRegForOperand(OpNum,
+                                MRI.getUnifiedRegNum(LR->getRegClass()->getID(),
+                                                     LR->getColor()));
+              else
+                // LR did NOT receive a color (register). Insert spill code.
+                insertCode4SpilledLR(LR, MInst, BBI, OpNum );
+            }
+        } // for each operand
       
-      // reset the stack offset for temporary variables since we may
-      // need that to spill
-      // mcInfo.popAllTempValues(TM);
-      // TODO ** : do later
       
-      //for(MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done();++OpI) {
-
-
-      // Now replace set the registers for operands in the machine instruction
-      //
-      for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
-
-       MachineOperand& Op = MInst->getOperand(OpNum);
-
-       if( Op.getOperandType() ==  MachineOperand::MO_VirtualRegister || 
-           Op.getOperandType() ==  MachineOperand::MO_CCRegister) {
-
-         const Value *const Val =  Op.getVRegValue();
-
-         // delete this condition checking later (must assert if Val is null)
-         if( !Val) {
-            if (DEBUG_RA)
-              cerr << "Warning: NULL Value found for operand\n";
-           continue;
-         }
-         assert( Val && "Value is NULL");   
-
-         LiveRange *const LR = LRI.getLiveRangeForValue(Val);
-
-         if ( !LR ) {
-
-           // nothing to worry if it's a const or a label
-
-            if (DEBUG_RA) {
-              cerr << "*NO LR for operand : " << Op ;
-             cerr << " [reg:" <<  Op.getAllocatedRegNum() << "]";
-             cerr << " in inst:\t" << *MInst << "\n";
-            }
-
-           // if register is not allocated, mark register as invalid
-           if( Op.getAllocatedRegNum() == -1)
-             Op.setRegForValue( MRI.getInvalidRegNum()); 
-           
-
-           continue;
-         }
-       
-         unsigned RCID = (LR->getRegClass())->getID();
-
-         if( LR->hasColor() ) {
-           Op.setRegForValue( MRI.getUnifiedRegNum(RCID, LR->getColor()) );
-         }
-         else {
-
-           // LR did NOT receive a color (register). Now, insert spill code
-           // for spilled opeands in this machine instruction
-
-           //assert(0 && "LR must be spilled");
-           insertCode4SpilledLR(LR, MInst, *BBI, OpNum );
-
-         }
-       }
-
-      } // for each operand
-
-
       // Now add instructions that the register allocator inserts before/after 
       // this machine instructions (done only for calls/rets/incoming args)
       // We do this here, to ensure that spill for an instruction is inserted
@@ -614,7 +564,7 @@ void PhyRegAlloc::updateMachineCode()
       // If there are instructions to be added, *before* this machine
       // instruction, add them now.
       //      
-      if(AddedInstrMap.count(MInst)) {
+      if (AddedInstrMap.count(MInst)) {
         PrependInstructions(AddedInstrMap[MInst].InstrnsBefore, MIVec, MII,"");
       }
       
@@ -631,16 +581,12 @@ void PhyRegAlloc::updateMachineCode()
        unsigned delay;
        if ((delay=TM.getInstrInfo().getNumDelaySlots(MInst->getOpCode())) >0){ 
          move2DelayedInstr(MInst,  *(MII+delay) );
-
-         if(DEBUG_RA)  cerr<< "\nMoved an added instr after the delay slot";
        }
-       
        else {
          // Here we can add the "instructions after" to the current
          // instruction since there are no delay slots for this instruction
          AppendInstructions(AddedInstrMap[MInst].InstrnsAfter, MIVec, MII,"");
        }  // if not delay
-       
       }
       
     } // for each machine instruction
@@ -668,6 +614,7 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR,
 
   MachineOperand& Op = MInst->getOperand(OpNum);
   bool isDef =  MInst->operandIsDefined(OpNum);
+  bool isDefAndUse =  MInst->operandIsDefinedAndUsed(OpNum);
   unsigned RegType = MRI.getRegType( LR );
   int SpillOff = LR->getSpillOffFromFP();
   RegClass *RC = LR->getRegClass();
@@ -675,57 +622,72 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR,
 
   mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) );
   
-  MachineInstr *MIBef=NULL,  *AdIMid=NULL, *MIAft=NULL;
+  vector<MachineInstr*> MIBef, MIAft;
+  vector<MachineInstr*> AdIMid;
   
-  int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,&LVSetBef, MIBef, MIAft);
+  // Choose a register to hold the spilled value.  This may insert code
+  // before and after MInst to free up the value.  If so, this code should
+  // be first and last in the spill sequence before/after MInst.
+  int TmpRegU = getUsableUniRegAtMI(RegType, &LVSetBef, MInst, MIBef, MIAft);
   
-  // get the added instructions for this instruciton
+  // Set the operand first so that it this register does not get used
+  // as a scratch register for later calls to getUsableUniRegAtMI below
+  MInst->SetRegForOperand(OpNum, TmpRegU);
+  
+  // get the added instructions for this instruction
   AddedInstrns &AI = AddedInstrMap[MInst];
-    
-  if (!isDef) {
+
+  // We may need a scratch register to copy the spilled value to/from memory.
+  // This may itself have to insert code to free up a scratch register.  
+  // Any such code should go before (after) the spill code for a load (store).
+  int scratchRegType = -1;
+  int scratchReg = -1;
+  if (MRI.regTypeNeedsScratchReg(RegType, scratchRegType))
+    {
+      scratchReg = this->getUsableUniRegAtMI(scratchRegType, &LVSetBef,
+                                             MInst, MIBef, MIAft);
+      assert(scratchReg != MRI.getInvalidRegNum());
+      MInst->getRegsUsed().insert(scratchReg); 
+    }
+  
+  if (!isDef || isDefAndUse) {
     // for a USE, we have to load the value of LR from stack to a TmpReg
     // and use the TmpReg as one operand of instruction
-
-    // actual loading instruction
-    AdIMid = MRI.cpMem2RegMI(MRI.getFramePointer(), SpillOff, TmpRegU,RegType);
-
-    if(MIBef)
-      AI.InstrnsBefore.push_back(MIBef);
-
-    AI.InstrnsBefore.push_back(AdIMid);
-
-    if(MIAft)
-      AI.InstrnsAfter.push_front(MIAft);
     
-  } else {   // if this is a Def
+    // actual loading instruction(s)
+    MRI.cpMem2RegMI(AdIMid, MRI.getFramePointer(), SpillOff, TmpRegU, RegType,
+                    scratchReg);
+    
+    // the actual load should be after the instructions to free up TmpRegU
+    MIBef.insert(MIBef.end(), AdIMid.begin(), AdIMid.end());
+    AdIMid.clear();
+  }
+  
+  if (isDef) {   // if this is a Def
     // for a DEF, we have to store the value produced by this instruction
     // on the stack position allocated for this LR
-
-    // actual storing instruction
-    AdIMid = MRI.cpReg2MemMI(TmpRegU, MRI.getFramePointer(), SpillOff,RegType);
-
-    if (MIBef)
-      AI.InstrnsBefore.push_back(MIBef);
-
-    AI.InstrnsAfter.push_front(AdIMid);
-
-    if (MIAft)
-      AI.InstrnsAfter.push_front(MIAft);
-
+    
+    // actual storing instruction(s)
+    MRI.cpReg2MemMI(AdIMid, TmpRegU, MRI.getFramePointer(), SpillOff, RegType,
+                    scratchReg);
+    
+    MIAft.insert(MIAft.begin(), AdIMid.begin(), AdIMid.end());
   }  // if !DEF
-
-  cerr << "\nFor Inst " << *MInst;
-  cerr << " - SPILLED LR: "; printSet(*LR);
-  cerr << "\n - Added Instructions:";
-  if (MIBef) cerr <<  *MIBef;
-  cerr <<  *AdIMid;
-  if (MIAft) cerr <<  *MIAft;
-
-  Op.setRegForValue(TmpRegU);    // set the opearnd
+  
+  // Finally, insert the entire spill code sequences before/after MInst
+  AI.InstrnsBefore.insert(AI.InstrnsBefore.end(), MIBef.begin(), MIBef.end());
+  AI.InstrnsAfter.insert(AI.InstrnsAfter.begin(), MIAft.begin(), MIAft.end());
+  
+  if (DEBUG_RA) {
+    cerr << "\nFor Inst " << *MInst;
+    cerr << " - SPILLED LR: "; printSet(*LR);
+    cerr << "\n - Added Instructions:";
+    for_each(MIBef.begin(), MIBef.end(), std::mem_fun(&MachineInstr::dump));
+    for_each(MIAft.begin(), MIAft.end(), std::mem_fun(&MachineInstr::dump));
+  }
 }
 
 
-
 //----------------------------------------------------------------------------
 // We can use the following method to get a temporary register to be used
 // BEFORE any given machine instruction. If there is a register available,
@@ -735,31 +697,47 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR,
 // Returned register number is the UNIFIED register number
 //----------------------------------------------------------------------------
 
-int PhyRegAlloc::getUsableUniRegAtMI(RegClass *RC, 
-                                 const int RegType,
-                                 const MachineInstr *MInst, 
-                                 const ValueSet *LVSetBef,
-                                 MachineInstr *&MIBef,
-                                 MachineInstr *&MIAft) {
-
+int PhyRegAlloc::getUsableUniRegAtMI(const int RegType,
+                                     const ValueSet *LVSetBef,
+                                     MachineInstr *MInst, 
+                                     std::vector<MachineInstr*>& MIBef,
+                                     std::vector<MachineInstr*>& MIAft) {
+  
+  RegClass* RC = this->getRegClassByID(MRI.getRegClassIDOfRegType(RegType));
+  
   int RegU =  getUnusedUniRegAtMI(RC, MInst, LVSetBef);
-
-
-  if( RegU != -1) {
-    // we found an unused register, so we can simply use it
-    MIBef = MIAft = NULL;
-  }
-  else {
+  
+  if (RegU == -1) {
     // we couldn't find an unused register. Generate code to free up a reg by
     // saving it on stack and restoring after the instruction
-
+    
     int TmpOff = mcInfo.pushTempValue(TM,  MRI.getSpilledRegSize(RegType) );
     
     RegU = getUniRegNotUsedByThisInst(RC, MInst);
-    MIBef = MRI.cpReg2MemMI(RegU, MRI.getFramePointer(), TmpOff, RegType );
-    MIAft = MRI.cpMem2RegMI(MRI.getFramePointer(), TmpOff, RegU, RegType );
+    
+    // Check if we need a scratch register to copy this register to memory.
+    int scratchRegType = -1;
+    if (MRI.regTypeNeedsScratchReg(RegType, scratchRegType))
+      {
+        int scratchReg = this->getUsableUniRegAtMI(scratchRegType, LVSetBef,
+                                                   MInst, MIBef, MIAft);
+        assert(scratchReg != MRI.getInvalidRegNum());
+        
+        // We may as well hold the value in the scratch register instead
+        // of copying it to memory and back.  But we have to mark the
+        // register as used by this instruction, so it does not get used
+        // as a scratch reg. by another operand or anyone else.
+        MInst->getRegsUsed().insert(scratchReg); 
+        MRI.cpReg2RegMI(MIBef, RegU, scratchReg, RegType);
+        MRI.cpReg2RegMI(MIAft, scratchReg, RegU, RegType);
+      }
+    else
+      { // the register can be copied directly to/from memory so do it.
+        MRI.cpReg2MemMI(MIBef, RegU, MRI.getFramePointer(), TmpOff, RegType);
+        MRI.cpMem2RegMI(MIAft, MRI.getFramePointer(), TmpOff, RegU, RegType);
+      }
   }
-
+  
   return RegU;
 }
 
@@ -779,24 +757,23 @@ int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC,
 
   unsigned NumAvailRegs =  RC->getNumOfAvailRegs();
   
-  bool *IsColorUsedArr = RC->getIsColorUsedArr();
+  std::vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
   
-  for(unsigned i=0; i <  NumAvailRegs; i++)     // Reset array
+  for (unsigned i=0; i <  NumAvailRegs; i++)     // Reset array
       IsColorUsedArr[i] = false;
       
   ValueSet::const_iterator LIt = LVSetBef->begin();
 
   // for each live var in live variable set after machine inst
-  for( ; LIt != LVSetBef->end(); ++LIt) {
+  for ( ; LIt != LVSetBef->end(); ++LIt) {
 
    //  get the live range corresponding to live var
     LiveRange *const LRofLV = LRI.getLiveRangeForValue(*LIt );    
 
     // LR can be null if it is a const since a const 
     // doesn't have a dominating def - see Assumptions above
-    if( LRofLV )     
-      if( LRofLV->hasColor() ) 
-       IsColorUsedArr[ LRofLV->getColor() ] = true;
+    if (LRofLV && LRofLV->getRegClass() == RC && LRofLV->hasColor() ) 
+      IsColorUsedArr[ LRofLV->getColor() ] = true;
   }
 
   // It is possible that one operand of this MInst was already spilled
@@ -805,16 +782,11 @@ int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC,
 
   setRelRegsUsedByThisInst(RC, MInst);
 
-  unsigned c;                         // find first unused color
-  for( c=0; c < NumAvailRegs; c++)  
-     if( ! IsColorUsedArr[ c ] ) break;
-   
-  if(c < NumAvailRegs) 
-    return  MRI.getUnifiedRegNum(RC->getID(), c);
-  else 
-    return -1;
-
-
+  for (unsigned c=0; c < NumAvailRegs; c++)   // find first unused color
+     if (!IsColorUsedArr[c])
+       return MRI.getUnifiedRegNum(RC->getID(), c);
+  
+  return -1;
 }
 
 
@@ -823,25 +795,21 @@ int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC,
 // by operands of a machine instruction. Returns the unified reg number.
 //----------------------------------------------------------------------------
 int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC, 
-                                        const MachineInstr *MInst) {
+                                            const MachineInstr *MInst) {
 
-  bool *IsColorUsedArr = RC->getIsColorUsedArr();
+  vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
   unsigned NumAvailRegs =  RC->getNumOfAvailRegs();
 
-
-  for(unsigned i=0; i < NumAvailRegs ; i++)   // Reset array
+  for (unsigned i=0; i < NumAvailRegs ; i++)   // Reset array
     IsColorUsedArr[i] = false;
 
   setRelRegsUsedByThisInst(RC, MInst);
 
-  unsigned c;                         // find first unused color
-  for( c=0; c <  RC->getNumOfAvailRegs(); c++)  
-     if( ! IsColorUsedArr[ c ] ) break;
-   
-  if(c < NumAvailRegs) 
-    return  MRI.getUnifiedRegNum(RC->getID(), c);
-  else 
-    assert( 0 && "FATAL: No free register could be found in reg class!!");
+  for (unsigned c=0; c < RC->getNumOfAvailRegs(); c++)// find first unused color
+    if (!IsColorUsedArr[c])
+      return  MRI.getUnifiedRegNum(RC->getID(), c);
+
+  assert(0 && "FATAL: No free register could be found in reg class!!");
   return 0;
 }
 
@@ -852,61 +820,55 @@ int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC,
 // instructions. Both explicit and implicit operands are set.
 //----------------------------------------------------------------------------
 void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC, 
-                                      const MachineInstr *MInst ) {
+                                           const MachineInstr *MInst ) {
 
bool *IsColorUsedArr = RC->getIsColorUsedArr();
 vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
   
- for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
-    
-   const MachineOperand& Op = MInst->getOperand(OpNum);
-
-    if( Op.getOperandType() ==  MachineOperand::MO_VirtualRegister || 
-       Op.getOperandType() ==  MachineOperand::MO_CCRegister ) {
-
-      const Value *const Val =  Op.getVRegValue();
-
-      if( Val ) 
-       if( MRI.getRegClassIDOfValue(Val) == RC->getID() ) {   
-         int Reg;
-         if( (Reg=Op.getAllocatedRegNum()) != -1) {
-           IsColorUsedArr[ Reg ] = true;
-         }
-         else {
-           // it is possilbe that this operand still is not marked with
-           // a register but it has a LR and that received a color
-
-           LiveRange *LROfVal =  LRI.getLiveRangeForValue(Val);
-           if( LROfVal) 
-             if( LROfVal->hasColor() )
-               IsColorUsedArr[ LROfVal->getColor() ] = true;
-         }
-       
-       } // if reg classes are the same
+  // Add the registers already marked as used by the instruction. 
+  // This should include any scratch registers that are used to save
+  // values across the instruction (e.g., for saving state register values).
+  const hash_set<int>& regsUsed = MInst->getRegsUsed();
+  for (hash_set<int>::const_iterator SI=regsUsed.begin(), SE=regsUsed.end();
+       SI != SE; ++SI)
+    {
+      unsigned classId = 0;
+      int classRegNum = MRI.getClassRegNum(*SI, classId);
+      if (RC->getID() == classId)
+        {
+          assert(classRegNum < (int) IsColorUsedArr.size() &&
+                 "Illegal register number for this reg class?");
+          IsColorUsedArr[classRegNum] = true;
+        }
     }
-    else if (Op.getOperandType() ==  MachineOperand::MO_MachineRegister) {
-      IsColorUsedArr[ Op.getMachineRegNum() ] = true;
+  
+  // Now add registers allocated to the live ranges of values used in
+  // the instruction.  These are not yet recorded in the instruction.
+  for (unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum)
+    {
+      const MachineOperand& Op = MInst->getOperand(OpNum);
+      
+      if (Op.getOperandType() == MachineOperand::MO_VirtualRegister || 
+          Op.getOperandType() == MachineOperand::MO_CCRegister)
+        if (const Value* Val = Op.getVRegValue())
+          if (MRI.getRegClassIDOfValue(Val) == RC->getID())
+            if (Op.getAllocatedRegNum() == -1)
+              if (LiveRange *LROfVal = LRI.getLiveRangeForValue(Val))
+                if (LROfVal->hasColor() )
+                  // this operand is in a LR that received a color
+                  IsColorUsedArr[LROfVal->getColor()] = true;
     }
- }
- // If there are implicit references, mark them as well
-
- for(unsigned z=0; z < MInst->getNumImplicitRefs(); z++) {
-
-   LiveRange *const LRofImpRef = 
-     LRI.getLiveRangeForValue( MInst->getImplicitRef(z)  );    
-   
-   if(LRofImpRef && LRofImpRef->hasColor())
-     IsColorUsedArr[LRofImpRef->getColor()] = true;
- }
+  
+  // If there are implicit references, mark their allocated regs as well
+  // 
+  for (unsigned z=0; z < MInst->getNumImplicitRefs(); z++)
+    if (const LiveRange*
+        LRofImpRef = LRI.getLiveRangeForValue(MInst->getImplicitRef(z)))    
+      if (LRofImpRef->hasColor())
+        // this implicit reference is in a LR that received a color
+        IsColorUsedArr[LRofImpRef->getColor()] = true;
 }
 
 
-
-
-
-
-
-
 //----------------------------------------------------------------------------
 // If there are delay slots for an instruction, the instructions
 // added after it must really go after the delayed instruction(s).
@@ -918,13 +880,13 @@ void PhyRegAlloc::move2DelayedInstr(const MachineInstr *OrigMI,
                                     const MachineInstr *DelayedMI) {
 
   // "added after" instructions of the original instr
-  std::deque<MachineInstr *> &OrigAft = AddedInstrMap[OrigMI].InstrnsAfter;
+  std::vector<MachineInstr *> &OrigAft = AddedInstrMap[OrigMI].InstrnsAfter;
 
   // "added instructions" of the delayed instr
   AddedInstrns &DelayAdI = AddedInstrMap[DelayedMI];
 
   // "added after" instructions of the delayed instr
-  std::deque<MachineInstr *> &DelayedAft = DelayAdI.InstrnsAfter;
+  std::vector<MachineInstr *> &DelayedAft = DelayAdI.InstrnsAfter;
 
   // go thru all the "added after instructions" of the original instruction
   // and append them to the "addded after instructions" of the delayed
@@ -947,35 +909,35 @@ void PhyRegAlloc::printMachineCode()
 
   for (Function::const_iterator BBI = Meth->begin(), BBE = Meth->end();
        BBI != BBE; ++BBI) {
-    cerr << "\n"; printLabel(*BBI); cerr << ": ";
+    cerr << "\n"; printLabel(BBI); cerr << ": ";
 
     // get the iterator for machine instructions
-    MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
+    MachineCodeForBasicBlock& MIVec = MachineCodeForBasicBlock::get(BBI);
     MachineCodeForBasicBlock::iterator MII = MIVec.begin();
 
     // iterate over all the machine instructions in BB
-    for( ; MII != MIVec.end(); ++MII) {  
+    for ( ; MII != MIVec.end(); ++MII) {  
       MachineInstr *const MInst = *MII; 
 
       cerr << "\n\t";
       cerr << TargetInstrDescriptors[MInst->getOpCode()].opCodeString;
 
-      for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
+      for (unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
        MachineOperand& Op = MInst->getOperand(OpNum);
 
-       ifOp.getOperandType() ==  MachineOperand::MO_VirtualRegister || 
+       if (Op.getOperandType() ==  MachineOperand::MO_VirtualRegister || 
            Op.getOperandType() ==  MachineOperand::MO_CCRegister /*|| 
            Op.getOperandType() ==  MachineOperand::MO_PCRelativeDisp*/ ) {
 
          const Value *const Val = Op.getVRegValue () ;
          // ****this code is temporary till NULL Values are fixed
-         if! Val ) {
+         if (! Val ) {
            cerr << "\t<*NULL*>";
            continue;
          }
 
          // if a label or a constant
-         if(isa<BasicBlock>(Val)) {
+         if (isa<BasicBlock>(Val)) {
            cerr << "\t"; printLabel(   Op.getVRegValue () );
          } else {
            // else it must be a register value
@@ -987,17 +949,17 @@ void PhyRegAlloc::printMachineCode()
            else 
              cerr << "(" << Val << ")";
 
-           ifOp.opIsDef() )
+           if (Op.opIsDef() )
              cerr << "*";
 
            const LiveRange *LROfVal = LRI.getLiveRangeForValue(Val);
-           ifLROfVal )
-             ifLROfVal->hasSpillOffset() )
+           if (LROfVal )
+             if (LROfVal->hasSpillOffset() )
                cerr << "$";
          }
 
        } 
-       else if(Op.getOperandType() ==  MachineOperand::MO_MachineRegister) {
+       else if (Op.getOperandType() ==  MachineOperand::MO_MachineRegister) {
          cerr << "\t" << "%" << MRI.getUnifiedRegName(Op.getMachineRegNum());
        }
 
@@ -1008,10 +970,10 @@ void PhyRegAlloc::printMachineCode()
     
 
       unsigned NumOfImpRefs =  MInst->getNumImplicitRefs();
-      ifNumOfImpRefs > 0) {
+      if (NumOfImpRefs > 0) {
        cerr << "\tImplicit:";
 
-       for(unsigned z=0; z < NumOfImpRefs; z++)
+       for (unsigned z=0; z < NumOfImpRefs; z++)
          cerr << RAV(MInst->getImplicitRef(z)) << "\t";
       }
 
@@ -1025,49 +987,13 @@ void PhyRegAlloc::printMachineCode()
 }
 
 
-#if 0
-
-//----------------------------------------------------------------------------
-//
-//----------------------------------------------------------------------------
-
-void PhyRegAlloc::colorCallRetArgs()
-{
-
-  CallRetInstrListType &CallRetInstList = LRI.getCallRetInstrList();
-  CallRetInstrListType::const_iterator It = CallRetInstList.begin();
-
-  for( ; It != CallRetInstList.end(); ++It ) {
-
-    const MachineInstr *const CRMI = *It;
-    unsigned OpCode =  CRMI->getOpCode();
-    // get the added instructions for this Call/Ret instruciton
-    AddedInstrns &AI = AddedInstrMap[CRMI];
-
-    // Tmp stack positions are needed by some calls that have spilled args
-    // So reset it before we call each such method
-    //mcInfo.popAllTempValues(TM);  
-
-    
-    if (TM.getInstrInfo().isCall(OpCode))
-      MRI.colorCallArgs(CRMI, LRI, &AI, *this);
-    else if (TM.getInstrInfo().isReturn(OpCode)) 
-      MRI.colorRetValue(CRMI, LRI, &AI);
-    else
-      assert(0 && "Non Call/Ret instrn in CallRetInstrList\n");
-  }
-}
-
-#endif 
-
 //----------------------------------------------------------------------------
 
 //----------------------------------------------------------------------------
 void PhyRegAlloc::colorIncomingArgs()
 {
-  const BasicBlock *const FirstBB = Meth->front();
-  const MachineInstr *FirstMI = FirstBB->getMachineInstrVec().front();
+  const BasicBlock &FirstBB = Meth->front();
+  const MachineInstr *FirstMI = MachineCodeForBasicBlock::get(&FirstBB).front();
   assert(FirstMI && "No machine instruction in entry BB");
 
   MRI.colorMethodArgs(Meth, LRI, &AddedInstrAtEntry);
@@ -1094,19 +1020,19 @@ void PhyRegAlloc::printLabel(const Value *const Val) {
 
 void PhyRegAlloc::markUnusableSugColors()
 {
-  if(DEBUG_RA ) cerr << "\nmarking unusable suggested colors ...\n";
+  if (DEBUG_RA ) cerr << "\nmarking unusable suggested colors ...\n";
 
   // hash map iterator
   LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin();   
   LiveRangeMapType::const_iterator HMIEnd = (LRI.getLiveRangeMap())->end();   
 
-    for(; HMI != HMIEnd ; ++HMI ) {
+    for (; HMI != HMIEnd ; ++HMI ) {
       if (HMI->first) { 
        LiveRange *L = HMI->second;      // get the LiveRange
        if (L) { 
-         if(L->hasSuggestedColor()) {
+         if (L->hasSuggestedColor()) {
            int RCID = L->getRegClass()->getID();
-           ifMRI.isRegVolatile( RCID,  L->getSuggestedColor()) &&
+           if (MRI.isRegVolatile( RCID,  L->getSuggestedColor()) &&
                L->isCallInterference() )
              L->setSuggestedColorUsable( false );
            else
@@ -1132,7 +1058,7 @@ void PhyRegAlloc::allocateStackSpace4SpilledLRs() {
   LiveRangeMapType::const_iterator HMI    = LRI.getLiveRangeMap()->begin();   
   LiveRangeMapType::const_iterator HMIEnd = LRI.getLiveRangeMap()->end();   
 
-  for( ; HMI != HMIEnd ; ++HMI) {
+  for ( ; HMI != HMIEnd ; ++HMI) {
     if (HMI->first && HMI->second) {
       LiveRange *L = HMI->second;      // get the LiveRange
       if (!L->hasColor())   //  NOTE: ** allocating the size of long Type **
@@ -1166,25 +1092,25 @@ void PhyRegAlloc::allocateRegisters()
   
   if (DEBUG_RA) {
     // print all LRs in all reg classes
-    for( unsigned int rc=0; rc < NumOfRegClasses  ; rc++)  
-      RegClassList[ rc ]->printIGNodeList(); 
+    for ( unsigned rc=0; rc < NumOfRegClasses  ; rc++)  
+      RegClassList[rc]->printIGNodeList(); 
     
     // print IGs in all register classes
-    for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)  
-      RegClassList[ rc ]->printIG();       
+    for ( unsigned rc=0; rc < NumOfRegClasses ; rc++)  
+      RegClassList[rc]->printIG();       
   }
   
 
   LRI.coalesceLRs();                    // coalesce all live ranges
   
 
-  ifDEBUG_RA) {
+  if (DEBUG_RA) {
     // print all LRs in all reg classes
-    for( unsigned int rc=0; rc < NumOfRegClasses  ; rc++)  
+    for ( unsigned rc=0; rc < NumOfRegClasses  ; rc++)  
       RegClassList[ rc ]->printIGNodeList(); 
     
     // print IGs in all register classes
-    for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)  
+    for ( unsigned rc=0; rc < NumOfRegClasses ; rc++)  
       RegClassList[ rc ]->printIG();       
   }
 
@@ -1196,7 +1122,7 @@ void PhyRegAlloc::allocateRegisters()
   markUnusableSugColors(); 
 
   // color all register classes using the graph coloring algo
-  for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)  
+  for (unsigned rc=0; rc < NumOfRegClasses ; rc++)  
     RegClassList[ rc ]->colorAllRegs();    
 
   // Atter grpah coloring, if some LRs did not receive a color (i.e, spilled)