blob: 7946837e06c4ff64da3e0bfc459c54f08b7824ae [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Top-level implementation for the PowerPC target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PPC.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000015#include "PPCMCAsmInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016#include "PPCTargetMachine.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000017#include "llvm/PassManager.h"
Dale Johannesen493492f2008-07-31 18:13:12 +000018#include "llvm/Target/TargetOptions.h"
Daniel Dunbarc680b012009-07-25 06:49:55 +000019#include "llvm/Target/TargetRegistry.h"
David Greene302008d2009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021using namespace llvm;
22
Daniel Dunbar6c566962010-03-20 22:36:22 +000023static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000024 Triple TheTriple(TT);
Daniel Dunbaree3b6c62009-08-13 17:03:38 +000025 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000026 if (TheTriple.getOS() == Triple::Darwin)
Chris Lattnercd4cab92009-08-22 21:03:30 +000027 return new PPCMCAsmInfoDarwin(isPPC64);
Chris Lattner621c44d2009-08-22 20:48:53 +000028 return new PPCLinuxMCAsmInfo(isPPC64);
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000029
30}
31
Daniel Dunbarc680b012009-07-25 06:49:55 +000032extern "C" void LLVMInitializePowerPCTarget() {
33 // Register the targets
34 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
35 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000036
Chris Lattner621c44d2009-08-22 20:48:53 +000037 RegisterAsmInfoFn C(ThePPC32Target, createMCAsmInfo);
38 RegisterAsmInfoFn D(ThePPC64Target, createMCAsmInfo);
Chris Lattner1e431382010-11-15 04:16:32 +000039
40 // Register the MC Code Emitter
41 TargetRegistry::RegisterCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter);
42 TargetRegistry::RegisterCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter);
Daniel Dunbarc680b012009-07-25 06:49:55 +000043}
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000044
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045
Chris Lattnerd9236ec2009-08-11 20:42:37 +000046PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000047 const std::string &FS, bool is64Bit)
Chris Lattnerd9236ec2009-08-11 20:42:37 +000048 : LLVMTargetMachine(T, TT),
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000049 Subtarget(TT, FS, is64Bit),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Anton Korobeynikovb87e6af2010-11-15 00:06:54 +000051 FrameInfo(Subtarget), JITInfo(*this, is64Bit),
Dan Gohmancfbb3232010-05-11 17:31:57 +000052 TLInfo(*this), TSInfo(*this),
Chris Lattner8a0631d2010-02-02 19:23:55 +000053 InstrItins(Subtarget.getInstrItineraryData()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000055 if (getRelocationModel() == Reloc::Default) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 if (Subtarget.isDarwin())
57 setRelocationModel(Reloc::DynamicNoPIC);
58 else
59 setRelocationModel(Reloc::Static);
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000060 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061}
62
63/// Override this for PowerPC. Tail merging happily breaks up instruction issue
64/// groups, which typically degrades performance.
Dan Gohman62ea18a2007-11-19 20:46:23 +000065bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000067PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000068 const std::string &FS)
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000069 : PPCTargetMachine(T, TT, FS, false) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070}
71
72
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000073PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000074 const std::string &FS)
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000075 : PPCTargetMachine(T, TT, FS, true) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076}
77
78
79//===----------------------------------------------------------------------===//
80// Pass Pipeline Configuration
81//===----------------------------------------------------------------------===//
82
Bill Wendling5ed22ac2009-04-29 23:29:43 +000083bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
84 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000085 // Install an instruction selector.
86 PM.add(createPPCISelDag(*this));
87 return false;
88}
89
Bill Wendling5ed22ac2009-04-29 23:29:43 +000090bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
91 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092 // Must run branch selection immediately preceding the asm printer.
93 PM.add(createPPCBranchSelectionPass());
94 return false;
95}
96
Bill Wendling5ed22ac2009-04-29 23:29:43 +000097bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
98 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +000099 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-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 Lopes1ea31ff2009-05-30 20:51:52 +0000120
121 return false;
122}