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