Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 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 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 13 | #include "PowerPC.h" |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 14 | #include "PowerPCTargetMachine.h" |
| 15 | #include "PPC32TargetMachine.h" |
| 16 | #include "PPC64TargetMachine.h" |
| 17 | #include "PPC32JITInfo.h" |
| 18 | #include "PPC64JITInfo.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 19 | #include "llvm/Module.h" |
| 20 | #include "llvm/PassManager.h" |
Misha Brukman | 8c9f520 | 2004-06-21 18:30:31 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFunction.h" |
| 23 | #include "llvm/CodeGen/Passes.h" |
Chris Lattner | 68905bb | 2004-07-11 04:17:58 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachineRegistry.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 26 | #include "llvm/Transforms/Scalar.h" |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 27 | #include "Support/CommandLine.h" |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 28 | #include <iostream> |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 31 | namespace llvm { |
| 32 | cl::opt<bool> AIX("aix", |
| 33 | cl::desc("Generate AIX/xcoff instead of Darwin/MachO"), |
| 34 | cl::Hidden); |
| 35 | } |
| 36 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 37 | namespace { |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 38 | const std::string PPC32 = "PowerPC/32bit"; |
| 39 | const std::string PPC64 = "PowerPC/64bit"; |
| 40 | |
| 41 | // Register the targets |
| 42 | RegisterTarget<PPC32TargetMachine> |
Misha Brukman | 9582822 | 2004-08-11 13:35:44 +0000 | [diff] [blame] | 43 | X("ppc32", " PowerPC 32-bit (experimental)"); |
Misha Brukman | f5f7068 | 2004-08-12 17:16:43 +0000 | [diff] [blame^] | 44 | //RegisterTarget<PPC64TargetMachine> |
| 45 | //Y("ppc64", " PowerPC 64-bit (unimplemented)"); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 48 | PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name, |
| 49 | IntrinsicLowering *IL, |
| 50 | const TargetData &TD, |
| 51 | const TargetFrameInfo &TFI, |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 52 | const PowerPCJITInfo &TJI, |
| 53 | bool is64b) |
| 54 | : TargetMachine(name, IL, TD), InstrInfo(is64b), FrameInfo(TFI), JITInfo(TJI) |
| 55 | {} |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 56 | |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 57 | unsigned PowerPCTargetMachine::getJITMatchQuality() { |
| 58 | #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) |
| 59 | return 10; |
| 60 | #else |
| 61 | return 0; |
| 62 | #endif |
| 63 | } |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 64 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 65 | /// addPassesToEmitAssembly - Add passes to the specified pass manager |
| 66 | /// to implement a static compiler for this target. |
| 67 | /// |
| 68 | bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM, |
| 69 | std::ostream &Out) { |
| 70 | bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this)); |
| 71 | |
| 72 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 73 | PM.add(createLowerGCPass()); |
| 74 | |
| 75 | // FIXME: Implement the invoke/unwind instructions! |
| 76 | PM.add(createLowerInvokePass()); |
| 77 | |
| 78 | // FIXME: Implement the switch instruction in the instruction selector! |
| 79 | PM.add(createLowerSwitchPass()); |
| 80 | |
| 81 | PM.add(createLowerConstantExpressionsPass()); |
| 82 | |
| 83 | // Make sure that no unreachable blocks are instruction selected. |
| 84 | PM.add(createUnreachableBlockEliminationPass()); |
| 85 | |
| 86 | if (LP64) |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 87 | PM.add(createPPC64ISelSimple(*this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 88 | else |
| 89 | PM.add(createPPC32ISelSimple(*this)); |
| 90 | |
| 91 | if (PrintMachineCode) |
| 92 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 93 | |
| 94 | PM.add(createRegisterAllocator()); |
| 95 | |
| 96 | if (PrintMachineCode) |
| 97 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 98 | |
Misha Brukman | 9582822 | 2004-08-11 13:35:44 +0000 | [diff] [blame] | 99 | // PowerPC-specific prolog/epilog code inserter to put the fills/spills in the |
| 100 | // right spots. |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 101 | PM.add(createPowerPCPEI()); |
| 102 | |
| 103 | // Must run branch selection immediately preceding the printer |
| 104 | PM.add(createPPCBranchSelectionPass()); |
| 105 | |
| 106 | if (AIX) |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 107 | PM.add(createPPC64AsmPrinter(Out, *this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 108 | else |
| 109 | PM.add(createPPC32AsmPrinter(Out, *this)); |
| 110 | |
| 111 | PM.add(createMachineCodeDeleter()); |
| 112 | return false; |
| 113 | } |
| 114 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 115 | void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) { |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 116 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 117 | PM.add(createLowerGCPass()); |
| 118 | |
| 119 | // FIXME: Implement the invoke/unwind instructions! |
| 120 | PM.add(createLowerInvokePass()); |
| 121 | |
| 122 | // FIXME: Implement the switch instruction in the instruction selector! |
| 123 | PM.add(createLowerSwitchPass()); |
| 124 | |
| 125 | PM.add(createLowerConstantExpressionsPass()); |
| 126 | |
| 127 | // Make sure that no unreachable blocks are instruction selected. |
| 128 | PM.add(createUnreachableBlockEliminationPass()); |
| 129 | |
| 130 | PM.add(createPPC32ISelSimple(TM)); |
| 131 | PM.add(createRegisterAllocator()); |
| 132 | PM.add(createPrologEpilogCodeInserter()); |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 133 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 134 | |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 135 | void PowerPCJITInfo::replaceMachineCodeForFunction(void *Old, void *New) { |
| 136 | assert(0 && "Cannot execute PowerPCJITInfo::replaceMachineCodeForFunction()"); |
| 137 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 138 | |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 139 | void *PowerPCJITInfo::getJITStubForFunction(Function *F, |
| 140 | MachineCodeEmitter &MCE) { |
| 141 | assert(0 && "Cannot execute PowerPCJITInfo::getJITStubForFunction()"); |
| 142 | return 0; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 143 | } |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 144 | |
| 145 | /// PowerPCTargetMachine ctor - Create an ILP32 architecture model |
| 146 | /// |
| 147 | PPC32TargetMachine::PPC32TargetMachine(const Module &M, |
| 148 | IntrinsicLowering *IL) |
| 149 | : PowerPCTargetMachine(PPC32, IL, |
| 150 | TargetData(PPC32,false,4,4,4,4,4,4,2,1,4), |
| 151 | TargetFrameInfo(TargetFrameInfo::StackGrowsDown,16,0), |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 152 | PPC32JITInfo(*this), false) {} |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 153 | |
| 154 | /// PPC64TargetMachine ctor - Create a LP64 architecture model |
| 155 | /// |
| 156 | PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL) |
| 157 | : PowerPCTargetMachine(PPC64, IL, |
| 158 | TargetData(PPC64,false,8,4,4,4,4,4,2,1,4), |
| 159 | TargetFrameInfo(TargetFrameInfo::StackGrowsDown,16,0), |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 160 | PPC64JITInfo(*this), true) {} |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 161 | |
| 162 | unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) { |
| 163 | if (M.getEndianness() == Module::BigEndian && |
| 164 | M.getPointerSize() == Module::Pointer32) |
| 165 | return 10; // Direct match |
| 166 | else if (M.getEndianness() != Module::AnyEndianness || |
| 167 | M.getPointerSize() != Module::AnyPointerSize) |
| 168 | return 0; // Match for some other target |
| 169 | |
| 170 | return getJITMatchQuality()/2; |
| 171 | } |
| 172 | |
| 173 | unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) { |
| 174 | if (M.getEndianness() == Module::BigEndian && |
| 175 | M.getPointerSize() == Module::Pointer64) |
| 176 | return 10; // Direct match |
| 177 | else if (M.getEndianness() != Module::AnyEndianness || |
| 178 | M.getPointerSize() != Module::AnyPointerSize) |
| 179 | return 0; // Match for some other target |
| 180 | |
| 181 | return getJITMatchQuality()/2; |
| 182 | } |