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