blob: 324fc5b1c95f1cda281d98302a0f4ea0890f462e [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"
Chris Lattner0cf0c372004-07-11 04:17:10 +000019#include "llvm/Target/TargetOptions.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.
Chris Lattner71d24aa2004-07-11 03:27:42 +000027 RegisterTarget<SparcV8TargetMachine> X("sparcv8"," SPARC V8 (experimental)");
Chris Lattnerd36c9702004-07-11 02:48:49 +000028}
29
Brian Gaekee785e532004-02-25 19:28:19 +000030/// SparcV8TargetMachine ctor - Create an ILP32 architecture model
31///
32SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
33 IntrinsicLowering *IL)
Brian Gaeke20503bd2004-12-09 18:51:02 +000034 : TargetMachine("SparcV8", IL, false, 4, 4, 8, 4, 8, 4, 2, 1, 4),
Brian Gaekeef8e48a2004-04-13 18:28:37 +000035 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), JITInfo(*this) {
Brian Gaekee785e532004-02-25 19:28:19 +000036}
37
Brian Gaeke0e2d4662004-10-09 05:57:01 +000038unsigned SparcV8TargetMachine::getJITMatchQuality() {
39 return 0; // No JIT yet.
40}
41
42unsigned SparcV8TargetMachine::getModuleMatchQuality(const Module &M) {
43 if (M.getEndianness() == Module::BigEndian &&
44 M.getPointerSize() == Module::Pointer32)
45#ifdef __sparc__
46 return 20; // BE/32 ==> Prefer sparcv8 on sparc
47#else
48 return 5; // BE/32 ==> Prefer ppc elsewhere
49#endif
50 else if (M.getEndianness() != Module::AnyEndianness ||
51 M.getPointerSize() != Module::AnyPointerSize)
52 return 0; // Match for some other target
53
54 return getJITMatchQuality()/2;
55}
56
Brian Gaekee785e532004-02-25 19:28:19 +000057/// addPassesToEmitAssembly - Add passes to the specified pass manager
58/// to implement a static compiler for this target.
59///
60bool SparcV8TargetMachine::addPassesToEmitAssembly(PassManager &PM,
61 std::ostream &Out) {
Brian Gaekef4052802004-06-15 20:37:12 +000062 // FIXME: Implement efficient support for garbage collection intrinsics.
63 PM.add(createLowerGCPass());
64
65 // Replace malloc and free instructions with library calls.
66 PM.add(createLowerAllocationsPass());
Brian Gaekea3c57622004-06-18 08:46:15 +000067
68 // FIXME: implement the select instruction in the instruction selector.
69 PM.add(createLowerSelectPass());
Brian Gaekef4052802004-06-15 20:37:12 +000070
71 // FIXME: implement the switch instruction in the instruction selector.
72 PM.add(createLowerSwitchPass());
73
74 // FIXME: implement the invoke/unwind instructions!
75 PM.add(createLowerInvokePass());
76
Chris Lattnera9a582f2004-07-02 05:49:11 +000077 PM.add(createLowerConstantExpressionsPass());
78
79 // Make sure that no unreachable blocks are instruction selected.
80 PM.add(createUnreachableBlockEliminationPass());
81
Chris Lattner1c809c52004-02-29 00:27:00 +000082 PM.add(createSparcV8SimpleInstructionSelector(*this));
83
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000084 // Print machine instructions as they were initially generated.
85 if (PrintMachineCode)
86 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000087
Brian Gaekee785e532004-02-25 19:28:19 +000088 PM.add(createRegisterAllocator());
89 PM.add(createPrologEpilogCodeInserter());
Chris Lattner1c809c52004-02-29 00:27:00 +000090
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000091 // Print machine instructions after register allocation and prolog/epilog
92 // insertion.
93 if (PrintMachineCode)
94 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000095
Brian Gaeke8a9acd12004-09-29 03:26:27 +000096 PM.add(createSparcV8FPMoverPass(*this));
Brian Gaeke86a87902004-04-06 23:21:24 +000097 PM.add(createSparcV8DelaySlotFillerPass(*this));
98
99 // Print machine instructions after filling delay slots.
100 if (PrintMachineCode)
101 PM.add(createMachineFunctionPrinterPass(&std::cerr));
102
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +0000103 // Output assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +0000104 PM.add(createSparcV8CodePrinterPass(Out, *this));
105
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +0000106 // Delete the MachineInstrs we generated, since they're no longer needed.
Brian Gaekee785e532004-02-25 19:28:19 +0000107 PM.add(createMachineCodeDeleter());
Chris Lattner9ff6ba12004-02-28 20:21:45 +0000108 return false;
Brian Gaekee785e532004-02-25 19:28:19 +0000109}
110
111/// addPassesToJITCompile - Add passes to the specified pass manager to
112/// implement a fast dynamic compiler for this target.
113///
114void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Brian Gaekef4052802004-06-15 20:37:12 +0000115 // FIXME: Implement efficient support for garbage collection intrinsics.
116 PM.add(createLowerGCPass());
117
118 // Replace malloc and free instructions with library calls.
119 PM.add(createLowerAllocationsPass());
120
Brian Gaekea3c57622004-06-18 08:46:15 +0000121 // FIXME: implement the select instruction in the instruction selector.
122 PM.add(createLowerSelectPass());
123
Brian Gaekef4052802004-06-15 20:37:12 +0000124 // FIXME: implement the switch instruction in the instruction selector.
125 PM.add(createLowerSwitchPass());
126
127 // FIXME: implement the invoke/unwind instructions!
128 PM.add(createLowerInvokePass());
Chris Lattnera9a582f2004-07-02 05:49:11 +0000129
130 PM.add(createLowerConstantExpressionsPass());
Brian Gaekef4052802004-06-15 20:37:12 +0000131
Chris Lattnera9a582f2004-07-02 05:49:11 +0000132 // Make sure that no unreachable blocks are instruction selected.
133 PM.add(createUnreachableBlockEliminationPass());
134
Brian Gaeke86a87902004-04-06 23:21:24 +0000135 PM.add(createSparcV8SimpleInstructionSelector(TM));
136
137 // Print machine instructions as they were initially generated.
138 if (PrintMachineCode)
139 PM.add(createMachineFunctionPrinterPass(&std::cerr));
140
Brian Gaekee785e532004-02-25 19:28:19 +0000141 PM.add(createRegisterAllocator());
142 PM.add(createPrologEpilogCodeInserter());
Brian Gaeke86a87902004-04-06 23:21:24 +0000143
144 // Print machine instructions after register allocation and prolog/epilog
145 // insertion.
146 if (PrintMachineCode)
147 PM.add(createMachineFunctionPrinterPass(&std::cerr));
148
Brian Gaeke8a9acd12004-09-29 03:26:27 +0000149 PM.add(createSparcV8FPMoverPass(TM));
Brian Gaeke86a87902004-04-06 23:21:24 +0000150 PM.add(createSparcV8DelaySlotFillerPass(TM));
151
152 // Print machine instructions after filling delay slots.
153 if (PrintMachineCode)
154 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Brian Gaekee785e532004-02-25 19:28:19 +0000155}