blob: c4a7408a663756b7a669e2a288038672fe17314e [file] [log] [blame]
Nate Begeman6cca84e2005-10-16 05:39:50 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00002//
Misha Brukmane05203f2004-06-21 16:55:25 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Brukmanb4402432005-04-21 23:30:14 +00007//
Misha Brukmane05203f2004-06-21 16:55:25 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00009//
Chris Lattner73785d22005-08-15 23:47:04 +000010// Top-level implementation for the PowerPC target.
Misha Brukmane05203f2004-06-21 16:55:25 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerbfca1ab2005-10-14 23:51:18 +000014#include "PPC.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000015#include "PPCMCAsmInfo.h"
Chris Lattner6f3b9542005-10-14 23:59:06 +000016#include "PPCTargetMachine.h"
Misha Brukmane05203f2004-06-21 16:55:25 +000017#include "llvm/PassManager.h"
Dale Johannesenc31eb202008-07-31 18:13:12 +000018#include "llvm/Target/TargetOptions.h"
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000019#include "llvm/Target/TargetRegistry.h"
David Greenea31f96c2009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Misha Brukmane05203f2004-06-21 16:55:25 +000021using namespace llvm;
22
Daniel Dunbarfed917e2010-03-20 22:36:22 +000023static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
Chris Lattner9a6cf912009-08-12 07:22:17 +000024 Triple TheTriple(TT);
Daniel Dunbar86c065d2009-08-13 17:03:38 +000025 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
Chris Lattner9a6cf912009-08-12 07:22:17 +000026 if (TheTriple.getOS() == Triple::Darwin)
Chris Lattner05457462009-08-22 21:03:30 +000027 return new PPCMCAsmInfoDarwin(isPPC64);
Chris Lattner7b26fce2009-08-22 20:48:53 +000028 return new PPCLinuxMCAsmInfo(isPPC64);
Chris Lattner9a6cf912009-08-12 07:22:17 +000029
30}
31
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000032extern "C" void LLVMInitializePowerPCTarget() {
33 // Register the targets
34 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
35 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
Chris Lattner9a6cf912009-08-12 07:22:17 +000036
Chris Lattner7b26fce2009-08-22 20:48:53 +000037 RegisterAsmInfoFn C(ThePPC32Target, createMCAsmInfo);
38 RegisterAsmInfoFn D(ThePPC64Target, createMCAsmInfo);
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000039}
Douglas Gregor1b731d52009-06-16 20:12:29 +000040
Jim Laskeyae92ce82006-09-07 23:39:26 +000041
Chris Lattner2c309702009-08-11 20:42:37 +000042PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
Daniel Dunbare8338102009-07-15 20:24:03 +000043 const std::string &FS, bool is64Bit)
Chris Lattner2c309702009-08-11 20:42:37 +000044 : LLVMTargetMachine(T, TT),
Daniel Dunbarc3719c32009-08-02 23:37:13 +000045 Subtarget(TT, FS, is64Bit),
Chris Lattner49cadab2006-06-17 00:01:04 +000046 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Chris Lattner572e2382006-11-18 01:34:43 +000047 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
Chris Lattnerd1e821f2010-02-02 19:23:55 +000048 InstrItins(Subtarget.getInstrItineraryData()) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000049
Anton Korobeynikov40d67c52008-02-20 11:22:39 +000050 if (getRelocationModel() == Reloc::Default) {
Evan Cheng73136df2006-02-22 20:19:42 +000051 if (Subtarget.isDarwin())
52 setRelocationModel(Reloc::DynamicNoPIC);
53 else
Jim Laskey28663c72006-12-21 20:26:09 +000054 setRelocationModel(Reloc::Static);
Anton Korobeynikov40d67c52008-02-20 11:22:39 +000055 }
Nate Begeman6cca84e2005-10-16 05:39:50 +000056}
57
Dale Johannesen82810c82007-05-22 17:14:46 +000058/// Override this for PowerPC. Tail merging happily breaks up instruction issue
59/// groups, which typically degrades performance.
Dan Gohmanaad83c82007-11-19 20:46:23 +000060bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen82810c82007-05-22 17:14:46 +000061
Daniel Dunbarc3719c32009-08-02 23:37:13 +000062PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbare8338102009-07-15 20:24:03 +000063 const std::string &FS)
Daniel Dunbarc3719c32009-08-02 23:37:13 +000064 : PPCTargetMachine(T, TT, FS, false) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000065}
66
67
Daniel Dunbarc3719c32009-08-02 23:37:13 +000068PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbare8338102009-07-15 20:24:03 +000069 const std::string &FS)
Daniel Dunbarc3719c32009-08-02 23:37:13 +000070 : PPCTargetMachine(T, TT, FS, true) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000071}
72
Misha Brukmanb4402432005-04-21 23:30:14 +000073
Chris Lattner12e97302006-09-04 04:14:57 +000074//===----------------------------------------------------------------------===//
75// Pass Pipeline Configuration
76//===----------------------------------------------------------------------===//
Nate Begemanf17ea0f2004-08-11 07:40:04 +000077
Bill Wendling026e5d72009-04-29 23:29:43 +000078bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
79 CodeGenOpt::Level OptLevel) {
Chris Lattnerc6aa8062005-08-17 19:33:30 +000080 // Install an instruction selector.
Chris Lattner33792a42006-01-12 01:46:07 +000081 PM.add(createPPCISelDag(*this));
Nate Begemanf17ea0f2004-08-11 07:40:04 +000082 return false;
83}
84
Bill Wendling026e5d72009-04-29 23:29:43 +000085bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
86 CodeGenOpt::Level OptLevel) {
Chris Lattner12e97302006-09-04 04:14:57 +000087 // Must run branch selection immediately preceding the asm printer.
88 PM.add(createPPCBranchSelectionPass());
89 return false;
90}
91
Bill Wendling026e5d72009-04-29 23:29:43 +000092bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
93 CodeGenOpt::Level OptLevel,
Daniel Dunbarc9013922009-07-15 22:33:19 +000094 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +000095 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
96 // FIXME: This should be moved to TargetJITInfo!!
97 if (Subtarget.isPPC64()) {
98 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
99 // instructions to materialize arbitrary global variable + function +
100 // constant pool addresses.
101 setRelocationModel(Reloc::PIC_);
102 // Temporary workaround for the inability of PPC64 JIT to handle jump
103 // tables.
104 DisableJumpTables = true;
105 } else {
106 setRelocationModel(Reloc::Static);
107 }
108
109 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
110 // writing?
111 Subtarget.SetJITMode();
112
113 // Machine code emitter pass for PowerPC.
114 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000115
116 return false;
117}