aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Target/PowerPC/PPC.h1
-rw-r--r--lib/Target/PowerPC/PPCISelLowering.cpp12
-rw-r--r--lib/Target/PowerPC/PPCSubtarget.cpp6
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/Target/PowerPC/PPC.h b/lib/Target/PowerPC/PPC.h
index d19e57a3ba..1f40a54b67 100644
--- a/lib/Target/PowerPC/PPC.h
+++ b/lib/Target/PowerPC/PPC.h
@@ -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;
diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp
index 6ea688d020..6f798c38ed 100644
--- a/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -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)".
diff --git a/lib/Target/PowerPC/PPCSubtarget.cpp b/lib/Target/PowerPC/PPCSubtarget.cpp
index 442017d8cd..f43c18d7df 100644
--- a/lib/Target/PowerPC/PPCSubtarget.cpp
+++ b/lib/Target/PowerPC/PPCSubtarget.cpp
@@ -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__)