blob: 7946837e06c4ff64da3e0bfc459c54f08b7824ae [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 Lattner26689592005-10-14 23:51:18 +000014#include "PPC.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000015#include "PPCMCAsmInfo.h"
Chris Lattner16e71f22005-10-14 23:59:06 +000016#include "PPCTargetMachine.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000017#include "llvm/PassManager.h"
Dale Johannesen72324642008-07-31 18:13:12 +000018#include "llvm/Target/TargetOptions.h"
Daniel Dunbar0c795d62009-07-25 06:49:55 +000019#include "llvm/Target/TargetRegistry.h"
David Greene71847812009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000021using namespace llvm;
22
Daniel Dunbar5d067fe2010-03-20 22:36:22 +000023static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
Chris Lattnera7ac47c2009-08-12 07:22:17 +000024 Triple TheTriple(TT);
Daniel Dunbarb42dad42009-08-13 17:03:38 +000025 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
Chris Lattnera7ac47c2009-08-12 07:22:17 +000026 if (TheTriple.getOS() == Triple::Darwin)
Chris Lattner2807afa2009-08-22 21:03:30 +000027 return new PPCMCAsmInfoDarwin(isPPC64);
Chris Lattneraf76e592009-08-22 20:48:53 +000028 return new PPCLinuxMCAsmInfo(isPPC64);
Chris Lattnera7ac47c2009-08-12 07:22:17 +000029
30}
31
Daniel Dunbar0c795d62009-07-25 06:49:55 +000032extern "C" void LLVMInitializePowerPCTarget() {
33 // Register the targets
34 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
35 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
Chris Lattnera7ac47c2009-08-12 07:22:17 +000036
Chris Lattneraf76e592009-08-22 20:48:53 +000037 RegisterAsmInfoFn C(ThePPC32Target, createMCAsmInfo);
38 RegisterAsmInfoFn D(ThePPC64Target, createMCAsmInfo);
Chris Lattner5ffe38e2010-11-15 04:16:32 +000039
40 // Register the MC Code Emitter
41 TargetRegistry::RegisterCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter);
42 TargetRegistry::RegisterCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter);
Daniel Dunbar0c795d62009-07-25 06:49:55 +000043}
Douglas Gregor1555a232009-06-16 20:12:29 +000044
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000045
Chris Lattner0a31d2f2009-08-11 20:42:37 +000046PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
Daniel Dunbar51b198a2009-07-15 20:24:03 +000047 const std::string &FS, bool is64Bit)
Chris Lattner0a31d2f2009-08-11 20:42:37 +000048 : LLVMTargetMachine(T, TT),
Daniel Dunbare28039c2009-08-02 23:37:13 +000049 Subtarget(TT, FS, is64Bit),
Chris Lattnerb1d26f62006-06-17 00:01:04 +000050 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Anton Korobeynikov33464912010-11-15 00:06:54 +000051 FrameInfo(Subtarget), JITInfo(*this, is64Bit),
Dan Gohmanff7a5622010-05-11 17:31:57 +000052 TLInfo(*this), TSInfo(*this),
Chris Lattner6914b862010-02-02 19:23:55 +000053 InstrItins(Subtarget.getInstrItineraryData()) {
Chris Lattner94de9a82006-06-16 01:37:27 +000054
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000055 if (getRelocationModel() == Reloc::Default) {
Evan Cheng4c1aa862006-02-22 20:19:42 +000056 if (Subtarget.isDarwin())
57 setRelocationModel(Reloc::DynamicNoPIC);
58 else
Jim Laskeybf111822006-12-21 20:26:09 +000059 setRelocationModel(Reloc::Static);
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000060 }
Nate Begeman21e463b2005-10-16 05:39:50 +000061}
62
Dale Johannesen81da02b2007-05-22 17:14:46 +000063/// Override this for PowerPC. Tail merging happily breaks up instruction issue
64/// groups, which typically degrades performance.
Dan Gohman50cdabc2007-11-19 20:46:23 +000065bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen81da02b2007-05-22 17:14:46 +000066
Daniel Dunbare28039c2009-08-02 23:37:13 +000067PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbar51b198a2009-07-15 20:24:03 +000068 const std::string &FS)
Daniel Dunbare28039c2009-08-02 23:37:13 +000069 : PPCTargetMachine(T, TT, FS, false) {
Chris Lattner94de9a82006-06-16 01:37:27 +000070}
71
72
Daniel Dunbare28039c2009-08-02 23:37:13 +000073PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbar51b198a2009-07-15 20:24:03 +000074 const std::string &FS)
Daniel Dunbare28039c2009-08-02 23:37:13 +000075 : PPCTargetMachine(T, TT, FS, true) {
Chris Lattner94de9a82006-06-16 01:37:27 +000076}
77
Misha Brukmanb5f662f2005-04-21 23:30:14 +000078
Chris Lattner1911fd42006-09-04 04:14:57 +000079//===----------------------------------------------------------------------===//
80// Pass Pipeline Configuration
81//===----------------------------------------------------------------------===//
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000082
Bill Wendling98a366d2009-04-29 23:29:43 +000083bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
84 CodeGenOpt::Level OptLevel) {
Chris Lattner8482dd82005-08-17 19:33:30 +000085 // Install an instruction selector.
Chris Lattner05f1fe82006-01-12 01:46:07 +000086 PM.add(createPPCISelDag(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000087 return false;
88}
89
Bill Wendling98a366d2009-04-29 23:29:43 +000090bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
91 CodeGenOpt::Level OptLevel) {
Chris Lattner1911fd42006-09-04 04:14:57 +000092 // Must run branch selection immediately preceding the asm printer.
93 PM.add(createPPCBranchSelectionPass());
94 return false;
95}
96
Bill Wendling98a366d2009-04-29 23:29:43 +000097bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
98 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +000099 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000100 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
101 // FIXME: This should be moved to TargetJITInfo!!
102 if (Subtarget.isPPC64()) {
103 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
104 // instructions to materialize arbitrary global variable + function +
105 // constant pool addresses.
106 setRelocationModel(Reloc::PIC_);
107 // Temporary workaround for the inability of PPC64 JIT to handle jump
108 // tables.
109 DisableJumpTables = true;
110 } else {
111 setRelocationModel(Reloc::Static);
112 }
113
114 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
115 // writing?
116 Subtarget.SetJITMode();
117
118 // Machine code emitter pass for PowerPC.
119 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000120
121 return false;
122}