1 //===-- PowerPCTargetMachine.cpp - Define TargetMachine for PowerPC -------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
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"
28 const std::string PPC32 = "Darwin/PowerPC";
29 // Register the target
30 RegisterTarget<PPC32TargetMachine>
31 X("powerpc-darwin", " Darwin/PowerPC (experimental)");
34 /// PowerPCTargetMachine ctor - Create an ILP32 architecture model
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)) {}
43 /// addPassesToEmitAssembly - Add passes to the specified pass manager
44 /// to implement a static compiler for this target.
46 bool PPC32TargetMachine::addPassesToEmitAssembly(PassManager &PM,
48 // FIXME: Implement efficient support for garbage collection intrinsics.
49 PM.add(createLowerGCPass());
51 // FIXME: Implement the invoke/unwind instructions!
52 PM.add(createLowerInvokePass());
54 // FIXME: Implement the switch instruction in the instruction selector!
55 PM.add(createLowerSwitchPass());
57 PM.add(createLowerConstantExpressionsPass());
59 // Make sure that no unreachable blocks are instruction selected.
60 PM.add(createUnreachableBlockEliminationPass());
62 PM.add(createPPC32ISelSimple(*this));
65 PM.add(createMachineFunctionPrinterPass(&std::cerr));
67 PM.add(createRegisterAllocator());
70 PM.add(createMachineFunctionPrinterPass(&std::cerr));
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());
76 // Must run branch selection immediately preceding the printer
77 PM.add(createPPCBranchSelectionPass());
78 PM.add(createPPC32AsmPrinter(Out, *this));
79 PM.add(createMachineCodeDeleter());
83 /// addPassesToJITCompile - Add passes to the specified pass manager to
84 /// implement a fast dynamic compiler for this target.
86 void PPC32JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
87 // FIXME: Implement efficient support for garbage collection intrinsics.
88 PM.add(createLowerGCPass());
90 // FIXME: Implement the invoke/unwind instructions!
91 PM.add(createLowerInvokePass());
93 // FIXME: Implement the switch instruction in the instruction selector!
94 PM.add(createLowerSwitchPass());
96 PM.add(createLowerConstantExpressionsPass());
98 // Make sure that no unreachable blocks are instruction selected.
99 PM.add(createUnreachableBlockEliminationPass());
101 PM.add(createPPC32ISelSimple(TM));
102 PM.add(createRegisterAllocator());
103 PM.add(createPrologEpilogCodeInserter());
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
114 return getJITMatchQuality()/2;