[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC.h PPCISelLowering.cpp PPCSubtarget.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Nov 17 10:55:59 PST 2005



Changes in directory llvm/lib/Target/PowerPC:

PPC.h updated: 1.23 -> 1.24
PPCISelLowering.cpp updated: 1.44 -> 1.45
PPCSubtarget.cpp updated: 1.15 -> 1.16
---
Log message:

add an option to generate completely non-pic code, corresponding to what
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.



---
Diffs of the changes:  (+17 -2)

 PPC.h               |    1 +
 PPCISelLowering.cpp |   12 ++++++++++--
 PPCSubtarget.cpp    |    6 ++++++
 3 files changed, 17 insertions(+), 2 deletions(-)


Index: llvm/lib/Target/PowerPC/PPC.h
diff -u llvm/lib/Target/PowerPC/PPC.h:1.23 llvm/lib/Target/PowerPC/PPC.h:1.24
--- llvm/lib/Target/PowerPC/PPC.h:1.23	Mon Oct 17 19:28:58 2005
+++ llvm/lib/Target/PowerPC/PPC.h	Thu Nov 17 12:55:48 2005
@@ -33,6 +33,7 @@
 FunctionPass *createAIXAsmPrinter(std::ostream &OS, TargetMachine &TM);
 
 extern bool PICEnabled;
+extern bool PPCGenerateStaticCode;
 extern PPCTargetEnum PPCTarget;
 } // end namespace llvm;
 


Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
diff -u llvm/lib/Target/PowerPC/PPCISelLowering.cpp:1.44 llvm/lib/Target/PowerPC/PPCISelLowering.cpp:1.45
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp:1.44	Thu Nov 17 12:30:17 2005
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp	Thu Nov 17 12:55:48 2005
@@ -333,12 +333,20 @@
     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: llvm/lib/Target/PowerPC/PPCSubtarget.cpp
diff -u llvm/lib/Target/PowerPC/PPCSubtarget.cpp:1.15 llvm/lib/Target/PowerPC/PPCSubtarget.cpp:1.16
--- llvm/lib/Target/PowerPC/PPCSubtarget.cpp:1.15	Tue Nov  1 14:07:00 2005
+++ llvm/lib/Target/PowerPC/PPCSubtarget.cpp	Thu Nov 17 12:55:48 2005
@@ -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 @@
                                      "  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__)






More information about the llvm-commits mailing list