blob: 48c50614345f7a08efa9cee2a24c9c847e8a583e [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"
Reid Spencer551ccae2004-09-01 22:55:40 +000028#include "llvm/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)");
Chris Lattnerf9088882004-08-20 18:09:18 +000045
46#if 0
Misha Brukman983e92d2004-08-19 21:36:14 +000047 RegisterTarget<PPC64TargetMachine>
48 Y("ppc64", " PowerPC 64-bit (unimplemented)");
Chris Lattnerf9088882004-08-20 18:09:18 +000049#endif
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000050}
51
Misha Brukman01458812004-08-11 00:11:25 +000052PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name,
53 IntrinsicLowering *IL,
54 const TargetData &TD,
Nate Begemanca068e82004-08-14 22:16:36 +000055 const PowerPCFrameInfo &TFI,
Misha Brukman66aa3e02004-08-17 05:06:47 +000056 const PowerPCJITInfo &TJI)
57 : TargetMachine(name, IL, TD), FrameInfo(TFI), JITInfo(TJI)
Misha Brukman1d3527e2004-08-11 23:47:08 +000058{}
Chris Lattnerd36c9702004-07-11 02:48:49 +000059
Misha Brukman01eca8d2004-07-12 23:36:12 +000060unsigned PowerPCTargetMachine::getJITMatchQuality() {
61#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
62 return 10;
63#else
64 return 0;
65#endif
66}
Misha Brukman01eca8d2004-07-12 23:36:12 +000067
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000068/// addPassesToEmitAssembly - Add passes to the specified pass manager
69/// to implement a static compiler for this target.
70///
71bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
72 std::ostream &Out) {
73 bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this));
74
75 // FIXME: Implement efficient support for garbage collection intrinsics.
76 PM.add(createLowerGCPass());
77
78 // FIXME: Implement the invoke/unwind instructions!
79 PM.add(createLowerInvokePass());
80
81 // FIXME: Implement the switch instruction in the instruction selector!
82 PM.add(createLowerSwitchPass());
83
84 PM.add(createLowerConstantExpressionsPass());
85
86 // Make sure that no unreachable blocks are instruction selected.
87 PM.add(createUnreachableBlockEliminationPass());
88
89 if (LP64)
Misha Brukman1d3527e2004-08-11 23:47:08 +000090 PM.add(createPPC64ISelSimple(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000091 else
92 PM.add(createPPC32ISelSimple(*this));
93
94 if (PrintMachineCode)
95 PM.add(createMachineFunctionPrinterPass(&std::cerr));
96
97 PM.add(createRegisterAllocator());
98
99 if (PrintMachineCode)
100 PM.add(createMachineFunctionPrinterPass(&std::cerr));
101
Nate Begemanca068e82004-08-14 22:16:36 +0000102 PM.add(createPrologEpilogCodeInserter());
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000103
Nate Begemanca068e82004-08-14 22:16:36 +0000104 // Must run branch selection immediately preceding the asm printer
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000105 PM.add(createPPCBranchSelectionPass());
106
107 if (AIX)
Nate Begemaned428532004-09-04 05:00:00 +0000108 PM.add(createAIXAsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000109 else
Nate Begemaned428532004-09-04 05:00:00 +0000110 PM.add(createDarwinAsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000111
112 PM.add(createMachineCodeDeleter());
113 return false;
114}
115
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000116void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000117 // FIXME: Implement efficient support for garbage collection intrinsics.
118 PM.add(createLowerGCPass());
119
120 // FIXME: Implement the invoke/unwind instructions!
121 PM.add(createLowerInvokePass());
122
123 // FIXME: Implement the switch instruction in the instruction selector!
124 PM.add(createLowerSwitchPass());
125
126 PM.add(createLowerConstantExpressionsPass());
127
128 // Make sure that no unreachable blocks are instruction selected.
129 PM.add(createUnreachableBlockEliminationPass());
130
131 PM.add(createPPC32ISelSimple(TM));
132 PM.add(createRegisterAllocator());
133 PM.add(createPrologEpilogCodeInserter());
Misha Brukman01458812004-08-11 00:11:25 +0000134}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000135
Misha Brukman01458812004-08-11 00:11:25 +0000136void PowerPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
137 assert(0 && "Cannot execute PowerPCJITInfo::replaceMachineCodeForFunction()");
138}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000139
Misha Brukman01458812004-08-11 00:11:25 +0000140void *PowerPCJITInfo::getJITStubForFunction(Function *F,
141 MachineCodeEmitter &MCE) {
142 assert(0 && "Cannot execute PowerPCJITInfo::getJITStubForFunction()");
143 return 0;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000144}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000145
146/// PowerPCTargetMachine ctor - Create an ILP32 architecture model
147///
Misha Brukman66aa3e02004-08-17 05:06:47 +0000148PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL)
149 : PowerPCTargetMachine(PPC32ID, IL,
150 TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,4),
Misha Brukman983e92d2004-08-19 21:36:14 +0000151 PowerPCFrameInfo(*this, false), PPC32JITInfo(*this)) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000152
153/// PPC64TargetMachine ctor - Create a LP64 architecture model
154///
155PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL)
Misha Brukman66aa3e02004-08-17 05:06:47 +0000156 : PowerPCTargetMachine(PPC64ID, IL,
157 TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,4),
Misha Brukman983e92d2004-08-19 21:36:14 +0000158 PowerPCFrameInfo(*this, true), PPC64JITInfo(*this)) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000159
160unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
161 if (M.getEndianness() == Module::BigEndian &&
162 M.getPointerSize() == Module::Pointer32)
163 return 10; // Direct match
164 else if (M.getEndianness() != Module::AnyEndianness ||
165 M.getPointerSize() != Module::AnyPointerSize)
166 return 0; // Match for some other target
167
168 return getJITMatchQuality()/2;
169}
170
171unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
172 if (M.getEndianness() == Module::BigEndian &&
173 M.getPointerSize() == Module::Pointer64)
174 return 10; // Direct match
175 else if (M.getEndianness() != Module::AnyEndianness ||
176 M.getPointerSize() != Module::AnyPointerSize)
177 return 0; // Match for some other target
178
179 return getJITMatchQuality()/2;
180}