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