Goodbye PPC pattern isel. You have served us well, but it is now time for
[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/IntrinsicLowering.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/CodeGen/Passes.h"
24 #include "llvm/Target/TargetOptions.h"
25 #include "llvm/Target/TargetMachineRegistry.h"
26 #include "llvm/Transforms/Scalar.h"
27 #include "llvm/Support/CommandLine.h"
28 #include <iostream>
29 using namespace llvm;
30
31 namespace {
32   // Register the targets
33   RegisterTarget<PPCTargetMachine>
34   X("ppc32", "  PowerPC");
35 }
36
37 unsigned PPCTargetMachine::getJITMatchQuality() {
38 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
39   return 10;
40 #else
41   return 0;
42 #endif
43 }
44
45 unsigned PPCTargetMachine::getModuleMatchQuality(const Module &M) {
46   // We strongly match "powerpc-*".
47   std::string TT = M.getTargetTriple();
48   if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
49     return 20;
50   
51   if (M.getEndianness()  == Module::BigEndian &&
52       M.getPointerSize() == Module::Pointer32)
53     return 10;                                   // Weak match
54   else if (M.getEndianness() != Module::AnyEndianness ||
55            M.getPointerSize() != Module::AnyPointerSize)
56     return 0;                                    // Match for some other target
57   
58   return getJITMatchQuality()/2;
59 }
60
61 PPCTargetMachine::PPCTargetMachine(const Module &M, IntrinsicLowering *IL,
62                                    const std::string &FS)
63 : TargetMachine("PowerPC", IL, false, 4, 4, 4, 4, 4, 4, 2, 1, 1),
64   Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this),
65   InstrItins(Subtarget.getInstrItineraryData()) {
66   if (TargetDefault == PPCTarget) {
67     if (Subtarget.isAIX()) PPCTarget = TargetAIX;
68     if (Subtarget.isDarwin()) PPCTarget = TargetDarwin;
69   }
70 }
71
72 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
73 /// a static compiler for this target.
74 ///
75 bool PPCTargetMachine::addPassesToEmitFile(PassManager &PM,
76                                            std::ostream &Out,
77                                            CodeGenFileType FileType,
78                                            bool Fast) {
79   if (FileType != TargetMachine::AssemblyFile) return true;
80   
81   // Run loop strength reduction before anything else.
82   if (!Fast) PM.add(createLoopStrengthReducePass());
83
84   // FIXME: Implement efficient support for garbage collection intrinsics.
85   PM.add(createLowerGCPass());
86
87   // FIXME: Implement the invoke/unwind instructions!
88   PM.add(createLowerInvokePass());
89   
90   // Clean up after other passes, e.g. merging critical edges.
91   if (!Fast) PM.add(createCFGSimplificationPass());
92
93   // FIXME: Implement the switch instruction in the instruction selector!
94   PM.add(createLowerSwitchPass());
95
96   // Make sure that no unreachable blocks are instruction selected.
97   PM.add(createUnreachableBlockEliminationPass());
98
99   // Install an instruction selector.
100   PM.add(createPPCISelDag(*this));
101
102   if (PrintMachineCode)
103     PM.add(createMachineFunctionPrinterPass(&std::cerr));
104
105   PM.add(createRegisterAllocator());
106
107   if (PrintMachineCode)
108     PM.add(createMachineFunctionPrinterPass(&std::cerr));
109
110   PM.add(createPrologEpilogCodeInserter());
111
112   // Must run branch selection immediately preceding the asm printer
113   PM.add(createPPCBranchSelectionPass());
114
115   // Decide which asm printer to use.  If the user has not specified one on
116   // the command line, choose whichever one matches the default (current host).
117   switch (PPCTarget) {
118   case TargetAIX:
119     PM.add(createAIXAsmPrinter(Out, *this));
120     break;
121   case TargetDefault:
122   case TargetDarwin:
123     PM.add(createDarwinAsmPrinter(Out, *this));
124     break;
125   }
126
127   PM.add(createMachineCodeDeleter());
128   return false;
129 }
130
131 void PPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
132   // The JIT does not support or need PIC.
133   PICEnabled = false;
134
135   // Run loop strength reduction before anything else.
136   PM.add(createLoopStrengthReducePass());
137
138   // FIXME: Implement efficient support for garbage collection intrinsics.
139   PM.add(createLowerGCPass());
140
141   // FIXME: Implement the invoke/unwind instructions!
142   PM.add(createLowerInvokePass());
143
144   // Clean up after other passes, e.g. merging critical edges.
145   PM.add(createCFGSimplificationPass());
146
147   // FIXME: Implement the switch instruction in the instruction selector!
148   PM.add(createLowerSwitchPass());
149
150   // Make sure that no unreachable blocks are instruction selected.
151   PM.add(createUnreachableBlockEliminationPass());
152
153   // Install an instruction selector.
154   PM.add(createPPCISelDag(TM));
155
156   PM.add(createRegisterAllocator());
157   PM.add(createPrologEpilogCodeInserter());
158
159   // Must run branch selection immediately preceding the asm printer
160   PM.add(createPPCBranchSelectionPass());
161
162   if (PrintMachineCode)
163     PM.add(createMachineFunctionPrinterPass(&std::cerr));
164 }
165