blob: 4a8a39477738836a0b7b9e0089a23e4cc9847d70 [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"
Chris Lattnerd36c9702004-07-11 02:48:49 +000020#include "llvm/Target/TargetMachineRegistry.h"
Brian Gaekef4052802004-06-15 20:37:12 +000021#include "llvm/Transforms/Scalar.h"
Chris Lattner38343f62004-07-04 17:19:21 +000022#include <iostream>
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000023using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000024
Chris Lattnerd36c9702004-07-11 02:48:49 +000025namespace {
26 // Register the target.
27 RegisterTarget<SparcV8TargetMachine> X("sparcv8", "SPARC V8 (experimental)");
28}
29
Brian Gaekee785e532004-02-25 19:28:19 +000030// allocateSparcV8TargetMachine - Allocate and return a subclass of
31// TargetMachine that implements the SparcV8 backend.
32//
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000033TargetMachine *llvm::allocateSparcV8TargetMachine(const Module &M,
34 IntrinsicLowering *IL) {
Brian Gaekee785e532004-02-25 19:28:19 +000035 return new SparcV8TargetMachine(M, IL);
36}
37
38/// SparcV8TargetMachine ctor - Create an ILP32 architecture model
39///
40SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
41 IntrinsicLowering *IL)
42 : TargetMachine("SparcV8", IL, true, 4, 4, 4, 4, 4),
Brian Gaekeef8e48a2004-04-13 18:28:37 +000043 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), JITInfo(*this) {
Brian Gaekee785e532004-02-25 19:28:19 +000044}
45
46/// addPassesToEmitAssembly - Add passes to the specified pass manager
47/// to implement a static compiler for this target.
48///
49bool SparcV8TargetMachine::addPassesToEmitAssembly(PassManager &PM,
50 std::ostream &Out) {
Brian Gaekef4052802004-06-15 20:37:12 +000051 // FIXME: Implement efficient support for garbage collection intrinsics.
52 PM.add(createLowerGCPass());
53
54 // Replace malloc and free instructions with library calls.
55 PM.add(createLowerAllocationsPass());
Brian Gaekea3c57622004-06-18 08:46:15 +000056
57 // FIXME: implement the select instruction in the instruction selector.
58 PM.add(createLowerSelectPass());
Brian Gaekef4052802004-06-15 20:37:12 +000059
60 // FIXME: implement the switch instruction in the instruction selector.
61 PM.add(createLowerSwitchPass());
62
63 // FIXME: implement the invoke/unwind instructions!
64 PM.add(createLowerInvokePass());
65
Chris Lattnera9a582f2004-07-02 05:49:11 +000066 PM.add(createLowerConstantExpressionsPass());
67
68 // Make sure that no unreachable blocks are instruction selected.
69 PM.add(createUnreachableBlockEliminationPass());
70
Chris Lattner1c809c52004-02-29 00:27:00 +000071 PM.add(createSparcV8SimpleInstructionSelector(*this));
72
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000073 // Print machine instructions as they were initially generated.
74 if (PrintMachineCode)
75 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000076
Brian Gaekee785e532004-02-25 19:28:19 +000077 PM.add(createRegisterAllocator());
78 PM.add(createPrologEpilogCodeInserter());
Chris Lattner1c809c52004-02-29 00:27:00 +000079
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000080 // Print machine instructions after register allocation and prolog/epilog
81 // insertion.
82 if (PrintMachineCode)
83 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000084
Brian Gaeke86a87902004-04-06 23:21:24 +000085 PM.add(createSparcV8DelaySlotFillerPass(*this));
86
87 // Print machine instructions after filling delay slots.
88 if (PrintMachineCode)
89 PM.add(createMachineFunctionPrinterPass(&std::cerr));
90
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000091 // Output assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +000092 PM.add(createSparcV8CodePrinterPass(Out, *this));
93
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000094 // Delete the MachineInstrs we generated, since they're no longer needed.
Brian Gaekee785e532004-02-25 19:28:19 +000095 PM.add(createMachineCodeDeleter());
Chris Lattner9ff6ba12004-02-28 20:21:45 +000096 return false;
Brian Gaekee785e532004-02-25 19:28:19 +000097}
98
99/// addPassesToJITCompile - Add passes to the specified pass manager to
100/// implement a fast dynamic compiler for this target.
101///
102void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Brian Gaekef4052802004-06-15 20:37:12 +0000103 // FIXME: Implement efficient support for garbage collection intrinsics.
104 PM.add(createLowerGCPass());
105
106 // Replace malloc and free instructions with library calls.
107 PM.add(createLowerAllocationsPass());
108
Brian Gaekea3c57622004-06-18 08:46:15 +0000109 // FIXME: implement the select instruction in the instruction selector.
110 PM.add(createLowerSelectPass());
111
Brian Gaekef4052802004-06-15 20:37:12 +0000112 // FIXME: implement the switch instruction in the instruction selector.
113 PM.add(createLowerSwitchPass());
114
115 // FIXME: implement the invoke/unwind instructions!
116 PM.add(createLowerInvokePass());
Chris Lattnera9a582f2004-07-02 05:49:11 +0000117
118 PM.add(createLowerConstantExpressionsPass());
Brian Gaekef4052802004-06-15 20:37:12 +0000119
Chris Lattnera9a582f2004-07-02 05:49:11 +0000120 // Make sure that no unreachable blocks are instruction selected.
121 PM.add(createUnreachableBlockEliminationPass());
122
Brian Gaeke86a87902004-04-06 23:21:24 +0000123 PM.add(createSparcV8SimpleInstructionSelector(TM));
124
125 // Print machine instructions as they were initially generated.
126 if (PrintMachineCode)
127 PM.add(createMachineFunctionPrinterPass(&std::cerr));
128
Brian Gaekee785e532004-02-25 19:28:19 +0000129 PM.add(createRegisterAllocator());
130 PM.add(createPrologEpilogCodeInserter());
Brian Gaeke86a87902004-04-06 23:21:24 +0000131
132 // Print machine instructions after register allocation and prolog/epilog
133 // insertion.
134 if (PrintMachineCode)
135 PM.add(createMachineFunctionPrinterPass(&std::cerr));
136
137 PM.add(createSparcV8DelaySlotFillerPass(TM));
138
139 // Print machine instructions after filling delay slots.
140 if (PrintMachineCode)
141 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Brian Gaekee785e532004-02-25 19:28:19 +0000142}