Breaking up the PowerPC target into 32- and 64-bit subparts, Part I: 32-bit.
[oota-llvm.git] / lib / Target / PowerPC / PPC32TargetMachine.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 "PPC32.h"
14 #include "PPC32JITInfo.h"
15 #include "PPC32TargetMachine.h"
16 #include "llvm/Module.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/CodeGen/IntrinsicLowering.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Target/TargetOptions.h"
22 #include "llvm/Target/TargetMachineRegistry.h"
23 #include "llvm/Transforms/Scalar.h"
24 #include <iostream>
25 using namespace llvm;
26
27 namespace {
28   const std::string PPC32 = "Darwin/PowerPC";
29   // Register the target
30   RegisterTarget<PPC32TargetMachine> 
31   X("powerpc-darwin", "  Darwin/PowerPC (experimental)");
32 }
33
34 /// PowerPCTargetMachine ctor - Create an ILP32 architecture model
35 ///
36 PPC32TargetMachine::PPC32TargetMachine(const Module &M,
37                                                IntrinsicLowering *IL)
38   : PowerPCTargetMachine(PPC32, IL, 
39                          TargetData(PPC32,false,4,4,4,4,4,4,2,1,4),
40                          TargetFrameInfo(TargetFrameInfo::StackGrowsDown,16,-4),
41                          PPC32JITInfo(*this)) {}
42
43 /// addPassesToEmitAssembly - Add passes to the specified pass manager
44 /// to implement a static compiler for this target.
45 ///
46 bool PPC32TargetMachine::addPassesToEmitAssembly(PassManager &PM,
47                                                      std::ostream &Out) {
48   // FIXME: Implement efficient support for garbage collection intrinsics.
49   PM.add(createLowerGCPass());
50
51   // FIXME: Implement the invoke/unwind instructions!
52   PM.add(createLowerInvokePass());
53
54   // FIXME: Implement the switch instruction in the instruction selector!
55   PM.add(createLowerSwitchPass());
56
57   PM.add(createLowerConstantExpressionsPass());
58
59   // Make sure that no unreachable blocks are instruction selected.
60   PM.add(createUnreachableBlockEliminationPass());
61
62   PM.add(createPPC32ISelSimple(*this));
63
64   if (PrintMachineCode)
65     PM.add(createMachineFunctionPrinterPass(&std::cerr));
66
67   PM.add(createRegisterAllocator());
68
69   if (PrintMachineCode)
70     PM.add(createMachineFunctionPrinterPass(&std::cerr));
71
72   // I want a PowerPC specific prolog/epilog code inserter so I can put the 
73   // fills/spills in the right spots.
74   PM.add(createPowerPCPEI());
75   
76   // Must run branch selection immediately preceding the printer
77   PM.add(createPPCBranchSelectionPass());
78   PM.add(createPPC32AsmPrinter(Out, *this));
79   PM.add(createMachineCodeDeleter());
80   return false;
81 }
82
83 /// addPassesToJITCompile - Add passes to the specified pass manager to
84 /// implement a fast dynamic compiler for this target.
85 ///
86 void PPC32JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
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   // FIXME: Implement the switch instruction in the instruction selector!
94   PM.add(createLowerSwitchPass());
95
96   PM.add(createLowerConstantExpressionsPass());
97
98   // Make sure that no unreachable blocks are instruction selected.
99   PM.add(createUnreachableBlockEliminationPass());
100
101   PM.add(createPPC32ISelSimple(TM));
102   PM.add(createRegisterAllocator());
103   PM.add(createPrologEpilogCodeInserter());
104 }
105
106 unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) {
107   if (M.getEndianness()  == Module::BigEndian &&
108       M.getPointerSize() == Module::Pointer32)
109     return 10;                                   // Direct match
110   else if (M.getEndianness() != Module::AnyEndianness ||
111            M.getPointerSize() != Module::AnyPointerSize)
112     return 0;                                    // Match for some other target
113
114   return getJITMatchQuality()/2;
115 }