Adds extern "C" ints to the .cpp files that use RegisterTarget, as
[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 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"
19 using 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.
26 extern "C" int SparcTargetMachineModule;
27 int SparcTargetMachineModule = 0;
28
29 // Register the target.
30 static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
31
32 const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
33   // FIXME: Handle Solaris subtarget someday :)
34   return new SparcELFTargetAsmInfo(*this);
35 }
36
37 /// SparcTargetMachine ctor - Create an ILP32 architecture model
38 ///
39 SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
40   : DataLayout("E-p:32:32-f128:128:128"),
41     Subtarget(M, FS), TLInfo(*this), InstrInfo(Subtarget),
42     FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
43 }
44
45 unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
46   std::string TT = M.getTargetTriple();
47   if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
48     return 20;
49   
50   // If the target triple is something non-sparc, we don't match.
51   if (!TT.empty()) return 0;
52
53   if (M.getEndianness()  == Module::BigEndian &&
54       M.getPointerSize() == Module::Pointer32)
55 #ifdef __sparc__
56     return 20;   // BE/32 ==> Prefer sparc on sparc
57 #else
58     return 5;    // BE/32 ==> Prefer ppc elsewhere
59 #endif
60   else if (M.getEndianness() != Module::AnyEndianness ||
61            M.getPointerSize() != Module::AnyPointerSize)
62     return 0;                                    // Match for some other target
63
64 #if defined(__sparc__)
65   return 10;
66 #else
67   return 0;
68 #endif
69 }
70
71 bool SparcTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
72   PM.add(createSparcISelDag(*this));
73   return false;
74 }
75
76 /// addPreEmitPass - This pass may be implemented by targets that want to run
77 /// passes immediately before machine code is emitted.  This should return
78 /// true if -print-machineinstrs should print out the code after the passes.
79 bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
80   PM.add(createSparcFPMoverPass(*this));
81   PM.add(createSparcDelaySlotFillerPass(*this));
82   return true;
83 }
84
85 bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast, 
86                                             raw_ostream &Out) {
87   // Output assembly language.
88   PM.add(createSparcCodePrinterPass(Out, *this));
89   return false;
90 }