[llvm-commits] [llvm] r45527 - in /llvm/trunk: include/llvm/CodeGen/MachineRelocation.h lib/ExecutionEngine/JIT/JITEmitter.cpp lib/Target/Alpha/AlphaCodeEmitter.cpp lib/Target/PowerPC/PPCCodeEmitter.cpp lib/Target/X86/X86CodeEmitter.cpp

Evan Cheng evan.cheng at apple.com
Wed Jan 2 18:56:28 PST 2008


Author: evancheng
Date: Wed Jan  2 20:56:28 2008
New Revision: 45527

URL: http://llvm.org/viewvc/llvm-project?rev=45527&view=rev
Log:
Change MachineRelocation::DoesntNeedFnStub to NeedStub. This fields will be used
for non-function GV relocations that require function address stubs (e.g. Mac OS X in non-static mode).

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineRelocation.h
    llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
    llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp
    llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp
    llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineRelocation.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineRelocation.h?rev=45527&r1=45526&r2=45527&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineRelocation.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineRelocation.h Wed Jan  2 20:56:28 2008
@@ -64,7 +64,7 @@
 
   unsigned TargetReloType : 6; // The target relocation ID.
   AddressType AddrType    : 4; // The field of Target to use.
-  bool DoesntNeedFnStub   : 1; // True if we don't need a fn stub.
+  bool NeedStub           : 1; // True if this relocation requires a stub.
   bool GOTRelative        : 1; // Should this relocation be relative to the GOT?
 
 public:
@@ -79,7 +79,7 @@
   ///
   static MachineRelocation getGV(intptr_t offset, unsigned RelocationType, 
                                  GlobalValue *GV, intptr_t cst = 0,
-                                 bool DoesntNeedFunctionStub = 0,
+                                 bool NeedStub = 0,
                                  bool GOTrelative = 0) {
     assert((RelocationType & ~63) == 0 && "Relocation type too large!");
     MachineRelocation Result;
@@ -87,7 +87,7 @@
     Result.ConstantVal = cst;
     Result.TargetReloType = RelocationType;
     Result.AddrType = isGV;
-    Result.DoesntNeedFnStub = DoesntNeedFunctionStub;
+    Result.NeedStub = NeedStub;
     Result.GOTRelative = GOTrelative;
     Result.Target.GV = GV;
     return Result;
@@ -103,7 +103,7 @@
     Result.ConstantVal = cst;
     Result.TargetReloType = RelocationType;
     Result.AddrType = isBB;
-    Result.DoesntNeedFnStub = false;
+    Result.NeedStub = false;
     Result.GOTRelative = false;
     Result.Target.MBB = MBB;
     return Result;
@@ -121,7 +121,7 @@
     Result.ConstantVal = cst;
     Result.TargetReloType = RelocationType;
     Result.AddrType = isExtSym;
-    Result.DoesntNeedFnStub = false;
+    Result.NeedStub = false;
     Result.GOTRelative = GOTrelative;
     Result.Target.ExtSym = ES;
     return Result;
@@ -138,7 +138,7 @@
     Result.ConstantVal = cst;
     Result.TargetReloType = RelocationType;
     Result.AddrType = isConstPool;
-    Result.DoesntNeedFnStub = false;
+    Result.NeedStub = false;
     Result.GOTRelative = false;
     Result.Target.Index = CPI;
     return Result;
@@ -155,7 +155,7 @@
     Result.ConstantVal = cst;
     Result.TargetReloType = RelocationType;
     Result.AddrType = isJumpTable;
-    Result.DoesntNeedFnStub = false;
+    Result.NeedStub = false;
     Result.GOTRelative = false;
     Result.Target.Index = JTI;
     return Result;
@@ -223,13 +223,12 @@
     return GOTRelative;
   }
 
