blob: a916b5c8ebdbbfbaf1c4f2ae2f75909e09241b5f [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
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
Dan Gohman089efff2008-05-13 00:00:25 +000021// Register the target.
22static RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023
24const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
25 return new SparcTargetAsmInfo(*this);
26}
27
28/// SparcTargetMachine ctor - Create an ILP32 architecture model
29///
30SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen4c39f712007-08-03 20:20:50 +000031 : DataLayout("E-p:32:32-f128:128:128"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000032 Subtarget(M, FS), InstrInfo(Subtarget),
33 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
34}
35
36unsigned 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
Dan Gohmane34aa772008-03-11 22:29:46 +000062bool SparcTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 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.
Dan Gohmane34aa772008-03-11 22:29:46 +000070bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071 PM.add(createSparcFPMoverPass(*this));
72 PM.add(createSparcDelaySlotFillerPass(*this));
73 return true;
74}
75
Dan Gohmane34aa772008-03-11 22:29:46 +000076bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077 std::ostream &Out) {
78 // Output assembly language.
79 PM.add(createSparcCodePrinterPass(Out, *this));
80 return false;
81}