add an option to generate completely non-pic code, corresponding to what
authorChris Lattner <sabre@nondot.org>
Thu, 17 Nov 2005 18:55:48 +0000 (18:55 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 17 Nov 2005 18:55:48 +0000 (18:55 +0000)
gcc -static produces on PPC.  This is used for building kexts and other things.

With this, materializing the address of a global looks like:

        lis r2, ha16(L_H$non_lazy_ptr)
        la r3, lo16(L_H$non_lazy_ptr)(r2)

we're still emitting stubs for functions, which is wrong.  That is next.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24399 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPC.h
lib/Target/PowerPC/PPCISelLowering.cpp
lib/Target/PowerPC/PPCSubtarget.cpp

index d19e57a3ba0333d9077d9a34d41c908e66e4c700..1f40a54b67f9e01fd8901ab05ae420e007ac0829 100644 (file)
@@ -33,6 +33,7 @@ FunctionPass *createDarwinAsmPrinter(std::ostream &OS, TargetMachine &TM);
 FunctionPass *createAIXAsmPrinter(std::ostream &OS, TargetMachine &TM);
 
 extern bool PICEnabled;
+extern bool PPCGenerateStaticCode;
 extern PPCTargetEnum PPCTarget;
 } // end namespace llvm;
 
index 6ea688d020ee03e39ce50befe26089bae78480d2..6f798c38ed8225b0093ec9bc9c287bbe16f62bd2 100644 (file)
@@ -333,12 +333,20 @@ SDOperand PPCTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
     return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi);
   }
   case ISD::GlobalAddress: {
-    // Only lower GlobalAddress on Darwin.
-    if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break;
     GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
     SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
     SDOperand Zero = DAG.getConstant(0, MVT::i32);
+
+    if (PPCGenerateStaticCode) {
+      // Generate non-pic code that has direct accesses to globals.  To do this
+      // the address of the global is just (hi(&g)+lo(&g)).
+      SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero);
+      SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, GA, Zero);
+      return DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
+    }
     
+    // Only lower GlobalAddress on Darwin.
+    if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break;
     SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero);
     if (PICEnabled) {
       // With PIC, the first instruction is actually "GR+hi(&G)".
index 442017d8cd2afa76ab3785e154951f47006bcbac..f43c18d7dfa621c344c3d3781670b009ba3e7102 100644 (file)
@@ -19,6 +19,7 @@
 
 using namespace llvm;
 PPCTargetEnum llvm::PPCTarget = TargetDefault;
+bool llvm::PPCGenerateStaticCode = false;
 
 namespace llvm {
   cl::opt<PPCTargetEnum, true>
@@ -29,6 +30,11 @@ namespace llvm {
                                      "  Enable Darwin codegen"),
                           clEnumValEnd),
                cl::location(PPCTarget), cl::init(TargetDefault));
+  
+  cl::opt<bool, true>
+  PPCStaticCode("ppc-static",
+                cl::desc("PowerPC: generate completely non-pic code"),
+                cl::location(PPCGenerateStaticCode));
 } 
  
 #if defined(__APPLE__)