On DataLayout, omit the default of p:64:64:64.
[oota-llvm.git] / lib / Target / PowerPC / PPCTargetMachine.cpp
1 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Top-level implementation for the PowerPC target.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PPCTargetMachine.h"
15 #include "PPC.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/MC/MCStreamer.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/FormattedStream.h"
21 #include "llvm/Support/TargetRegistry.h"
22 #include "llvm/Target/TargetOptions.h"
23 using namespace llvm;
24
25 static cl::
26 opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden,
27                         cl::desc("Disable CTR loops for PPC"));
28
29 extern "C" void LLVMInitializePowerPCTarget() {
30   // Register the targets
31   RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
32   RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
33   RegisterTargetMachine<PPC64TargetMachine> C(ThePPC64LETarget);
34 }
35
36 /// Return the datalayout string of a subtarget.
37 static std::string getDataLayoutString(const PPCSubtarget &ST) {
38   // PPC is big endian.
39   std::string Ret = "E";
40
41   // PPC32 has 32 bit pointers.
42   if (!ST.isPPC64())
43     Ret += "-p:32:32";
44
45   // Note, the alignment values for f64 and i64 on ppc64 in Darwin
46   // documentation are wrong; these are correct (i.e. "what gcc does").
47   Ret += "-i64:64:64";
48
49   // Set support for 128 floats depending on the ABI.
50   if (!ST.isPPC64() || !ST.isSVR4ABI())
51     Ret += "-f128:64:128";
52
53   // PPC64 has 32 and 64 bit registers, PPC32 has only 32 bit ones.
54   if (ST.isPPC64())
55     Ret += "-n32:64";
56   else
57     Ret += "-n32";
58
59   return Ret;
60 }
61
62 PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
63                                    StringRef CPU, StringRef FS,
64                                    const TargetOptions &Options,
65                                    Reloc::Model RM, CodeModel::Model CM,
66                                    CodeGenOpt::Level OL,
67                                    bool is64Bit)
68   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
69     Subtarget(TT, CPU, FS, is64Bit),
70     DL(getDataLayoutString(Subtarget)), InstrInfo(*this),
71     FrameLowering(Subtarget), JITInfo(*this, is64Bit),
72     TLInfo(*this), TSInfo(*this),
73     InstrItins(Subtarget.getInstrItineraryData()) {
74
75   // The binutils for the BG/P are too old for CFI.
76   if (Subtarget.isBGP())
77     setMCUseCFI(false);
78   initAsmInfo();
79 }
80
81 void PPC32TargetMachine::anchor() { }
82
83 PPC32TargetMachine::PPC32TargetMachine(const Target &T, StringRef TT,
84                                        StringRef CPU, StringRef FS,
85                                        const TargetOptions &Options,
86                                        Reloc::Model RM, CodeModel::Model CM,
87                                        CodeGenOpt::Level OL)
88   : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
89 }
90
91 void PPC64TargetMachine::anchor() { }
92
93 PPC64TargetMachine::PPC64TargetMachine(const Target &T, StringRef TT,
94                                        StringRef CPU,  StringRef FS,
95                                        const TargetOptions &Options,
96                                        Reloc::Model RM, CodeModel::Model CM,
97                                        CodeGenOpt::Level OL)
98   : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
99 }
100
101
102 //===----------------------------------------------------------------------===//
103 // Pass Pipeline Configuration
104 //===----------------------------------------------------------------------===//
105
106 namespace {
107 /// PPC Code Generator Pass Configuration Options.
108 class PPCPassConfig : public TargetPassConfig {
109 public:
110   PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM)
111     : TargetPassConfig(TM, PM) {}
112
113   PPCTargetMachine &getPPCTargetMachine() const {
114     return getTM<PPCTargetMachine>();
115   }
116
117   const PPCSubtarget &getPPCSubtarget() const {
118     return *getPPCTargetMachine().getSubtargetImpl();
119   }
120
121   virtual bool addPreISel();
122   virtual bool addILPOpts();
123   virtual bool addInstSelector();
124   virtual bool addPreSched2();
125   virtual bool addPreEmitPass();
126 };
127 } // namespace
128
129 TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) {
130   return new PPCPassConfig(this, PM);
131 }
132
133 bool PPCPassConfig::addPreISel() {
134   if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
135     addPass(createPPCCTRLoops(getPPCTargetMachine()));
136
137   return false;
138 }
139
140 bool PPCPassConfig::addILPOpts() {
141   if (getPPCSubtarget().hasISEL()) {
142     addPass(&EarlyIfConverterID);
143     return true;
144   }
145
146   return false;
147 }
148
149 bool PPCPassConfig::addInstSelector() {
150   // Install an instruction selector.
151   addPass(createPPCISelDag(getPPCTargetMachine()));
152
153 #ifndef NDEBUG
154   if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
155     addPass(createPPCCTRLoopsVerify());
156 #endif
157
158   return false;
159 }
160
161 bool PPCPassConfig::addPreSched2() {
162   if (getOptLevel() != CodeGenOpt::None)
163     addPass(&IfConverterID);
164
165   return true;
166 }
167
168 bool PPCPassConfig::addPreEmitPass() {
169   if (getOptLevel() != CodeGenOpt::None)
170     addPass(createPPCEarlyReturnPass());
171   // Must run branch selection immediately preceding the asm printer.
172   addPass(createPPCBranchSelectionPass());
173   return false;
174 }
175
176 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
177                                       JITCodeEmitter &JCE) {
178   // Inform the subtarget that we are in JIT mode.  FIXME: does this break macho
179   // writing?
180   Subtarget.SetJITMode();
181
182   // Machine code emitter pass for PowerPC.
183   PM.add(createPPCJITCodeEmitterPass(*this, JCE));
184
185   return false;
186 }
187
188 void PPCTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
189   // Add first the target-independent BasicTTI pass, then our PPC pass. This
190   // allows the PPC pass to delegate to the target independent layer when
191   // appropriate.
192   PM.add(createBasicTargetTransformInfoPass(this));
193   PM.add(createPPCTargetTransformInfoPass(this));
194 }
195