blob: b7e45a3e0b8dc2b869120e9553c7ab565c4a0f3c [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"
Nate Begemanca068e82004-08-14 22:16:36 +000015#include "PowerPCFrameInfo.h"
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000016#include "PPC32TargetMachine.h"
17#include "PPC64TargetMachine.h"
18#include "PPC32JITInfo.h"
19#include "PPC64JITInfo.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000020#include "llvm/Module.h"
21#include "llvm/PassManager.h"
Misha Brukman8c9f5202004-06-21 18:30:31 +000022#include "llvm/CodeGen/IntrinsicLowering.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000023#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/Passes.h"
Chris Lattner68905bb2004-07-11 04:17:58 +000025#include "llvm/Target/TargetOptions.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000026#include "llvm/Target/TargetMachineRegistry.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000027#include "llvm/Transforms/Scalar.h"
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000028#include "Support/CommandLine.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000029#include <iostream>
Misha Brukman5dfe3a92004-06-21 16:55:25 +000030using namespace llvm;
31
Misha Brukman1d3527e2004-08-11 23:47:08 +000032namespace llvm {
33 cl::opt<bool> AIX("aix",
34 cl::desc("Generate AIX/xcoff instead of Darwin/MachO"),
35 cl::Hidden);
36}
37
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000038namespace {
Misha Brukman66aa3e02004-08-17 05:06:47 +000039 const std::string PPC32ID = "PowerPC/32bit";
40 const std::string PPC64ID = "PowerPC/64bit";
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000041
42 // Register the targets
43 RegisterTarget<PPC32TargetMachine>
Misha Brukman95828222004-08-11 13:35:44 +000044 X("ppc32", " PowerPC 32-bit (experimental)");
Misha Brukmanf5f70682004-08-12 17:16:43 +000045 //RegisterTarget<PPC64TargetMachine>
46 //Y("ppc64", " PowerPC 64-bit (unimplemented)");
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000047}
48
Misha Brukman01458812004-08-11 00:11:25 +000049PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name,
50 IntrinsicLowering *IL,
51 const TargetData &TD,
Nate Begemanca068e82004-08-14 22:16:36 +000052 const PowerPCFrameInfo &TFI,
Misha Brukman66aa3e02004-08-17 05:06:47 +000053 const PowerPCJITInfo &TJI)
54 : TargetMachine(name, IL, TD), FrameInfo(TFI), JITInfo(TJI)
Misha Brukman1d3527e2004-08-11 23:47:08 +000055{}
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
Nate Begemanca068e82004-08-14 22:16:36 +000099 PM.add(createPrologEpilogCodeInserter());
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000100
Nate Begemanca068e82004-08-14 22:16:36 +0000101 // Must run branch selection immediately preceding the asm printer
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000102 PM.add(createPPCBranchSelectionPass());
103
104 if (AIX)
Misha Brukman1d3527e2004-08-11 23:47:08 +0000105 PM.add(createPPC64AsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000106 else
Misha Brukman66aa3e02004-08-17 05:06:47 +0000107 PM.add(createPPC32AsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000108
109 PM.add(createMachineCodeDeleter());
110 return false;
111}
112
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000113void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000114 // FIXME: Implement efficient support for garbage collection intrinsics.
115 PM.add(createLowerGCPass());
116
117 // FIXME: Implement the invoke/unwind instructions!
118 PM.add(createLowerInvokePass());
119
120 // FIXME: Implement the switch instruction in the instruction selector!
121 PM.add(createLowerSwitchPass());
122
123 PM.add(createLowerConstantExpressionsPass());
124
125 // Make sure that no unreachable blocks are instruction selected.
126 PM.add(createUnreachableBlockEliminationPass());
127
128 PM.add(createPPC32ISelSimple(TM));
129 PM.add(createRegisterAllocator());
130 PM.add(createPrologEpilogCodeInserter());
Misha Brukman01458812004-08-11 00:11:25 +0000131}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000132
Misha Brukman01458812004-08-11 00:11:25 +0000133void PowerPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
134 assert(0 && "Cannot execute PowerPCJITInfo::replaceMachineCodeForFunction()");
135}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000136
Misha Brukman01458812004-08-11 00:11:25 +0000137void *PowerPCJITInfo::getJITStubForFunction(Function *F,
138 MachineCodeEmitter &MCE) {
139 assert(0 && "Cannot execute PowerPCJITInfo::getJITStubForFunction()");
140 return 0;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000141}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000142
143/// PowerPCTargetMachine ctor - Create an ILP32 architecture model
144///
Misha Brukman66aa3e02004-08-17 05:06:47 +0000145PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL)
146 : PowerPCTargetMachine(PPC32ID, IL,
147 TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,4),
148 PowerPCFrameInfo(*this), PPC32JITInfo(*this)) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000149
150/// PPC64TargetMachine ctor - Create a LP64 architecture model
151///
152PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL)
Misha Brukman66aa3e02004-08-17 05:06:47 +0000153 : PowerPCTargetMachine(PPC64ID, IL,
154 TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,4),
155 PowerPCFrameInfo(*this), PPC64JITInfo(*this)) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000156
157unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
158 if (M.getEndianness() == Module::BigEndian &&
159 M.getPointerSize() == Module::Pointer32)
160 return 10; // Direct match
161 else if (M.getEndianness() != Module::AnyEndianness ||
162 M.getPointerSize() != Module::AnyPointerSize)
163 return 0; // Match for some other target
164
165 return getJITMatchQuality()/2;
166}
167
168unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
169 if (M.getEndianness() == Module::BigEndian &&
170 M.getPointerSize() == Module::Pointer64)
171 return 10; // Direct match
172 else if (M.getEndianness() != Module::AnyEndianness ||
173 M.getPointerSize() != Module::AnyPointerSize)
174 return 0; // Match for some other target
175
176 return getJITMatchQuality()/2;
177}