blob: 131bdcc35b4efa3c0ad2f619668423b8b35afc5d [file] [log] [blame]
Daniel Dunbarc984df82009-07-15 06:35:19 +00001//===-- SparcTargetInfo.cpp - Sparc Target Implementation -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Dunbar4cb1e132009-07-18 23:03:22 +000010#include "Sparc.h"
Daniel Dunbarc984df82009-07-15 06:35:19 +000011#include "llvm/Module.h"
12#include "llvm/Target/TargetRegistry.h"
13using namespace llvm;
14
Daniel Dunbar4cb1e132009-07-18 23:03:22 +000015Target llvm::TheSparcTarget;
Daniel Dunbarc984df82009-07-15 06:35:19 +000016
17static unsigned Sparc_JITMatchQuality() {
18 return 0;
19}
20
21static unsigned Sparc_TripleMatchQuality(const std::string &TT) {
22 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
23 return 20;
24
25 return 0;
26}
27
28static unsigned Sparc_ModuleMatchQuality(const Module &M) {
29 // Check for a triple match.
30 if (unsigned Q = Sparc_TripleMatchQuality(M.getTargetTriple()))
31 return Q;
32
33 // Otherwise if the target triple is non-empty, we don't match.
34 if (!M.getTargetTriple().empty()) return 0;
35
36 // FIXME: This is bad, the target matching algorithm shouldn't depend on the
37 // host.
38 if (M.getEndianness() == Module::BigEndian &&
39 M.getPointerSize() == Module::Pointer32)
40#ifdef __sparc__
41 return 20; // BE/32 ==> Prefer sparc on sparc
42#else
43 return 5; // BE/32 ==> Prefer ppc elsewhere
44#endif
45 else if (M.getEndianness() != Module::AnyEndianness ||
46 M.getPointerSize() != Module::AnyPointerSize)
47 return 0; // Match for some other target
48
49#if defined(__sparc__)
50 return 10;
51#else
52 return 0;
53#endif
54}
55
56extern "C" void LLVMInitializeSparcTargetInfo() {
57 TargetRegistry::RegisterTarget(TheSparcTarget, "sparc",
58 "Sparc",
59 &Sparc_TripleMatchQuality,
60 &Sparc_ModuleMatchQuality,
61 &Sparc_JITMatchQuality);
62}