blob: d113976699124c198a9234c951b9b7f24426bbe4 [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00009//
Chris Lattnerb0096bd2005-08-15 23:47:04 +000010// Top-level implementation for the PowerPC target.
Misha Brukman5dfe3a92004-06-21 16:55:25 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner16e71f22005-10-14 23:59:06 +000014#include "PPCTargetMachine.h"
Craig Topper79aa3412012-03-17 18:46:09 +000015#include "PPC.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000016#include "llvm/PassManager.h"
Chris Lattnerb46443a2010-11-15 08:49:58 +000017#include "llvm/MC/MCStreamer.h"
Andrew Trick843ee2e2012-02-03 05:12:41 +000018#include "llvm/CodeGen/Passes.h"
Dale Johannesen72324642008-07-31 18:13:12 +000019#include "llvm/Target/TargetOptions.h"
David Greene71847812009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000021#include "llvm/Support/TargetRegistry.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000022using namespace llvm;
23
Daniel Dunbar0c795d62009-07-25 06:49:55 +000024extern "C" void LLVMInitializePowerPCTarget() {
25 // Register the targets
Andrew Trick8247e0d2012-02-03 05:12:30 +000026 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
Daniel Dunbar0c795d62009-07-25 06:49:55 +000027 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
28}
Douglas Gregor1555a232009-06-16 20:12:29 +000029
Evan Cheng43966132011-07-19 06:37:02 +000030PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
31 StringRef CPU, StringRef FS,
Nick Lewycky8a8d4792011-12-02 22:16:29 +000032 const TargetOptions &Options,
Evan Cheng34ad6db2011-07-20 07:51:56 +000033 Reloc::Model RM, CodeModel::Model CM,
Evan Chengb95fc312011-11-16 08:38:26 +000034 CodeGenOpt::Level OL,
Evan Cheng34ad6db2011-07-20 07:51:56 +000035 bool is64Bit)
Nick Lewycky8a8d4792011-12-02 22:16:29 +000036 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Evan Cheng276365d2011-06-30 01:53:36 +000037 Subtarget(TT, CPU, FS, is64Bit),
Chris Lattnerb1d26f62006-06-17 00:01:04 +000038 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000039 FrameLowering(Subtarget), JITInfo(*this, is64Bit),
Dan Gohmanff7a5622010-05-11 17:31:57 +000040 TLInfo(*this), TSInfo(*this),
Chris Lattner6914b862010-02-02 19:23:55 +000041 InstrItins(Subtarget.getInstrItineraryData()) {
Hal Finkel70272aa2012-04-02 19:09:04 +000042
43 // The binutils for the BG/P are too old for CFI.
44 if (Subtarget.isBGP())
45 setMCUseCFI(false);
Nate Begeman21e463b2005-10-16 05:39:50 +000046}
47
David Blaikie2d24e2a2011-12-20 02:50:00 +000048void PPC32TargetMachine::anchor() { }
49
Andrew Trick8247e0d2012-02-03 05:12:30 +000050PPC32TargetMachine::PPC32TargetMachine(const Target &T, StringRef TT,
Evan Cheng34ad6db2011-07-20 07:51:56 +000051 StringRef CPU, StringRef FS,
Nick Lewycky8a8d4792011-12-02 22:16:29 +000052 const TargetOptions &Options,
Evan Chengb95fc312011-11-16 08:38:26 +000053 Reloc::Model RM, CodeModel::Model CM,
54 CodeGenOpt::Level OL)
Nick Lewycky8a8d4792011-12-02 22:16:29 +000055 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
Chris Lattner94de9a82006-06-16 01:37:27 +000056}
57
David Blaikie2d24e2a2011-12-20 02:50:00 +000058void PPC64TargetMachine::anchor() { }
Chris Lattner94de9a82006-06-16 01:37:27 +000059
Andrew Trick8247e0d2012-02-03 05:12:30 +000060PPC64TargetMachine::PPC64TargetMachine(const Target &T, StringRef TT,
Evan Cheng34ad6db2011-07-20 07:51:56 +000061 StringRef CPU, StringRef FS,
Nick Lewycky8a8d4792011-12-02 22:16:29 +000062 const TargetOptions &Options,
Evan Chengb95fc312011-11-16 08:38:26 +000063 Reloc::Model RM, CodeModel::Model CM,
64 CodeGenOpt::Level OL)
Nick Lewycky8a8d4792011-12-02 22:16:29 +000065 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
Chris Lattner94de9a82006-06-16 01:37:27 +000066}
67
Misha Brukmanb5f662f2005-04-21 23:30:14 +000068
Chris Lattner1911fd42006-09-04 04:14:57 +000069//===----------------------------------------------------------------------===//
70// Pass Pipeline Configuration
71//===----------------------------------------------------------------------===//
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000072
Andrew Trick843ee2e2012-02-03 05:12:41 +000073namespace {
74/// PPC Code Generator Pass Configuration Options.
75class PPCPassConfig : public TargetPassConfig {
76public:
Andrew Trick061efcf2012-02-04 02:56:59 +000077 PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM)
78 : TargetPassConfig(TM, PM) {}
Andrew Trick843ee2e2012-02-03 05:12:41 +000079
80 PPCTargetMachine &getPPCTargetMachine() const {
81 return getTM<PPCTargetMachine>();
82 }
83
84 virtual bool addInstSelector();
Andrew Trick843ee2e2012-02-03 05:12:41 +000085 virtual bool addPreEmitPass();
86};
87} // namespace
88
Andrew Trick061efcf2012-02-04 02:56:59 +000089TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) {
Andrew Trick61f1e3d2012-02-08 21:22:48 +000090 TargetPassConfig *PassConfig = new PPCPassConfig(this, PM);
91
92 // Override this for PowerPC. Tail merging happily breaks up instruction issue
93 // groups, which typically degrades performance.
94 PassConfig->setEnableTailMerge(false);
95
96 return PassConfig;
Andrew Trick843ee2e2012-02-03 05:12:41 +000097}
98
99bool PPCPassConfig::addInstSelector() {
Chris Lattner8482dd82005-08-17 19:33:30 +0000100 // Install an instruction selector.
Andrew Trick843ee2e2012-02-03 05:12:41 +0000101 PM.add(createPPCISelDag(getPPCTargetMachine()));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000102 return false;
103}
104
Andrew Trick843ee2e2012-02-03 05:12:41 +0000105bool PPCPassConfig::addPreEmitPass() {
Chris Lattner1911fd42006-09-04 04:14:57 +0000106 // Must run branch selection immediately preceding the asm printer.
107 PM.add(createPPCBranchSelectionPass());
108 return false;
109}
110
Bill Wendling98a366d2009-04-29 23:29:43 +0000111bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000112 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000113 // FIXME: This should be moved to TargetJITInfo!!
Evan Cheng43966132011-07-19 06:37:02 +0000114 if (Subtarget.isPPC64())
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000115 // Temporary workaround for the inability of PPC64 JIT to handle jump
116 // tables.
Andrew Trick8247e0d2012-02-03 05:12:30 +0000117 Options.DisableJumpTables = true;
118
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000119 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
120 // writing?
121 Subtarget.SetJITMode();
Andrew Trick8247e0d2012-02-03 05:12:30 +0000122
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000123 // Machine code emitter pass for PowerPC.
124 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000125
126 return false;
127}