Don't pass target name into TargetData anymore, it is never used or needed.
[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 * 0/*FIXME: not PPC64-JIT support yet! */;
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()),
91     FrameInfo(*this, false), JITInfo(*this), TLInfo(*this),
92     InstrItins(Subtarget.getInstrItineraryData()) {
93
94   if (TargetDefault == PPCTarget) {
95     if (Subtarget.isAIX()) PPCTarget = TargetAIX;
96     if (Subtarget.isDarwin()) PPCTarget = TargetDarwin;
97   }
98   if (getRelocationModel() == Reloc::Default)
99     if (Subtarget.isDarwin())
100       setRelocationModel(Reloc::DynamicNoPIC);
101     else
102       setRelocationModel(Reloc::PIC);
103 }
104
105 PPC32TargetMachine::PPC32TargetMachine(const Module &M, const std::string &FS) 
106   : PPCTargetMachine(M, FS, false) {
107 }
108
109
110 PPC64TargetMachine::PPC64TargetMachine(const Module &M, const std::string &FS)
111   : PPCTargetMachine(M, FS, true) {
112 }
113
114 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
115 /// a static compiler for this target.
116 ///
117 bool PPCTargetMachine::addPassesToEmitFile(PassManager &PM,
118                                            std::ostream &Out,
119                                            CodeGenFileType FileType,
120                                            bool Fast) {
121   if (FileType != TargetMachine::AssemblyFile) return true;
122   
123   // Run loop strength reduction before anything else.
124   if (!Fast) PM.add(createLoopStrengthReducePass(&TLInfo));
125
126   // FIXME: Implement efficient support for garbage collection intrinsics.
127   PM.add(createLowerGCPass());
128
129   // FIXME: Implement the invoke/unwind instructions!
130   PM.add(createLowerInvokePass());
131   
132   // Clean up after other passes, e.g. merging critical edges.
133   if (!Fast) PM.add(createCFGSimplificationPass());
134
135   // Make sure that no unreachable blocks are instruction selected.
136   PM.add(createUnreachableBlockEliminationPass());
137
138   // Install an instruction selector.
139   PM.add(createPPCISelDag(*this));
140
141   if (PrintMachineCode)
142     PM.add(createMachineFunctionPrinterPass(&std::cerr));
143
144   PM.add(createRegisterAllocator());
145
146   if (PrintMachineCode)
147     PM.add(createMachineFunctionPrinterPass(&std::cerr));
148
149   PM.add(createPrologEpilogCodeInserter());
150
151   // Must run branch selection immediately preceding the asm printer
152   PM.add(createPPCBranchSelectionPass());
153
154   // Decide which asm printer to use.  If the user has not specified one on
155   // the command line, choose whichever one matches the default (current host).
156   switch (PPCTarget) {
157   case TargetAIX:
158     PM.add(createAIXAsmPrinter(Out, *this));
159     break;
160   case TargetDefault:
161   case TargetDarwin:
162     PM.add(createDarwinAsmPrinter(Out, *this));
163     break;
164   }
165
166   PM.add(createMachineCodeDeleter());
167   return false;
168 }
169
170 void PPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
171   // The JIT should use the static relocation model.
172   TM.setRelocationModel(Reloc::Static);
173
174   // Run loop strength reduction before anything else.
175   PM.add(createLoopStrengthReducePass(TM.getTargetLowering()));
176
177   // FIXME: Implement efficient support for garbage collection intrinsics.
178   PM.add(createLowerGCPass());
179
180   // FIXME: Implement the invoke/unwind instructions!
181   PM.add(createLowerInvokePass());
182
183   // Clean up after other passes, e.g. merging critical edges.
184   PM.add(createCFGSimplificationPass());
185
186   // Make sure that no unreachable blocks are instruction selected.
187   PM.add(createUnreachableBlockEliminationPass());
188
189   // Install an instruction selector.
190   PM.add(createPPCISelDag(TM));
191
192   PM.add(createRegisterAllocator());
193   PM.add(createPrologEpilogCodeInserter());
194
195   // Must run branch selection immediately preceding the asm printer
196   PM.add(createPPCBranchSelectionPass());
197
198   if (PrintMachineCode)
199     PM.add(createMachineFunctionPrinterPass(&std::cerr));
200 }
201