blob: d2c72650ff0af7e6c4bf066739add61bd44c5cc0 [file] [log] [blame]
Brian Gaekee785e532004-02-25 19:28:19 +00001//===-- SparcV8TargetMachine.cpp - Define TargetMachine for SparcV8 -------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Brian Gaekee785e532004-02-25 19:28:19 +00003// 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.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Brian Gaekee785e532004-02-25 19:28:19 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00009//
Brian Gaekee785e532004-02-25 19:28:19 +000010//
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,
Jim Laskeyb1e11802005-09-01 21:38:21 +000034 IntrinsicLowering *IL,
35 const std::string &FS)
Brian Gaeke56c5d732004-12-11 05:19:04 +000036 : TargetMachine("SparcV8", IL, false, 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
Brian Gaeke0e2d4662004-10-09 05:57:01 +000040unsigned SparcV8TargetMachine::getJITMatchQuality() {
41 return 0; // No JIT yet.
42}
43
44unsigned SparcV8TargetMachine::getModuleMatchQuality(const Module &M) {
Chris Lattner3ea78c42004-12-12 17:40:28 +000045 std::string TT = M.getTargetTriple();
46 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
47 return 20;
48
Brian Gaeke0e2d4662004-10-09 05:57:01 +000049 if (M.getEndianness() == Module::BigEndian &&
50 M.getPointerSize() == Module::Pointer32)
51#ifdef __sparc__
52 return 20; // BE/32 ==> Prefer sparcv8 on sparc
53#else
54 return 5; // BE/32 ==> Prefer ppc elsewhere
55#endif
56 else if (M.getEndianness() != Module::AnyEndianness ||
57 M.getPointerSize() != Module::AnyPointerSize)
58 return 0; // Match for some other target
59
60 return getJITMatchQuality()/2;
61}
62
Chris Lattner0431c962005-06-25 02:48:37 +000063/// addPassesToEmitFile - Add passes to the specified pass manager
Brian Gaekee785e532004-02-25 19:28:19 +000064/// to implement a static compiler for this target.
65///
Chris Lattner0431c962005-06-25 02:48:37 +000066bool SparcV8TargetMachine::addPassesToEmitFile(PassManager &PM,
67 std::ostream &Out,
Chris Lattnerce8eb0c2005-11-08 02:11:51 +000068 CodeGenFileType FileType,
69 bool Fast) {
Chris Lattner0431c962005-06-25 02:48:37 +000070 if (FileType != TargetMachine::AssemblyFile) return true;
71
Brian Gaekef4052802004-06-15 20:37:12 +000072 // FIXME: Implement efficient support for garbage collection intrinsics.
73 PM.add(createLowerGCPass());
74
75 // Replace malloc and free instructions with library calls.
76 PM.add(createLowerAllocationsPass());
Brian Gaekea3c57622004-06-18 08:46:15 +000077
Brian Gaekef4052802004-06-15 20:37:12 +000078 // FIXME: implement the switch instruction in the instruction selector.
79 PM.add(createLowerSwitchPass());
80
81 // FIXME: implement the invoke/unwind instructions!
82 PM.add(createLowerInvokePass());
83
Chris Lattnera9a582f2004-07-02 05:49:11 +000084 // Make sure that no unreachable blocks are instruction selected.
85 PM.add(createUnreachableBlockEliminationPass());
86
Brian Gaeke5aefa8a2004-12-10 08:39:30 +000087 // FIXME: implement the select instruction in the instruction selector.
88 PM.add(createLowerSelectPass());
Brian Gaeke56c5d732004-12-11 05:19:04 +000089
90 // Print LLVM code input to instruction selector:
91 if (PrintMachineCode)
Brian Gaeke74be3a52004-12-11 22:17:07 +000092 PM.add(new PrintFunctionPass());
Misha Brukmanb5f662f2005-04-21 23:30:14 +000093
Chris Lattner1c809c52004-02-29 00:27:00 +000094 PM.add(createSparcV8SimpleInstructionSelector(*this));
95
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000096 // Print machine instructions as they were initially generated.
97 if (PrintMachineCode)
98 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000099
Brian Gaekee785e532004-02-25 19:28:19 +0000100 PM.add(createRegisterAllocator());
101 PM.add(createPrologEpilogCodeInserter());
Chris Lattner1c809c52004-02-29 00:27:00 +0000102
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +0000103 // Print machine instructions after register allocation and prolog/epilog
104 // insertion.
105 if (PrintMachineCode)
106 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +0000107
Brian Gaeke8a9acd12004-09-29 03:26:27 +0000108 PM.add(createSparcV8FPMoverPass(*this));
Brian Gaeke86a87902004-04-06 23:21:24 +0000109 PM.add(createSparcV8DelaySlotFillerPass(*this));
110
111 // Print machine instructions after filling delay slots.
112 if (PrintMachineCode)
113 PM.add(createMachineFunctionPrinterPass(&std::cerr));
114
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +0000115 // Output assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +0000116 PM.add(createSparcV8CodePrinterPass(Out, *this));
117
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +0000118 // Delete the MachineInstrs we generated, since they're no longer needed.
Brian Gaekee785e532004-02-25 19:28:19 +0000119 PM.add(createMachineCodeDeleter());
Chris Lattner9ff6ba12004-02-28 20:21:45 +0000120 return false;
Brian Gaekee785e532004-02-25 19:28:19 +0000121}
122
123/// addPassesToJITCompile - Add passes to the specified pass manager to
124/// implement a fast dynamic compiler for this target.
125///
126void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Brian Gaekef4052802004-06-15 20:37:12 +0000127 // FIXME: Implement efficient support for garbage collection intrinsics.
128 PM.add(createLowerGCPass());
129
130 // Replace malloc and free instructions with library calls.
131 PM.add(createLowerAllocationsPass());
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000132
Brian Gaekef4052802004-06-15 20:37:12 +0000133 // FIXME: implement the switch instruction in the instruction selector.
134 PM.add(createLowerSwitchPass());
135
136 // FIXME: implement the invoke/unwind instructions!
137 PM.add(createLowerInvokePass());
Chris Lattnera9a582f2004-07-02 05:49:11 +0000138
Chris Lattnera9a582f2004-07-02 05:49:11 +0000139 // Make sure that no unreachable blocks are instruction selected.
140 PM.add(createUnreachableBlockEliminationPass());
141
Brian Gaeke5aefa8a2004-12-10 08:39:30 +0000142 // FIXME: implement the select instruction in the instruction selector.
143 PM.add(createLowerSelectPass());
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000144
Brian Gaekeb3a86a62004-12-11 18:41:09 +0000145 // Print LLVM code input to instruction selector:
146 if (PrintMachineCode)
147 PM.add(new PrintFunctionPass());
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000148
Brian Gaeke86a87902004-04-06 23:21:24 +0000149 PM.add(createSparcV8SimpleInstructionSelector(TM));
150
151 // Print machine instructions as they were initially generated.
152 if (PrintMachineCode)
153 PM.add(createMachineFunctionPrinterPass(&std::cerr));
154
Brian Gaekee785e532004-02-25 19:28:19 +0000155 PM.add(createRegisterAllocator());
156 PM.add(createPrologEpilogCodeInserter());
Brian Gaeke86a87902004-04-06 23:21:24 +0000157
158 // Print machine instructions after register allocation and prolog/epilog
159 // insertion.
160 if (PrintMachineCode)
161 PM.add(createMachineFunctionPrinterPass(&std::cerr));
162
Brian Gaeke8a9acd12004-09-29 03:26:27 +0000163 PM.add(createSparcV8FPMoverPass(TM));
Brian Gaeke86a87902004-04-06 23:21:24 +0000164 PM.add(createSparcV8DelaySlotFillerPass(TM));
165
166 // Print machine instructions after filling delay slots.
167 if (PrintMachineCode)
168 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Brian Gaekee785e532004-02-25 19:28:19 +0000169}