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