Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 1 | //===-- SparcV8TargetMachine.cpp - Define TargetMachine for SparcV8 -------===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +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 | // |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 9 | // |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "SparcV8TargetMachine.h" |
| 14 | #include "SparcV8.h" |
Brian Gaeke | 56c5d73 | 2004-12-11 05:19:04 +0000 | [diff] [blame] | 15 | #include "llvm/Assembly/PrintModulePass.h" |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 16 | #include "llvm/Module.h" |
| 17 | #include "llvm/PassManager.h" |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" |
| 19 | #include "llvm/CodeGen/Passes.h" |
Chris Lattner | 0cf0c37 | 2004-07-11 04:17:10 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachineRegistry.h" |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 22 | #include "llvm/Transforms/Scalar.h" |
Chris Lattner | 38343f6 | 2004-07-04 17:19:21 +0000 | [diff] [blame] | 23 | #include <iostream> |
Chris Lattner | 8d8a6bc | 2004-02-28 19:52:49 +0000 | [diff] [blame] | 24 | using namespace llvm; |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 25 | |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 26 | namespace { |
| 27 | // Register the target. |
Chris Lattner | 71d24aa | 2004-07-11 03:27:42 +0000 | [diff] [blame] | 28 | RegisterTarget<SparcV8TargetMachine> X("sparcv8"," SPARC V8 (experimental)"); |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 31 | /// SparcV8TargetMachine ctor - Create an ILP32 architecture model |
| 32 | /// |
| 33 | SparcV8TargetMachine::SparcV8TargetMachine(const Module &M, |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame^] | 34 | IntrinsicLowering *IL, |
| 35 | const std::string &FS) |
Brian Gaeke | 56c5d73 | 2004-12-11 05:19:04 +0000 | [diff] [blame] | 36 | : TargetMachine("SparcV8", IL, false, 4, 4), |
Brian Gaeke | ef8e48a | 2004-04-13 18:28:37 +0000 | [diff] [blame] | 37 | FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), JITInfo(*this) { |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Brian Gaeke | 0e2d466 | 2004-10-09 05:57:01 +0000 | [diff] [blame] | 40 | unsigned SparcV8TargetMachine::getJITMatchQuality() { |
| 41 | return 0; // No JIT yet. |
| 42 | } |
| 43 | |
| 44 | unsigned SparcV8TargetMachine::getModuleMatchQuality(const Module &M) { |
Chris Lattner | 3ea78c4 | 2004-12-12 17:40:28 +0000 | [diff] [blame] | 45 | std::string TT = M.getTargetTriple(); |
| 46 | if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-") |
| 47 | return 20; |
| 48 | |
Brian Gaeke | 0e2d466 | 2004-10-09 05:57:01 +0000 | [diff] [blame] | 49 | if (M.getEndianness() == Module::BigEndian && |
| 50 | M.getPointerSize() == Module::Pointer32) |
| 51 | #ifdef __sparc__ |
| 52 | return 20; // BE/32 ==> Prefer sparcv8 on sparc |
| 53 | #else |
| 54 | return 5; // BE/32 ==> Prefer ppc elsewhere |
| 55 | #endif |
| 56 | else if (M.getEndianness() != Module::AnyEndianness || |
| 57 | M.getPointerSize() != Module::AnyPointerSize) |
| 58 | return 0; // Match for some other target |
| 59 | |
| 60 | return getJITMatchQuality()/2; |
| 61 | } |
| 62 | |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 63 | /// addPassesToEmitFile - Add passes to the specified pass manager |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 64 | /// to implement a static compiler for this target. |
| 65 | /// |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 66 | bool SparcV8TargetMachine::addPassesToEmitFile(PassManager &PM, |
| 67 | std::ostream &Out, |
| 68 | CodeGenFileType FileType) { |
| 69 | if (FileType != TargetMachine::AssemblyFile) return true; |
| 70 | |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 71 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 72 | PM.add(createLowerGCPass()); |
| 73 | |
| 74 | // Replace malloc and free instructions with library calls. |
| 75 | PM.add(createLowerAllocationsPass()); |
Brian Gaeke | a3c5762 | 2004-06-18 08:46:15 +0000 | [diff] [blame] | 76 | |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 77 | // FIXME: implement the switch instruction in the instruction selector. |
| 78 | PM.add(createLowerSwitchPass()); |
| 79 | |
| 80 | // FIXME: implement the invoke/unwind instructions! |
| 81 | PM.add(createLowerInvokePass()); |
| 82 | |
Chris Lattner | a9a582f | 2004-07-02 05:49:11 +0000 | [diff] [blame] | 83 | PM.add(createLowerConstantExpressionsPass()); |
| 84 | |
| 85 | // Make sure that no unreachable blocks are instruction selected. |
| 86 | PM.add(createUnreachableBlockEliminationPass()); |
| 87 | |
Brian Gaeke | 5aefa8a | 2004-12-10 08:39:30 +0000 | [diff] [blame] | 88 | // FIXME: implement the select instruction in the instruction selector. |
| 89 | PM.add(createLowerSelectPass()); |
Brian Gaeke | 56c5d73 | 2004-12-11 05:19:04 +0000 | [diff] [blame] | 90 | |
| 91 | // Print LLVM code input to instruction selector: |
| 92 | if (PrintMachineCode) |
Brian Gaeke | 74be3a5 | 2004-12-11 22:17:07 +0000 | [diff] [blame] | 93 | PM.add(new PrintFunctionPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 94 | |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 95 | PM.add(createSparcV8SimpleInstructionSelector(*this)); |
| 96 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 97 | // Print machine instructions as they were initially generated. |
| 98 | if (PrintMachineCode) |
| 99 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 100 | |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 101 | PM.add(createRegisterAllocator()); |
| 102 | PM.add(createPrologEpilogCodeInserter()); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 103 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 104 | // Print machine instructions after register allocation and prolog/epilog |
| 105 | // insertion. |
| 106 | if (PrintMachineCode) |
| 107 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 108 | |
Brian Gaeke | 8a9acd1 | 2004-09-29 03:26:27 +0000 | [diff] [blame] | 109 | PM.add(createSparcV8FPMoverPass(*this)); |
Brian Gaeke | 86a8790 | 2004-04-06 23:21:24 +0000 | [diff] [blame] | 110 | PM.add(createSparcV8DelaySlotFillerPass(*this)); |
| 111 | |
| 112 | // Print machine instructions after filling delay slots. |
| 113 | if (PrintMachineCode) |
| 114 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 115 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 116 | // Output assembly language. |
Brian Gaeke | 4acfd03 | 2004-03-04 06:00:41 +0000 | [diff] [blame] | 117 | PM.add(createSparcV8CodePrinterPass(Out, *this)); |
| 118 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 119 | // Delete the MachineInstrs we generated, since they're no longer needed. |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 120 | PM.add(createMachineCodeDeleter()); |
Chris Lattner | 9ff6ba1 | 2004-02-28 20:21:45 +0000 | [diff] [blame] | 121 | return false; |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /// addPassesToJITCompile - Add passes to the specified pass manager to |
| 125 | /// implement a fast dynamic compiler for this target. |
| 126 | /// |
| 127 | void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) { |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 128 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 129 | PM.add(createLowerGCPass()); |
| 130 | |
| 131 | // Replace malloc and free instructions with library calls. |
| 132 | PM.add(createLowerAllocationsPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 133 | |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 134 | // FIXME: implement the switch instruction in the instruction selector. |
| 135 | PM.add(createLowerSwitchPass()); |
| 136 | |
| 137 | // FIXME: implement the invoke/unwind instructions! |
| 138 | PM.add(createLowerInvokePass()); |
Chris Lattner | a9a582f | 2004-07-02 05:49:11 +0000 | [diff] [blame] | 139 | |
| 140 | PM.add(createLowerConstantExpressionsPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 141 | |
Chris Lattner | a9a582f | 2004-07-02 05:49:11 +0000 | [diff] [blame] | 142 | // Make sure that no unreachable blocks are instruction selected. |
| 143 | PM.add(createUnreachableBlockEliminationPass()); |
| 144 | |
Brian Gaeke | 5aefa8a | 2004-12-10 08:39:30 +0000 | [diff] [blame] | 145 | // FIXME: implement the select instruction in the instruction selector. |
| 146 | PM.add(createLowerSelectPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 147 | |
Brian Gaeke | b3a86a6 | 2004-12-11 18:41:09 +0000 | [diff] [blame] | 148 | // Print LLVM code input to instruction selector: |
| 149 | if (PrintMachineCode) |
| 150 | PM.add(new PrintFunctionPass()); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 151 | |
Brian Gaeke | 86a8790 | 2004-04-06 23:21:24 +0000 | [diff] [blame] | 152 | PM.add(createSparcV8SimpleInstructionSelector(TM)); |
| 153 | |
| 154 | // Print machine instructions as they were initially generated. |
| 155 | if (PrintMachineCode) |
| 156 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 157 | |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 158 | PM.add(createRegisterAllocator()); |
| 159 | PM.add(createPrologEpilogCodeInserter()); |
Brian Gaeke | 86a8790 | 2004-04-06 23:21:24 +0000 | [diff] [blame] | 160 | |
| 161 | // Print machine instructions after register allocation and prolog/epilog |
| 162 | // insertion. |
| 163 | if (PrintMachineCode) |
| 164 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 165 | |
Brian Gaeke | 8a9acd1 | 2004-09-29 03:26:27 +0000 | [diff] [blame] | 166 | PM.add(createSparcV8FPMoverPass(TM)); |
Brian Gaeke | 86a8790 | 2004-04-06 23:21:24 +0000 | [diff] [blame] | 167 | PM.add(createSparcV8DelaySlotFillerPass(TM)); |
| 168 | |
| 169 | // Print machine instructions after filling delay slots. |
| 170 | if (PrintMachineCode) |
| 171 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 172 | } |