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 | // |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 10 | // Top-level implementation for the PowerPC target. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 14 | #include "PowerPC.h" |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 15 | #include "PowerPCTargetMachine.h" |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 16 | #include "PowerPCFrameInfo.h" |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 17 | #include "PPC32TargetMachine.h" |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 18 | #include "PPC32JITInfo.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 19 | #include "llvm/Module.h" |
| 20 | #include "llvm/PassManager.h" |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/Verifier.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 | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 32 | namespace { |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 33 | const std::string PPC32ID = "PowerPC/32bit"; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 34 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 35 | // Register the targets |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 36 | RegisterTarget<PPC32TargetMachine> |
Chris Lattner | cbb9812 | 2004-10-10 16:26:13 +0000 | [diff] [blame] | 37 | X("ppc32", " PowerPC 32-bit"); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 40 | PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name, |
| 41 | IntrinsicLowering *IL, |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 42 | const Module &M, |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 43 | const TargetData &TD, |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 44 | const PowerPCFrameInfo &TFI) |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 45 | : TargetMachine(name, IL, TD), FrameInfo(TFI), Subtarget(M) { |
| 46 | if (TargetDefault == PPCTarget) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 47 | if (Subtarget.isAIX()) PPCTarget = TargetAIX; |
| 48 | if (Subtarget.isDarwin()) PPCTarget = TargetDarwin; |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 51 | |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 52 | unsigned PPC32TargetMachine::getJITMatchQuality() { |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 53 | #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) |
| 54 | return 10; |
| 55 | #else |
| 56 | return 0; |
| 57 | #endif |
| 58 | } |
Misha Brukman | 01eca8d | 2004-07-12 23:36:12 +0000 | [diff] [blame] | 59 | |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 60 | /// addPassesToEmitFile - Add passes to the specified pass manager to implement |
| 61 | /// a static compiler for this target. |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 62 | /// |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 63 | bool PowerPCTargetMachine::addPassesToEmitFile(PassManager &PM, |
| 64 | std::ostream &Out, |
| 65 | CodeGenFileType FileType) { |
| 66 | if (FileType != TargetMachine::AssemblyFile) return true; |
| 67 | |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 68 | // Run loop strength reduction before anything else. |
| 69 | PM.add(createLoopStrengthReducePass()); |
| 70 | PM.add(createCFGSimplificationPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 71 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 72 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 73 | PM.add(createLowerGCPass()); |
| 74 | |
| 75 | // FIXME: Implement the invoke/unwind instructions! |
| 76 | PM.add(createLowerInvokePass()); |
| 77 | |
| 78 | // FIXME: Implement the switch instruction in the instruction selector! |
| 79 | PM.add(createLowerSwitchPass()); |
| 80 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 81 | // Make sure that no unreachable blocks are instruction selected. |
| 82 | PM.add(createUnreachableBlockEliminationPass()); |
| 83 | |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 84 | // Default to pattern ISel |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 85 | if (PatternISelTriState == 0) { |
| 86 | PM.add(createLowerConstantExpressionsPass()); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 87 | PM.add(createPPC32ISelSimple(*this)); |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 88 | } else |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 89 | PM.add(createPPC32ISelPattern(*this)); |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 90 | |
| 91 | if (PrintMachineCode) |
| 92 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 93 | |
| 94 | PM.add(createRegisterAllocator()); |
| 95 | |
| 96 | if (PrintMachineCode) |
| 97 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 98 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 99 | PM.add(createPrologEpilogCodeInserter()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 100 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 101 | // Must run branch selection immediately preceding the asm printer |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 102 | PM.add(createPPCBranchSelectionPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 103 | |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 104 | // Decide which asm printer to use. If the user has not specified one on |
| 105 | // the command line, choose whichever one matches the default (current host). |
| 106 | switch (PPCTarget) { |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 107 | case TargetAIX: |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 108 | PM.add(createAIXAsmPrinter(Out, *this)); |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 109 | break; |
Chris Lattner | 4e624ec | 2005-08-05 16:17:22 +0000 | [diff] [blame] | 110 | case TargetDefault: |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 111 | case TargetDarwin: |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 112 | PM.add(createDarwinAsmPrinter(Out, *this)); |
Nate Begeman | 3d72d14 | 2005-08-04 20:49:48 +0000 | [diff] [blame] | 113 | break; |
| 114 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 115 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 116 | PM.add(createMachineCodeDeleter()); |
| 117 | return false; |
| 118 | } |
| 119 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 120 | void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) { |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 121 | // The JIT does not support or need PIC. |
| 122 | PICEnabled = false; |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 123 | |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 124 | // Run loop strength reduction before anything else. |
| 125 | PM.add(createLoopStrengthReducePass()); |
| 126 | PM.add(createCFGSimplificationPass()); |
Chris Lattner | 0c74906 | 2005-03-02 06:19:22 +0000 | [diff] [blame] | 127 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 128 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 129 | PM.add(createLowerGCPass()); |
| 130 | |
| 131 | // FIXME: Implement the invoke/unwind instructions! |
| 132 | PM.add(createLowerInvokePass()); |
| 133 | |
| 134 | // FIXME: Implement the switch instruction in the instruction selector! |
| 135 | PM.add(createLowerSwitchPass()); |
| 136 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 137 | // Make sure that no unreachable blocks are instruction selected. |
| 138 | PM.add(createUnreachableBlockEliminationPass()); |
| 139 | |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 140 | // Default to pattern ISel |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 141 | if (PatternISelTriState == 0) { |
| 142 | PM.add(createLowerConstantExpressionsPass()); |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 143 | PM.add(createPPC32ISelSimple(TM)); |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 144 | } else { |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 145 | PM.add(createPPC32ISelPattern(TM)); |
Chris Lattner | b0096bd | 2005-08-15 23:47:04 +0000 | [diff] [blame^] | 146 | } |
Nate Begeman | f8b0294 | 2005-04-15 22:12:16 +0000 | [diff] [blame] | 147 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 148 | PM.add(createRegisterAllocator()); |
| 149 | PM.add(createPrologEpilogCodeInserter()); |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 150 | |
| 151 | // Must run branch selection immediately preceding the asm printer |
| 152 | PM.add(createPPCBranchSelectionPass()); |
| 153 | |
| 154 | if (PrintMachineCode) |
| 155 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Misha Brukman | 0145881 | 2004-08-11 00:11:25 +0000 | [diff] [blame] | 156 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 157 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 158 | /// PowerPCTargetMachine ctor - Create an ILP32 architecture model |
| 159 | /// |
Misha Brukman | 66aa3e0 | 2004-08-17 05:06:47 +0000 | [diff] [blame] | 160 | PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL) |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 161 | : PowerPCTargetMachine(PPC32ID, IL, M, |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 162 | TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,1), |
Chris Lattner | e4fce6f | 2004-11-23 05:56:40 +0000 | [diff] [blame] | 163 | PowerPCFrameInfo(*this, false)), JITInfo(*this) {} |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 164 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 165 | unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) { |
Chris Lattner | 3ea78c4 | 2004-12-12 17:40:28 +0000 | [diff] [blame] | 166 | // We strongly match "powerpc-*". |
| 167 | std::string TT = M.getTargetTriple(); |
| 168 | if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-") |
| 169 | return 20; |
| 170 | |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 171 | if (M.getEndianness() == Module::BigEndian && |
| 172 | M.getPointerSize() == Module::Pointer32) |
Chris Lattner | 3ea78c4 | 2004-12-12 17:40:28 +0000 | [diff] [blame] | 173 | return 10; // Weak match |
Nate Begeman | 7a4fe9b | 2004-08-11 07:40:04 +0000 | [diff] [blame] | 174 | else if (M.getEndianness() != Module::AnyEndianness || |
| 175 | M.getPointerSize() != Module::AnyPointerSize) |
| 176 | return 0; // Match for some other target |
| 177 | |
| 178 | return getJITMatchQuality()/2; |
| 179 | } |