blob: a867503573da20702c076d37b2361ec5465c929e [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"
Brian Gaeke56c5d732004-12-11 05:19:04 +000015#include "llvm/Assembly/PrintModulePass.h"
Brian Gaekee785e532004-02-25 19:28:19 +000016#include "llvm/Module.h"
17#include "llvm/PassManager.h"
Brian Gaekee785e532004-02-25 19:28:19 +000018#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/Passes.h"
Chris Lattner0cf0c372004-07-11 04:17:10 +000020#include "llvm/Target/TargetOptions.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000021#include "llvm/Target/TargetMachineRegistry.h"
Brian Gaekef4052802004-06-15 20:37:12 +000022#include "llvm/Transforms/Scalar.h"
Chris Lattner38343f62004-07-04 17:19:21 +000023#include <iostream>
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000024using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000025
Chris Lattnerd36c9702004-07-11 02:48:49 +000026namespace {
27 // Register the target.
Chris Lattner71d24aa2004-07-11 03:27:42 +000028 RegisterTarget<SparcV8TargetMachine> X("sparcv8"," SPARC V8 (experimental)");
Chris Lattnerd36c9702004-07-11 02:48:49 +000029}
30
Brian Gaekee785e532004-02-25 19:28:19 +000031/// SparcV8TargetMachine ctor - Create an ILP32 architecture model
32///
33SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
34 IntrinsicLowering *IL)
Brian Gaeke56c5d732004-12-11 05:19:04 +000035 : TargetMachine("SparcV8", IL, false, 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
Brian Gaeke0e2d4662004-10-09 05:57:01 +000039unsigned SparcV8TargetMachine::getJITMatchQuality() {
40 return 0; // No JIT yet.
41}
42
43unsigned SparcV8TargetMachine::getModuleMatchQuality(const Module &M) {
44 if (M.getEndianness() == Module::BigEndian &&
45 M.getPointerSize() == Module::Pointer32)
46#ifdef __sparc__
47 return 20; // BE/32 ==> Prefer sparcv8 on sparc
48#else
49 return 5; // BE/32 ==> Prefer ppc elsewhere
50#endif
51 else if (M.getEndianness() != Module::AnyEndianness ||
52 M.getPointerSize() != Module::AnyPointerSize)
53 return 0; // Match for some other target
54
55 return getJITMatchQuality()/2;
56}
57
Brian Gaekee785e532004-02-25 19:28:19 +000058/// addPassesToEmitAssembly - Add passes to the specified pass manager
59/// to implement a static compiler for this target.
60///
61bool SparcV8TargetMachine::addPassesToEmitAssembly(PassManager &PM,
62 std::ostream &Out) {
Brian Gaekef4052802004-06-15 20:37:12 +000063 // FIXME: Implement efficient support for garbage collection intrinsics.
64 PM.add(createLowerGCPass());
65
66 // Replace malloc and free instructions with library calls.
67 PM.add(createLowerAllocationsPass());
Brian Gaekea3c57622004-06-18 08:46:15 +000068
Brian Gaekef4052802004-06-15 20:37:12 +000069 // FIXME: implement the switch instruction in the instruction selector.
70 PM.add(createLowerSwitchPass());
71
72 // FIXME: implement the invoke/unwind instructions!
73 PM.add(createLowerInvokePass());
74
Chris Lattnera9a582f2004-07-02 05:49:11 +000075 PM.add(createLowerConstantExpressionsPass());
76
77 // Make sure that no unreachable blocks are instruction selected.
78 PM.add(createUnreachableBlockEliminationPass());
79
Brian Gaeke5aefa8a2004-12-10 08:39:30 +000080 // FIXME: implement the select instruction in the instruction selector.
81 PM.add(createLowerSelectPass());
Brian Gaeke56c5d732004-12-11 05:19:04 +000082
83 // Print LLVM code input to instruction selector:
84 if (PrintMachineCode)
Brian Gaeke74be3a52004-12-11 22:17:07 +000085 PM.add(new PrintFunctionPass());
Brian Gaeke5aefa8a2004-12-10 08:39:30 +000086
Chris Lattner1c809c52004-02-29 00:27:00 +000087 PM.add(createSparcV8SimpleInstructionSelector(*this));
88
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000089 // Print machine instructions as they were initially generated.
90 if (PrintMachineCode)
91 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000092
Brian Gaekee785e532004-02-25 19:28:19 +000093 PM.add(createRegisterAllocator());
94 PM.add(createPrologEpilogCodeInserter());
Chris Lattner1c809c52004-02-29 00:27:00 +000095
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000096 // Print machine instructions after register allocation and prolog/epilog
97 // insertion.
98 if (PrintMachineCode)
99 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +0000100
Brian Gaeke8a9acd12004-09-29 03:26:27 +0000101 PM.add(createSparcV8FPMoverPass(*this));
Brian Gaeke86a87902004-04-06 23:21:24 +0000102 PM.add(createSparcV8DelaySlotFillerPass(*this));
103
104 // Print machine instructions after filling delay slots.
105 if (PrintMachineCode)
106 PM.add(createMachineFunctionPrinterPass(&std::cerr));
107
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +0000108 // Output assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +0000109 PM.add(createSparcV8CodePrinterPass(Out, *this));
110
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +0000111 // Delete the MachineInstrs we generated, since they're no longer needed.
Brian Gaekee785e532004-02-25 19:28:19 +0000112 PM.add(createMachineCodeDeleter());
Chris Lattner9ff6ba12004-02-28 20:21:45 +0000113 return false;
Brian Gaekee785e532004-02-25 19:28:19 +0000114}
115
116/// addPassesToJITCompile - Add passes to the specified pass manager to
117/// implement a fast dynamic compiler for this target.
118///
119void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Brian Gaekef4052802004-06-15 20:37:12 +0000120 // FIXME: Implement efficient support for garbage collection intrinsics.
121 PM.add(createLowerGCPass());
122
123 // Replace malloc and free instructions with library calls.
124 PM.add(createLowerAllocationsPass());
125
126 // FIXME: implement the switch instruction in the instruction selector.
127 PM.add(createLowerSwitchPass());
128
129 // FIXME: implement the invoke/unwind instructions!
130 PM.add(createLowerInvokePass());
Chris Lattnera9a582f2004-07-02 05:49:11 +0000131
132 PM.add(createLowerConstantExpressionsPass());
Brian Gaekef4052802004-06-15 20:37:12 +0000133
Chris Lattnera9a582f2004-07-02 05:49:11 +0000134 // Make sure that no unreachable blocks are instruction selected.
135 PM.add(createUnreachableBlockEliminationPass());
136
Brian Gaeke5aefa8a2004-12-10 08:39:30 +0000137 // FIXME: implement the select instruction in the instruction selector.
138 PM.add(createLowerSelectPass());
139
Brian Gaekeb3a86a62004-12-11 18:41:09 +0000140 // Print LLVM code input to instruction selector:
141 if (PrintMachineCode)
142 PM.add(new PrintFunctionPass());
143
Brian Gaeke86a87902004-04-06 23:21:24 +0000144 PM.add(createSparcV8SimpleInstructionSelector(TM));
145
146 // Print machine instructions as they were initially generated.
147 if (PrintMachineCode)
148 PM.add(createMachineFunctionPrinterPass(&std::cerr));
149
Brian Gaekee785e532004-02-25 19:28:19 +0000150 PM.add(createRegisterAllocator());
151 PM.add(createPrologEpilogCodeInserter());
Brian Gaeke86a87902004-04-06 23:21:24 +0000152
153 // Print machine instructions after register allocation and prolog/epilog
154 // insertion.
155 if (PrintMachineCode)
156 PM.add(createMachineFunctionPrinterPass(&std::cerr));
157
Brian Gaeke8a9acd12004-09-29 03:26:27 +0000158 PM.add(createSparcV8FPMoverPass(TM));
Brian Gaeke86a87902004-04-06 23:21:24 +0000159 PM.add(createSparcV8DelaySlotFillerPass(TM));
160
161 // Print machine instructions after filling delay slots.
162 if (PrintMachineCode)
163 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Brian Gaekee785e532004-02-25 19:28:19 +0000164}