1 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Top-level implementation for the PowerPC target.
12 //===----------------------------------------------------------------------===//
14 #include "PPCTargetMachine.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"
26 opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden,
27 cl::desc("Disable CTR loops for PPC"));
29 extern "C" void LLVMInitializePowerPCTarget() {
30 // Register the targets
31 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
32 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
35 PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
36 StringRef CPU, StringRef FS,
37 const TargetOptions &Options,
38 Reloc::Model RM, CodeModel::Model CM,
41 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
42 Subtarget(TT, CPU, FS, is64Bit),
43 DL(Subtarget.getDataLayoutString()), InstrInfo(*this),
44 FrameLowering(Subtarget), JITInfo(*this, is64Bit),
45 TLInfo(*this), TSInfo(*this),
46 InstrItins(Subtarget.getInstrItineraryData()) {
48 // The binutils for the BG/P are too old for CFI.
49 if (Subtarget.isBGP())
54 void PPC32TargetMachine::anchor() { }
56 PPC32TargetMachine::PPC32TargetMachine(const Target &T, StringRef TT,
57 StringRef CPU, StringRef FS,
58 const TargetOptions &Options,
59 Reloc::Model RM, CodeModel::Model CM,
61 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
64 void PPC64TargetMachine::anchor() { }
66 PPC64TargetMachine::PPC64TargetMachine(const Target &T, StringRef TT,
67 StringRef CPU, StringRef FS,
68 const TargetOptions &Options,
69 Reloc::Model RM, CodeModel::Model CM,
71 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
75 //===----------------------------------------------------------------------===//
76 // Pass Pipeline Configuration
77 //===----------------------------------------------------------------------===//
80 /// PPC Code Generator Pass Configuration Options.
81 class PPCPassConfig : public TargetPassConfig {
83 PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM)
84 : TargetPassConfig(TM, PM) {}
86 PPCTargetMachine &getPPCTargetMachine() const {
87 return getTM<PPCTargetMachine>();
90 const PPCSubtarget &getPPCSubtarget() const {
91 return *getPPCTargetMachine().getSubtargetImpl();
94 virtual bool addPreISel();
95 virtual bool addILPOpts();
96 virtual bool addInstSelector();
97 virtual bool addPreSched2();
98 virtual bool addPreEmitPass();
102 TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) {
103 return new PPCPassConfig(this, PM);
106 bool PPCPassConfig::addPreISel() {
107 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
108 addPass(createPPCCTRLoops(getPPCTargetMachine()));
113 bool PPCPassConfig::addILPOpts() {
114 if (getPPCSubtarget().hasISEL()) {
115 addPass(&EarlyIfConverterID);
122 bool PPCPassConfig::addInstSelector() {
123 // Install an instruction selector.
124 addPass(createPPCISelDag(getPPCTargetMachine()));
127 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
128 addPass(createPPCCTRLoopsVerify());
134 bool PPCPassConfig::addPreSched2() {
135 if (getOptLevel() != CodeGenOpt::None)
136 addPass(&IfConverterID);
141 bool PPCPassConfig::addPreEmitPass() {
142 if (getOptLevel() != CodeGenOpt::None)
143 addPass(createPPCEarlyReturnPass());
144 // Must run branch selection immediately preceding the asm printer.
145 addPass(createPPCBranchSelectionPass());
149 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
150 JITCodeEmitter &JCE) {
151 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
153 Subtarget.SetJITMode();
155 // Machine code emitter pass for PowerPC.
156 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
161 void PPCTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
162 // Add first the target-independent BasicTTI pass, then our PPC pass. This
163 // allows the PPC pass to delegate to the target independent layer when
165 PM.add(createBasicTargetTransformInfoPass(this));
166 PM.add(createPPCTargetTransformInfoPass(this));