SparcTargetMachine.cpp revision 225503a5b5de954788ad1e4bc9c69211de334c05
1//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
13#include "SparcTargetAsmInfo.h"
14#include "SparcTargetMachine.h"
15#include "Sparc.h"
16#include "llvm/Module.h"
17#include "llvm/PassManager.h"
18#include "llvm/Target/TargetMachineRegistry.h"
19using namespace llvm;
20
21// Register the target.
22static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
23
24// No assembler printer by default
25SparcTargetMachine::AsmPrinterCtorFn SparcTargetMachine::AsmPrinterCtor = 0;
26
27
28// Force static initialization when called from llvm/InitializeAllTargets.h
29namespace llvm {
30  void InitializeSparcTarget() { }
31}
32
33const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
34  // FIXME: Handle Solaris subtarget someday :)
35  return new SparcELFTargetAsmInfo(*this);
36}
37
38/// SparcTargetMachine ctor - Create an ILP32 architecture model
39///
40SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
41  : DataLayout("E-p:32:32-f128:128:128"),
42    Subtarget(M, FS), TLInfo(*this), InstrInfo(Subtarget),
43    FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
44}
45
46unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
47  std::string TT = M.getTargetTriple();
48  if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
49    return 20;
50
51  // If the target triple is something non-sparc, we don't match.
52  if (!TT.empty()) return 0;
53
54  if (M.getEndianness()  == Module::BigEndian &&
55      M.getPointerSize() == Module::Pointer32)
56#ifdef __sparc__
57    return 20;   // BE/32 ==> Prefer sparc on sparc
58#else
59    return 5;    // BE/32 ==> Prefer ppc elsewhere
60#endif
61  else if (M.getEndianness() != Module::AnyEndianness ||
62           M.getPointerSize() != Module::AnyPointerSize)
63    return 0;                                    // Match for some other target
64
65#if defined(__sparc__)
66  return 10;
67#else
68  return 0;
69#endif
70}
71
72bool SparcTargetMachine::addInstSelector(PassManagerBase &PM,
73                                         CodeGenOpt::Level OptLevel) {
74  PM.add(createSparcISelDag(*this));
75  return false;
76}
77
78/// addPreEmitPass - This pass may be implemented by targets that want to run
79/// passes immediately before machine code is emitted.  This should return
80/// true if -print-machineinstrs should print out the code after the passes.
81bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM,
82                                        CodeGenOpt::Level OptLevel){
83  PM.add(createSparcFPMoverPass(*this));
84  PM.add(createSparcDelaySlotFillerPass(*this));
85  return true;
86}
87
88bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
89                                            CodeGenOpt::Level OptLevel,
90                                            bool Verbose,
91                                            raw_ostream &Out) {
92  // Output assembly language.
93  assert(AsmPrinterCtor && "AsmPrinter was not linked in");
94  if (AsmPrinterCtor)
95    PM.add(AsmPrinterCtor(Out, *this, OptLevel, Verbose));
96  return false;
97}
98