Don't avoid cfi instructions on the bg/p.
[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   const Triple &T = ST.getTargetTriple();
39
40   // PPC is big endian.
41   std::string Ret = "E";
42
43   Ret += DataLayout::getManglingComponent(T);
44
45   // PPC32 has 32 bit pointers. The PS3 (OS Lv2) is a PPC64 machine with 32 bit
46   // pointers.
47   if (!ST.isPPC64() || T.getOS() == Triple::Lv2)
48     Ret += "-p:32:32";
49
50   // Note, the alignment values for f64 and i64 on ppc64 in Darwin
51   // documentation are wrong; these are correct (i.e. "what gcc does").
52   if (ST.isPPC64() || ST.isSVR4ABI())
53     Ret += "-i64:64";
54   else
55     Ret += "-f64:32:64";
56
57   // PPC64 has 32 and 64 bit registers, PPC32 has only 32 bit ones.
58   if (ST.isPPC64())
59     Ret += "-n32:64";
60   else
61     Ret += "-n32";
62
63   return Ret;
64 }
65
66 PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
67                                    StringRef CPU, StringRef FS,
68                                    const TargetOptions &Options,
69                                    Reloc::Model RM, CodeModel::Model CM,
70                                    CodeGenOpt::Level OL,
71                                    bool is64Bit)
72   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
73     Subtarget(TT, CPU, FS, is64Bit, OL),
74     DL(getDataLayoutString(Subtarget)), InstrInfo(*this),
75     FrameLowering(Subtarget), JITInfo(*this, is64Bit),
76     TLInfo(*this), TSInfo(*this),
77     InstrItins(Subtarget.getInstrItineraryData()) {
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