Change indentation of a whole bunch of code, no real changes here.
[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   : TargetMachine(name, IL, TD), FrameInfo(TFI)
57 {}
58
59 unsigned PPC32TargetMachine::getJITMatchQuality() {
60 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
61   return 10;
62 #else
63   return 0;
64 #endif
65 }
66
67 /// addPassesToEmitAssembly - Add passes to the specified pass manager
68 /// to implement a static compiler for this target.
69 ///
70 bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
71                                                    std::ostream &Out) {
72   bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this));
73   
74   // FIXME: Implement efficient support for garbage collection intrinsics.
75   PM.add(createLowerGCPass());
76
77   // FIXME: Implement the invoke/unwind instructions!
78   PM.add(createLowerInvokePass());
79
80   // FIXME: Implement the switch instruction in the instruction selector!
81   PM.add(createLowerSwitchPass());
82
83   PM.add(createLowerConstantExpressionsPass());
84
85   // Make sure that no unreachable blocks are instruction selected.
86   PM.add(createUnreachableBlockEliminationPass());
87
88   if (LP64)
89     PM.add(createPPC64ISelSimple(*this));
90   else
91     PM.add(createPPC32ISelSimple(*this));
92
93   if (PrintMachineCode)
94     PM.add(createMachineFunctionPrinterPass(&std::cerr));
95
96   PM.add(createRegisterAllocator());
97
98   if (PrintMachineCode)
99     PM.add(createMachineFunctionPrinterPass(&std::cerr));
100
101   PM.add(createPrologEpilogCodeInserter());
102   
103   // Must run branch selection immediately preceding the asm printer
104   PM.add(createPPCBranchSelectionPass());
105   
106   if (AIX)
107     PM.add(createAIXAsmPrinter(Out, *this));
108   else
109     PM.add(createDarwinAsmPrinter(Out, *this));
110     
111   PM.add(createMachineCodeDeleter());
112   return false;
113 }
114
115 void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
116   // FIXME: Implement efficient support for garbage collection intrinsics.
117   PM.add(createLowerGCPass());
118
119   // FIXME: Implement the invoke/unwind instructions!
120   PM.add(createLowerInvokePass());
121
122   // FIXME: Implement the switch instruction in the instruction selector!
123   PM.add(createLowerSwitchPass());
124
125   PM.add(createLowerConstantExpressionsPass());
126
127   // Make sure that no unreachable blocks are instruction selected.
128   PM.add(createUnreachableBlockEliminationPass());
129
130   PM.add(createPPC32ISelSimple(TM));
131   PM.add(createRegisterAllocator());
132   PM.add(createPrologEpilogCodeInserter());
133
134   // Must run branch selection immediately preceding the asm printer
135   PM.add(createPPCBranchSelectionPass());
136
137   if (PrintMachineCode)
138     PM.add(createMachineFunctionPrinterPass(&std::cerr));
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,1),
146                          PowerPCFrameInfo(*this, false)), JITInfo(*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,1),
153                          PowerPCFrameInfo(*this, true)) {}
154
155 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
156   // We strongly match "powerpc-*".
157   std::string TT = M.getTargetTriple();
158   if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
159     return 20;
160
161   if (M.getEndianness()  == Module::BigEndian &&
162       M.getPointerSize() == Module::Pointer32)
163     return 10;                                   // Weak match
164   else if (M.getEndianness() != Module::AnyEndianness ||
165            M.getPointerSize() != Module::AnyPointerSize)
166     return 0;                                    // Match for some other target
167
168   return getJITMatchQuality()/2;
169 }
170
171 unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) {
172   if (M.getEndianness()  == Module::BigEndian &&
173       M.getPointerSize() == Module::Pointer64)
174     return 10;                                   // Direct match
175   else if (M.getEndianness() != Module::AnyEndianness ||
176            M.getPointerSize() != Module::AnyPointerSize)
177     return 0;                                    // Match for some other target
178
179   return getJITMatchQuality()/2;
180 }