Implement getModuleMatchQuality and getJITMatchQuality() for PowerPC
[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 "PowerPCTargetMachine.h"
14 #include "PowerPC.h"
15 #include "llvm/Module.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/CodeGen/IntrinsicLowering.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include "llvm/Target/TargetMachineRegistry.h"
22 #include "llvm/Transforms/Scalar.h"
23 #include <iostream>
24 using namespace llvm;
25
26 namespace {
27   // Register the target.
28   RegisterTarget<PowerPCTargetMachine> X("powerpc", "  PowerPC (experimental)");
29 }
30
31 unsigned PowerPCTargetMachine::getJITMatchQuality() {
32 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
33   return 10;
34 #else
35   return 0;
36 #endif
37 }
38   
39 unsigned PowerPCTargetMachine::getModuleMatchQuality(const Module &M) {
40   if (M.getEndianness()  == Module::BigEndian &&
41       M.getPointerSize() == Module::Pointer32)
42     return 10;                                   // Direct match
43   else if (M.getEndianness() != Module::AnyEndianness ||
44            M.getPointerSize() != Module::AnyPointerSize)
45     return 0;                                    // Match for some other target
46
47   return getJITMatchQuality()/2;
48 }
49
50
51 /// PowerPCTargetMachine ctor - Create an ILP32 architecture model
52 ///
53 /// FIXME: Should double alignment be 8 bytes?  Then we get a PtrAl != DoubleAl
54 /// abort
55 PowerPCTargetMachine::PowerPCTargetMachine(const Module &M,
56                                            IntrinsicLowering *IL)
57   : TargetMachine("PowerPC", IL, false, 4, 4, 4, 4, 4, 4, 4, 4),
58     FrameInfo(TargetFrameInfo::StackGrowsDown, 16, -4), JITInfo(*this) {
59 }
60
61 /// addPassesToEmitAssembly - Add passes to the specified pass manager
62 /// to implement a static compiler for this target.
63 ///
64 bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
65                                                std::ostream &Out) {
66   // FIXME: Implement efficient support for garbage collection intrinsics.
67   PM.add(createLowerGCPass());
68
69   // FIXME: Implement the invoke/unwind instructions!
70   PM.add(createLowerInvokePass());
71
72   // FIXME: Implement the switch instruction in the instruction selector!
73   PM.add(createLowerSwitchPass());
74
75   PM.add(createLowerConstantExpressionsPass());
76
77   // Make sure that no unreachable blocks are instruction selected.
78   PM.add(createUnreachableBlockEliminationPass());
79
80   PM.add(createPPCSimpleInstructionSelector(*this));
81
82   if (PrintMachineCode)
83     PM.add(createMachineFunctionPrinterPass(&std::cerr));
84
85   PM.add(createRegisterAllocator());
86
87   if (PrintMachineCode)
88     PM.add(createMachineFunctionPrinterPass(&std::cerr));
89
90   PM.add(createPrologEpilogCodeInserter());
91   PM.add(createPPCCodePrinterPass(Out, *this));
92   PM.add(createMachineCodeDeleter());
93   return false;
94 }
95
96 /// addPassesToJITCompile - Add passes to the specified pass manager to
97 /// implement a fast dynamic compiler for this target.
98 ///
99 void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
100   // FIXME: Implement efficient support for garbage collection intrinsics.
101   PM.add(createLowerGCPass());
102
103   // FIXME: Implement the invoke/unwind instructions!
104   PM.add(createLowerInvokePass());
105
106   // FIXME: Implement the switch instruction in the instruction selector!
107   PM.add(createLowerSwitchPass());
108
109   PM.add(createLowerConstantExpressionsPass());
110
111   // Make sure that no unreachable blocks are instruction selected.
112   PM.add(createUnreachableBlockEliminationPass());
113
114   PM.add(createPPCSimpleInstructionSelector(TM));
115   PM.add(createRegisterAllocator());
116   PM.add(createPrologEpilogCodeInserter());
117 }
118