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