-  /// doesntNeedFunctionStub - This function returns true if the JIT for this
-  /// target is capable of directly handling the relocated instruction without
-  /// using a stub function.  It is always conservatively correct for this flag
-  /// to be false, but targets can improve their compilation callback functions
-  /// to handle more general cases if they want improved performance.
-  bool doesntNeedFunctionStub() const {
-    return DoesntNeedFnStub;
+  /// doesntNeedStub - This function returns true if the JIT for this target
+  /// target is capable of directly handling the relocated GlobalValue reference
+  /// without using either a stub function or issuing an extra load to get the
+  /// GV address.
+  bool doesntNeedStub() const {
+    return !NeedStub;
   }
 
   /// getGlobalValue - If this is a global value reference, return the

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=45527&r1=45526&r2=45527&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Wed Jan  2 20:56:28 2008
@@ -444,12 +444,12 @@
         ResultPtr = TheJIT->getPointerToNamedFunction(MR.getString());
 
         // If the target REALLY wants a stub for this function, emit it now.
-        if (!MR.doesntNeedFunctionStub())
+        if (!MR.doesntNeedStub())
           ResultPtr = Resolver.getExternalFunctionStub(ResultPtr);
       } else if (MR.isGlobalValue()) {
         ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
                                        BufferBegin+MR.getMachineCodeOffset(),
-                                       MR.doesntNeedFunctionStub());
+                                       MR.doesntNeedStub());
       } else if (MR.isBasicBlock()) {
         ResultPtr = (void*)getMachineBasicBlockAddress(MR.getBasicBlock());
       } else if (MR.isConstantPoolIndex()) {

Modified: llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp?rev=45527&r1=45526&r2=45527&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/Alpha/AlphaCodeEmitter.cpp Wed Jan  2 20:56:28 2008
@@ -196,7 +196,8 @@
     if (MO.isGlobalAddress())
       MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(),
                                                  Reloc, MO.getGlobal(), Offset,
-                                                 false, useGOT));
+                                                 isa<Function>(MO.getGlobal()),
+                                                 useGOT));
     else if (MO.isExternalSymbol())
       MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
                                                      Reloc, MO.getSymbolName(),

Modified: llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp?rev=45527&r1=45526&r2=45527&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCCodeEmitter.cpp Wed Jan  2 20:56:28 2008
@@ -189,7 +189,8 @@
     MachineRelocation R;
     if (MO.isGlobalAddress()) {
       R = MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
-                                   MO.getGlobal(), 0);
+                                   MO.getGlobal(),
+                                   isa<Function>(MO.getGlobal()), 0);
     } else if (MO.isExternalSymbol()) {
       R = MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
                                        Reloc, MO.getSymbolName(), 0);

Modified: llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp?rev=45527&r1=45526&r2=45527&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp Wed Jan  2 20:56:28 2008
@@ -40,17 +40,20 @@
     intptr_t PICBase;
     bool Is64BitMode;
     bool IsPIC;
+    bool IsStatic;
   public:
     static char ID;
     explicit Emitter(TargetMachine &tm, MachineCodeEmitter &mce)
       : MachineFunctionPass((intptr_t)&ID), II(0), TD(0), TM(tm), 
       MCE(mce), PICBase(0), Is64BitMode(false),
-      IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
+      IsPIC(TM.getRelocationModel() == Reloc::PIC_),
+      IsStatic(TM.getRelocationModel() == Reloc::Static) {}
     Emitter(TargetMachine &tm, MachineCodeEmitter &mce,
             const X86InstrInfo &ii, const TargetData &td, bool is64)
       : MachineFunctionPass((intptr_t)&ID), II(&ii), TD(&td), TM(tm), 
       MCE(mce), PICBase(0), Is64BitMode(is64),
-      IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
+      IsPIC(TM.getRelocationModel() == Reloc::PIC_),
+      IsStatic(TM.getRelocationModel() == Reloc::Static) {}
 
     bool runOnMachineFunction(MachineFunction &MF);
 
@@ -64,13 +67,12 @@
     void emitPCRelativeBlockAddress(MachineBasicBlock *MBB);
     void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
                            int Disp = 0, intptr_t PCAdj = 0,
-                           bool DoesntNeedStub = false, bool isPIC = false);
-    void emitExternalSymbolAddress(const char *ES, unsigned Reloc,
-                                   bool isPIC = false);
+                           bool NeedStub = false);
+    void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
     void emitConstPoolAddress(unsigned CPI, unsigned Reloc, int Disp = 0,
-                              intptr_t PCAdj = 0, bool isPIC = false);
+                              intptr_t PCAdj = 0);
     void emitJumpTableAddress(unsigned JTI, unsigned Reloc,
-                              intptr_t PCAdj = 0, bool isPIC = false);
+                              intptr_t PCAdj = 0);
 
     void emitDisplacementField(const MachineOperand *RelocOp, int DispVal,
                                intptr_t PCAdj = 0);
