blob: 98912a2353127e578281e2c466628e7f48539b4b [file] [log] [blame]
Chris Lattner7c90f732006-02-05 05:50:24 +00001//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Brian Gaekee785e532004-02-25 19:28:19 +00003// 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.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Brian Gaekee785e532004-02-25 19:28:19 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00009//
Brian Gaekee785e532004-02-25 19:28:19 +000010//
11//===----------------------------------------------------------------------===//
12
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000013#include "SparcTargetAsmInfo.h"
Chris Lattner7c90f732006-02-05 05:50:24 +000014#include "SparcTargetMachine.h"
15#include "Sparc.h"
Brian Gaekee785e532004-02-25 19:28:19 +000016#include "llvm/Module.h"
17#include "llvm/PassManager.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000018#include "llvm/Target/TargetMachineRegistry.h"
Chris Lattner38343f62004-07-04 17:19:21 +000019#include <iostream>
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000020using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000021
Chris Lattnerd36c9702004-07-11 02:48:49 +000022namespace {
23 // Register the target.
Chris Lattner7c90f732006-02-05 05:50:24 +000024 RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
Chris Lattnerd36c9702004-07-11 02:48:49 +000025}
26
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000027const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
28 return new SparcTargetAsmInfo(*this);
29}
30
Chris Lattner7c90f732006-02-05 05:50:24 +000031/// SparcTargetMachine ctor - Create an ILP32 architecture model
Brian Gaekee785e532004-02-25 19:28:19 +000032///
Chris Lattnerbc641b92006-03-23 05:43:16 +000033SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Chris Lattnerc4fa3862006-09-03 18:44:02 +000034 : DataLayout("E-p:32:32"),
Chris Lattner69d39092006-02-04 06:58:46 +000035 Subtarget(M, FS), InstrInfo(Subtarget),
Chris Lattner03a83c92005-12-16 06:06:07 +000036 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
Brian Gaeke0e2d4662004-10-09 05:57:01 +000037}
38
Chris Lattner7c90f732006-02-05 05:50:24 +000039unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
Chris Lattner3ea78c42004-12-12 17:40:28 +000040 std::string TT = M.getTargetTriple();
41 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
42 return 20;
43
Brian Gaeke0e2d4662004-10-09 05:57:01 +000044 if (M.getEndianness() == Module::BigEndian &&
45 M.getPointerSize() == Module::Pointer32)
46#ifdef __sparc__
Chris Lattner7c90f732006-02-05 05:50:24 +000047 return 20; // BE/32 ==> Prefer sparc on sparc
Brian Gaeke0e2d4662004-10-09 05:57:01 +000048#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
Chris Lattner03a83c92005-12-16 06:06:07 +000055 return 0;
Brian Gaeke0e2d4662004-10-09 05:57:01 +000056}
57
Chris Lattner1911fd42006-09-04 04:14:57 +000058bool SparcTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
Chris Lattner7c90f732006-02-05 05:50:24 +000059 PM.add(createSparcISelDag(*this));
Chris Lattner9ff6ba12004-02-28 20:21:45 +000060 return false;
Brian Gaekee785e532004-02-25 19:28:19 +000061}
62
Chris Lattner1911fd42006-09-04 04:14:57 +000063/// 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}