LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PPCTargetMachine.cpp
Go to the documentation of this file.
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"
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
34 }
35 
37  StringRef CPU, StringRef FS,
38  const TargetOptions &Options,
41  bool is64Bit)
42  : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
43  Subtarget(TT, CPU, FS, is64Bit),
44  DL(Subtarget.getDataLayoutString()), InstrInfo(*this),
45  FrameLowering(Subtarget), JITInfo(*this, is64Bit),
46  TLInfo(*this), TSInfo(*this),
47  InstrItins(Subtarget.getInstrItineraryData()) {
48 
49  // The binutils for the BG/P are too old for CFI.
50  if (Subtarget.isBGP())
51  setMCUseCFI(false);
52  initAsmInfo();
53 }
54 
55 void PPC32TargetMachine::anchor() { }
56 
58  StringRef CPU, StringRef FS,
59  const TargetOptions &Options,
62  : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
63 }
64 
65 void PPC64TargetMachine::anchor() { }
66 
68  StringRef CPU, StringRef FS,
69  const TargetOptions &Options,
72  : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
73 }
74 
75 
76 //===----------------------------------------------------------------------===//
77 // Pass Pipeline Configuration
78 //===----------------------------------------------------------------------===//
79 
80 namespace {
81 /// PPC Code Generator Pass Configuration Options.
82 class PPCPassConfig : public TargetPassConfig {
83 public:
84  PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM)
85  : TargetPassConfig(TM, PM) {}
86 
87  PPCTargetMachine &getPPCTargetMachine() const {
88  return getTM<PPCTargetMachine>();
89  }
90 
91  const PPCSubtarget &getPPCSubtarget() const {
92  return *getPPCTargetMachine().getSubtargetImpl();
93  }
94 
95  virtual bool addPreISel();
96  virtual bool addILPOpts();
97  virtual bool addInstSelector();
98  virtual bool addPreSched2();
99  virtual bool addPreEmitPass();
100 };
101 } // namespace
102 
104  return new PPCPassConfig(this, PM);
105 }
106 
107 bool PPCPassConfig::addPreISel() {
108  if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
109  addPass(createPPCCTRLoops(getPPCTargetMachine()));
110 
111  return false;
112 }
113 
114 bool PPCPassConfig::addILPOpts() {
115  if (getPPCSubtarget().hasISEL()) {
116  addPass(&EarlyIfConverterID);
117  return true;
118  }
119 
120  return false;
121 }
122 
123 bool PPCPassConfig::addInstSelector() {
124  // Install an instruction selector.
125  addPass(createPPCISelDag(getPPCTargetMachine()));
126 
127 #ifndef NDEBUG
128  if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
129  addPass(createPPCCTRLoopsVerify());
130 #endif
131 
132  return false;
133 }
134 
135 bool PPCPassConfig::addPreSched2() {
136  if (getOptLevel() != CodeGenOpt::None)
137  addPass(&IfConverterID);
138 
139  return true;
140 }
141 
142 bool PPCPassConfig::addPreEmitPass() {
143  if (getOptLevel() != CodeGenOpt::None)
144  addPass(createPPCEarlyReturnPass());
145  // Must run branch selection immediately preceding the asm printer.
146  addPass(createPPCBranchSelectionPass());
147  return false;
148 }
149 
150 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
151  JITCodeEmitter &JCE) {
152  // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
153  // writing?
154  Subtarget.SetJITMode();
155 
156  // Machine code emitter pass for PowerPC.
157  PM.add(createPPCJITCodeEmitterPass(*this, JCE));
158 
159  return false;
160 }
161 
162 void PPCTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
163  // Add first the target-independent BasicTTI pass, then our PPC pass. This
164  // allows the PPC pass to delegate to the target independent layer when
165  // appropriate.
167  PM.add(createPPCTargetTransformInfoPass(this));
168 }
169 
virtual bool addCodeEmitter(PassManagerBase &PM, JITCodeEmitter &JCE)
void setMCUseCFI(bool Value)
setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
ImmutablePass * createBasicTargetTransformInfoPass(const TargetMachine *TM)
Create a basic TargetTransformInfo analysis pass.
char & EarlyIfConverterID
virtual TargetPassConfig * createPassConfig(PassManagerBase &PM)
bool isBGP() const
isBGP - True if this is a BG/P platform.
Definition: PPCSubtarget.h:204
PPC64TargetMachine(const Target &T, StringRef TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL)
#define false
Definition: ConvertUTF.c:64
FunctionPass * createPPCJITCodeEmitterPass(PPCTargetMachine &TM, JITCodeEmitter &MCE)
PPC32TargetMachine(const Target &T, StringRef TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL)
FunctionPass * createPPCCTRLoopsVerify()
virtual void addAnalysisPasses(PassManagerBase &PM)
Register PPC analysis passes with a pass manager.
FunctionPass * createPPCBranchSelectionPass()
#define true
Definition: ConvertUTF.c:65
FunctionPass * createPPCEarlyReturnPass()
void LLVMInitializePowerPCTarget()
FunctionPass * createPPCCTRLoops(PPCTargetMachine &TM)
Target ThePPC32Target
Target ThePPC64LETarget
ImmutablePass * createPPCTargetTransformInfoPass(const PPCTargetMachine *TM)
Creates an PPC-specific Target Transformation Info pass.
static cl::opt< bool > DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden, cl::desc("Disable CTR loops for PPC"))
char & IfConverterID
IfConverter - This pass performs machine code if conversion.
PPCTargetMachine(const Target &T, StringRef TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL, bool is64Bit)
Target ThePPC64Target
FunctionPass * createPPCISelDag(PPCTargetMachine &TM)