blob: b25915e25a1a7c9da8c24e3dbf96722fa2dcd3da [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>
Chris Lattnercbb98122004-10-10 16:26:13 +000044 X("ppc32", " PowerPC 32-bit");
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() {
Chris Lattner097714b2004-10-25 20:53:41 +000061 return 0;
Misha Brukman01eca8d2004-07-12 23:36:12 +000062#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
63 return 10;
64#else
65 return 0;
66#endif
67}
Misha Brukman01eca8d2004-07-12 23:36:12 +000068
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000069/// addPassesToEmitAssembly - Add passes to the specified pass manager
70/// to implement a static compiler for this target.
71///
72bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
73 std::ostream &Out) {
74 bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this));
75
76 // FIXME: Implement efficient support for garbage collection intrinsics.
77 PM.add(createLowerGCPass());
78
79 // FIXME: Implement the invoke/unwind instructions!
80 PM.add(createLowerInvokePass());
81
82 // FIXME: Implement the switch instruction in the instruction selector!
83 PM.add(createLowerSwitchPass());
84
85 PM.add(createLowerConstantExpressionsPass());
86
87 // Make sure that no unreachable blocks are instruction selected.
88 PM.add(createUnreachableBlockEliminationPass());
89
90 if (LP64)
Misha Brukman1d3527e2004-08-11 23:47:08 +000091 PM.add(createPPC64ISelSimple(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000092 else
93 PM.add(createPPC32ISelSimple(*this));
94
95 if (PrintMachineCode)
96 PM.add(createMachineFunctionPrinterPass(&std::cerr));
97
98 PM.add(createRegisterAllocator());
99
100 if (PrintMachineCode)
101 PM.add(createMachineFunctionPrinterPass(&std::cerr));
102
Nate Begemanca068e82004-08-14 22:16:36 +0000103 PM.add(createPrologEpilogCodeInserter());
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000104
Nate Begemanca068e82004-08-14 22:16:36 +0000105 // Must run branch selection immediately preceding the asm printer
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000106 PM.add(createPPCBranchSelectionPass());
107
108 if (AIX)
Nate Begemaned428532004-09-04 05:00:00 +0000109 PM.add(createAIXAsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000110 else
Nate Begemaned428532004-09-04 05:00:00 +0000111 PM.add(createDarwinAsmPrinter(Out, *this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000112
113 PM.add(createMachineCodeDeleter());
114 return false;
115}
116
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000117void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000118 // FIXME: Implement efficient support for garbage collection intrinsics.
119 PM.add(createLowerGCPass());
120
121 // FIXME: Implement the invoke/unwind instructions!
122 PM.add(createLowerInvokePass());
123
124 // FIXME: Implement the switch instruction in the instruction selector!
125 PM.add(createLowerSwitchPass());
126
127 PM.add(createLowerConstantExpressionsPass());
128
129 // Make sure that no unreachable blocks are instruction selected.
130 PM.add(createUnreachableBlockEliminationPass());
131
132 PM.add(createPPC32ISelSimple(TM));
133 PM.add(createRegisterAllocator());
134 PM.add(createPrologEpilogCodeInserter());
Misha Brukman01458812004-08-11 00:11:25 +0000135}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000136
Misha Brukman01458812004-08-11 00:11:25 +0000137void PowerPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
138 assert(0 && "Cannot execute PowerPCJITInfo::replaceMachineCodeForFunction()");
139}
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000140
Misha Brukman01458812004-08-11 00:11:25 +0000141void *PowerPCJITInfo::getJITStubForFunction(Function *F,
142 MachineCodeEmitter &MCE) {
143 assert(0 && "Cannot execute PowerPCJITInfo::getJITStubForFunction()");
144 return 0;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000145}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000146
147/// PowerPCTargetMachine ctor - Create an ILP32 architecture model
148///
Misha Brukman66aa3e02004-08-17 05:06:47 +0000149PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL)
150 : PowerPCTargetMachine(PPC32ID, IL,
151 TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,4),
Misha Brukman983e92d2004-08-19 21:36:14 +0000152 PowerPCFrameInfo(*this, false), PPC32JITInfo(*this)) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000153
154/// PPC64TargetMachine ctor - Create a LP64 architecture model
155///
156PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL)
Misha Brukman66aa3e02004-08-17 05:06:47 +0000157 : PowerPCTargetMachine(PPC64ID, IL,
158 TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,4),
Misha Brukman983e92d2004-08-19 21:36:14 +0000159 PowerPCFrameInfo(*this, true), PPC64JITInfo(*this)) {}
Nate Begeman7a4fe9b2004-08-11 07:40:04 +0000160
161unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
162 if (M.getEndianness() == Module::BigEndian &&
163 M.getPointerSize() == Module::Pointer32)
164 return 10; // Direct match
165 else if (M.getEndianness() != Module::AnyEndianness ||
166 M.getPointerSize() != Module::AnyPointerSize)
167 return 0; // Match for some other target
168
169 return getJITMatchQuality()/2;
170}
171
172unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
173 if (M.getEndianness() == Module::BigEndian &&
174 M.getPointerSize() == Module::Pointer64)
175 return 10; // Direct match
176 else if (M.getEndianness() != Module::AnyEndianness ||
177 M.getPointerSize() != Module::AnyPointerSize)
178 return 0; // Match for some other target
179
180 return getJITMatchQuality()/2;
181}