blob: fd0f12429a04433d51f3af086116e723a8e111a9 [file] [log] [blame]
Chris Lattner158e1f52006-02-05 05:50:24 +00001//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner158e1f52006-02-05 05:50:24 +00007//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
Jim Laskeyae92ce82006-09-07 23:39:26 +000013#include "SparcTargetAsmInfo.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000014#include "SparcTargetMachine.h"
15#include "Sparc.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000016#include "llvm/Module.h"
17#include "llvm/PassManager.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000018#include "llvm/Target/TargetMachineRegistry.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000019using namespace llvm;
20
Dan Gohmand78c4002008-05-13 00:00:25 +000021// Register the target.
Dan Gohman9c4b7d52008-10-14 20:25:08 +000022static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
Chris Lattner158e1f52006-02-05 05:50:24 +000023
Chris Lattner3773afe2009-06-19 15:48:10 +000024// No assembler printer by default
25SparcTargetMachine::AsmPrinterCtorFn SparcTargetMachine::AsmPrinterCtor = 0;
26
27
Douglas Gregor1b731d52009-06-16 20:12:29 +000028// Force static initialization when called from llvm/InitializeAllTargets.h
29namespace llvm {
30 void InitializeSparcTarget() { }
31}
32
Jim Laskeyae92ce82006-09-07 23:39:26 +000033const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +000034 // FIXME: Handle Solaris subtarget someday :)
35 return new SparcELFTargetAsmInfo(*this);
Jim Laskeyae92ce82006-09-07 23:39:26 +000036}
37
Chris Lattner158e1f52006-02-05 05:50:24 +000038/// SparcTargetMachine ctor - Create an ILP32 architecture model
39///
Chris Lattner6f95ab72006-03-23 05:43:16 +000040SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Dale Johannesenc5283ec2007-08-03 20:20:50 +000041 : DataLayout("E-p:32:32-f128:128:128"),
Dan Gohman2c836cf2008-10-03 16:55:19 +000042 Subtarget(M, FS), TLInfo(*this), InstrInfo(Subtarget),
Chris Lattner158e1f52006-02-05 05:50:24 +000043 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
44}
45
46unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
47 std::string TT = M.getTargetTriple();
48 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
49 return 20;
Chris Lattner517290a2007-07-09 17:25:29 +000050
51 // If the target triple is something non-sparc, we don't match.
52 if (!TT.empty()) return 0;
Chris Lattner158e1f52006-02-05 05:50:24 +000053
54 if (M.getEndianness() == Module::BigEndian &&
55 M.getPointerSize() == Module::Pointer32)
56#ifdef __sparc__
57 return 20; // BE/32 ==> Prefer sparc on sparc
58#else
59 return 5; // BE/32 ==> Prefer ppc elsewhere
60#endif
61 else if (M.getEndianness() != Module::AnyEndianness ||
62 M.getPointerSize() != Module::AnyPointerSize)
63 return 0; // Match for some other target
64
Chris Lattner6e544a92007-07-11 16:32:10 +000065#if defined(__sparc__)
66 return 10;
67#else
Chris Lattner158e1f52006-02-05 05:50:24 +000068 return 0;
Chris Lattner6e544a92007-07-11 16:32:10 +000069#endif
Chris Lattner158e1f52006-02-05 05:50:24 +000070}
71
Bill Wendling084669a2009-04-29 00:15:41 +000072bool SparcTargetMachine::addInstSelector(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +000073 CodeGenOpt::Level OptLevel) {
Chris Lattner158e1f52006-02-05 05:50:24 +000074 PM.add(createSparcISelDag(*this));
Chris Lattner158e1f52006-02-05 05:50:24 +000075 return false;
76}
77
Chris Lattner12e97302006-09-04 04:14:57 +000078/// addPreEmitPass - This pass may be implemented by targets that want to run
79/// passes immediately before machine code is emitted. This should return
80/// true if -print-machineinstrs should print out the code after the passes.
Bill Wendling026e5d72009-04-29 23:29:43 +000081bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM,
82 CodeGenOpt::Level OptLevel){
Chris Lattner12e97302006-09-04 04:14:57 +000083 PM.add(createSparcFPMoverPass(*this));
84 PM.add(createSparcDelaySlotFillerPass(*this));
85 return true;
86}
87
Bill Wendling084669a2009-04-29 00:15:41 +000088bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +000089 CodeGenOpt::Level OptLevel,
Bill Wendling084669a2009-04-29 00:15:41 +000090 bool Verbose,
91 raw_ostream &Out) {
Chris Lattner12e97302006-09-04 04:14:57 +000092 // Output assembly language.
Chris Lattner3773afe2009-06-19 15:48:10 +000093 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
94 if (AsmPrinterCtor)
95 PM.add(AsmPrinterCtor(Out, *this, OptLevel, Verbose));
Chris Lattner12e97302006-09-04 04:14:57 +000096 return false;
97}