[llvm-commits] CVS: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp X86CodeEmitter.cpp X86ISelLowering.cpp X86IntelAsmPrinter.cpp X86TargetMachine.cpp

Evan Cheng evan.cheng at apple.com
Wed Feb 22 12:19:55 PST 2006



Changes in directory llvm/lib/Target/X86:

X86ATTAsmPrinter.cpp updated: 1.23 -> 1.24
X86CodeEmitter.cpp updated: 1.90 -> 1.91
X86ISelLowering.cpp updated: 1.93 -> 1.94
X86IntelAsmPrinter.cpp updated: 1.17 -> 1.18
X86TargetMachine.cpp updated: 1.104 -> 1.105
---
Log message:

- Added option -relocation-model to set relocation model. Valid values include static, pic,
dynamic-no-pic, and default.
PPC and x86 default is dynamic-no-pic for Darwin, pic for others.
- Removed options -enable-pic and -ppc-static.


---
Diffs of the changes:  (+29 -20)

 X86ATTAsmPrinter.cpp   |   14 +++++++-------
 X86CodeEmitter.cpp     |    4 +++-
 X86ISelLowering.cpp    |    9 +++++----
 X86IntelAsmPrinter.cpp |   13 +++++++------
 X86TargetMachine.cpp   |    9 +++++++--
 5 files changed, 29 insertions(+), 20 deletions(-)


Index: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.23 llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.24
--- llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.23	Fri Feb 17 18:15:05 2006
+++ llvm/lib/Target/X86/X86ATTAsmPrinter.cpp	Wed Feb 22 14:19:42 2006
@@ -119,7 +119,7 @@
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp && !isCallOp) O << '$';
     // Darwin block shameless ripped from PPCAsmPrinter.cpp
-    if (forDarwin) {
+    if (forDarwin && TM.getRelocationModel() != Reloc::Static) {
       GlobalValue *GV = MO.getGlobal();
       std::string Name = Mang->getValueName(GV);
       // Link-once, External, or Weakly-linked global variables need
@@ -133,7 +133,7 @@
         } else {
           GVStubs.insert(Name);
           O << "L" << Name << "$non_lazy_ptr";
-          if (PICEnabled)
+          if (TM.getRelocationModel() == Reloc::PIC)
             O << "-\"L" << getFunctionNumber() << "$pb\"";
         }
       } else {
@@ -150,14 +150,14 @@
   }
   case MachineOperand::MO_ExternalSymbol: {
     bool isCallOp = Modifier && !strcmp(Modifier, "call");
-    bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
-    if (isCallOp && forDarwin) {
-      std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+    if (isCallOp && forDarwin && TM.getRelocationModel() != Reloc::Static) {
+      std::string Name(GlobalPrefix);
+      Name += MO.getSymbolName();
       FnStubs.insert(Name);
       O << "L" << Name << "$stub";
       return;
     }
-    if (!isMemOp && !isCallOp) O << '$';
+    if (!isCallOp) O << '$';
     O << GlobalPrefix << MO.getSymbolName();
     return;
   }
@@ -198,7 +198,7 @@
   } else if (BaseReg.isConstantPoolIndex()) {
     O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
       << BaseReg.getConstantPoolIndex();
-    if (forDarwin && PICEnabled)
+    if (forDarwin && TM.getRelocationModel() == Reloc::PIC)
       O << "-\"L" << getFunctionNumber() << "$pb\"";
     if (DispSpec.getImmedValue())
       O << "+" << DispSpec.getImmedValue();


Index: llvm/lib/Target/X86/X86CodeEmitter.cpp
diff -u llvm/lib/Target/X86/X86CodeEmitter.cpp:1.90 llvm/lib/Target/X86/X86CodeEmitter.cpp:1.91
--- llvm/lib/Target/X86/X86CodeEmitter.cpp:1.90	Fri Feb 17 18:57:10 2006
+++ llvm/lib/Target/X86/X86CodeEmitter.cpp	Wed Feb 22 14:19:42 2006
@@ -77,6 +77,9 @@
 }
 
 bool Emitter::runOnMachineFunction(MachineFunction &MF) {
+  assert((MF.getTarget().getRelocationModel() != Reloc::Default ||
+          MF.getTarget().getRelocationModel() != Reloc::Static) &&
+         "JIT relocation model must be set to static or default!");
   II = ((X86TargetMachine&)MF.getTarget()).getInstrInfo();
 
   MCE.startFunction(MF);
@@ -97,7 +100,6 @@
 }
 
 void Emitter::emitBasicBlock(const MachineBasicBlock &MBB) {
-  assert(!PICEnabled && "CodeEmitter does not support PIC!");
   if (uint64_t Addr = MCE.getCurrentPCValue())
     BasicBlockAddrs[&MBB] = Addr;
 


Index: llvm/lib/Target/X86/X86ISelLowering.cpp
diff -u llvm/lib/Target/X86/X86ISelLowering.cpp:1.93 llvm/lib/Target/X86/X86ISelLowering.cpp:1.94
--- llvm/lib/Target/X86/X86ISelLowering.cpp:1.93	Tue Feb 21 20:26:30 2006
+++ llvm/lib/Target/X86/X86ISelLowering.cpp	Wed Feb 22 14:19:42 2006
@@ -1836,7 +1836,7 @@
     if (getTargetMachine().
         getSubtarget<X86Subtarget>().isTargetDarwin()) {
       // With PIC, the address is actually $g + Offset.
-      if (PICEnabled)
+      if (getTargetMachine().getRelocationModel() == Reloc::PIC)
         Result = DAG.getNode(ISD::ADD, getPointerTy(),
                 DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result);    
     }
@@ -1851,7 +1851,7 @@
       GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
       SDOperand Addr = DAG.getTargetGlobalAddress(GV, getPointerTy());
       // With PIC, the address is actually $g + Offset.
-      if (PICEnabled)
+      if (getTargetMachine().getRelocationModel() == Reloc::PIC)
         Addr = DAG.getNode(ISD::ADD, getPointerTy(),
                       DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Addr);
 
@@ -1859,8 +1859,9 @@
       // the value at address GV, not the value of GV itself.  This means that
       // the GlobalAddress must be in the base or index register of the address,
       // not the GV offset field.
-      if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
-          (GV->isExternal() && !GV->hasNotBeenReadFromBytecode()))
+      if (getTargetMachine().getRelocationModel() != Reloc::Static &&
+          (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
+           (GV->isExternal() && !GV->hasNotBeenReadFromBytecode())))
         Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(),
                              Addr, DAG.getSrcValue(NULL));
     }


