SparcTargetMachine.cpp revision bb978c7e98371cd253d6af4a2ba0b8cacdbd0aff
1//===-- 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/Assembly/PrintModulePass.h"
16#include "llvm/Module.h"
17#include "llvm/PassManager.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/Passes.h"
20#include "llvm/Target/TargetOptions.h"
21#include "llvm/Target/TargetMachineRegistry.h"
22#include "llvm/Transforms/Scalar.h"
23#include "llvm/Support/CommandLine.h"
24#include <iostream>
25using namespace llvm;
26
27namespace {
28  // Register the target.
29  RegisterTarget<SparcV8TargetMachine> X("sparcv8","  SPARC V8 (experimental)");
30}
31
32/// SparcV8TargetMachine ctor - Create an ILP32 architecture model
33///
34SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
35                                           IntrinsicLowering *IL,
36                                           const std::string &FS)
37  : TargetMachine("SparcV8", IL, false, 4, 4),
38    FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
39}
40
41unsigned SparcV8TargetMachine::getModuleMatchQuality(const Module &M) {
42  std::string TT = M.getTargetTriple();
43  if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
44    return 20;
45
46  if (M.getEndianness()  == Module::BigEndian &&
47      M.getPointerSize() == Module::Pointer32)
48#ifdef __sparc__
49    return 20;   // BE/32 ==> Prefer sparcv8 on sparc
50#else
51    return 5;    // BE/32 ==> Prefer ppc elsewhere
52#endif
53  else if (M.getEndianness() != Module::AnyEndianness ||
54           M.getPointerSize() != Module::AnyPointerSize)
55    return 0;                                    // Match for some other target
56
57  return 0;
58}
59
60/// addPassesToEmitFile - Add passes to the specified pass manager
61/// to implement a static compiler for this target.
62///
63bool SparcV8TargetMachine::addPassesToEmitFile(PassManager &PM,
64                                               std::ostream &Out,
65                                               CodeGenFileType FileType,
66                                               bool Fast) {
67  if (FileType != TargetMachine::AssemblyFile) return true;
68
69  // FIXME: Implement efficient support for garbage collection intrinsics.
70  PM.add(createLowerGCPass());
71
72  // FIXME: implement the invoke/unwind instructions!
73  PM.add(createLowerInvokePass());
74
75  // FIXME: implement the switch instruction in the instruction selector.
76  PM.add(createLowerSwitchPass());
77
78  // Print LLVM code input to instruction selector:
79  if (PrintMachineCode)
80    PM.add(new PrintFunctionPass());
81
82  // Make sure that no unreachable blocks are instruction selected.
83  PM.add(createUnreachableBlockEliminationPass());
84
85  PM.add(createSparcV8ISelDag(*this));
86
87  // Print machine instructions as they were initially generated.
88  if (PrintMachineCode)
89    PM.add(createMachineFunctionPrinterPass(&std::cerr));
90
91  PM.add(createRegisterAllocator());
92  PM.add(createPrologEpilogCodeInserter());
93
94  // Print machine instructions after register allocation and prolog/epilog
95  // insertion.
96  if (PrintMachineCode)
97    PM.add(createMachineFunctionPrinterPass(&std::cerr));
98
99  PM.add(createSparcV8FPMoverPass(*this));
100
101  PM.add(createSparcV8DelaySlotFillerPass(*this));
102
103  // Print machine instructions after filling delay slots.
104  if (PrintMachineCode)
105    PM.add(createMachineFunctionPrinterPass(&std::cerr));
106
107  // Output assembly language.
108  PM.add(createSparcV8CodePrinterPass(Out, *this));
109
110  // Delete the MachineInstrs we generated, since they're no longer needed.
111  PM.add(createMachineCodeDeleter());
112  return false;
113}
114
115