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" |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 15 | #include "PowerPCFrameInfo.h" |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 16 | #include "PPC32TargetMachine.h" |
| 17 | #include "PPC64TargetMachine.h" |
| 18 | #include "PPC32JITInfo.h" |
| 19 | #include "PPC64JITInfo.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 20 | #include "llvm/Module.h" |
| 21 | #include "llvm/PassManager.h" |
Misha Brukman | 8c9f520 | 2004-06-21 18:30:31 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineFunction.h" |
| 24 | #include "llvm/CodeGen/Passes.h" |
Chris Lattner | 68905bb | 2004-07-11 04:17:58 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetMachineRegistry.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 27 | #include "llvm/Transforms/Scalar.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 28 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 29 | #include <iostream> |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 32 | namespace llvm { |
| 33 | cl::opt<bool> AIX("aix", |
| 34 | cl::desc("Generate AIX/xcoff instead of Darwin/MachO"), |
| 35 | cl::Hidden); |
| 36 | } |
| 37 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 38 | namespace { |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 39 | const std::string PPC32ID = "PowerPC/32bit"; |
| 40 | const std::string PPC64ID = "PowerPC/64bit"; |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 41 | |
| 42 | // Register the targets |
| 43 | RegisterTarget<PPC32TargetMachine> |
Chris Lattner | cbb9812 | 2004-10-10 16:26:13 +0000 | [diff] [blame] | 44 | X("ppc32", " PowerPC 32-bit"); |
Chris Lattner | f908888 | 2004-08-20 18:09:18 +0000 | [diff] [blame] | 45 | |
| 46 | #if 0 |
Misha Brukman | 983e92d | 2004-08-19 21:36:14 +0000 | [diff] [blame] | 47 | RegisterTarget<PPC64TargetMachine> |
| 48 | Y("ppc64", " PowerPC 64-bit (unimplemented)"); |
Chris Lattner | f908888 | 2004-08-20 18:09:18 +0000 | [diff] [blame] | 49 | #endif |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 52 | PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name, |
| 53 | IntrinsicLowering *IL, |
| 54 | const TargetData &TD, |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 55 | const PowerPCFrameInfo &TFI) |
| 56 | : TargetMachine(name, IL, TD), FrameInfo(TFI) |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 57 | {} |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 58 | |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 59 | unsigned PPC32TargetMachine::getJITMatchQuality() { |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 60 | #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) |
| 61 | return 10; |
| 62 | #else |
| 63 | return 0; |
| 64 | #endif |
| 65 | } |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 66 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 67 | /// addPassesToEmitAssembly - Add passes to the specified pass manager |
| 68 | /// to implement a static compiler for this target. |
| 69 | /// |
| 70 | bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM, |
| 71 | std::ostream &Out) { |
| 72 | bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this)); |
| 73 | |
| 74 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 75 | PM.add(createLowerGCPass()); |
| 76 | |
| 77 | // FIXME: Implement the invoke/unwind instructions! |
| 78 | PM.add(createLowerInvokePass()); |
| 79 | |
| 80 | // FIXME: Implement the switch instruction in the instruction selector! |
| 81 | PM.add(createLowerSwitchPass()); |
| 82 | |
| 83 | PM.add(createLowerConstantExpressionsPass()); |
| 84 | |
| 85 | // Make sure that no unreachable blocks are instruction selected. |
| 86 | PM.add(createUnreachableBlockEliminationPass()); |
| 87 | |
| 88 | if (LP64) |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 89 | PM.add(createPPC64ISelSimple(*this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 90 | else |
| 91 | PM.add(createPPC32ISelSimple(*this)); |
| 92 | |
| 93 | if (PrintMachineCode) |
| 94 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 95 | |
| 96 | PM.add(createRegisterAllocator()); |
| 97 | |
| 98 | if (PrintMachineCode) |
| 99 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 100 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 101 | PM.add(createPrologEpilogCodeInserter()); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 102 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 103 | // Must run branch selection immediately preceding the asm printer |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 104 | PM.add(createPPCBranchSelectionPass()); |
| 105 | |
| 106 | if (AIX) |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 107 | PM.add(createAIXAsmPrinter(Out, *this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 108 | else |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 109 | PM.add(createDarwinAsmPrinter(Out, *this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 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()); |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 133 | |
| 134 | // Must run branch selection immediately preceding the asm printer |
| 135 | PM.add(createPPCBranchSelectionPass()); |
| 136 | |
| 137 | if (PrintMachineCode) |
| 138 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 139 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 140 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 141 | /// PowerPCTargetMachine ctor - Create an ILP32 architecture model |
| 142 | /// |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 143 | PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL) |
| 144 | : PowerPCTargetMachine(PPC32ID, IL, |
Chris Lattner | 9d0087e | 2004-11-28 21:16:45 +0000 | [diff] [blame^] | 145 | TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,1), |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 146 | PowerPCFrameInfo(*this, false)), JITInfo(*this) {} |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 147 | |
| 148 | /// PPC64TargetMachine ctor - Create a LP64 architecture model |
| 149 | /// |
| 150 | PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL) |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 151 | : PowerPCTargetMachine(PPC64ID, IL, |
Chris Lattner | 9d0087e | 2004-11-28 21:16:45 +0000 | [diff] [blame^] | 152 | TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,1), |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 153 | PowerPCFrameInfo(*this, true)) {} |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 154 | |
| 155 | unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) { |
| 156 | if (M.getEndianness() == Module::BigEndian && |
| 157 | M.getPointerSize() == Module::Pointer32) |
| 158 | return 10; // Direct match |
| 159 | else if (M.getEndianness() != Module::AnyEndianness || |
| 160 | M.getPointerSize() != Module::AnyPointerSize) |
| 161 | return 0; // Match for some other target |
| 162 | |
| 163 | return getJITMatchQuality()/2; |
| 164 | } |
| 165 | |
| 166 | unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) { |
| 167 | if (M.getEndianness() == Module::BigEndian && |
| 168 | M.getPointerSize() == Module::Pointer64) |
| 169 | return 10; // Direct match |
| 170 | else if (M.getEndianness() != Module::AnyEndianness || |
| 171 | M.getPointerSize() != Module::AnyPointerSize) |
| 172 | return 0; // Match for some other target |
| 173 | |
| 174 | return getJITMatchQuality()/2; |
| 175 | } |