Make all of the TargetMachine subclasses use the new string TargetData methods.
[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"),
62   DataLayout(std::string("PowerPC"), std::string("E-p:32:32-d:64:32-l:64:32")),
63   Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this),
64   TLInfo(*this), InstrItins(Subtarget.getInstrItineraryData()) {
65   if (TargetDefault == PPCTarget) {
66     if (Subtarget.isAIX()) PPCTarget = TargetAIX;
67     if (Subtarget.isDarwin()) PPCTarget = TargetDarwin;
68   }
69   if (getRelocationModel() == Reloc::Default)
70     if (Subtarget.isDarwin())
71       setRelocationModel(Reloc::DynamicNoPIC);
72     else
73       setRelocationModel(Reloc::PIC);
74 }
75
76 /// addPassesToEmitFile - Add passes to the specified pass manager to implement
77 /// a static compiler for this target.
78 ///
79 bool PPCTargetMachine::addPassesToEmitFile(PassManager &PM,
80                                            std::ostream &Out,
81                                            CodeGenFileType FileType,
82                                            bool Fast) {
83   if (FileType != TargetMachine::AssemblyFile) return true;
84   
85   // Run loop strength reduction before anything else.
86   if (!Fast) PM.add(createLoopStrengthReducePass(&TLInfo));
87
88   // FIXME: Implement efficient support for garbage collection intrinsics.
89   PM.add(createLowerGCPass());
90
91   // FIXME: Implement the invoke/unwind instructions!
92   PM.add(createLowerInvokePass());
93   
94   // Clean up after other passes, e.g. merging critical edges.
95   if (!Fast) PM.add(createCFGSimplificationPass());
96
97   // Make sure that no unreachable blocks are instruction selected.
98   PM.add(createUnreachableBlockEliminationPass());
99
100   // Install an instruction selector.
101   PM.add(createPPCISelDag(*this));
102
103   if (PrintMachineCode)
104     PM.add(createMachineFunctionPrinterPass(&std::cerr));
105
106   PM.add(createRegisterAllocator());
107
108   if (PrintMachineCode)
109     PM.add(createMachineFunctionPrinterPass(&std::cerr));
110
111   PM.add(createPrologEpilogCodeInserter());
112
113   // Must run branch selection immediately preceding the asm printer
114   PM.add(createPPCBranchSelectionPass());
115
116   // Decide which asm printer to use.  If the user has not specified one on
117   // the command line, choose whichever one matches the default (current host).
118   switch (PPCTarget) {
119   case TargetAIX:
120     PM.add(createAIXAsmPrinter(Out, *this));
121     break;
122   case TargetDefault:
123   case TargetDarwin:
124     PM.add(createDarwinAsmPrinter(Out, *this));
125     break;
126   }
127
128   PM.add(createMachineCodeDeleter());
129   return false;
130 }
131
132 void PPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
133   // The JIT should use the static relocation model.
134   TM.setRelocationModel(Reloc::Static);
135
136   // Run loop strength reduction before anything else.
137   PM.add(createLoopStrengthReducePass(TM.getTargetLowering()));
138
139   // FIXME: Implement efficient support for garbage collection intrinsics.
140   PM.add(createLowerGCPass());
141
142   // FIXME: Implement the invoke/unwind instructions!
143   PM.add(createLowerInvokePass());
144
145   // Clean up after other passes, e.g. merging critical edges.
146   PM.add(createCFGSimplificationPass());
147
148   // Make sure that no unreachable blocks are instruction selected.
149   PM.add(createUnreachableBlockEliminationPass());
150
151   // Install an instruction selector.
152   PM.add(createPPCISelDag(TM));
153
154   PM.add(createRegisterAllocator());
155   PM.add(createPrologEpilogCodeInserter());
156
157   // Must run branch selection immediately preceding the asm printer
158   PM.add(createPPCBranchSelectionPass());
159
160   if (PrintMachineCode)
161     PM.add(createMachineFunctionPrinterPass(&std::cerr));
162 }
163