blob: 344b88b81764646fc58372c7717fa38a462d127c [file] [log] [blame]
Brian Gaekee785e532004-02-25 19:28:19 +00001//===-- 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 Gaekee785e532004-02-25 19:28:19 +000017#include "llvm/CodeGen/MachineFunction.h"
18#include "llvm/CodeGen/Passes.h"
Misha Brukman0280aa92004-06-21 21:54:40 +000019#include "llvm/Target/TargetMachineImpls.h"
Brian Gaekef4052802004-06-15 20:37:12 +000020#include "llvm/Transforms/Scalar.h"
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000021using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000022
23// allocateSparcV8TargetMachine - Allocate and return a subclass of
24// TargetMachine that implements the SparcV8 backend.
25//
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000026TargetMachine *llvm::allocateSparcV8TargetMachine(const Module &M,
27 IntrinsicLowering *IL) {
Brian Gaekee785e532004-02-25 19:28:19 +000028 return new SparcV8TargetMachine(M, IL);
29}
30
31/// SparcV8TargetMachine ctor - Create an ILP32 architecture model
32///
33SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
34 IntrinsicLowering *IL)
35 : TargetMachine("SparcV8", IL, true, 4, 4, 4, 4, 4),
Brian Gaekeef8e48a2004-04-13 18:28:37 +000036 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), JITInfo(*this) {
Brian Gaekee785e532004-02-25 19:28:19 +000037}
38
39/// addPassesToEmitAssembly - Add passes to the specified pass manager
40/// to implement a static compiler for this target.
41///
42bool SparcV8TargetMachine::addPassesToEmitAssembly(PassManager &PM,
43 std::ostream &Out) {
Brian Gaekef4052802004-06-15 20:37:12 +000044 // 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 Gaekea3c57622004-06-18 08:46:15 +000049
50 // FIXME: implement the select instruction in the instruction selector.
51 PM.add(createLowerSelectPass());
Brian Gaekef4052802004-06-15 20:37:12 +000052
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 Lattner1c809c52004-02-29 00:27:00 +000059 PM.add(createSparcV8SimpleInstructionSelector(*this));
60
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000061 // Print machine instructions as they were initially generated.
62 if (PrintMachineCode)
63 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000064
Brian Gaekee785e532004-02-25 19:28:19 +000065 PM.add(createRegisterAllocator());
66 PM.add(createPrologEpilogCodeInserter());
Chris Lattner1c809c52004-02-29 00:27:00 +000067
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000068 // Print machine instructions after register allocation and prolog/epilog
69 // insertion.
70 if (PrintMachineCode)
71 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000072
Brian Gaeke86a87902004-04-06 23:21:24 +000073 PM.add(createSparcV8DelaySlotFillerPass(*this));
74
75 // Print machine instructions after filling delay slots.
76 if (PrintMachineCode)
77 PM.add(createMachineFunctionPrinterPass(&std::cerr));
78
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000079 // Output assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +000080 PM.add(createSparcV8CodePrinterPass(Out, *this));
81
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000082 // Delete the MachineInstrs we generated, since they're no longer needed.
Brian Gaekee785e532004-02-25 19:28:19 +000083 PM.add(createMachineCodeDeleter());
Chris Lattner9ff6ba12004-02-28 20:21:45 +000084 return false;
Brian Gaekee785e532004-02-25 19:28:19 +000085}
86
87/// addPassesToJITCompile - Add passes to the specified pass manager to
88/// implement a fast dynamic compiler for this target.
89///
90void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Brian Gaekef4052802004-06-15 20:37:12 +000091 // FIXME: Implement efficient support for garbage collection intrinsics.
92 PM.add(createLowerGCPass());
93
94 // Replace malloc and free instructions with library calls.
95 PM.add(createLowerAllocationsPass());
96
Brian Gaekea3c57622004-06-18 08:46:15 +000097 // FIXME: implement the select instruction in the instruction selector.
98 PM.add(createLowerSelectPass());
99
Brian Gaekef4052802004-06-15 20:37:12 +0000100 // FIXME: implement the switch instruction in the instruction selector.
101 PM.add(createLowerSwitchPass());
102
103 // FIXME: implement the invoke/unwind instructions!
104 PM.add(createLowerInvokePass());
105
Brian Gaeke86a87902004-04-06 23:21:24 +0000106 PM.add(createSparcV8SimpleInstructionSelector(TM));
107
108 // Print machine instructions as they were initially generated.
109 if (PrintMachineCode)
110 PM.add(createMachineFunctionPrinterPass(&std::cerr));
111
Brian Gaekee785e532004-02-25 19:28:19 +0000112 PM.add(createRegisterAllocator());
113 PM.add(createPrologEpilogCodeInserter());
Brian Gaeke86a87902004-04-06 23:21:24 +0000114
115 // Print machine instructions after register allocation and prolog/epilog
116 // insertion.
117 if (PrintMachineCode)
118 PM.add(createMachineFunctionPrinterPass(&std::cerr));
119
120 PM.add(createSparcV8DelaySlotFillerPass(TM));
121
122 // Print machine instructions after filling delay slots.
123 if (PrintMachineCode)
124 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Brian Gaekee785e532004-02-25 19:28:19 +0000125}