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 | |
Daniel Dunbar | 4cb1e13 | 2009-07-18 23:03:22 +0000 | [diff] [blame^] | 10 | #include "Sparc.h" |
Daniel Dunbar | c984df8 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 11 | #include "llvm/Module.h" |
| 12 | #include "llvm/Target/TargetRegistry.h" |
| 13 | using namespace llvm; |
| 14 | |
Daniel Dunbar | 4cb1e13 | 2009-07-18 23:03:22 +0000 | [diff] [blame^] | 15 | Target llvm::TheSparcTarget; |
Daniel Dunbar | c984df8 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 16 | |
| 17 | static unsigned Sparc_JITMatchQuality() { |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | static 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 | |
| 28 | static 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 | |
| 56 | extern "C" void LLVMInitializeSparcTargetInfo() { |
| 57 | TargetRegistry::RegisterTarget(TheSparcTarget, "sparc", |
| 58 | "Sparc", |
| 59 | &Sparc_TripleMatchQuality, |
| 60 | &Sparc_ModuleMatchQuality, |
| 61 | &Sparc_JITMatchQuality); |
| 62 | } |