blob: 97856697b91bbe4708ddcbbc73ba8a5debfde720 [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 {
Anton Korobeynikovdb9a8952008-08-07 09:51:25 +000025 // FIXME: Handle Solaris subtarget someday :)
26 return new SparcELFTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027}
28
29/// SparcTargetMachine ctor - Create an ILP32 architecture model
30///
31SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen4c39f712007-08-03 20:20:50 +000032 : DataLayout("E-p:32:32-f128:128:128"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 Subtarget(M, FS), 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
Dan Gohmane34aa772008-03-11 22:29:46 +000063bool SparcTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064 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.
Dan Gohmane34aa772008-03-11 22:29:46 +000071bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072 PM.add(createSparcFPMoverPass(*this));
73 PM.add(createSparcDelaySlotFillerPass(*this));
74 return true;
75}
76
Dan Gohmane34aa772008-03-11 22:29:46 +000077bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000078 std::ostream &Out) {
79 // Output assembly language.
80 PM.add(createSparcCodePrinterPass(Out, *this));
81 return false;
82}