1 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Top-level implementation for the PowerPC target.
12 //===----------------------------------------------------------------------===//
15 #include "PPCTargetAsmInfo.h"
16 #include "PPCTargetMachine.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Target/TargetMachineRegistry.h"
23 // Register the targets
24 RegisterTarget<PPC32TargetMachine>
25 X("ppc32", " PowerPC 32");
26 RegisterTarget<PPC64TargetMachine>
27 Y("ppc64", " PowerPC 64");
30 const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
31 return new DarwinTargetAsmInfo(*this);
34 unsigned PPC32TargetMachine::getJITMatchQuality() {
35 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
36 if (sizeof(void*) == 4)
41 unsigned PPC64TargetMachine::getJITMatchQuality() {
42 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
43 if (sizeof(void*) == 8)
49 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
50 // We strongly match "powerpc-*".
51 std::string TT = M.getTargetTriple();
52 if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
55 if (M.getEndianness() == Module::BigEndian &&
56 M.getPointerSize() == Module::Pointer32)
57 return 10; // Weak match
58 else if (M.getEndianness() != Module::AnyEndianness ||
59 M.getPointerSize() != Module::AnyPointerSize)
60 return 0; // Match for some other target
62 return getJITMatchQuality()/2;
65 unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
66 // We strongly match "powerpc64-*".
67 std::string TT = M.getTargetTriple();
68 if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
71 if (M.getEndianness() == Module::BigEndian &&
72 M.getPointerSize() == Module::Pointer64)
73 return 10; // Weak match
74 else if (M.getEndianness() != Module::AnyEndianness ||
75 M.getPointerSize() != Module::AnyPointerSize)
76 return 0; // Match for some other target
78 return getJITMatchQuality()/2;
82 PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS,
84 : Subtarget(M, FS, is64Bit),
85 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
86 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
87 InstrItins(Subtarget.getInstrItineraryData()) {
89 if (getRelocationModel() == Reloc::Default)
90 if (Subtarget.isDarwin())
91 setRelocationModel(Reloc::DynamicNoPIC);
93 setRelocationModel(Reloc::PIC_);
96 PPC32TargetMachine::PPC32TargetMachine(const Module &M, const std::string &FS)
97 : PPCTargetMachine(M, FS, false) {
101 PPC64TargetMachine::PPC64TargetMachine(const Module &M, const std::string &FS)
102 : PPCTargetMachine(M, FS, true) {
106 //===----------------------------------------------------------------------===//
107 // Pass Pipeline Configuration
108 //===----------------------------------------------------------------------===//
110 bool PPCTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
111 // Install an instruction selector.
112 PM.add(createPPCISelDag(*this));
116 bool PPCTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
118 // Must run branch selection immediately preceding the asm printer.
119 PM.add(createPPCBranchSelectionPass());
123 bool PPCTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
125 PM.add(createPPCAsmPrinterPass(Out, *this));
129 bool PPCTargetMachine::addObjectWriter(FunctionPassManager &PM, bool Fast,
131 // FIXME: support PPC ELF files at some point
132 addPPCMachOObjectWriterPass(PM, Out, *this);
136 bool PPCTargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
137 MachineCodeEmitter &MCE) {
138 // The JIT should use the static relocation model.
139 // FIXME: This should be moved to TargetJITInfo!!
140 setRelocationModel(Reloc::Static);
142 // Machine code emitter pass for PowerPC.
143 PM.add(createPPCCodeEmitterPass(*this, MCE));