Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 1 | //===-- PowerPCTargetMachine.cpp - Define TargetMachine for PowerPC -------===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 2 | // |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 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. |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 7 | // |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 9 | // |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 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 { |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 33 | bool PPCCRopts; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 34 | cl::opt<bool> AIX("aix", |
| 35 | cl::desc("Generate AIX/xcoff instead of Darwin/MachO"), |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 36 | cl::Hidden); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 37 | cl::opt<bool> EnablePPCLSR("enable-lsr-for-ppc", |
| 38 | cl::desc("Enable LSR for PPC (beta)"), |
Chris Lattner | 0c74906 | 2005-03-02 06:19:22 +0000 | [diff] [blame] | 39 | cl::Hidden); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 40 | cl::opt<bool, true> EnablePPCCRopts("enable-cc-opts", |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 41 | cl::desc("Enable opts using condition regs (beta)"), |
| 42 | cl::location(PPCCRopts), |
| 43 | cl::init(false), |
| 44 | cl::Hidden); |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 47 | namespace { |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 48 | const std::string PPC32ID = "PowerPC/32bit"; |
| 49 | const std::string PPC64ID = "PowerPC/64bit"; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 50 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 51 | // Register the targets |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 52 | RegisterTarget<PPC32TargetMachine> |
Chris Lattner | cbb9812 | 2004-10-10 16:26:13 +0000 | [diff] [blame] | 53 | X("ppc32", " PowerPC 32-bit"); |
Chris Lattner | f908888 | 2004-08-20 18:09:18 +0000 | [diff] [blame] | 54 | |
| 55 | #if 0 |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 56 | RegisterTarget<PPC64TargetMachine> |
Misha Brukman | 983e92d | 2004-08-19 21:36:14 +0000 | [diff] [blame] | 57 | Y("ppc64", " PowerPC 64-bit (unimplemented)"); |
Chris Lattner | f908888 | 2004-08-20 18:09:18 +0000 | [diff] [blame] | 58 | #endif |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 61 | PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name, |
| 62 | IntrinsicLowering *IL, |
| 63 | const TargetData &TD, |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 64 | const PowerPCFrameInfo &TFI) |
| 65 | : TargetMachine(name, IL, TD), FrameInfo(TFI) |
Misha Brukman | 1d3527e | 2004-08-11 23:47:08 +0000 | [diff] [blame] | 66 | {} |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 67 | |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 68 | unsigned PPC32TargetMachine::getJITMatchQuality() { |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 69 | #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) |
| 70 | return 10; |
| 71 | #else |
| 72 | return 0; |
| 73 | #endif |
| 74 | } |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 75 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 76 | /// addPassesToEmitAssembly - Add passes to the specified pass manager |
| 77 | /// to implement a static compiler for this target. |
| 78 | /// |
| 79 | bool PowerPCTargetMachine::addPassesToEmitAssembly(PassManager &PM, |
| 80 | std::ostream &Out) { |
| 81 | bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(this)); |
Chris Lattner | 0c74906 | 2005-03-02 06:19:22 +0000 | [diff] [blame] | 82 | |
Chris Lattner | 4318a3d | 2005-03-02 21:56:00 +0000 | [diff] [blame] | 83 | if (EnablePPCLSR) { |
Chris Lattner | 0c74906 | 2005-03-02 06:19:22 +0000 | [diff] [blame] | 84 | PM.add(createLoopStrengthReducePass()); |
Chris Lattner | 4318a3d | 2005-03-02 21:56:00 +0000 | [diff] [blame] | 85 | PM.add(createCFGSimplificationPass()); |
| 86 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 87 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 88 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 89 | PM.add(createLowerGCPass()); |
| 90 | |
| 91 | // FIXME: Implement the invoke/unwind instructions! |
| 92 | PM.add(createLowerInvokePass()); |
| 93 | |
| 94 | // FIXME: Implement the switch instruction in the instruction selector! |
| 95 | PM.add(createLowerSwitchPass()); |
| 96 | |
| 97 | PM.add(createLowerConstantExpressionsPass()); |
| 98 | |
| 99 | // Make sure that no unreachable blocks are instruction selected. |
| 100 | PM.add(createUnreachableBlockEliminationPass()); |
| 101 | |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 102 | // Default to pattern ISel |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 103 | if (LP64) |
Nate Begeman | d3e6b94 | 2005-04-05 08:51:15 +0000 | [diff] [blame] | 104 | PM.add(createPPC64ISelPattern(*this)); |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 105 | else if (PatternISelTriState == 0) |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 106 | PM.add(createPPC32ISelSimple(*this)); |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 107 | else |
| 108 | PM.add(createPPC32ISelPattern(*this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 109 | |
| 110 | if (PrintMachineCode) |
| 111 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 112 | |
| 113 | PM.add(createRegisterAllocator()); |
| 114 | |
| 115 | if (PrintMachineCode) |
| 116 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 117 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 118 | PM.add(createPrologEpilogCodeInserter()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 119 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 120 | // Must run branch selection immediately preceding the asm printer |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 121 | PM.add(createPPCBranchSelectionPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 122 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 123 | if (AIX) |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 124 | PM.add(createAIXAsmPrinter(Out, *this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 125 | else |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 126 | PM.add(createDarwinAsmPrinter(Out, *this)); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 127 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 128 | PM.add(createMachineCodeDeleter()); |
| 129 | return false; |
| 130 | } |
| 131 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 132 | void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) { |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 133 | bool LP64 = (0 != dynamic_cast<PPC64TargetMachine *>(&TM)); |
| 134 | |
Chris Lattner | 4318a3d | 2005-03-02 21:56:00 +0000 | [diff] [blame] | 135 | if (EnablePPCLSR) { |
Chris Lattner | 0c74906 | 2005-03-02 06:19:22 +0000 | [diff] [blame] | 136 | PM.add(createLoopStrengthReducePass()); |
Chris Lattner | 4318a3d | 2005-03-02 21:56:00 +0000 | [diff] [blame] | 137 | PM.add(createCFGSimplificationPass()); |
| 138 | } |
Chris Lattner | 0c74906 | 2005-03-02 06:19:22 +0000 | [diff] [blame] | 139 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 140 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 141 | PM.add(createLowerGCPass()); |
| 142 | |
| 143 | // FIXME: Implement the invoke/unwind instructions! |
| 144 | PM.add(createLowerInvokePass()); |
| 145 | |
| 146 | // FIXME: Implement the switch instruction in the instruction selector! |
| 147 | PM.add(createLowerSwitchPass()); |
| 148 | |
| 149 | PM.add(createLowerConstantExpressionsPass()); |
| 150 | |
| 151 | // Make sure that no unreachable blocks are instruction selected. |
| 152 | PM.add(createUnreachableBlockEliminationPass()); |
| 153 | |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 154 | // Default to pattern ISel |
| 155 | if (LP64) |
| 156 | PM.add(createPPC64ISelPattern(TM)); |
| 157 | else if (PatternISelTriState == 0) |
| 158 | PM.add(createPPC32ISelSimple(TM)); |
| 159 | else |
| 160 | PM.add(createPPC32ISelPattern(TM)); |
| 161 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 162 | PM.add(createRegisterAllocator()); |
| 163 | PM.add(createPrologEpilogCodeInserter()); |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 164 | |
| 165 | // Must run branch selection immediately preceding the asm printer |
| 166 | PM.add(createPPCBranchSelectionPass()); |
| 167 | |
| 168 | if (PrintMachineCode) |
| 169 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 170 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 171 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 172 | /// PowerPCTargetMachine ctor - Create an ILP32 architecture model |
| 173 | /// |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 174 | PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL) |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame^] | 175 | : PowerPCTargetMachine(PPC32ID, IL, |
Chris Lattner | 9d0087e | 2004-11-28 21:16:45 +0000 | [diff] [blame] | 176 | TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,1), |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 177 | PowerPCFrameInfo(*this, false)), JITInfo(*this) {} |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 178 | |
| 179 | /// PPC64TargetMachine ctor - Create a LP64 architecture model |
| 180 | /// |
| 181 | PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL) |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 182 | : PowerPCTargetMachine(PPC64ID, IL, |
Chris Lattner | 9d0087e | 2004-11-28 21:16:45 +0000 | [diff] [blame] | 183 | TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,1), |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 184 | PowerPCFrameInfo(*this, true)) {} |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 185 | |
| 186 | unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) { |
Chris Lattner | 3ea78c4 | 2004-12-12 17:40:28 +0000 | [diff] [blame] | 187 | // We strongly match "powerpc-*". |
| 188 | std::string TT = M.getTargetTriple(); |
| 189 | if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-") |
| 190 | return 20; |
| 191 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 192 | if (M.getEndianness() == Module::BigEndian && |
| 193 | M.getPointerSize() == Module::Pointer32) |
Chris Lattner | 3ea78c4 | 2004-12-12 17:40:28 +0000 | [diff] [blame] | 194 | return 10; // Weak match |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 195 | else if (M.getEndianness() != Module::AnyEndianness || |
| 196 | M.getPointerSize() != Module::AnyPointerSize) |
| 197 | return 0; // Match for some other target |
| 198 | |
| 199 | return getJITMatchQuality()/2; |
| 200 | } |
| 201 | |
| 202 | unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) { |
| 203 | if (M.getEndianness() == Module::BigEndian && |
| 204 | M.getPointerSize() == Module::Pointer64) |
| 205 | return 10; // Direct match |
| 206 | else if (M.getEndianness() != Module::AnyEndianness || |
| 207 | M.getPointerSize() != Module::AnyPointerSize) |
| 208 | return 0; // Match for some other target |
| 209 | |
| 210 | return getJITMatchQuality()/2; |
| 211 | } |