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