[llvm-commits] CVS: llvm/lib/Target/X86/X86ISelLowering.cpp X86Subtarget.cpp X86Subtarget.h X86TargetMachine.cpp

Anton Korobeynikov asl at math.spbu.ru
Fri Dec 22 14:29:20 PST 2006



Changes in directory llvm/lib/Target/X86:

X86ISelLowering.cpp updated: 1.306 -> 1.307
X86Subtarget.cpp updated: 1.45 -> 1.46
X86Subtarget.h updated: 1.23 -> 1.24
X86TargetMachine.cpp updated: 1.132 -> 1.133
---
Log message:

Refactored JIT codegen for mingw32. Now we're using standart relocation 
type for distinguish JIT & non-JIT instead of "dirty" hacks :)


---
Diffs of the changes:  (+32 -44)

 X86ISelLowering.cpp  |   46 +++++++++++++++++++++++++---------------------
 X86Subtarget.cpp     |   15 +++------------
 X86Subtarget.h       |   10 +++-------
 X86TargetMachine.cpp |    5 +----
 4 files changed, 32 insertions(+), 44 deletions(-)


Index: llvm/lib/Target/X86/X86ISelLowering.cpp
diff -u llvm/lib/Target/X86/X86ISelLowering.cpp:1.306 llvm/lib/Target/X86/X86ISelLowering.cpp:1.307
--- llvm/lib/Target/X86/X86ISelLowering.cpp:1.306	Thu Dec 14 15:55:39 2006
+++ llvm/lib/Target/X86/X86ISelLowering.cpp	Fri Dec 22 16:29:05 2006
@@ -664,8 +664,10 @@
   // If the callee is a GlobalAddress node (quite common, every direct call is)
   // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
-    // We should use extra load for direct calls to dllimported functions
-    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(), true))
+    // We should use extra load for direct calls to dllimported functions in
+    // non-JIT mode.
+    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(),
+                                        getTargetMachine(), true))
       Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
   } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
     Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
@@ -1201,8 +1203,10 @@
   // If the callee is a GlobalAddress node (quite common, every direct call is)
   // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
-    // We should use extra load for direct calls to dllimported functions
-    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(), true))
+    // We should use extra load for direct calls to dllimported functions in
+    // non-JIT mode.
+    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(),
+                                        getTargetMachine(), true))
       Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
   } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
     Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
@@ -1698,8 +1702,10 @@
   // If the callee is a GlobalAddress node (quite common, every direct call is)
   // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
-    // We should use extra load for direct calls to dllimported functions
-    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(), true))
+    // We should use extra load for direct calls to dllimported functions in
+    // non-JIT mode.
+    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(),
+                                        getTargetMachine(), true))
       Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
   } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
     Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
@@ -1996,8 +2002,10 @@
   // If the callee is a GlobalAddress node (quite common, every direct call is)
   // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
-    // We should use extra load for direct calls to dllimported functions
-    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(), true))
+    // We should use extra load for direct calls to dllimported functions in
+    // non-JIT mode.
+    if (!Subtarget->GVRequiresExtraLoad(G->getGlobal(),
+                                        getTargetMachine(), true))
       Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
   } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
     Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
@@ -3868,17 +3876,14 @@
       Result = DAG.getNode(ISD::ADD, getPointerTy(),
                            DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()),
                            Result);
-
-    // For Darwin, external and weak symbols are indirect, so we want to load
-    // 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 (getTargetMachine().getRelocationModel() != Reloc::Static &&
-        Subtarget->GVRequiresExtraLoad(GV, false))
-      Result = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), Result, NULL, 0);
-  } else if (Subtarget->GVRequiresExtraLoad(GV, false)) {
-    Result = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), Result, NULL, 0);
   }
+  
+  // For Darwin & Mingw32, external and weak symbols are indirect, so we want to
+  // load 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. Platform check is inside GVRequiresExtraLoad() call
+  if (Subtarget->GVRequiresExtraLoad(GV, getTargetMachine(), false))
+    Result = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), Result, NULL, 0);
 
   return Result;
 }
@@ -5010,9 +5015,8 @@
   if (Subtarget->is64Bit() &&
       getTargetMachine().getCodeModel() != CodeModel::Small)
     return false;
-  Reloc::Model RModel = getTargetMachine().getRelocationModel();
-  return (RModel == Reloc::Static) ||
-    !Subtarget->GVRequiresExtraLoad(GV, false);
+  
+  return (!Subtarget->GVRequiresExtraLoad(GV, getTargetMachine(), false));
 }
 
 /// isShuffleMaskLegal - Targets can use this to indicate that they only