Index: llvm/lib/Target/X86/X86IntelAsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86IntelAsmPrinter.cpp:1.17 llvm/lib/Target/X86/X86IntelAsmPrinter.cpp:1.18
--- llvm/lib/Target/X86/X86IntelAsmPrinter.cpp:1.17	Fri Feb 17 18:15:05 2006
+++ llvm/lib/Target/X86/X86IntelAsmPrinter.cpp	Wed Feb 22 14:19:42 2006
@@ -113,7 +113,7 @@
     bool isCallOp = Modifier && !strcmp(Modifier, "call");
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp && !isCallOp) O << "OFFSET ";
-    if (forDarwin) {
+    if (forDarwin && TM.getRelocationModel() != Reloc::Static) {
       GlobalValue *GV = MO.getGlobal();
       std::string Name = Mang->getValueName(GV);
       if (!isMemOp && !isCallOp) O << '$';
@@ -128,7 +128,7 @@
         } else {
           GVStubs.insert(Name);
           O << "L" << Name << "$non_lazy_ptr";
-          if (PICEnabled)
+          if (TM.getRelocationModel() == Reloc::PIC)
             O << "-\"L" << getFunctionNumber() << "$pb\"";
         }
       } else {
@@ -145,13 +145,14 @@
   }
   case MachineOperand::MO_ExternalSymbol: {
     bool isCallOp = Modifier && !strcmp(Modifier, "call");
-    bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
-    if (isCallOp && forDarwin) {
-      std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+    if (isCallOp && forDarwin && TM.getRelocationModel() != Reloc::Static) {
+      std::string Name(GlobalPrefix);
+      Name += MO.getSymbolName();
       FnStubs.insert(Name);
       O << "L" << Name << "$stub";
       return;
     }
+    if (!isCallOp) O << "OFFSET ";
     O << GlobalPrefix << MO.getSymbolName();
     return;
   }
@@ -177,7 +178,7 @@
   } else if (BaseReg.isConstantPoolIndex()) {
     O << "[" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
       << BaseReg.getConstantPoolIndex();
-    if (forDarwin && PICEnabled)
+    if (forDarwin && TM.getRelocationModel() == Reloc::PIC)
       O << "-\"L" << getFunctionNumber() << "$pb\"";
 
     if (IndexReg.getReg()) {


Index: llvm/lib/Target/X86/X86TargetMachine.cpp
diff -u llvm/lib/Target/X86/X86TargetMachine.cpp:1.104 llvm/lib/Target/X86/X86TargetMachine.cpp:1.105
--- llvm/lib/Target/X86/X86TargetMachine.cpp:1.104	Fri Feb 17 19:49:25 2006
+++ llvm/lib/Target/X86/X86TargetMachine.cpp	Wed Feb 22 14:19:42 2006
@@ -76,6 +76,11 @@
     FrameInfo(TargetFrameInfo::StackGrowsDown,
               Subtarget.getStackAlignment(), -4),
     JITInfo(*this) {
+  if (getRelocationModel() == Reloc::Default)
+    if (Subtarget.isTargetDarwin())
+      setRelocationModel(Reloc::DynamicNoPIC);
+    else
+      setRelocationModel(Reloc::PIC);
 }
 
 
@@ -149,8 +154,8 @@
 /// not supported for this target.
 ///
 void X86JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
-  // The JIT does not support or need PIC.
-  PICEnabled = false;
+  // The JIT should use static relocation model.
+  TM.setRelocationModel(Reloc::Static);
 
   // FIXME: Implement efficient support for garbage collection intrinsics.
   PM.add(createLowerGCPass());






More information about the llvm-commits mailing list