blob: ca275daec175138b8aa7b82aa98bb743cccbdec7 [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//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// 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 Lattner8d8a6bc2004-02-28 19:52:49 +000019using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000020
Oscar Fuentes92adc192008-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 Gohman844731a2008-05-13 00:00:25 +000029// Register the target.
Dan Gohmanb8cab922008-10-14 20:25:08 +000030static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
Chris Lattnerd36c9702004-07-11 02:48:49 +000031
Douglas Gregor1555a232009-06-16 20:12:29 +000032// Force static initialization when called from llvm/InitializeAllTargets.h
33namespace llvm {
34 void InitializeSparcTarget() { }
35}
36
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000037const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
Anton Korobeynikov5b794b92008-08-07 09:51:25 +000038 // FIXME: Handle Solaris subtarget someday :)
39 return new SparcELFTargetAsmInfo(*this);
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000040}
41
Chris Lattner7c90f732006-02-05 05:50:24 +000042/// SparcTargetMachine ctor - Create an ILP32 architecture model
Brian Gaekee785e532004-02-25 19:28:19 +000043///
Chris Lattnerbc641b92006-03-23 05:43:16 +000044SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen8c1e6a12007-08-03 20:20:50 +000045 : DataLayout("E-p:32:32-f128:128:128"),
Dan Gohmanda8ac5f2008-10-03 16:55:19 +000046 Subtarget(M, FS), TLInfo(*this), InstrInfo(Subtarget),
Chris Lattner03a83c92005-12-16 06:06:07 +000047 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
Brian Gaeke0e2d4662004-10-09 05:57:01 +000048}
49
Chris Lattner7c90f732006-02-05 05:50:24 +000050unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
Chris Lattner3ea78c42004-12-12 17:40:28 +000051 std::string TT = M.getTargetTriple();
52 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
53 return 20;
Chris Lattner87bdba62007-07-09 17:25:29 +000054
55 // If the target triple is something non-sparc, we don't match.
56 if (!TT.empty()) return 0;
Chris Lattner3ea78c42004-12-12 17:40:28 +000057
Brian Gaeke0e2d4662004-10-09 05:57:01 +000058 if (M.getEndianness() == Module::BigEndian &&
59 M.getPointerSize() == Module::Pointer32)
60#ifdef __sparc__
Chris Lattner7c90f732006-02-05 05:50:24 +000061 return 20; // BE/32 ==> Prefer sparc on sparc
Brian Gaeke0e2d4662004-10-09 05:57:01 +000062#else
63 return 5; // BE/32 ==> Prefer ppc elsewhere
64#endif
65 else if (M.getEndianness() != Module::AnyEndianness ||
66 M.getPointerSize() != Module::AnyPointerSize)
67 return 0; // Match for some other target
68
Chris Lattner082ced92007-07-11 16:32:10 +000069#if defined(__sparc__)
70 return 10;
71#else
Chris Lattner03a83c92005-12-16 06:06:07 +000072 return 0;
Chris Lattner082ced92007-07-11 16:32:10 +000073#endif
Brian Gaeke0e2d4662004-10-09 05:57:01 +000074}
75
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000076bool SparcTargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000077 CodeGenOpt::Level OptLevel) {
Chris Lattner7c90f732006-02-05 05:50:24 +000078 PM.add(createSparcISelDag(*this));
Chris Lattner9ff6ba12004-02-28 20:21:45 +000079 return false;
Brian Gaekee785e532004-02-25 19:28:19 +000080}
81
Chris Lattner1911fd42006-09-04 04:14:57 +000082/// addPreEmitPass - This pass may be implemented by targets that want to run
83/// passes immediately before machine code is emitted. This should return
84/// true if -print-machineinstrs should print out the code after the passes.
Bill Wendling98a366d2009-04-29 23:29:43 +000085bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM,
86 CodeGenOpt::Level OptLevel){
Chris Lattner1911fd42006-09-04 04:14:57 +000087 PM.add(createSparcFPMoverPass(*this));
88 PM.add(createSparcDelaySlotFillerPass(*this));
89 return true;
90}
91
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000092bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000093 CodeGenOpt::Level OptLevel,
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000094 bool Verbose,
95 raw_ostream &Out) {
Chris Lattner1911fd42006-09-04 04:14:57 +000096 // Output assembly language.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000097 PM.add(createSparcCodePrinterPass(Out, *this, OptLevel, Verbose));
Chris Lattner1911fd42006-09-04 04:14:57 +000098 return false;
99}