@@ -137,12 +139,11 @@
 ///
 void Emitter::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
                                 int Disp /* = 0 */, intptr_t PCAdj /* = 0 */,
-                                bool DoesntNeedStub /* = false */,
-                                bool isPIC /* = false */) {
-  if (isPIC)
+                                bool NeedStub /* = false */) {
+  if (Reloc == X86::reloc_picrel_word)
     PCAdj += PICBase;
   MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
-                                             GV, PCAdj, DoesntNeedStub));
+                                             GV, PCAdj, NeedStub));
   if (Reloc == X86::reloc_absolute_dword)
     MCE.emitWordLE(0);
   MCE.emitWordLE(Disp); // The relocated value will be added to the displacement
@@ -151,9 +152,8 @@
 /// emitExternalSymbolAddress - Arrange for the address of an external symbol to
 /// be emitted to the current location in the function, and allow it to be PC
 /// relative.
-void Emitter::emitExternalSymbolAddress(const char *ES, unsigned Reloc,
-                                        bool isPIC /* = false */) {
-  intptr_t PCAdj = isPIC ? PICBase : 0;
+void Emitter::emitExternalSymbolAddress(const char *ES, unsigned Reloc) {
+  intptr_t PCAdj = (Reloc == X86::reloc_picrel_word) ? PICBase : 0;
   MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
                                                  Reloc, ES, PCAdj));
   if (Reloc == X86::reloc_absolute_dword)
@@ -166,9 +166,8 @@
 /// relative.
 void Emitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc,
                                    int Disp /* = 0 */,
-                                   intptr_t PCAdj /* = 0 */,
-                                   bool isPIC /* = false */) {
-  if (isPIC)
+                                   intptr_t PCAdj /* = 0 */) {
+  if (Reloc == X86::reloc_picrel_word)
     PCAdj += PICBase;
   MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
                                                     Reloc, CPI, PCAdj));
@@ -181,9 +180,8 @@
 /// be emitted to the current location in the function, and allow it to be PC
 /// relative.
 void Emitter::emitJumpTableAddress(unsigned JTI, unsigned Reloc,
-                                   intptr_t PCAdj /* = 0 */,
-                                   bool isPIC /* = false */) {
-  if (isPIC)
+                                   intptr_t PCAdj /* = 0 */) {
+  if (Reloc == X86::reloc_picrel_word)
     PCAdj += PICBase;
   MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
                                                     Reloc, JTI, PCAdj));
@@ -241,17 +239,18 @@
     // But it's probably not beneficial.
     //  89 05 00 00 00 00    	mov    %eax,0(%rip)  # PC-relative
     //	89 04 25 00 00 00 00 	mov    %eax,0x0      # Absolute
-    unsigned rt= Is64BitMode ? X86::reloc_pcrel_word
+    unsigned rt = Is64BitMode ? X86::reloc_pcrel_word
       : (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
+    bool NeedStub = !IsStatic || isa<Function>(RelocOp->getGlobal());
     emitGlobalAddress(RelocOp->getGlobal(), rt, RelocOp->getOffset(),
-                      PCAdj, false, IsPIC);
+                      PCAdj, NeedStub);
   } else if (RelocOp->isConstantPoolIndex()) {
     unsigned rt = Is64BitMode ? X86::reloc_pcrel_word : X86::reloc_picrel_word;
     emitConstPoolAddress(RelocOp->getIndex(), rt,
-                         RelocOp->getOffset(), PCAdj, IsPIC);
+                         RelocOp->getOffset(), PCAdj);
   } else if (RelocOp->isJumpTableIndex()) {
     unsigned rt = Is64BitMode ? X86::reloc_pcrel_word : X86::reloc_picrel_word;
-    emitJumpTableAddress(RelocOp->getIndex(), rt, PCAdj, IsPIC);
+    emitJumpTableAddress(RelocOp->getIndex(), rt, PCAdj);
   } else {
     assert(0 && "Unknown value to relocate!");
   }
