Add completely untested support for mtcrf/mfcrf encoding
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9RegInfo.cpp
index 33690f8aa4924ae862ce17dbfe182441279c41ef..8a827187aee650e9936a9046d0811a622d9d9367 100644 (file)
@@ -1,4 +1,4 @@
-//===-- SparcRegInfo.cpp - Sparc Target Register Information --------------===//
+//===-- SparcV9RegInfo.cpp - SparcV9 Target Register Information ----------===//
 // 
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,27 +7,28 @@
 // 
 //===----------------------------------------------------------------------===//
 //
-// This file contains implementation of Sparc specific helper methods
+// This file contains implementations of SparcV9 specific helper methods
 // used for register allocation.
 //
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineFunctionInfo.h"
-#include "llvm/CodeGen/InstrSelection.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
-#include "llvm/CodeGen/MachineCodeForInstruction.h"
-#include "llvm/CodeGen/MachineInstrAnnot.h"
+#include "MachineFunctionInfo.h"
+#include "MachineCodeForInstruction.h"
+#include "MachineInstrAnnot.h"
 #include "RegAlloc/LiveRangeInfo.h"
 #include "RegAlloc/LiveRange.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
-#include "llvm/iTerminators.h"
-#include "llvm/iOther.h"
-#include "SparcInternals.h"
-#include "SparcRegClassInfo.h"
-#include "SparcRegInfo.h"
-#include "SparcTargetMachine.h"
+#include "llvm/Instructions.h"
+#include "SparcV9Internals.h"
+#include "SparcV9RegClassInfo.h"
+#include "SparcV9RegInfo.h"
+#include "SparcV9FrameInfo.h"
+#include "SparcV9TargetMachine.h"
+#include "SparcV9TmpInstr.h"
+#include <iostream>
 
 namespace llvm {
 
@@ -35,16 +36,16 @@ enum {
   BadRegClass = ~0
 };
 
-SparcRegInfo::SparcRegInfo(const SparcTargetMachine &tgt)
-  : TargetRegInfo(tgt), NumOfIntArgRegs(6), NumOfFloatArgRegs(32)
+SparcV9RegInfo::SparcV9RegInfo(const SparcV9TargetMachine &tgt)
+  : target (tgt), NumOfIntArgRegs (6), NumOfFloatArgRegs (32)
 {
-  MachineRegClassArr.push_back(new SparcIntRegClass(IntRegClassID));
-  MachineRegClassArr.push_back(new SparcFloatRegClass(FloatRegClassID));
-  MachineRegClassArr.push_back(new SparcIntCCRegClass(IntCCRegClassID));
-  MachineRegClassArr.push_back(new SparcFloatCCRegClass(FloatCCRegClassID));
-  MachineRegClassArr.push_back(new SparcSpecialRegClass(SpecialRegClassID));
+  MachineRegClassArr.push_back(new SparcV9IntRegClass(IntRegClassID));
+  MachineRegClassArr.push_back(new SparcV9FloatRegClass(FloatRegClassID));
+  MachineRegClassArr.push_back(new SparcV9IntCCRegClass(IntCCRegClassID));
+  MachineRegClassArr.push_back(new SparcV9FloatCCRegClass(FloatCCRegClassID));
+  MachineRegClassArr.push_back(new SparcV9SpecialRegClass(SpecialRegClassID));
   
-  assert(SparcFloatRegClass::StartOfNonVolatileRegs == 32 && 
+  assert(SparcV9FloatRegClass::StartOfNonVolatileRegs == 32 && 
          "32 Float regs are used for float arg passing");
 }
 
@@ -52,31 +53,31 @@ SparcRegInfo::SparcRegInfo(const SparcTargetMachine &tgt)
 // getZeroRegNum - returns the register that contains always zero.
 // this is the unified register number
 //
-unsigned SparcRegInfo::getZeroRegNum() const {
-  return getUnifiedRegNum(SparcRegInfo::IntRegClassID,
-                          SparcIntRegClass::g0);
+unsigned SparcV9RegInfo::getZeroRegNum() const {
+  return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
+                          SparcV9IntRegClass::g0);
 }
 
 // getCallAddressReg - returns the reg used for pushing the address when a
 // method is called. This can be used for other purposes between calls
 //
-unsigned SparcRegInfo::getCallAddressReg() const {
-  return getUnifiedRegNum(SparcRegInfo::IntRegClassID,
-                          SparcIntRegClass::o7);
+unsigned SparcV9RegInfo::getCallAddressReg() const {
+  return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
+                          SparcV9IntRegClass::o7);
 }
 
 // Returns the register containing the return address.
 // It should be made sure that this  register contains the return 
 // value when a return instruction is reached.
 //
-unsigned SparcRegInfo::getReturnAddressReg() const {
-  return getUnifiedRegNum(SparcRegInfo::IntRegClassID,
-                          SparcIntRegClass::i7);
+unsigned SparcV9RegInfo::getReturnAddressReg() const {
+  return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
+                          SparcV9IntRegClass::i7);
 }
 
 // Register get name implementations...
 
-// Int register names in same order as enum in class SparcIntRegClass
+// Int register names in same order as enum in class SparcV9IntRegClass
 static const char * const IntRegNames[] = {
   "o0", "o1", "o2", "o3", "o4", "o5",       "o7",
   "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
@@ -86,7 +87,7 @@ static const char * const IntRegNames[] = {
   "o6"
 }; 
 
-const char * const SparcIntRegClass::getRegName(unsigned reg) const {
+const char * const SparcV9IntRegClass::getRegName(unsigned reg) const {
   assert(reg < NumOfAllRegs);
   return IntRegNames[reg];
 }
@@ -101,17 +102,16 @@ static const char * const FloatRegNames[] = {
   "f60", "f61", "f62", "f63"
 };
 
-const char * const SparcFloatRegClass::getRegName(unsigned reg) const {
+const char * const SparcV9FloatRegClass::getRegName(unsigned reg) const {
   assert (reg < NumOfAllRegs);
   return FloatRegNames[reg];
 }
 
-
 static const char * const IntCCRegNames[] = {    
   "xcc",  "icc",  "ccr"
 };
 
-const char * const SparcIntCCRegClass::getRegName(unsigned reg) const {
+const char * const SparcV9IntCCRegClass::getRegName(unsigned reg) const {
   assert(reg < 3);
   return IntCCRegNames[reg];
 }
@@ -120,8 +120,8 @@ static const char * const FloatCCRegNames[] = {
   "fcc0", "fcc1",  "fcc2",  "fcc3"
 };
 
-const char * const SparcFloatCCRegClass::getRegName(unsigned reg) const {
-  assert (reg < 5);
+const char * const SparcV9FloatCCRegClass::getRegName(unsigned reg) const {
+  assert (reg < 4);
   return FloatCCRegNames[reg];
 }
 
@@ -129,21 +129,21 @@ static const char * const SpecialRegNames[] = {
   "fsr"
 };
 
-const char * const SparcSpecialRegClass::getRegName(unsigned reg) const {
+const char * const SparcV9SpecialRegClass::getRegName(unsigned reg) const {
   assert (reg < 1);
   return SpecialRegNames[reg];
 }
 
 // Get unified reg number for frame pointer
-unsigned SparcRegInfo::getFramePointer() const {
-  return getUnifiedRegNum(SparcRegInfo::IntRegClassID,
-                          SparcIntRegClass::i6);
+unsigned SparcV9RegInfo::getFramePointer() const {
+  return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
+                          SparcV9IntRegClass::i6);
 }
 
 // Get unified reg number for stack pointer
-unsigned SparcRegInfo::getStackPointer() const {
-  return getUnifiedRegNum(SparcRegInfo::IntRegClassID,
-                          SparcIntRegClass::o6);
+unsigned SparcV9RegInfo::getStackPointer() const {
+  return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
+                          SparcV9IntRegClass::o6);
 }
 
 
@@ -175,14 +175,14 @@ isVarArgsCall(const MachineInstr *CallMI) {
 //                           regClassId is set to the register class ID.
 // 
 int
-SparcRegInfo::regNumForIntArg(bool inCallee, bool isVarArgsCall,
+SparcV9RegInfo::regNumForIntArg(bool inCallee, bool isVarArgsCall,
                                    unsigned argNo, unsigned& regClassId) const
 {
   regClassId = IntRegClassID;
   if (argNo >= NumOfIntArgRegs)
     return getInvalidRegNum();
   else
-    return argNo + (inCallee? SparcIntRegClass::i0 : SparcIntRegClass::o0);
+    return argNo + (inCallee? SparcV9IntRegClass::i0 : SparcV9IntRegClass::o0);
 }
 
 // Get the register number for the specified FP argument #argNo,
@@ -194,7 +194,7 @@ SparcRegInfo::regNumForIntArg(bool inCallee, bool isVarArgsCall,
 //                           regClassId is set to the register class ID.
 // 
 int
-SparcRegInfo::regNumForFPArg(unsigned regType,
+SparcV9RegInfo::regNumForFPArg(unsigned regType,
                                   bool inCallee, bool isVarArgsCall,
                                   unsigned argNo, unsigned& regClassId) const
 {
@@ -205,10 +205,10 @@ SparcRegInfo::regNumForFPArg(unsigned regType,
       regClassId = FloatRegClassID;
       if (regType == FPSingleRegType)
         return (argNo*2+1 >= NumOfFloatArgRegs)?
-          getInvalidRegNum() : SparcFloatRegClass::f0 + (argNo * 2 + 1);
+          getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2 + 1);
       else if (regType == FPDoubleRegType)
         return (argNo*2 >= NumOfFloatArgRegs)?
-          getInvalidRegNum() : SparcFloatRegClass::f0 + (argNo * 2);
+          getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2);
       else
         assert(0 && "Illegal FP register type");
        return 0;
@@ -220,10 +220,10 @@ SparcRegInfo::regNumForFPArg(unsigned regType,
 // Finds the return address of a call sparc specific call instruction
 //---------------------------------------------------------------------------
 
-// The following 4  methods are used to find the RegType (SparcInternals.h)
+// The following 4  methods are used to find the RegType (SparcV9Internals.h)
 // of a LiveRange, a Value, and for a given register unified reg number.
 //
-int SparcRegInfo::getRegTypeForClassAndType(unsigned regClassID,
+int SparcV9RegInfo::getRegTypeForClassAndType(unsigned regClassID,
                                                  const Type* type) const
 {
   switch (regClassID) {
@@ -239,17 +239,17 @@ int SparcRegInfo::getRegTypeForClassAndType(unsigned regClassID,
   }
 }
 
-int SparcRegInfo::getRegTypeForDataType(const Type* type) const
+int SparcV9RegInfo::getRegTypeForDataType(const Type* type) const
 {
   return getRegTypeForClassAndType(getRegClassIDOfType(type), type);
 }
 
-int SparcRegInfo::getRegTypeForLR(const LiveRange *LR) const
+int SparcV9RegInfo::getRegTypeForLR(const LiveRange *LR) const
 {
   return getRegTypeForClassAndType(LR->getRegClassID(), LR->getType());
 }
 
-int SparcRegInfo::getRegType(int unifiedRegNum) const
+int SparcV9RegInfo::getRegType(int unifiedRegNum) const
 {
   if (unifiedRegNum < 32) 
     return IntRegType;
@@ -257,10 +257,12 @@ int SparcRegInfo::getRegType(int unifiedRegNum) const
     return FPSingleRegType;
   else if (unifiedRegNum < (64 + 32))
     return FPDoubleRegType;
-  else if (unifiedRegNum < (64+32+4))
-    return FloatCCRegType;
-  else if (unifiedRegNum < (64+32+4+2))  
-    return IntCCRegType;             
+  else if (unifiedRegNum < (64+32+3))
+    return IntCCRegType;
+  else if (unifiedRegNum < (64+32+3+4))  
+    return FloatCCRegType;             
+  else if (unifiedRegNum < (64+32+3+4+1))  
+    return SpecialRegType;             
   else 
     assert(0 && "Invalid unified register number in getRegType");
   return 0;
@@ -269,9 +271,9 @@ int SparcRegInfo::getRegType(int unifiedRegNum) const
 
 // To find the register class used for a specified Type
 //
-unsigned SparcRegInfo::getRegClassIDOfType(const Type *type,
+unsigned SparcV9RegInfo::getRegClassIDOfType(const Type *type,
                                                 bool isCCReg) const {
-  Type::PrimitiveID ty = type->getPrimitiveID();
+  Type::TypeID ty = type->getTypeID();
   unsigned res;
     
   // FIXME: Comparing types like this isn't very safe...
@@ -292,13 +294,14 @@ unsigned SparcRegInfo::getRegClassIDOfType(const Type *type,
     return res;
 }
 
-unsigned SparcRegInfo::getRegClassIDOfRegType(int regType) const {
+unsigned SparcV9RegInfo::getRegClassIDOfRegType(int regType) const {
   switch(regType) {
   case IntRegType:      return IntRegClassID;
   case FPSingleRegType:
   case FPDoubleRegType: return FloatRegClassID;
   case IntCCRegType:    return IntCCRegClassID;
   case FloatCCRegType:  return FloatCCRegClassID;
+  case SpecialRegType:  return SpecialRegClassID;
   default:
     assert(0 && "Invalid register type in getRegClassIDOfRegType");
     return 0;
@@ -309,14 +312,14 @@ unsigned SparcRegInfo::getRegClassIDOfRegType(int regType) const {
 // Suggests a register for the ret address in the RET machine instruction.
 // We always suggest %i7 by convention.
 //---------------------------------------------------------------------------
-void SparcRegInfo::suggestReg4RetAddr(MachineInstr *RetMI, 
+void SparcV9RegInfo::suggestReg4RetAddr(MachineInstr *RetMI, 
                                           LiveRangeInfo& LRI) const {
 
-  assert(target.getInstrInfo().isReturn(RetMI->getOpcode()));
+  assert(target.getInstrInfo()->isReturn(RetMI->getOpcode()));
   
   // return address is always mapped to i7 so set it immediately
   RetMI->SetRegForOperand(0, getUnifiedRegNum(IntRegClassID,
-                                              SparcIntRegClass::i7));
+                                              SparcV9IntRegClass::i7));
   
   // Possible Optimization: 
   // Instead of setting the color, we can suggest one. In that case,
@@ -329,16 +332,16 @@ void SparcRegInfo::suggestReg4RetAddr(MachineInstr *RetMI,
   // assert( RetAddrVal && "LR for ret address must be created at start");
   // LiveRange * RetAddrLR = LRI.getLiveRangeForValue( RetAddrVal);  
   // RetAddrLR->setSuggestedColor(getUnifiedRegNum( IntRegClassID, 
-  //                              SparcIntRegOrdr::i7) );
+  //                              SparcV9IntRegOrdr::i7) );
 }
 
 
 //---------------------------------------------------------------------------
 // Suggests a register for the ret address in the JMPL/CALL machine instr.
-// Sparc ABI dictates that %o7 be used for this purpose.
+// SparcV9 ABI dictates that %o7 be used for this purpose.
 //---------------------------------------------------------------------------
 void
-SparcRegInfo::suggestReg4CallAddr(MachineInstr * CallMI,
+SparcV9RegInfo::suggestReg4CallAddr(MachineInstr * CallMI,
                                        LiveRangeInfo& LRI) const
 {
   CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI); 
@@ -350,19 +353,19 @@ SparcRegInfo::suggestReg4CallAddr(MachineInstr * CallMI,
   assert(RetAddrLR && "INTERNAL ERROR: No LR for return address of call!");
 
   unsigned RegClassID = RetAddrLR->getRegClassID();
-  RetAddrLR->setColor(getUnifiedRegNum(IntRegClassID, SparcIntRegClass::o7));
+  RetAddrLR->setColor(getUnifiedRegNum(IntRegClassID, SparcV9IntRegClass::o7));
 }
 
 
 
 //---------------------------------------------------------------------------
 //  This method will suggest colors to incoming args to a method. 
-//  According to the Sparc ABI, the first 6 incoming args are in 
+//  According to the SparcV9 ABI, the first 6 incoming args are in 
 //  %i0 - %i5 (if they are integer) OR in %f0 - %f31 (if they are float).
 //  If the arg is passed on stack due to the lack of regs, NOTHING will be
 //  done - it will be colored (or spilled) as a normal live range.
 //---------------------------------------------------------------------------
-void SparcRegInfo::suggestRegs4MethodArgs(const Function *Meth, 
+void SparcV9RegInfo::suggestRegs4MethodArgs(const Function *Meth, 
                                               LiveRangeInfo& LRI) const 
 {
   // Check if this is a varArgs function. needed for choosing regs.
@@ -371,7 +374,7 @@ void SparcRegInfo::suggestRegs4MethodArgs(const Function *Meth,
   // Count the arguments, *ignoring* whether they are int or FP args.
   // Use this common arg numbering to pick the right int or fp register.
   unsigned argNo=0;
-  for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend();
+  for(Function::const_arg_iterator I = Meth->arg_begin(), E = Meth->arg_end();
       I != E; ++I, ++argNo) {
     LiveRange *LR = LRI.getLiveRangeForValue(I);
     assert(LR && "No live range found for method arg");
@@ -395,7 +398,7 @@ void SparcRegInfo::suggestRegs4MethodArgs(const Function *Meth,
 // the correct hardware registers if they did not receive the correct
 // (suggested) color through graph coloring.
 //---------------------------------------------------------------------------
-void SparcRegInfo::colorMethodArgs(const Function *Meth, 
+void SparcV9RegInfo::colorMethodArgs(const Function *Meth, 
                             LiveRangeInfo &LRI,
                             std::vector<MachineInstr*>& InstrnsBefore,
                             std::vector<MachineInstr*>& InstrnsAfter) const {
@@ -407,7 +410,7 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
   // for each argument
   // for each argument.  count INT and FP arguments separately.
   unsigned argNo=0, intArgNo=0, fpArgNo=0;
-  for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend();
+  for(Function::const_arg_iterator I = Meth->arg_begin(), E = Meth->arg_end();
       I != E; ++I, ++argNo) {
     // get the LR of arg
     LiveRange *LR = LRI.getLiveRangeForValue(I);
@@ -453,7 +456,7 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
       //
       if( isArgInReg ) {
        if( regClassIDOfArgReg != RegClassID ) {
-          assert(0 && "This could should work but it is not tested yet");
+         // NOTE: This code has not been well-tested.
           
          // It is a variable argument call: the float reg must go in a %o reg.
          // We have to move an int reg to a float reg via memory.
@@ -463,7 +466,7 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
                  regClassIDOfArgReg == IntRegClassID &&
                  "This should only be an Int register for an FP argument");
           
-         int TmpOff = MachineFunction::get(Meth).getInfo()->pushTempValue(
+         int TmpOff = MachineFunction::get(Meth).getInfo<SparcV9FunctionInfo>()->pushTempValue(
                                                 getSpilledRegSize(regType));
          cpReg2MemMI(InstrnsBefore,
                       UniArgReg, getFramePointer(), TmpOff, IntRegType);
@@ -480,7 +483,7 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
        // Now the arg is coming on stack. Since the LR received a register,
        // we just have to load the arg on stack into that register
        //
-        const TargetFrameInfo& frameInfo = target.getFrameInfo();
+        const TargetFrameInfo& frameInfo = *target.getFrameInfo();
        int offsetFromFP =
           frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
                                          argNo);
@@ -490,7 +493,7 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
         // a full double-word so the offset does not need to be adjusted.
         if (regType == FPSingleRegType) {
           unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
-          unsigned slotSize = frameInfo.getSizeOfEachArgOnStack();
+          unsigned slotSize = SparcV9FrameInfo::SizeOfEachArgOnStack;
           assert(argSize <= slotSize && "Insufficient slot size!");
           offsetFromFP += slotSize - argSize;
         }
@@ -538,7 +541,7 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
        // since this method is called before any other method that makes
        // uses of the stack pos of the LR (e.g., updateMachineInstr)
         // 
-        const TargetFrameInfo& frameInfo = target.getFrameInfo();
+        const TargetFrameInfo& frameInfo = *target.getFrameInfo();
        int offsetFromFP =
           frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
                                          argNo);
@@ -548,7 +551,7 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
         // a full double-word so the offset does not need to be adjusted.
         if (regType == FPSingleRegType) {
           unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
-          unsigned slotSize = frameInfo.getSizeOfEachArgOnStack();
+          unsigned slotSize = SparcV9FrameInfo::SizeOfEachArgOnStack;
           assert(argSize <= slotSize && "Insufficient slot size!");
           offsetFromFP += slotSize - argSize;
         }
@@ -568,9 +571,9 @@ void SparcRegInfo::colorMethodArgs(const Function *Meth,
 // This method is called before graph coloring to suggest colors to the
 // outgoing call args and the return value of the call.
 //---------------------------------------------------------------------------
-void SparcRegInfo::suggestRegs4CallArgs(MachineInstr *CallMI, 
+void SparcV9RegInfo::suggestRegs4CallArgs(MachineInstr *CallMI, 
                                             LiveRangeInfo& LRI) const {
-  assert ( (target.getInstrInfo()).isCall(CallMI->getOpcode()) );
+  assert ( (target.getInstrInfo())->isCall(CallMI->getOpcode()) );
 
   CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI); 
   
@@ -588,9 +591,9 @@ void SparcRegInfo::suggestRegs4CallArgs(MachineInstr *CallMI,
 
     // now suggest a register depending on the register class of ret arg
     if( RegClassID == IntRegClassID ) 
-      RetValLR->setSuggestedColor(SparcIntRegClass::o0);
+      RetValLR->setSuggestedColor(SparcV9IntRegClass::o0);
     else if (RegClassID == FloatRegClassID ) 
-      RetValLR->setSuggestedColor(SparcFloatRegClass::f0 );
+      RetValLR->setSuggestedColor(SparcV9FloatRegClass::f0 );
     else assert( 0 && "Unknown reg class for return value of call\n");
   }
 
@@ -636,10 +639,10 @@ void SparcRegInfo::suggestRegs4CallArgs(MachineInstr *CallMI,
 // this method is called for an LLVM return instruction to identify which
 // values will be returned from this method and to suggest colors.
 //---------------------------------------------------------------------------
-void SparcRegInfo::suggestReg4RetValue(MachineInstr *RetMI, 
+void SparcV9RegInfo::suggestReg4RetValue(MachineInstr *RetMI, 
                                             LiveRangeInfo& LRI) const {
 
-  assert( (target.getInstrInfo()).isReturn( RetMI->getOpcode() ) );
+  assert( target.getInstrInfo()->isReturn( RetMI->getOpcode() ) );
 
   suggestReg4RetAddr(RetMI, LRI);
 
@@ -650,8 +653,8 @@ void SparcRegInfo::suggestReg4RetValue(MachineInstr *RetMI,
   if (const Value *RetVal = retI->getReturnValue())
     if (LiveRange *const LR = LRI.getLiveRangeForValue(RetVal))
       LR->setSuggestedColor(LR->getRegClassID() == IntRegClassID
-                            ? (unsigned) SparcIntRegClass::i0
-                            : (unsigned) SparcFloatRegClass::f0);
+                            ? (unsigned) SparcV9IntRegClass::i0
+                            : (unsigned) SparcV9FloatRegClass::f0);
 }
 
 //---------------------------------------------------------------------------
@@ -664,7 +667,7 @@ void SparcRegInfo::suggestReg4RetValue(MachineInstr *RetMI,
 //---------------------------------------------------------------------------
 
 bool
-SparcRegInfo::regTypeNeedsScratchReg(int RegType,
+SparcV9RegInfo::regTypeNeedsScratchReg(int RegType,
                                           int& scratchRegType) const
 {
   if (RegType == IntCCRegType)
@@ -681,7 +684,7 @@ SparcRegInfo::regTypeNeedsScratchReg(int RegType,
 //---------------------------------------------------------------------------
 
 void
-SparcRegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
+SparcV9RegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
                                unsigned SrcReg,
                                unsigned DestReg,
                                int RegType) const {
@@ -697,8 +700,8 @@ SparcRegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
     if (getRegType(DestReg) == IntRegType) {
       // copy intCC reg to int reg
       MI = (BuildMI(V9::RDCCR, 2)
-            .addMReg(getUnifiedRegNum(SparcRegInfo::IntCCRegClassID,
-                                      SparcIntCCRegClass::ccr))
+            .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
+                                      SparcV9IntCCRegClass::ccr))
             .addMReg(DestReg,MachineOperand::Def));
     } else {
       // copy int reg to intCC reg
@@ -706,9 +709,9 @@ SparcRegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
              && "Can only copy CC reg to/from integer reg");
       MI = (BuildMI(V9::WRCCRr, 3)
             .addMReg(SrcReg)
-            .addMReg(SparcIntRegClass::g0)
-            .addMReg(getUnifiedRegNum(SparcRegInfo::IntCCRegClassID,
-                                      SparcIntCCRegClass::ccr),
+            .addMReg(SparcV9IntRegClass::g0)
+            .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
+                                      SparcV9IntCCRegClass::ccr),
                      MachineOperand::Def));
     }
     break;
@@ -741,81 +744,80 @@ SparcRegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
     mvec.push_back(MI);
 }
 
-//---------------------------------------------------------------------------
-// Copy from a register to memory (i.e., Store). Register number must 
-// be the unified register number
-//---------------------------------------------------------------------------
-
-
-void
-SparcRegInfo::cpReg2MemMI(std::vector<MachineInstr*>& mvec,
-                               unsigned SrcReg, 
-                               unsigned PtrReg,
-                               int Offset, int RegType,
-                               int scratchReg) const {
-  MachineInstr * MI = NULL;
-  int OffReg = -1;
-
-  // If the Offset will not fit in the signed-immediate field, find an
-  // unused register to hold the offset value.  This takes advantage of
-  // the fact that all the opcodes used below have the same size immed. field.
-  // Use the register allocator, PRA, to find an unused reg. at this MI.
-  // 
-  if (RegType != IntCCRegType)          // does not use offset below
-    if (! target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset)) {
-#ifdef CAN_FIND_FREE_REGISTER_TRANSPARENTLY
-      RegClass* RC = PRA.getRegClassByID(this->getRegClassIDOfRegType(RegType));
-      OffReg = PRA.getUnusedUniRegAtMI(RC, RegType, MInst, LVSetBef);
-#else
-      // Default to using register g4 for holding large offsets
-      OffReg = getUnifiedRegNum(SparcRegInfo::IntRegClassID,
-                                SparcIntRegClass::g4);
-#endif
-      assert(OffReg >= 0 && "FIXME: cpReg2MemMI cannot find an unused reg.");
-      mvec.push_back(BuildMI(V9::SETSW, 2).addZImm(Offset).addReg(OffReg));
-    }
+/// cpReg2MemMI - Generate SparcV9 MachineInstrs to store a register
+/// (SrcReg) to memory, at [PtrReg + Offset].  Register numbers must be the
+/// unified register numbers.  RegType must be the SparcV9 register type
+/// of SrcReg. When SrcReg is %ccr, scratchReg must be the
+/// number of a free integer register.  The newly-generated MachineInstrs
+/// are appended to mvec.
+///
+void SparcV9RegInfo::cpReg2MemMI(std::vector<MachineInstr*>& mvec,
+                                 unsigned SrcReg, unsigned PtrReg, int Offset,
+                                 int RegType, int scratchReg) const {
+  unsigned OffReg = SparcV9::g4; // Use register g4 for holding large offsets
+  bool useImmediateOffset = true;
+
+  // If the Offset will not fit in the signed-immediate field, we put it in
+  // register g4. This takes advantage of the fact that all the opcodes
+  // used below have the same size immed. field.
+  if (RegType != IntCCRegType
+      && !target.getInstrInfo()->constantFitsInImmedField(V9::LDXi, Offset)) {
+    // Put the offset into a register. We could do this in fewer steps,
+    // in some cases (see CreateSETSWConst()) but we're being lazy.
+    MachineInstr *MI = BuildMI(V9::SETHI, 2).addZImm(Offset).addMReg(OffReg,
+      MachineOperand::Def);
+    MI->getOperand(0).markHi32();
+    mvec.push_back(MI);
+    MI = BuildMI(V9::ORi,3).addMReg(OffReg).addZImm(Offset).addMReg(OffReg,
+      MachineOperand::Def);
+    MI->getOperand(1).markLo32();
+    mvec.push_back(MI);
+    MI = BuildMI(V9::SRAi5,3).addMReg(OffReg).addZImm(0).addMReg(OffReg,
+      MachineOperand::Def);
+    mvec.push_back(MI);
+    useImmediateOffset = false;
+  }
 
+  MachineInstr *MI = 0;
   switch (RegType) {
   case IntRegType:
-    if (target.getInstrInfo().constantFitsInImmedField(V9::STXi, Offset))
+    if (useImmediateOffset)
       MI = BuildMI(V9::STXi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
     else
       MI = BuildMI(V9::STXr,3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
     break;
 
   case FPSingleRegType:
-    if (target.getInstrInfo().constantFitsInImmedField(V9::STFi, Offset))
+    if (useImmediateOffset)
       MI = BuildMI(V9::STFi, 3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
     else
       MI = BuildMI(V9::STFr, 3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
     break;
 
   case FPDoubleRegType:
-    if (target.getInstrInfo().constantFitsInImmedField(V9::STDFi, Offset))
+    if (useImmediateOffset)
       MI = BuildMI(V9::STDFi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
     else
       MI = BuildMI(V9::STDFr,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(OffReg);
     break;
 
   case IntCCRegType:
-    assert(scratchReg >= 0 && "Need scratch reg to store %ccr to memory");
-    assert(getRegType(scratchReg) ==IntRegType && "Invalid scratch reg");
-    MI = (BuildMI(V9::RDCCR, 2)
-          .addMReg(getUnifiedRegNum(SparcRegInfo::IntCCRegClassID,
-                                    SparcIntCCRegClass::ccr))
-          .addMReg(scratchReg, MachineOperand::Def));
+    assert(scratchReg >= 0 && getRegType(scratchReg) == IntRegType
+           && "Need a scratch reg of integer type to load or store %ccr");
+    MI = BuildMI(V9::RDCCR, 2).addMReg(SparcV9::ccr)
+           .addMReg(scratchReg, MachineOperand::Def);
     mvec.push_back(MI);
-    
     cpReg2MemMI(mvec, scratchReg, PtrReg, Offset, IntRegType);
     return;
 
+  case SpecialRegType: // used only for %fsr itself.
   case FloatCCRegType: {
-    unsigned fsrReg =  getUnifiedRegNum(SparcRegInfo::SpecialRegClassID,
-                                           SparcSpecialRegClass::fsr);
-    if (target.getInstrInfo().constantFitsInImmedField(V9::STXFSRi, Offset))
-      MI=BuildMI(V9::STXFSRi,3).addMReg(fsrReg).addMReg(PtrReg).addSImm(Offset);
+    if (useImmediateOffset)
+      MI = BuildMI(V9::STXFSRi,3).addMReg(SparcV9::fsr).addMReg(PtrReg)
+             .addSImm(Offset);
     else
-      MI=BuildMI(V9::STXFSRr,3).addMReg(fsrReg).addMReg(PtrReg).addMReg(OffReg);
+      MI = BuildMI(V9::STXFSRr,3).addMReg(SparcV9::fsr).addMReg(PtrReg)
+             .addMReg(OffReg);
     break;
   }
   default:
@@ -824,45 +826,42 @@ SparcRegInfo::cpReg2MemMI(std::vector<MachineInstr*>& mvec,
   mvec.push_back(MI);
 }
 
+/// cpMem2RegMI - Generate SparcV9 MachineInstrs to load a register
+/// (DestReg) from memory, at [PtrReg + Offset].  Register numbers must be the
+/// unified register numbers.  RegType must be the SparcV9 register type
+/// of DestReg. When DestReg is %ccr, scratchReg must be the
+/// number of a free integer register.  The newly-generated MachineInstrs
+/// are appended to mvec.
+///
+void SparcV9RegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
+                                 unsigned PtrReg, int Offset, unsigned DestReg,
+                                 int RegType, int scratchReg) const {
+  unsigned OffReg = SparcV9::g4; // Use register g4 for holding large offsets
+  bool useImmediateOffset = true;
+
+  // If the Offset will not fit in the signed-immediate field, we put it in
+  // register g4. This takes advantage of the fact that all the opcodes
+  // used below have the same size immed. field.
+  if (RegType != IntCCRegType
+      && !target.getInstrInfo()->constantFitsInImmedField(V9::LDXi, Offset)) {
+    MachineInstr *MI = BuildMI(V9::SETHI, 2).addZImm(Offset).addMReg(OffReg,
+      MachineOperand::Def);
+    MI->getOperand(0).markHi32();
+    mvec.push_back(MI);
+    MI = BuildMI(V9::ORi,3).addMReg(OffReg).addZImm(Offset).addMReg(OffReg,
+      MachineOperand::Def);
+    MI->getOperand(1).markLo32();
+    mvec.push_back(MI);
+    MI = BuildMI(V9::SRAi5,3).addMReg(OffReg).addZImm(0).addMReg(OffReg,
+      MachineOperand::Def);
+    mvec.push_back(MI);
+    useImmediateOffset = false;
+  }
 
-//---------------------------------------------------------------------------
-// Copy from memory to a reg (i.e., Load) Register number must be the unified
-// register number
-//---------------------------------------------------------------------------
-
-
-void
-SparcRegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
-                               unsigned PtrReg,        
-                               int Offset,
-                               unsigned DestReg,
-                               int RegType,
-                               int scratchReg) const {
-  MachineInstr * MI = NULL;
-  int OffReg = -1;
-
-  // If the Offset will not fit in the signed-immediate field, find an
-  // unused register to hold the offset value.  This takes advantage of
-  // the fact that all the opcodes used below have the same size immed. field.
-  // Use the register allocator, PRA, to find an unused reg. at this MI.
-  // 
-  if (RegType != IntCCRegType)          // does not use offset below
-    if (! target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset)) {
-#ifdef CAN_FIND_FREE_REGISTER_TRANSPARENTLY
-      RegClass* RC = PRA.getRegClassByID(this->getRegClassIDOfRegType(RegType));
-      OffReg = PRA.getUnusedUniRegAtMI(RC, RegType, MInst, LVSetBef);
-#else
-      // Default to using register g4 for holding large offsets
-      OffReg = getUnifiedRegNum(SparcRegInfo::IntRegClassID,
-                                SparcIntRegClass::g4);
-#endif
-      assert(OffReg >= 0 && "FIXME: cpReg2MemMI cannot find an unused reg.");
-      mvec.push_back(BuildMI(V9::SETSW, 2).addZImm(Offset).addReg(OffReg));
-    }
-
+  MachineInstr *MI = 0;
   switch (RegType) {
   case IntRegType:
-    if (target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset))
+    if (useImmediateOffset)
       MI = BuildMI(V9::LDXi, 3).addMReg(PtrReg).addSImm(Offset)
           .addMReg(DestReg, MachineOperand::Def);
     else
@@ -871,7 +870,7 @@ SparcRegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
     break;
 
   case FPSingleRegType:
-    if (target.getInstrInfo().constantFitsInImmedField(V9::LDFi, Offset))
+    if (useImmediateOffset)
       MI = BuildMI(V9::LDFi, 3).addMReg(PtrReg).addSImm(Offset)
           .addMReg(DestReg, MachineOperand::Def);
     else
@@ -880,7 +879,7 @@ SparcRegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
     break;
 
   case FPDoubleRegType:
-    if (target.getInstrInfo().constantFitsInImmedField(V9::LDDFi, Offset))
+    if (useImmediateOffset)
       MI= BuildMI(V9::LDDFi, 3).addMReg(PtrReg).addSImm(Offset)
           .addMReg(DestReg, MachineOperand::Def);
     else
@@ -889,25 +888,21 @@ SparcRegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
     break;
 
   case IntCCRegType:
-    assert(scratchReg >= 0 && "Need scratch reg to load %ccr from memory");
-    assert(getRegType(scratchReg) ==IntRegType && "Invalid scratch reg");
+    assert(scratchReg >= 0 && getRegType(scratchReg) == IntRegType
+           && "Need a scratch reg of integer type to load or store %ccr");
     cpMem2RegMI(mvec, PtrReg, Offset, scratchReg, IntRegType);
-    MI = (BuildMI(V9::WRCCRr, 3)
-          .addMReg(scratchReg)
-          .addMReg(SparcIntRegClass::g0)
-          .addMReg(getUnifiedRegNum(SparcRegInfo::IntCCRegClassID,
-                                    SparcIntCCRegClass::ccr), MachineOperand::Def));
+    MI = BuildMI(V9::WRCCRr, 3).addMReg(scratchReg).addMReg(SparcV9::g0)
+           .addMReg(SparcV9::ccr, MachineOperand::Def);
     break;
     
+  case SpecialRegType: // used only for %fsr itself
   case FloatCCRegType: {
-    unsigned fsrRegNum =  getUnifiedRegNum(SparcRegInfo::SpecialRegClassID,
-                                           SparcSpecialRegClass::fsr);
-    if (target.getInstrInfo().constantFitsInImmedField(V9::LDXFSRi, Offset))
+    if (useImmediateOffset)
       MI = BuildMI(V9::LDXFSRi, 3).addMReg(PtrReg).addSImm(Offset)
-        .addMReg(fsrRegNum, MachineOperand::UseAndDef);
+        .addMReg(SparcV9::fsr, MachineOperand::Def);
     else
       MI = BuildMI(V9::LDXFSRr, 3).addMReg(PtrReg).addMReg(OffReg)
-        .addMReg(fsrRegNum, MachineOperand::UseAndDef);
+        .addMReg(SparcV9::fsr, MachineOperand::Def);
     break;
   }
   default:
@@ -924,12 +919,12 @@ SparcRegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
 
 
 void
-SparcRegInfo::cpValue2Value(Value *Src, Value *Dest,
-                                 std::vector<MachineInstr*>& mvec) const {
+SparcV9RegInfo::cpValue2Value(Value *Src, Value *Dest,
+                              std::vector<MachineInstr*>& mvec) const {
   int RegType = getRegTypeForDataType(Src->getType());
   MachineInstr * MI = NULL;
 
-  switch( RegType ) {
+  switch (RegType) {
   case IntRegType:
     MI = BuildMI(V9::ADDr, 3).addReg(Src).addMReg(getZeroRegNum())
       .addRegDef(Dest);
@@ -941,7 +936,7 @@ SparcRegInfo::cpValue2Value(Value *Src, Value *Dest,
     MI = BuildMI(V9::FMOVD, 2).addReg(Src).addRegDef(Dest);
     break;
   default:
-    assert(0 && "Unknow RegType in CpValu2Value");
+    assert(0 && "Unknown RegType in cpValue2Value");
   }
 
   mvec.push_back(MI);
@@ -953,7 +948,7 @@ SparcRegInfo::cpValue2Value(Value *Src, Value *Dest,
 // Print the register assigned to a LR
 //---------------------------------------------------------------------------
 
-void SparcRegInfo::printReg(const LiveRange *LR) const {
+void SparcV9RegInfo::printReg(const LiveRange *LR) const {
   unsigned RegClassID = LR->getRegClassID();
   std::cerr << " Node ";