Index: llvm/lib/Target/X86/X86Subtarget.cpp
diff -u llvm/lib/Target/X86/X86Subtarget.cpp:1.45 llvm/lib/Target/X86/X86Subtarget.cpp:1.46
--- llvm/lib/Target/X86/X86Subtarget.cpp:1.45	Wed Dec 20 14:40:30 2006
+++ llvm/lib/Target/X86/X86Subtarget.cpp	Fri Dec 22 16:29:05 2006
@@ -15,6 +15,7 @@
 #include "X86GenSubtarget.inc"
 #include "llvm/Module.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Target/TargetMachine.h"
 using namespace llvm;
 
 cl::opt<X86Subtarget::AsmWriterFlavorTy>
@@ -31,9 +32,10 @@
 /// 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.
 bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
+                                       const TargetMachine& TM,
                                        bool isDirectCall) const
 {
-  if (GenerateExtraLoadsForGVs)
+  if (TM.getRelocationModel() != Reloc::Static)
     if (isTargetDarwin()) {
       return (!isDirectCall &&
               (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
@@ -208,16 +210,6 @@
   }
 }
 
-/// SetJITMode - This is called to inform the subtarget info that we are
-/// producing code for the JIT.
-void X86Subtarget::SetJITMode()
-{
-  // JIT mode doesn't want extra loads for dllimported symbols, it knows exactly
-  // where everything is.
-  if (isTargetCygwin())
-    GenerateExtraLoadsForGVs = false;
-}
-
 X86Subtarget::X86Subtarget(const Module &M, const std::string &FS, bool is64Bit)
   : AsmFlavor(AsmWriterFlavor)
   , X86SSELevel(NoMMXSSE)
@@ -226,7 +218,6 @@
   // FIXME: this is a known good value for Yonah. How about others?
   , MinRepStrSizeThreshold(128)
   , Is64Bit(is64Bit)
-  , GenerateExtraLoadsForGVs(true)
   , TargetType(isELF) { // Default to ELF unless otherwise specified.
 
   // Determine default and user specified characteristics


Index: llvm/lib/Target/X86/X86Subtarget.h
diff -u llvm/lib/Target/X86/X86Subtarget.h:1.23 llvm/lib/Target/X86/X86Subtarget.h:1.24
--- llvm/lib/Target/X86/X86Subtarget.h:1.23	Tue Dec 19 19:03:20 2006
+++ llvm/lib/Target/X86/X86Subtarget.h	Fri Dec 22 16:29:05 2006
@@ -21,6 +21,7 @@
 namespace llvm {
 class Module;
 class GlobalValue;
+class TargetMachine;
 
 class X86Subtarget : public TargetSubtarget {
 public:
@@ -61,9 +62,6 @@
   /// pointer size is 64 bit.
   bool Is64Bit;
 
-  /// GenerateExtraLoadsForGVs - True if we should generate extra loads for
-  /// indirect symbols (e.g. dllimported symbols on windows).
-  bool GenerateExtraLoadsForGVs;
 public:
   enum {
     isELF, isCygwin, isDarwin, isWindows
@@ -114,11 +112,9 @@
   /// symbols are indirect, loading the value at address GV rather then 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.
-  bool GVRequiresExtraLoad(const GlobalValue* GV, bool isDirectCall) const;
+  bool GVRequiresExtraLoad(const GlobalValue* GV, const TargetMachine& TM,
+                           bool isDirectCall) const;
 
-  /// SetJITMode - This is called to inform the subtarget info that we are
-  /// producing code for the JIT.
-  void SetJITMode();
 };
 
 namespace X86 {


Index: llvm/lib/Target/X86/X86TargetMachine.cpp
diff -u llvm/lib/Target/X86/X86TargetMachine.cpp:1.132 llvm/lib/Target/X86/X86TargetMachine.cpp:1.133
--- llvm/lib/Target/X86/X86TargetMachine.cpp:1.132	Tue Dec 19 19:03:20 2006
+++ llvm/lib/Target/X86/X86TargetMachine.cpp	Fri Dec 22 16:29:05 2006
@@ -115,7 +115,7 @@
               Subtarget.getStackAlignment(), Subtarget.is64Bit() ? -8 : -4),
     InstrInfo(*this), JITInfo(*this), TLInfo(*this) {
   if (getRelocationModel() == Reloc::Default)
-    if (Subtarget.isTargetDarwin())
+    if (Subtarget.isTargetDarwin() || Subtarget.isTargetCygwin())
       setRelocationModel(Reloc::DynamicNoPIC);
     else
       setRelocationModel(Reloc::Static);
@@ -167,9 +167,6 @@
   if (Subtarget.is64Bit())
     setCodeModel(CodeModel::Large);
 
-  // Inform the subtarget that we are in JIT mode.
-  Subtarget.SetJITMode(); 
-  
   PM.add(createX86CodeEmitterPass(*this, MCE));
   return false;
 }






More information about the llvm-commits mailing list