Remove what little AIX support we have. It has never been tested and isn't
[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 #endif
43   return 0;
44 }
45 unsigned PPC64TargetMachine::getJITMatchQuality() {
46 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
47   if (sizeof(void*) == 8)
48     return 10;
49 #endif
50   return 0;
51 }
52
53 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
54   // We strongly match "powerpc-*".
55   std::string TT = M.getTargetTriple();
56   if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
57     return 20;
58   
59   if (M.getEndianness()  == Module::BigEndian &&
60       M.getPointerSize() == Module::Pointer32)
61     return 10;                                   // Weak match
62   else if (M.getEndianness() != Module::AnyEndianness ||
63            M.getPointerSize() != Module::AnyPointerSize)
64     return 0;                                    // Match for some other target
65   
66   return getJITMatchQuality()/2;
67 }
68
69 unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
70   // We strongly match "powerpc64-*".
71   std::string TT = M.getTargetTriple();
72   if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
73     return 20;
74   
75   if (M.getEndianness()  == Module::BigEndian &&
76       M.getPointerSize() == Module::Pointer64)
77     return 10;                                   // Weak match
78   else if (M.getEndianness() != Module::AnyEndianness ||
79            M.getPointerSize() != Module::AnyPointerSize)
80     return 0;                                    // Match for some other target
81   
82   return getJITMatchQuality()/2;
83 }
84
85
86 PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS,
87                                    bool is64Bit)
88   : TargetMachine("PowerPC"), Subtarget(M, FS, is64Bit),
89     DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
90     FrameInfo(*this, false), JITInfo(*this), TLInfo(*this),
91     InstrItins(Subtarget.getInstrItineraryData()) {
92
93   if (getRelocationModel() == Reloc::Default)
94     if (Subtarget.isDarwin())
95       setRelocationModel(Reloc::DynamicNoPIC);
96     else
97       setRelocationModel(Reloc::PIC);
98 }
99
100 PPC32TargetMachine::PPC32TargetMachine(const Module &M, const std::string &FS) 
101   : PPCTargetMachine(M, FS, false) {
102 }
103
104
105 PPC64TargetMachine::PPC64TargetMachine(const Module &M, const std::string &FS)
106   : PPCTargetMachine(M, FS, true) {
107 }
108
109 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
110 /// a static compiler for this target.
111 ///
112 bool PPCTargetMachine::addPassesToEmitFile(PassManager &PM,
113                                            std::ostream &Out,
114                                            CodeGenFileType FileType,
115                                            bool Fast) {
116   if (FileType != TargetMachine::AssemblyFile) return true;
117   
118   // Run loop strength reduction before anything else.
119   if (!Fast) PM.add(createLoopStrengthReducePass(&TLInfo));
120
121   // FIXME: Implement efficient support for garbage collection intrinsics.
122   PM.add(createLowerGCPass());
123
124   // FIXME: Implement the invoke/unwind instructions!
125   PM.add(createLowerInvokePass());
126   
127   // Clean up after other passes, e.g. merging critical edges.
128   if (!Fast) PM.add(createCFGSimplificationPass());
129
130   // Make sure that no unreachable blocks are instruction selected.
131   PM.add(createUnreachableBlockEliminationPass());
132
133   // Install an instruction selector.
134   PM.add(createPPCISelDag(*this));
135
136   if (PrintMachineCode)
137     PM.add(createMachineFunctionPrinterPass(&std::cerr));
138
139   PM.add(createRegisterAllocator());
140
141   if (PrintMachineCode)
142     PM.add(createMachineFunctionPrinterPass(&std::cerr));
143
144   PM.add(createPrologEpilogCodeInserter());
145
146   // Must run branch selection immediately preceding the asm printer
147   PM.add(createPPCBranchSelectionPass());
148
149   PM.add(createDarwinAsmPrinter(Out, *this));
150
151   PM.add(createMachineCodeDeleter());
152   return false;
153 }
154
155 void PPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
156   // The JIT should use the static relocation model.
157   TM.setRelocationModel(Reloc::Static);
158
159   // Run loop strength reduction before anything else.
160   PM.add(createLoopStrengthReducePass(TM.getTargetLowering()));
161
162   // FIXME: Implement efficient support for garbage collection intrinsics.
163   PM.add(createLowerGCPass());
164
165   // FIXME: Implement the invoke/unwind instructions!
166   PM.add(createLowerInvokePass());
167
168   // Clean up after other passes, e.g. merging critical edges.
169   PM.add(createCFGSimplificationPass());
170
171   // Make sure that no unreachable blocks are instruction selected.
172   PM.add(createUnreachableBlockEliminationPass());
173
174   // Install an instruction selector.
175   PM.add(createPPCISelDag(TM));
176
177   PM.add(createRegisterAllocator());
178   PM.add(createPrologEpilogCodeInserter());
179
180   // Must run branch selection immediately preceding the asm printer
181   PM.add(createPPCBranchSelectionPass());
182
183   if (PrintMachineCode)
184     PM.add(createMachineFunctionPrinterPass(&std::cerr));
185 }
186