SparcTargetMachine.cpp revision 1555a23335400143f2b54a66aedc4b5cbbb79f8d
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/// SparcTargetMachineModule - Note that this is used on hosts that
22/// cannot link in a library unless there are references into the
23/// library.  In particular, it seems that it is not possible to get
24/// things to work on Win32 without this.  Though it is unused, do not
25/// remove it.
26extern "C" int SparcTargetMachineModule;
27int SparcTargetMachineModule = 0;
28
29// Register the target.
30static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
31
32// Force static initialization when called from llvm/InitializeAllTargets.h
33namespace llvm {
34  void InitializeSparcTarget() { }
35}
36
37const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
38  // FIXME: Handle Solaris subtarget someday :)
39  return new SparcELFTargetAsmInfo(*this);
40}
41
42/// SparcTargetMachine ctor - Create an ILP32 architecture model
43///
44SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
45  : DataLayout("E-p:32:32-f128:128:128"),
46    Subtarget(M, FS), TLInfo(*this), InstrInfo(Subtarget),
47    FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
48}
49
50unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
51  std::string TT = M.getTargetTriple();
52  if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
53    return 20;
54
55  // If the target triple is something non-sparc, we don't match.
56  if (!TT.empty()) return 0;
57
58  if (M.getEndianness()  == Module::BigEndian &&
59      M.getPointerSize() == Module::Pointer32)
60#ifdef __sparc__
61    return 20;   // BE/32 ==> Prefer sparc on sparc
62#else
63    return 5;    // BE/32 ==> Prefer ppc elsewhere
64#endif
65  else if (M.getEndianness() != Module::AnyEndianness ||
66           M.getPointerSize() != Module::AnyPointerSize)
67    return 0;                                    // Match for some other target
68
69#if defined(__sparc__)
70  return 10;
71#else
72  return 0;
73#endif
74}
75
76bool SparcTargetMachine::addInstSelector(PassManagerBase &PM,
77                                         CodeGenOpt::Level OptLevel) {
78  PM.add(createSparcISelDag(*this));
79  return false;
80}
81
82/// addPreEmitPass - This pass may be implemented by targets that want to run
83/// passes immediately before machine code is emitted.  This should return
84/// true if -print-machineinstrs should print out the code after the passes.
85bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM,
86                                        CodeGenOpt::Level OptLevel){
87  PM.add(createSparcFPMoverPass(*this));
88  PM.add(createSparcDelaySlotFillerPass(*this));
89  return true;
90}
91
92bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
93                                            CodeGenOpt::Level OptLevel,
94                                            bool Verbose,
95                                            raw_ostream &Out) {
96  // Output assembly language.
97  PM.add(createSparcCodePrinterPass(Out, *this, OptLevel, Verbose));
98  return false;
99}
100