SparcTargetMachine.cpp revision fde1b3bb2f15b74c713d98a79fcddaff1ac00dd1
1//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file was developed by the LLVM research group and is distributed under 6// the University of Illinois Open Source 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#include <iostream> 20using namespace llvm; 21 22namespace { 23 // Register the target. 24 RegisterTarget<SparcTargetMachine> X("sparc", " SPARC"); 25} 26 27const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const { 28 return new SparcTargetAsmInfo(*this); 29} 30 31/// SparcTargetMachine ctor - Create an ILP32 architecture model 32/// 33SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS) 34 : DataLayout("E-p:32:32"), 35 Subtarget(M, FS), InstrInfo(Subtarget), 36 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) { 37} 38 39unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) { 40 std::string TT = M.getTargetTriple(); 41 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-") 42 return 20; 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 return 0; 56} 57 58bool SparcTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) { 59 PM.add(createSparcISelDag(*this)); 60 return false; 61} 62 63/// addPreEmitPass - This pass may be implemented by targets that want to run 64/// passes immediately before machine code is emitted. This should return 65/// true if -print-machineinstrs should print out the code after the passes. 66bool SparcTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) { 67 PM.add(createSparcFPMoverPass(*this)); 68 PM.add(createSparcDelaySlotFillerPass(*this)); 69 return true; 70} 71 72bool SparcTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 73 std::ostream &Out) { 74 // Output assembly language. 75 PM.add(createSparcCodePrinterPass(Out, *this)); 76 return false; 77} 78