blob: 95fe1be190e06ffbcac307c7e3d00bd9601a5968 [file] [log] [blame]
Misha Brukman5dfe3a92004-06-21 16:55:25 +00001//===-- PowerPCTargetMachine.cpp - Define TargetMachine for PowerPC -------===//
2//
3// The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
Misha Brukman5dfe3a92004-06-21 16:55:25 +000013#include "PowerPC.h"
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000014#include "PowerPCTargetMachine.h"
15#include "PPC32TargetMachine.h"
16#include "PPC64TargetMachine.h"
17#include "PPC32JITInfo.h"
18#include "PPC64JITInfo.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000019#include "llvm/Module.h"
20#include "llvm/PassManager.h"
Misha Brukman8c9f5202004-06-21 18:30:31 +000021#include "llvm/CodeGen/IntrinsicLowering.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000022#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/Passes.h"
Chris Lattner68905bb2004-07-11 04:17:58 +000024#include "llvm/Target/TargetOptions.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000025#include "llvm/Target/TargetMachineRegistry.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000026#include "llvm/Transforms/Scalar.h"
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000027#include "Support/CommandLine.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000028#include <iostream>
Misha Brukman5dfe3a92004-06-21 16:55:25 +000029using namespace llvm;
30
Misha Brukman1d3527e2004-08-11 23:47:08 +000031namespace llvm {
32 cl::opt<bool> AIX("aix",
33 cl::desc("Generate AIX/xcoff instead of Darwin/MachO"),
34 cl::Hidden);
35}
36
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000037namespace {
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000038 const std::string PPC32 = "PowerPC/32bit";
39 const std::string PPC64 = "PowerPC/64bit";
40
41 // Register the targets
42 RegisterTarget<PPC32TargetMachine>
Misha Brukman95828222004-08-11 13:35:44 +000043 X("ppc32", " PowerPC 32-bit (experimental)");
Misha Brukmanf5f70682004-08-12 17:16:43 +000044 //RegisterTarget<PPC64TargetMachine>
45 //Y("ppc64", " PowerPC 64-bit (unimplemented)");
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000046}
47
Misha Brukman01458812004-08-11 00:11:25 +000048PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name,
49 IntrinsicLowering *IL,
50 const TargetData &TD,
51 const TargetFrameInfo &TFI,
Misha Brukman1d3527e2004-08-11 23:47:08 +000052 const PowerPCJITInfo &TJI,
53 bool is64b)
54 : TargetMachine(name, IL, TD), InstrInfo(is64b), FrameInfo(TFI), JITInfo(TJI)
55{}
Chris Lattnerd36c9702004-07-11 02:48:49 +000056
Misha Brukman01eca8d2004-07-12 23:36:12 +000057unsigned PowerPCTargetMachine::getJITMatchQuality() {
58#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
59 return 10;
60#else
61 return 0;
62#endif
63}
Misha Brukman01eca8d2004-07-12 23:36:12 +000064
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000065/// addPassesToEmitAssembly - Add passes to the specified pass manager
66/// to implement a static compiler for this target.
67///
68bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
69 std::ostream &Out) {
70 bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this));
71
72 // FIXME: Implement efficient support for garbage collection intrinsics.
73 PM.add(createLowerGCPass());
74
75 // FIXME: Implement the invoke/unwind instructions!
76 PM.add(createLowerInvokePass());
77
78 // FIXME: Implement the switch instruction in the instruction selector!
79 PM.add(createLowerSwitchPass());
80
81 PM.add(createLowerConstantExpressionsPass());
82
83 // Make sure that no unreachable blocks are instruction selected.
84 PM.add(createUnreachableBlockEliminationPass());
85
86 if (LP64)
Misha Brukman1d3527e2004-08-11 23:47:08 +000087 PM.add(createPPC64ISelSimple(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000088 else
89 PM.add(createPPC32ISelSimple(*this));
90
91 if (PrintMachineCode)
92 PM.add(createMachineFunctionPrinterPass(&std::cerr));
93
94 PM.add(createRegisterAllocator());
95
96 if (PrintMachineCode)
97 PM.add(createMachineFunctionPrinterPass(&std::cerr));
98
Misha Brukman95828222004-08-11 13:35:44 +000099 // PowerPC-specific prolog/epilog code inserter to put the fills/spills in the
100 // right spots.
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000101 PM.add(createPowerPCPEI());
102
103 // Must run branch selection immediately preceding the printer
104 PM.add(createPPCBranchSelectionPass());
105
106 if (AIX)
Misha Brukman1d3527e2004-08-11 23:47:08 +0000107 PM.add(createPPC64AsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000108 else
109 PM.add(createPPC32AsmPrinter(Out, *this));
110
111 PM.add(createMachineCodeDeleter());
112 return false;
113}
114
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000115void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000116 // FIXME: Implement efficient support for garbage collection intrinsics.
117 PM.add(createLowerGCPass());
118
119 // FIXME: Implement the invoke/unwind instructions!
120 PM.add(createLowerInvokePass());
121
122 // FIXME: Implement the switch instruction in the instruction selector!
123 PM.add(createLowerSwitchPass());
124
125 PM.add(createLowerConstantExpressionsPass());
126
127 // Make sure that no unreachable blocks are instruction selected.
128 PM.add(createUnreachableBlockEliminationPass());
129
130 PM.add(createPPC32ISelSimple(TM));
131 PM.add(createRegisterAllocator());
132 PM.add(createPrologEpilogCodeInserter());
Misha Brukman01458812004-08-11 00:11:25 +0000133}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000134
Misha Brukman01458812004-08-11 00:11:25 +0000135void PowerPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
136 assert(0 && "Cannot execute PowerPCJITInfo::replaceMachineCodeForFunction()");
137}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000138
Misha Brukman01458812004-08-11 00:11:25 +0000139void *PowerPCJITInfo::getJITStubForFunction(Function *F,
140 MachineCodeEmitter &MCE) {
141 assert(0 && "Cannot execute PowerPCJITInfo::getJITStubForFunction()");
142 return 0;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000143}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000144
145/// PowerPCTargetMachine ctor - Create an ILP32 architecture model
146///
147PPC32TargetMachine::PPC32TargetMachine(const Module &M,
148 IntrinsicLowering *IL)
149 : PowerPCTargetMachine(PPC32, IL,
150 TargetData(PPC32,false,4,4,4,4,4,4,2,1,4),
151 TargetFrameInfo(TargetFrameInfo::StackGrowsDown,16,0),
Misha Brukman1d3527e2004-08-11 23:47:08 +0000152 PPC32JITInfo(*this), false) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000153
154/// PPC64TargetMachine ctor - Create a LP64 architecture model
155///
156PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL)
157 : PowerPCTargetMachine(PPC64, IL,
158 TargetData(PPC64,false,8,4,4,4,4,4,2,1,4),
159 TargetFrameInfo(TargetFrameInfo::StackGrowsDown,16,0),
Misha Brukman1d3527e2004-08-11 23:47:08 +0000160 PPC64JITInfo(*this), true) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000161
162unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
163 if (M.getEndianness() == Module::BigEndian &&
164 M.getPointerSize() == Module::Pointer32)
165 return 10; // Direct match
166 else if (M.getEndianness() != Module::AnyEndianness ||
167 M.getPointerSize() != Module::AnyPointerSize)
168 return 0; // Match for some other target
169
170 return getJITMatchQuality()/2;
171}
172
173unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
174 if (M.getEndianness() == Module::BigEndian &&
175 M.getPointerSize() == Module::Pointer64)
176 return 10; // Direct match
177 else if (M.getEndianness() != Module::AnyEndianness ||
178 M.getPointerSize() != Module::AnyPointerSize)
179 return 0; // Match for some other target
180
181 return getJITMatchQuality()/2;
182}