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 //===----------------------------------------------------------------------===//
13 #include "PowerPCTargetMachine.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"
27 // Register the target.
28 RegisterTarget<PowerPCTargetMachine> X("powerpc", " PowerPC (experimental)");
31 unsigned PowerPCTargetMachine::getJITMatchQuality() {
32 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER)
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
47 return getJITMatchQuality()/2;
51 /// PowerPCTargetMachine ctor - Create an ILP32 architecture model
53 /// FIXME: Should double alignment be 8 bytes? Then we get a PtrAl != DoubleAl
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) {
61 /// addPassesToEmitAssembly - Add passes to the specified pass manager
62 /// to implement a static compiler for this target.
64 bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM,
66 // FIXME: Implement efficient support for garbage collection intrinsics.
67 PM.add(createLowerGCPass());
69 // FIXME: Implement the invoke/unwind instructions!
70 PM.add(createLowerInvokePass());
72 // FIXME: Implement the switch instruction in the instruction selector!
73 PM.add(createLowerSwitchPass());
75 PM.add(createLowerConstantExpressionsPass());
77 // Make sure that no unreachable blocks are instruction selected.
78 PM.add(createUnreachableBlockEliminationPass());
80 PM.add(createPPCSimpleInstructionSelector(*this));
83 PM.add(createMachineFunctionPrinterPass(&std::cerr));
85 PM.add(createRegisterAllocator());
88 PM.add(createMachineFunctionPrinterPass(&std::cerr));
90 PM.add(createPrologEpilogCodeInserter());
91 PM.add(createPPCCodePrinterPass(Out, *this));
92 PM.add(createMachineCodeDeleter());
96 /// addPassesToJITCompile - Add passes to the specified pass manager to
97 /// implement a fast dynamic compiler for this target.
99 void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
100 // FIXME: Implement efficient support for garbage collection intrinsics.
101 PM.add(createLowerGCPass());
103 // FIXME: Implement the invoke/unwind instructions!
104 PM.add(createLowerInvokePass());
106 // FIXME: Implement the switch instruction in the instruction selector!
107 PM.add(createLowerSwitchPass());
109 PM.add(createLowerConstantExpressionsPass());
111 // Make sure that no unreachable blocks are instruction selected.
112 PM.add(createUnreachableBlockEliminationPass());
114 PM.add(createPPCSimpleInstructionSelector(TM));
115 PM.add(createRegisterAllocator());
116 PM.add(createPrologEpilogCodeInserter());