Completely rearchitect the interface between targets and the pass manager.
[oota-llvm.git] / lib / Target / Sparc / SparcTargetMachine.cpp
1 //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
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 "SparcTargetMachine.h"
14 #include "Sparc.h"
15 #include "llvm/Module.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/Target/TargetMachineRegistry.h"
18 #include <iostream>
19 using namespace llvm;
20
21 namespace {
22   // Register the target.
23   RegisterTarget<SparcTargetMachine> X("sparc", "  SPARC");
24 }
25
26 /// SparcTargetMachine ctor - Create an ILP32 architecture model
27 ///
28 SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
29   : DataLayout("E-p:32:32"),
30     Subtarget(M, FS), InstrInfo(Subtarget),
31     FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
32 }
33
34 unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
35   std::string TT = M.getTargetTriple();
36   if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
37     return 20;
38
39   if (M.getEndianness()  == Module::BigEndian &&
40       M.getPointerSize() == Module::Pointer32)
41 #ifdef __sparc__
42     return 20;   // BE/32 ==> Prefer sparc on sparc
43 #else
44     return 5;    // BE/32 ==> Prefer ppc elsewhere
45 #endif
46   else if (M.getEndianness() != Module::AnyEndianness ||
47            M.getPointerSize() != Module::AnyPointerSize)
48     return 0;                                    // Match for some other target
49
50   return 0;
51 }
52
53 bool SparcTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
54   PM.add(createSparcISelDag(*this));
55   return false;
56 }
57
58 /// addPreEmitPass - This pass may be implemented by targets that want to run
59 /// passes immediately before machine code is emitted.  This should return
60 /// true if -print-machineinstrs should print out the code after the passes.
61 bool SparcTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
62   PM.add(createSparcFPMoverPass(*this));
63   PM.add(createSparcDelaySlotFillerPass(*this));
64   return true;
65 }
66
67 bool SparcTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
68                                             std::ostream &Out) {
69   // Output assembly language.
70   PM.add(createSparcCodePrinterPass(Out, *this));
71   return false;
72 }