blob: 167e7ec246a1d5eeea530dd82514ff1bf77510a3 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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
21namespace {
22 // Register the target.
23 RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
24}
25
26const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
27 return new SparcTargetAsmInfo(*this);
28}
29
30/// SparcTargetMachine ctor - Create an ILP32 architecture model
31///
32SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Dale Johannesen4c39f712007-08-03 20:20:50 +000033 : DataLayout("E-p:32:32-f128:128:128"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +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;
42
43 // If the target triple is something non-sparc, we don't match.
44 if (!TT.empty()) return 0;
45
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
57#if defined(__sparc__)
58 return 10;
59#else
60 return 0;
61#endif
62}
63
64bool SparcTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
65 PM.add(createSparcISelDag(*this));
66 return false;
67}
68
69/// 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.
72bool SparcTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
73 PM.add(createSparcFPMoverPass(*this));
74 PM.add(createSparcDelaySlotFillerPass(*this));
75 return true;
76}
77
78bool SparcTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
79 std::ostream &Out) {
80 // Output assembly language.
81 PM.add(createSparcCodePrinterPass(Out, *this));
82 return false;
83}