blob: a83c75e439c00a0c6076f9577ed486c301253bb3 [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 {
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000039 const std::string PPC32 = "PowerPC/32bit";
40 const std::string PPC64 = "PowerPC/64bit";
41
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 Brukman1d3527e2004-08-11 23:47:08 +000053 const PowerPCJITInfo &TJI,
54 bool is64b)
55 : TargetMachine(name, IL, TD), InstrInfo(is64b), FrameInfo(TFI), JITInfo(TJI)
56{}
Chris Lattnerd36c9702004-07-11 02:48:49 +000057
Misha Brukman01eca8d2004-07-12 23:36:12 +000058unsigned PowerPCTargetMachine::getJITMatchQuality() {
59#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
60 return 10;
61#else
62 return 0;
63#endif
64}
Misha Brukman01eca8d2004-07-12 23:36:12 +000065
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000066/// addPassesToEmitAssembly - Add passes to the specified pass manager
67/// to implement a static compiler for this target.
68///
69bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
70 std::ostream &Out) {
71 bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this));
72
73 // FIXME: Implement efficient support for garbage collection intrinsics.
74 PM.add(createLowerGCPass());
75
76 // FIXME: Implement the invoke/unwind instructions!
77 PM.add(createLowerInvokePass());
78
79 // FIXME: Implement the switch instruction in the instruction selector!
80 PM.add(createLowerSwitchPass());
81
82 PM.add(createLowerConstantExpressionsPass());
83
84 // Make sure that no unreachable blocks are instruction selected.
85 PM.add(createUnreachableBlockEliminationPass());
86
87 if (LP64)
Misha Brukman1d3527e2004-08-11 23:47:08 +000088 PM.add(createPPC64ISelSimple(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000089 else
90 PM.add(createPPC32ISelSimple(*this));
91
92 if (PrintMachineCode)
93 PM.add(createMachineFunctionPrinterPass(&std::cerr));
94
95 PM.add(createRegisterAllocator());
96
97 if (PrintMachineCode)
98 PM.add(createMachineFunctionPrinterPass(&std::cerr));
99
Nate Begemanca068e82004-08-14 22:16:36 +0000100 PM.add(createPrologEpilogCodeInserter());
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000101
Nate Begemanca068e82004-08-14 22:16:36 +0000102 // Must run branch selection immediately preceding the asm printer
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000103 PM.add(createPPCBranchSelectionPass());
104
105 if (AIX)
Misha Brukman1d3527e2004-08-11 23:47:08 +0000106 PM.add(createPPC64AsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000107 else
Nate Begemanca068e82004-08-14 22:16:36 +0000108 PM.add(createPPCAsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000109
110 PM.add(createMachineCodeDeleter());
111 return false;
112}
113
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000114void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000115 // FIXME: Implement efficient support for garbage collection intrinsics.
116 PM.add(createLowerGCPass());
117
118 // FIXME: Implement the invoke/unwind instructions!
119 PM.add(createLowerInvokePass());
120
121 // FIXME: Implement the switch instruction in the instruction selector!
122 PM.add(createLowerSwitchPass());
123
124 PM.add(createLowerConstantExpressionsPass());
125
126 // Make sure that no unreachable blocks are instruction selected.
127 PM.add(createUnreachableBlockEliminationPass());
128
129 PM.add(createPPC32ISelSimple(TM));
130 PM.add(createRegisterAllocator());
131 PM.add(createPrologEpilogCodeInserter());
Misha Brukman01458812004-08-11 00:11:25 +0000132}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000133
Misha Brukman01458812004-08-11 00:11:25 +0000134void PowerPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
135 assert(0 && "Cannot execute PowerPCJITInfo::replaceMachineCodeForFunction()");
136}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000137
Misha Brukman01458812004-08-11 00:11:25 +0000138void *PowerPCJITInfo::getJITStubForFunction(Function *F,
139 MachineCodeEmitter &MCE) {
140 assert(0 && "Cannot execute PowerPCJITInfo::getJITStubForFunction()");
141 return 0;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000142}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000143
144/// PowerPCTargetMachine ctor - Create an ILP32 architecture model
145///
146PPC32TargetMachine::PPC32TargetMachine(const Module &M,
147 IntrinsicLowering *IL)
148 : PowerPCTargetMachine(PPC32, IL,
149 TargetData(PPC32,false,4,4,4,4,4,4,2,1,4),
Nate Begemanca068e82004-08-14 22:16:36 +0000150 PowerPCFrameInfo(*this), PPC32JITInfo(*this), false) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000151
152/// PPC64TargetMachine ctor - Create a LP64 architecture model
153///
154PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL)
155 : PowerPCTargetMachine(PPC64, IL,
156 TargetData(PPC64,false,8,4,4,4,4,4,2,1,4),
Nate Begemanca068e82004-08-14 22:16:36 +0000157 PowerPCFrameInfo(*this), PPC64JITInfo(*this), true) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000158
159unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
160 if (M.getEndianness() == Module::BigEndian &&
161 M.getPointerSize() == Module::Pointer32)
162 return 10; // Direct match
163 else if (M.getEndianness() != Module::AnyEndianness ||
164 M.getPointerSize() != Module::AnyPointerSize)
165 return 0; // Match for some other target
166
167 return getJITMatchQuality()/2;
168}
169
170unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
171 if (M.getEndianness() == Module::BigEndian &&
172 M.getPointerSize() == Module::Pointer64)
173 return 10; // Direct match
174 else if (M.getEndianness() != Module::AnyEndianness ||
175 M.getPointerSize() != Module::AnyPointerSize)
176 return 0; // Match for some other target
177
178 return getJITMatchQuality()/2;
179}