Undisable ppc64 jit
[oota-llvm.git] / lib / Target / PowerPC / PPCTargetMachine.cpp
1 //===-- PPCTargetMachine.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 // Top-level implementation for the PowerPC target.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PPC.h"
15 #include "PPCFrameInfo.h"
16 #include "PPCTargetMachine.h"
17 #include "PPCJITInfo.h"
18 #include "llvm/Module.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/Analysis/Verifier.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/Passes.h"
23 #include "llvm/Target/TargetOptions.h"
24 #include "llvm/Target/TargetMachineRegistry.h"
25 #include "llvm/Transforms/Scalar.h"
26 #include "llvm/Support/CommandLine.h"
27 #include <iostream>
28 using namespace llvm;
29
30 namespace {
31   // Register the targets
32   RegisterTarget<PPC32TargetMachine>
33   X("ppc32", "  PowerPC 32");
34   RegisterTarget<PPC64TargetMachine>
35   Y("ppc64", "  PowerPC 64");
36 }
37
38 unsigned PPC32TargetMachine::getJITMatchQuality() {
39 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
40   if (sizeof(void*) == 4)
41     return 10;
42 #else
43   return 0;
44 #endif
45 }
46 unsigned PPC64TargetMachine::getJITMatchQuality() {
47 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
48   if (sizeof(void*) == 8)
49     return 10;
50 #endif
51   return 0;
52 }
53
54 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
55   // We strongly match "powerpc-*".
56   std::string TT = M.getTargetTriple();
57   if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
58     return 20;
59   
60   if (M.getEndianness()  == Module::BigEndian &&
61       M.getPointerSize() == Module::Pointer32)
62     return 10;                                   // Weak match
63   else if (M.getEndianness() != Module::AnyEndianness ||
64            M.getPointerSize() != Module::AnyPointerSize)
65     return 0;                                    // Match for some other target
66   
67   return getJITMatchQuality()/2;
68 }
69
70 unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
71   // We strongly match "powerpc64-*".
72   std::string TT = M.getTargetTriple();
73   if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
74     return 20;
75   
76   if (M.getEndianness()  == Module::BigEndian &&
77       M.getPointerSize() == Module::Pointer64)
78     return 10;                                   // Weak match
79   else if (M.getEndianness() != Module::AnyEndianness ||
80            M.getPointerSize() != Module::AnyPointerSize)
81     return 0;                                    // Match for some other target
82   
83   return getJITMatchQuality()/2;
84 }
85
86
87 PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS,
88                                    bool is64Bit)
89   : TargetMachine("PowerPC"), Subtarget(M, FS, is64Bit),
90     DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
91     FrameInfo(*this, false), JITInfo(*this), TLInfo(*this),
92     InstrItins(Subtarget.getInstrItineraryData()) {
93
94   if (getRelocationModel() == Reloc::Default)
95     if (Subtarget.isDarwin())
96       setRelocationModel(Reloc::DynamicNoPIC);
97     else
98       setRelocationModel(Reloc::PIC);
99 }
100
101 PPC32TargetMachine::PPC32TargetMachine(const Module &M, const std::string &FS) 
102   : PPCTargetMachine(M, FS, false) {
103 }
104
105
106 PPC64TargetMachine::PPC64TargetMachine(const Module &M, const std::string &FS)
107   : PPCTargetMachine(M, FS, true) {
108 }
109
110 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
111 /// a static compiler for this target.
112 ///
113 bool PPCTargetMachine::addPassesToEmitFile(PassManager &PM,
114                                            std::ostream &Out,
115                                            CodeGenFileType FileType,
116                                            bool Fast) {
117   if (FileType != TargetMachine::AssemblyFile) return true;
118   
119   // Run loop strength reduction before anything else.
120   if (!Fast) PM.add(createLoopStrengthReducePass(&TLInfo));
121
122   // FIXME: Implement efficient support for garbage collection intrinsics.
123   PM.add(createLowerGCPass());
124
125   // FIXME: Implement the invoke/unwind instructions!
126   PM.add(createLowerInvokePass());
127   
128   // Clean up after other passes, e.g. merging critical edges.
129   if (!Fast) PM.add(createCFGSimplificationPass());
130
131   // Make sure that no unreachable blocks are instruction selected.
132   PM.add(createUnreachableBlockEliminationPass());
133
134   // Install an instruction selector.
135   PM.add(createPPCISelDag(*this));
136
137   if (PrintMachineCode)
138     PM.add(createMachineFunctionPrinterPass(&std::cerr));
139
140   PM.add(createRegisterAllocator());
141
142   if (PrintMachineCode)
143     PM.add(createMachineFunctionPrinterPass(&std::cerr));
144
145   PM.add(createPrologEpilogCodeInserter());
146
147   // Must run branch selection immediately preceding the asm printer
148   PM.add(createPPCBranchSelectionPass());
149
150   // Decide which asm printer to use.  If the user has not specified one on
151   // the command line, choose whichever one matches the default (current host).
152   if (Subtarget.isAIX())
153     PM.add(createAIXAsmPrinter(Out, *this));
154   else
155     PM.add(createDarwinAsmPrinter(Out, *this));
156
157   PM.add(createMachineCodeDeleter());
158   return false;
159 }
160
161 void PPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
162   // The JIT should use the static relocation model.
163   TM.setRelocationModel(Reloc::Static);
164
165   // Run loop strength reduction before anything else.
166   PM.add(createLoopStrengthReducePass(TM.getTargetLowering()));
167
168   // FIXME: Implement efficient support for garbage collection intrinsics.
169   PM.add(createLowerGCPass());
170
171   // FIXME: Implement the invoke/unwind instructions!
172   PM.add(createLowerInvokePass());
173
174   // Clean up after other passes, e.g. merging critical edges.
175   PM.add(createCFGSimplificationPass());
176
177   // Make sure that no unreachable blocks are instruction selected.
178   PM.add(createUnreachableBlockEliminationPass());
179
180   // Install an instruction selector.
181   PM.add(createPPCISelDag(TM));
182
183   PM.add(createRegisterAllocator());
184   PM.add(createPrologEpilogCodeInserter());
185
186   // Must run branch selection immediately preceding the asm printer
187   PM.add(createPPCBranchSelectionPass());
188
189   if (PrintMachineCode)
190     PM.add(createMachineFunctionPrinterPass(&std::cerr));
191 }
192