Remove this method, it's not clear how it could be implemented indep of 32 or 64...
[oota-llvm.git] / lib / Target / PowerPC / PPCTargetMachine.cpp
1 //===-- 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
13 #include "PowerPC.h"
14 #include "PowerPCTargetMachine.h"
15 #include "PowerPCFrameInfo.h"
16 #include "PPC32TargetMachine.h"
17 #include "PPC64TargetMachine.h"
18 #include "PPC32JITInfo.h"
19 #include "PPC64JITInfo.h"
20 #include "llvm/Module.h"
21 #include "llvm/PassManager.h"
22 #include "llvm/CodeGen/IntrinsicLowering.h"
23 #include "llvm/CodeGen/MachineFunction.h"
24 #include "llvm/CodeGen/Passes.h"
25 #include "llvm/Target/TargetOptions.h"
26 #include "llvm/Target/TargetMachineRegistry.h"
27 #include "llvm/Transforms/Scalar.h"
28 #include "llvm/Support/CommandLine.h"
29 #include <iostream>
30 using namespace llvm;
31
32 namespace llvm {
33   cl::opt<bool> AIX("aix", 
34                     cl::desc("Generate AIX/xcoff instead of Darwin/MachO"), 
35                     cl::Hidden);
36 }
37
38 namespace {
39   const std::string PPC32ID = "PowerPC/32bit";
40   const std::string PPC64ID = "PowerPC/64bit";
41   
42   // Register the targets
43   RegisterTarget<PPC32TargetMachine> 
44   X("ppc32", "  PowerPC 32-bit");
45
46 #if 0
47   RegisterTarget<PPC64TargetMachine> 
48   Y("ppc64", "  PowerPC 64-bit (unimplemented)");
49 #endif
50 }
51
52 PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name,
53                                            IntrinsicLowering *IL,
54                                            const TargetData &TD,
55                                            const PowerPCFrameInfo &TFI,
56                                            const PowerPCJITInfo &TJI) 
57   : TargetMachine(name, IL, TD), FrameInfo(TFI), JITInfo(TJI) 
58 {}
59
60 unsigned PowerPCTargetMachine::getJITMatchQuality() {
61   return 0;
62 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
63   return 10;
64 #else
65   return 0;
66 #endif
67 }
68
69 /// addPassesToEmitAssembly - Add passes to the specified pass manager
70 /// to implement a static compiler for this target.
71 ///
72 bool 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)
91     PM.add(createPPC64ISelSimple(*this));
92   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
103   PM.add(createPrologEpilogCodeInserter());
104   
105   // Must run branch selection immediately preceding the asm printer
106   PM.add(createPPCBranchSelectionPass());
107   
108   if (AIX)
109     PM.add(createAIXAsmPrinter(Out, *this));
110   else
111     PM.add(createDarwinAsmPrinter(Out, *this));
112     
113   PM.add(createMachineCodeDeleter());
114   return false;
115 }
116
117 void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
118   // 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());
135 }
136
137 void PowerPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
138   assert(0 && "Cannot execute PowerPCJITInfo::replaceMachineCodeForFunction()");
139 }
140
141 /// PowerPCTargetMachine ctor - Create an ILP32 architecture model
142 ///
143 PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL)
144   : PowerPCTargetMachine(PPC32ID, IL, 
145                          TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,4),
146                          PowerPCFrameInfo(*this, false), PPC32JITInfo(*this)) {}
147
148 /// PPC64TargetMachine ctor - Create a LP64 architecture model
149 ///
150 PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL)
151   : PowerPCTargetMachine(PPC64ID, IL,
152                          TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,4),
153                          PowerPCFrameInfo(*this, true), PPC64JITInfo(*this)) {}
154
155 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
156   if (M.getEndianness()  == Module::BigEndian &&
157       M.getPointerSize() == Module::Pointer32)
158     return 10;                                   // Direct match
159   else if (M.getEndianness() != Module::AnyEndianness ||
160            M.getPointerSize() != Module::AnyPointerSize)
161     return 0;                                    // Match for some other target
162
163   return getJITMatchQuality()/2;
164 }
165
166 unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
167   if (M.getEndianness()  == Module::BigEndian &&
168       M.getPointerSize() == Module::Pointer64)
169     return 10;                                   // Direct match
170   else if (M.getEndianness() != Module::AnyEndianness ||
171            M.getPointerSize() != Module::AnyPointerSize)
172     return 0;                                    // Match for some other target
173
174   return getJITMatchQuality()/2;
175 }