1 //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #include "SparcTargetAsmInfo.h"
14 #include "SparcTargetMachine.h"
16 #include "llvm/Module.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/Target/TargetMachineRegistry.h"
21 // Register the target.
22 static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
24 // No assembler printer by default
25 SparcTargetMachine::AsmPrinterCtorFn SparcTargetMachine::AsmPrinterCtor = 0;
28 // Force static initialization when called from llvm/InitializeAllTargets.h
30 void InitializeSparcTarget() { }
33 const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
34 // FIXME: Handle Solaris subtarget someday :)
35 return new SparcELFTargetAsmInfo(*this);
38 /// SparcTargetMachine ctor - Create an ILP32 architecture model
40 SparcTargetMachine::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) {
46 unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
47 std::string TT = M.getTargetTriple();
48 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
51 // If the target triple is something non-sparc, we don't match.
52 if (!TT.empty()) return 0;
54 if (M.getEndianness() == Module::BigEndian &&
55 M.getPointerSize() == Module::Pointer32)
57 return 20; // BE/32 ==> Prefer sparc on sparc
59 return 5; // BE/32 ==> Prefer ppc elsewhere
61 else if (M.getEndianness() != Module::AnyEndianness ||
62 M.getPointerSize() != Module::AnyPointerSize)
63 return 0; // Match for some other target
65 #if defined(__sparc__)
72 bool SparcTargetMachine::addInstSelector(PassManagerBase &PM,
73 CodeGenOpt::Level OptLevel) {
74 PM.add(createSparcISelDag(*this));
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.
81 bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM,
82 CodeGenOpt::Level OptLevel){
83 PM.add(createSparcFPMoverPass(*this));
84 PM.add(createSparcDelaySlotFillerPass(*this));
88 bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
89 CodeGenOpt::Level OptLevel,
92 // Output assembly language.
93 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
95 PM.add(AsmPrinterCtor(Out, *this, OptLevel, Verbose));