@@ -602,14 +601,12 @@
       if (MO.isMachineBasicBlock()) {
         emitPCRelativeBlockAddress(MO.getMBB());
       } else if (MO.isGlobalAddress()) {
-        bool NeedStub = Is64BitMode ||
-                        Opcode == X86::TAILJMPd ||
-                        Opcode == X86::TAILJMPr || Opcode == X86::TAILJMPm;
+        bool NeedStub = !IsStatic ||
+          (Is64BitMode && TM.getCodeModel() == CodeModel::Large);
         emitGlobalAddress(MO.getGlobal(), X86::reloc_pcrel_word,
-                          0, 0, !NeedStub, false);
+                          0, 0, NeedStub);
       } else if (MO.isExternalSymbol()) {
-        emitExternalSymbolAddress(MO.getSymbolName(),
-                                  X86::reloc_pcrel_word, false);
+        emitExternalSymbolAddress(MO.getSymbolName(), X86::reloc_pcrel_word);
       } else if (MO.isImmediate()) {
         emitConstant(MO.getImm(), sizeOfImm(Desc));
       } else {
@@ -636,14 +633,15 @@
           : (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
         if (Opcode == X86::MOV64ri)
           rt = X86::reloc_absolute_dword;  // FIXME: add X86II flag?
-        if (MO1.isGlobalAddress())
-          emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), false, IsPIC);
-        else if (MO1.isExternalSymbol())
-          emitExternalSymbolAddress(MO1.getSymbolName(), rt, IsPIC);
+        if (MO1.isGlobalAddress()) {
+          bool NeedStub = !IsStatic || isa<Function>(MO1.getGlobal());
+          emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), 0, NeedStub);
+        } else if (MO1.isExternalSymbol())
+          emitExternalSymbolAddress(MO1.getSymbolName(), rt);
         else if (MO1.isConstantPoolIndex())
-          emitConstPoolAddress(MO1.getIndex(), rt, IsPIC);
+          emitConstPoolAddress(MO1.getIndex(), rt);
         else if (MO1.isJumpTableIndex())
-          emitJumpTableAddress(MO1.getIndex(), rt, IsPIC);
+          emitJumpTableAddress(MO1.getIndex(), rt);
       }
     }
     break;
@@ -705,14 +703,15 @@
           : (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
         if (Opcode == X86::MOV64ri32)
           rt = X86::reloc_absolute_word;  // FIXME: add X86II flag?
-        if (MO1.isGlobalAddress())
-          emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), false, IsPIC);
-        else if (MO1.isExternalSymbol())
-          emitExternalSymbolAddress(MO1.getSymbolName(), rt, IsPIC);
+        if (MO1.isGlobalAddress()) {
+          bool NeedStub = !IsStatic || isa<Function>(MO1.getGlobal());
+          emitGlobalAddress(MO1.getGlobal(), rt, MO1.getOffset(), 0, NeedStub);
+        } else if (MO1.isExternalSymbol())
+          emitExternalSymbolAddress(MO1.getSymbolName(), rt);
         else if (MO1.isConstantPoolIndex())
-          emitConstPoolAddress(MO1.getIndex(), rt, IsPIC);
+          emitConstPoolAddress(MO1.getIndex(), rt);
         else if (MO1.isJumpTableIndex())
-          emitJumpTableAddress(MO1.getIndex(), rt, IsPIC);
+          emitJumpTableAddress(MO1.getIndex(), rt);
       }
     }
     break;
@@ -739,14 +738,15 @@
           : (IsPIC ? X86::reloc_picrel_word : X86::reloc_absolute_word);
         if (Opcode == X86::MOV64mi32)
           rt = X86::reloc_absolute_word;  // FIXME: add X86II flag?
-        if (MO.isGlobalAddress())
-          emitGlobalAddress(MO.getGlobal(), rt, MO.getOffset(), false, IsPIC);
-        else if (MO.isExternalSymbol())
-          emitExternalSymbolAddress(MO.getSymbolName(), rt, IsPIC);
+        if (MO.isGlobalAddress()) {
+          bool NeedStub = !IsStatic || isa<Function>(MO.getGlobal());
+          emitGlobalAddress(MO.getGlobal(), rt, MO.getOffset(), 0, NeedStub);
+        } else if (MO.isExternalSymbol())
+          emitExternalSymbolAddress(MO.getSymbolName(), rt);
         else if (MO.isConstantPoolIndex())
-          emitConstPoolAddress(MO.getIndex(), rt, IsPIC);
+          emitConstPoolAddress(MO.getIndex(), rt);
         else if (MO.isJumpTableIndex())
-          emitJumpTableAddress(MO.getIndex(), rt, IsPIC);
+          emitJumpTableAddress(MO.getIndex(), rt);
       }
     }
     break;





More information about the llvm-commits mailing list