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