blob: cdd902cf83118bc1c054891a6ec54d6a659c9f15 [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 Lattner38343f62004-07-04 17:19:21 +000021#include <iostream>
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000022using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000023
24// allocateSparcV8TargetMachine - Allocate and return a subclass of
25// TargetMachine that implements the SparcV8 backend.
26//
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000027TargetMachine *llvm::allocateSparcV8TargetMachine(const Module &M,
28 IntrinsicLowering *IL) {
Brian Gaekee785e532004-02-25 19:28:19 +000029 return new SparcV8TargetMachine(M, IL);
30}
31
32/// SparcV8TargetMachine ctor - Create an ILP32 architecture model
33///
34SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
35 IntrinsicLowering *IL)
36 : TargetMachine("SparcV8", IL, true, 4, 4, 4, 4, 4),
Brian Gaekeef8e48a2004-04-13 18:28:37 +000037 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), JITInfo(*this) {
Brian Gaekee785e532004-02-25 19:28:19 +000038}
39
40/// addPassesToEmitAssembly - Add passes to the specified pass manager
41/// to implement a static compiler for this target.
42///
43bool SparcV8TargetMachine::addPassesToEmitAssembly(PassManager &PM,
44 std::ostream &Out) {
Brian Gaekef4052802004-06-15 20:37:12 +000045 // 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 Gaekea3c57622004-06-18 08:46:15 +000050
51 // FIXME: implement the select instruction in the instruction selector.
52 PM.add(createLowerSelectPass());
Brian Gaekef4052802004-06-15 20:37:12 +000053
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 Lattnera9a582f2004-07-02 05:49:11 +000060 PM.add(createLowerConstantExpressionsPass());
61
62 // Make sure that no unreachable blocks are instruction selected.
63 PM.add(createUnreachableBlockEliminationPass());
64
Chris Lattner1c809c52004-02-29 00:27:00 +000065 PM.add(createSparcV8SimpleInstructionSelector(*this));
66
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000067 // Print machine instructions as they were initially generated.
68 if (PrintMachineCode)
69 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000070
Brian Gaekee785e532004-02-25 19:28:19 +000071 PM.add(createRegisterAllocator());
72 PM.add(createPrologEpilogCodeInserter());
Chris Lattner1c809c52004-02-29 00:27:00 +000073
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000074 // Print machine instructions after register allocation and prolog/epilog
75 // insertion.
76 if (PrintMachineCode)
77 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000078
Brian Gaeke86a87902004-04-06 23:21:24 +000079 PM.add(createSparcV8DelaySlotFillerPass(*this));
80
81 // Print machine instructions after filling delay slots.
82 if (PrintMachineCode)
83 PM.add(createMachineFunctionPrinterPass(&std::cerr));
84
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000085 // Output assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +000086 PM.add(createSparcV8CodePrinterPass(Out, *this));
87
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000088 // Delete the MachineInstrs we generated, since they're no longer needed.
Brian Gaekee785e532004-02-25 19:28:19 +000089 PM.add(createMachineCodeDeleter());
Chris Lattner9ff6ba12004-02-28 20:21:45 +000090 return false;
Brian Gaekee785e532004-02-25 19:28:19 +000091}
92
93/// addPassesToJITCompile - Add passes to the specified pass manager to
94/// implement a fast dynamic compiler for this target.
95///
96void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Brian Gaekef4052802004-06-15 20:37:12 +000097 // 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 Gaekea3c57622004-06-18 08:46:15 +0000103 // FIXME: implement the select instruction in the instruction selector.
104 PM.add(createLowerSelectPass());
105
Brian Gaekef4052802004-06-15 20:37:12 +0000106 // 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 Lattnera9a582f2004-07-02 05:49:11 +0000111
112 PM.add(createLowerConstantExpressionsPass());
Brian Gaekef4052802004-06-15 20:37:12 +0000113
Chris Lattnera9a582f2004-07-02 05:49:11 +0000114 // Make sure that no unreachable blocks are instruction selected.
115 PM.add(createUnreachableBlockEliminationPass());
116
Brian Gaeke86a87902004-04-06 23:21:24 +0000117 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 Gaekee785e532004-02-25 19:28:19 +0000123 PM.add(createRegisterAllocator());
124 PM.add(createPrologEpilogCodeInserter());
Brian Gaeke86a87902004-04-06 23:21:24 +0000125
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 Gaekee785e532004-02-25 19:28:19 +0000136}