Daniel Dunbar | c984df8 | 2009-07-15 06:35:19 +0000 | [diff] [blame^] | 1 | //===-- 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 | |
| 10 | #include "llvm/Module.h" |
| 11 | #include "llvm/Target/TargetRegistry.h" |
| 12 | using namespace llvm; |
| 13 | |
| 14 | Target TheSparcTarget; |
| 15 | |
| 16 | static unsigned Sparc_JITMatchQuality() { |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | static unsigned Sparc_TripleMatchQuality(const std::string &TT) { |
| 21 | if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-") |
| 22 | return 20; |
| 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | static unsigned Sparc_ModuleMatchQuality(const Module &M) { |
| 28 | // Check for a triple match. |
| 29 | if (unsigned Q = Sparc_TripleMatchQuality(M.getTargetTriple())) |
| 30 | return Q; |
| 31 | |
| 32 | // Otherwise if the target triple is non-empty, we don't match. |
| 33 | if (!M.getTargetTriple().empty()) return 0; |
| 34 | |
| 35 | // FIXME: This is bad, the target matching algorithm shouldn't depend on the |
| 36 | // host. |
| 37 | if (M.getEndianness() == Module::BigEndian && |
| 38 | M.getPointerSize() == Module::Pointer32) |
| 39 | #ifdef __sparc__ |
| 40 | return 20; // BE/32 ==> Prefer sparc on sparc |
| 41 | #else |
| 42 | return 5; // BE/32 ==> Prefer ppc elsewhere |
| 43 | #endif |
| 44 | else if (M.getEndianness() != Module::AnyEndianness || |
| 45 | M.getPointerSize() != Module::AnyPointerSize) |
| 46 | return 0; // Match for some other target |
| 47 | |
| 48 | #if defined(__sparc__) |
| 49 | return 10; |
| 50 | #else |
| 51 | return 0; |
| 52 | #endif |
| 53 | } |
| 54 | |
| 55 | extern "C" void LLVMInitializeSparcTargetInfo() { |
| 56 | TargetRegistry::RegisterTarget(TheSparcTarget, "sparc", |
| 57 | "Sparc", |
| 58 | &Sparc_TripleMatchQuality, |
| 59 | &Sparc_ModuleMatchQuality, |
| 60 | &Sparc_JITMatchQuality); |
| 61 | } |