blob: 63da5af51e6b3a6b55e7a9991fda7270da57efd6 [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)
34 : TargetMachine("SparcV8", IL, true, 4, 4, 4, 4, 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
38/// addPassesToEmitAssembly - Add passes to the specified pass manager
39/// to implement a static compiler for this target.
40///
41bool SparcV8TargetMachine::addPassesToEmitAssembly(PassManager &PM,
42 std::ostream &Out) {
Brian Gaekef4052802004-06-15 20:37:12 +000043 // FIXME: Implement efficient support for garbage collection intrinsics.
44 PM.add(createLowerGCPass());
45
46 // Replace malloc and free instructions with library calls.
47 PM.add(createLowerAllocationsPass());
Brian Gaekea3c57622004-06-18 08:46:15 +000048
49 // FIXME: implement the select instruction in the instruction selector.
50 PM.add(createLowerSelectPass());
Brian Gaekef4052802004-06-15 20:37:12 +000051
52 // FIXME: implement the switch instruction in the instruction selector.
53 PM.add(createLowerSwitchPass());
54
55 // FIXME: implement the invoke/unwind instructions!
56 PM.add(createLowerInvokePass());
57
Chris Lattnera9a582f2004-07-02 05:49:11 +000058 PM.add(createLowerConstantExpressionsPass());
59
60 // Make sure that no unreachable blocks are instruction selected.
61 PM.add(createUnreachableBlockEliminationPass());
62
Chris Lattner1c809c52004-02-29 00:27:00 +000063 PM.add(createSparcV8SimpleInstructionSelector(*this));
64
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000065 // Print machine instructions as they were initially generated.
66 if (PrintMachineCode)
67 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000068
Brian Gaekee785e532004-02-25 19:28:19 +000069 PM.add(createRegisterAllocator());
70 PM.add(createPrologEpilogCodeInserter());
Chris Lattner1c809c52004-02-29 00:27:00 +000071
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000072 // Print machine instructions after register allocation and prolog/epilog
73 // insertion.
74 if (PrintMachineCode)
75 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Chris Lattner1c809c52004-02-29 00:27:00 +000076
Brian Gaeke86a87902004-04-06 23:21:24 +000077 PM.add(createSparcV8DelaySlotFillerPass(*this));
78
79 // Print machine instructions after filling delay slots.
80 if (PrintMachineCode)
81 PM.add(createMachineFunctionPrinterPass(&std::cerr));
82
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000083 // Output assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +000084 PM.add(createSparcV8CodePrinterPass(Out, *this));
85
Brian Gaeke7a3ae1f2004-03-04 19:22:16 +000086 // Delete the MachineInstrs we generated, since they're no longer needed.
Brian Gaekee785e532004-02-25 19:28:19 +000087 PM.add(createMachineCodeDeleter());
Chris Lattner9ff6ba12004-02-28 20:21:45 +000088 return false;
Brian Gaekee785e532004-02-25 19:28:19 +000089}
90
91/// addPassesToJITCompile - Add passes to the specified pass manager to
92/// implement a fast dynamic compiler for this target.
93///
94void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
Brian Gaekef4052802004-06-15 20:37:12 +000095 // FIXME: Implement efficient support for garbage collection intrinsics.
96 PM.add(createLowerGCPass());
97
98 // Replace malloc and free instructions with library calls.
99 PM.add(createLowerAllocationsPass());
100
Brian Gaekea3c57622004-06-18 08:46:15 +0000101 // FIXME: implement the select instruction in the instruction selector.
102 PM.add(createLowerSelectPass());
103
Brian Gaekef4052802004-06-15 20:37:12 +0000104 // FIXME: implement the switch instruction in the instruction selector.
105 PM.add(createLowerSwitchPass());
106
107 // FIXME: implement the invoke/unwind instructions!
108 PM.add(createLowerInvokePass());
Chris Lattnera9a582f2004-07-02 05:49:11 +0000109
110 PM.add(createLowerConstantExpressionsPass());
Brian Gaekef4052802004-06-15 20:37:12 +0000111
Chris Lattnera9a582f2004-07-02 05:49:11 +0000112 // Make sure that no unreachable blocks are instruction selected.
113 PM.add(createUnreachableBlockEliminationPass());
114
Brian Gaeke86a87902004-04-06 23:21:24 +0000115 PM.add(createSparcV8SimpleInstructionSelector(TM));
116
117 // Print machine instructions as they were initially generated.
118 if (PrintMachineCode)
119 PM.add(createMachineFunctionPrinterPass(&std::cerr));
120
Brian Gaekee785e532004-02-25 19:28:19 +0000121 PM.add(createRegisterAllocator());
122 PM.add(createPrologEpilogCodeInserter());
Brian Gaeke86a87902004-04-06 23:21:24 +0000123
124 // Print machine instructions after register allocation and prolog/epilog
125 // insertion.
126 if (PrintMachineCode)
127 PM.add(createMachineFunctionPrinterPass(&std::cerr));
128
129 PM.add(createSparcV8DelaySlotFillerPass(TM));
130
131 // Print machine instructions after filling delay slots.
132 if (PrintMachineCode)
133 PM.add(createMachineFunctionPrinterPass(&std::cerr));
Brian Gaekee785e532004-02-25 19:28:19 +0000134}