Eliminate object-relinking support from CMake. Fixes PR 4429 and
[oota-llvm.git] / lib / Target / Mips / MipsISelDAGToDAG.cpp
index e1efaa7dc8a708950f603981c4f2fd0275db530c..53de1bbea66e42204aa91f5b675c051e6d22f285 100644 (file)
@@ -70,7 +70,19 @@ private:
   // Include the pieces autogenerated from the target description.
   #include "MipsGenDAGISel.inc"
 
-  SDValue getGlobalBaseReg();
+  /// getTargetMachine - Return a reference to the TargetMachine, casted
+  /// to the target-specific type.
+  const MipsTargetMachine &getTargetMachine() {
+    return static_cast<const MipsTargetMachine &>(TM);
+  }
+
+  /// getInstrInfo - Return a reference to the TargetInstrInfo, casted
+  /// to the target-specific type.
+  const MipsInstrInfo *getInstrInfo() {
+    return getTargetMachine().getInstrInfo();
+  }
+
+  SDNode *getGlobalBaseReg();
   SDNode *Select(SDValue N);
 
   // Complex Pattern.
@@ -116,19 +128,10 @@ InstructionSelect()
 
 /// getGlobalBaseReg - Output the instructions required to put the
 /// GOT address into a register.
-SDValue MipsDAGToDAGISel::getGlobalBaseReg() {
-  MachineFunction* MF = BB->getParent();
-  unsigned GP = 0;
-  for(MachineRegisterInfo::livein_iterator ii = MF->getRegInfo().livein_begin(),
-        ee = MF->getRegInfo().livein_end(); ii != ee; ++ii)
-    if (ii->first == Mips::GP) {
-      GP = ii->second;
-      break;
-    }
-  assert(GP && "GOT PTR not in liveins");
-  // FIXME is there a sensible place to get debug info for this?
-  return CurDAG->getCopyFromReg(CurDAG->getEntryNode(), 
-                                DebugLoc::getUnknownLoc(), GP, MVT::i32);
+SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
+  MachineFunction *MF = BB->getParent();
+  unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
+  return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
 }
 
 /// ComplexPattern used on MipsInstrInfo
@@ -244,7 +247,7 @@ Select(SDValue N)
       SDNode *AddCarry = CurDAG->getTargetNode(Mips::ADDu, dl, VT, 
                                                SDValue(Carry,0), RHS);
 
-      return CurDAG->SelectNodeTo(N.getNode(), MOp, VT, MVT::Flag, 
+      return CurDAG->SelectNodeTo(N.getNode(), MOp, VT, MVT::Flag,
                                   LHS, SDValue(AddCarry,0));
     }
 
@@ -321,11 +324,8 @@ Select(SDValue N)
     }
 
     // Get target GOT address.
-    case ISD::GLOBAL_OFFSET_TABLE: {
-      SDValue Result = getGlobalBaseReg();
-      ReplaceUses(N, Result);
-      return NULL;
-    }
+    case ISD::GLOBAL_OFFSET_TABLE:
+      return getGlobalBaseReg();
 
     /// Handle direct and indirect calls when using PIC. On PIC, when 
     /// GOT is smaller than about 64k (small code) the GA target is