blob: 38f6d6a9014db2cb36925dd25dd9b75b5ca05fcb [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
21namespace {
22 // Register the target.
23 RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
24}
25
Jim Laskeyae92ce82006-09-07 23:39:26 +000026const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
27 return new SparcTargetAsmInfo(*this);
28}
29
Chris Lattner158e1f52006-02-05 05:50:24 +000030/// SparcTargetMachine ctor - Create an ILP32 architecture model
31///
Chris Lattner6f95ab72006-03-23 05:43:16 +000032SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Dale Johannesenc5283ec2007-08-03 20:20:50 +000033 : DataLayout("E-p:32:32-f128:128:128"),
Chris Lattner158e1f52006-02-05 05:50:24 +000034 Subtarget(M, FS), InstrInfo(Subtarget),
35 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
36}
37
38unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
39 std::string TT = M.getTargetTriple();
40 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
41 return 20;
Chris Lattner517290a2007-07-09 17:25:29 +000042
43 // If the target triple is something non-sparc, we don't match.
44 if (!TT.empty()) return 0;
Chris Lattner158e1f52006-02-05 05:50:24 +000045
46 if (M.getEndianness() == Module::BigEndian &&
47 M.getPointerSize() == Module::Pointer32)
48#ifdef __sparc__
49 return 20; // BE/32 ==> Prefer sparc on sparc
50#else
51 return 5; // BE/32 ==> Prefer ppc elsewhere
52#endif
53 else if (M.getEndianness() != Module::AnyEndianness ||
54 M.getPointerSize() != Module::AnyPointerSize)
55 return 0; // Match for some other target
56
Chris Lattner6e544a92007-07-11 16:32:10 +000057#if defined(__sparc__)
58 return 10;
59#else
Chris Lattner158e1f52006-02-05 05:50:24 +000060 return 0;
Chris Lattner6e544a92007-07-11 16:32:10 +000061#endif
Chris Lattner158e1f52006-02-05 05:50:24 +000062}
63
Dan Gohman24570832008-03-11 22:29:46 +000064bool SparcTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
Chris Lattner158e1f52006-02-05 05:50:24 +000065 PM.add(createSparcISelDag(*this));
Chris Lattner158e1f52006-02-05 05:50:24 +000066 return false;
67}
68
Chris Lattner12e97302006-09-04 04:14:57 +000069/// addPreEmitPass - This pass may be implemented by targets that want to run
70/// passes immediately before machine code is emitted. This should return
71/// true if -print-machineinstrs should print out the code after the passes.
Dan Gohman24570832008-03-11 22:29:46 +000072bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
Chris Lattner12e97302006-09-04 04:14:57 +000073 PM.add(createSparcFPMoverPass(*this));
74 PM.add(createSparcDelaySlotFillerPass(*this));
75 return true;
76}
77
Dan Gohman24570832008-03-11 22:29:46 +000078bool SparcTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Chris Lattner12e97302006-09-04 04:14:57 +000079 std::ostream &Out) {
80 // Output assembly language.
81 PM.add(createSparcCodePrinterPass(Out, *this));
82 return false;
83}