Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 1 | //===-- SparcV8TargetMachine.cpp - Define TargetMachine for SparcV8 -------===// |
| 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 | |
| 13 | #include "SparcV8TargetMachine.h" |
| 14 | #include "SparcV8.h" |
| 15 | #include "llvm/Module.h" |
| 16 | #include "llvm/PassManager.h" |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineFunction.h" |
| 18 | #include "llvm/CodeGen/Passes.h" |
Misha Brukman | 0280aa9 | 2004-06-21 21:54:40 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetMachineImpls.h" |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 20 | #include "llvm/Transforms/Scalar.h" |
Chris Lattner | 38343f6 | 2004-07-04 17:19:21 +0000 | [diff] [blame^] | 21 | #include <iostream> |
Chris Lattner | 8d8a6bc | 2004-02-28 19:52:49 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 23 | |
| 24 | // allocateSparcV8TargetMachine - Allocate and return a subclass of |
| 25 | // TargetMachine that implements the SparcV8 backend. |
| 26 | // |
Chris Lattner | 8d8a6bc | 2004-02-28 19:52:49 +0000 | [diff] [blame] | 27 | TargetMachine *llvm::allocateSparcV8TargetMachine(const Module &M, |
| 28 | IntrinsicLowering *IL) { |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 29 | return new SparcV8TargetMachine(M, IL); |
| 30 | } |
| 31 | |
| 32 | /// SparcV8TargetMachine ctor - Create an ILP32 architecture model |
| 33 | /// |
| 34 | SparcV8TargetMachine::SparcV8TargetMachine(const Module &M, |
| 35 | IntrinsicLowering *IL) |
| 36 | : TargetMachine("SparcV8", IL, true, 4, 4, 4, 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 | |
| 40 | /// addPassesToEmitAssembly - Add passes to the specified pass manager |
| 41 | /// to implement a static compiler for this target. |
| 42 | /// |
| 43 | bool SparcV8TargetMachine::addPassesToEmitAssembly(PassManager &PM, |
| 44 | std::ostream &Out) { |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 45 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 46 | PM.add(createLowerGCPass()); |
| 47 | |
| 48 | // Replace malloc and free instructions with library calls. |
| 49 | PM.add(createLowerAllocationsPass()); |
Brian Gaeke | a3c5762 | 2004-06-18 08:46:15 +0000 | [diff] [blame] | 50 | |
| 51 | // FIXME: implement the select instruction in the instruction selector. |
| 52 | PM.add(createLowerSelectPass()); |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 53 | |
| 54 | // FIXME: implement the switch instruction in the instruction selector. |
| 55 | PM.add(createLowerSwitchPass()); |
| 56 | |
| 57 | // FIXME: implement the invoke/unwind instructions! |
| 58 | PM.add(createLowerInvokePass()); |
| 59 | |
Chris Lattner | a9a582f | 2004-07-02 05:49:11 +0000 | [diff] [blame] | 60 | PM.add(createLowerConstantExpressionsPass()); |
| 61 | |
| 62 | // Make sure that no unreachable blocks are instruction selected. |
| 63 | PM.add(createUnreachableBlockEliminationPass()); |
| 64 | |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 65 | PM.add(createSparcV8SimpleInstructionSelector(*this)); |
| 66 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 67 | // Print machine instructions as they were initially generated. |
| 68 | if (PrintMachineCode) |
| 69 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 70 | |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 71 | PM.add(createRegisterAllocator()); |
| 72 | PM.add(createPrologEpilogCodeInserter()); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 73 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 74 | // Print machine instructions after register allocation and prolog/epilog |
| 75 | // insertion. |
| 76 | if (PrintMachineCode) |
| 77 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Chris Lattner | 1c809c5 | 2004-02-29 00:27:00 +0000 | [diff] [blame] | 78 | |
Brian Gaeke | 86a8790 | 2004-04-06 23:21:24 +0000 | [diff] [blame] | 79 | PM.add(createSparcV8DelaySlotFillerPass(*this)); |
| 80 | |
| 81 | // Print machine instructions after filling delay slots. |
| 82 | if (PrintMachineCode) |
| 83 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 84 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 85 | // Output assembly language. |
Brian Gaeke | 4acfd03 | 2004-03-04 06:00:41 +0000 | [diff] [blame] | 86 | PM.add(createSparcV8CodePrinterPass(Out, *this)); |
| 87 | |
Brian Gaeke | 7a3ae1f | 2004-03-04 19:22:16 +0000 | [diff] [blame] | 88 | // Delete the MachineInstrs we generated, since they're no longer needed. |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 89 | PM.add(createMachineCodeDeleter()); |
Chris Lattner | 9ff6ba1 | 2004-02-28 20:21:45 +0000 | [diff] [blame] | 90 | return false; |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /// addPassesToJITCompile - Add passes to the specified pass manager to |
| 94 | /// implement a fast dynamic compiler for this target. |
| 95 | /// |
| 96 | void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) { |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 97 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 98 | PM.add(createLowerGCPass()); |
| 99 | |
| 100 | // Replace malloc and free instructions with library calls. |
| 101 | PM.add(createLowerAllocationsPass()); |
| 102 | |
Brian Gaeke | a3c5762 | 2004-06-18 08:46:15 +0000 | [diff] [blame] | 103 | // FIXME: implement the select instruction in the instruction selector. |
| 104 | PM.add(createLowerSelectPass()); |
| 105 | |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 106 | // FIXME: implement the switch instruction in the instruction selector. |
| 107 | PM.add(createLowerSwitchPass()); |
| 108 | |
| 109 | // FIXME: implement the invoke/unwind instructions! |
| 110 | PM.add(createLowerInvokePass()); |
Chris Lattner | a9a582f | 2004-07-02 05:49:11 +0000 | [diff] [blame] | 111 | |
| 112 | PM.add(createLowerConstantExpressionsPass()); |
Brian Gaeke | f405280 | 2004-06-15 20:37:12 +0000 | [diff] [blame] | 113 | |
Chris Lattner | a9a582f | 2004-07-02 05:49:11 +0000 | [diff] [blame] | 114 | // Make sure that no unreachable blocks are instruction selected. |
| 115 | PM.add(createUnreachableBlockEliminationPass()); |
| 116 | |
Brian Gaeke | 86a8790 | 2004-04-06 23:21:24 +0000 | [diff] [blame] | 117 | PM.add(createSparcV8SimpleInstructionSelector(TM)); |
| 118 | |
| 119 | // Print machine instructions as they were initially generated. |
| 120 | if (PrintMachineCode) |
| 121 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 122 | |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 123 | PM.add(createRegisterAllocator()); |
| 124 | PM.add(createPrologEpilogCodeInserter()); |
Brian Gaeke | 86a8790 | 2004-04-06 23:21:24 +0000 | [diff] [blame] | 125 | |
| 126 | // Print machine instructions after register allocation and prolog/epilog |
| 127 | // insertion. |
| 128 | if (PrintMachineCode) |
| 129 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 130 | |
| 131 | PM.add(createSparcV8DelaySlotFillerPass(TM)); |
| 132 | |
| 133 | // Print machine instructions after filling delay slots. |
| 134 | if (PrintMachineCode) |
| 135 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 136 | } |