blob: 784800fd9229910755045fd0d59b80444ffeaab8 [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
Oscar Fuentes4f012352008-11-15 21:36:30 +000021/// SparcTargetMachineModule - Note that this is used on hosts that
22/// cannot link in a library unless there are references into the
23/// library. In particular, it seems that it is not possible to get
24/// things to work on Win32 without this. Though it is unused, do not
25/// remove it.
26extern "C" int SparcTargetMachineModule;
27int SparcTargetMachineModule = 0;
28
Dan Gohman089efff2008-05-13 00:00:25 +000029// Register the target.
Dan Gohman669b9bf2008-10-14 20:25:08 +000030static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031
32const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
Anton Korobeynikovdb9a8952008-08-07 09:51:25 +000033 // FIXME: Handle Solaris subtarget someday :)
34 return new SparcELFTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035}
36
37/// SparcTargetMachine ctor - Create an ILP32 architecture model
38///
39SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen4c39f712007-08-03 20:20:50 +000040 : DataLayout("E-p:32:32-f128:128:128"),
Dan Gohmanf2b29572008-10-03 16:55:19 +000041 Subtarget(M, FS), TLInfo(*this), InstrInfo(Subtarget),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
43}
44
45unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
46 std::string TT = M.getTargetTriple();
47 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
48 return 20;
49
50 // If the target triple is something non-sparc, we don't match.
51 if (!TT.empty()) return 0;
52
53 if (M.getEndianness() == Module::BigEndian &&
54 M.getPointerSize() == Module::Pointer32)
55#ifdef __sparc__
56 return 20; // BE/32 ==> Prefer sparc on sparc
57#else
58 return 5; // BE/32 ==> Prefer ppc elsewhere
59#endif
60 else if (M.getEndianness() != Module::AnyEndianness ||
61 M.getPointerSize() != Module::AnyPointerSize)
62 return 0; // Match for some other target
63
64#if defined(__sparc__)
65 return 10;
66#else
67 return 0;
68#endif
69}
70
Dan Gohmane34aa772008-03-11 22:29:46 +000071bool SparcTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072 PM.add(createSparcISelDag(*this));
73 return false;
74}
75
76/// addPreEmitPass - This pass may be implemented by targets that want to run
77/// passes immediately before machine code is emitted. This should return
78/// true if -print-machineinstrs should print out the code after the passes.
Dan Gohmane34aa772008-03-11 22:29:46 +000079bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080 PM.add(createSparcFPMoverPass(*this));
81 PM.add(createSparcDelaySlotFillerPass(*this));
82 return true;
83}
84
Dan Gohmane34aa772008-03-11 22:29:46 +000085bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Owen Anderson847b99b2008-08-21 00:14:44 +000086 raw_ostream &Out) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087 // Output assembly language.
Bill Wendling4f405312009-02-24 08:30:20 +000088 PM.add(createSparcCodePrinterPass(Out, *this, Fast));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089 return false;
90}