aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/TargetRegistry.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-07-26 02:12:58 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-07-26 02:12:58 +0000
commita5881e3060aee9f82aef3747a97650e5eafe893a (patch)
tree91b295074626e17cb0342c1de0959a5a6c2349b0 /lib/Support/TargetRegistry.cpp
parent13b9251eb1343eb4c93944f5d6838404c27a7273 (diff)
Add TargetRegistry::lookupTarget.
- This is a simplified mechanism which just looks up a target based on the target triple, with a few additional flags. - Remove getClosestStaticTargetForModule, the moral equivalent is now: lookupTarget(Mod->getTargetTriple, true, false, ...); - This no longer does the fuzzy matching with target data (based on endianness and pointer width) that getClosestStaticTargetForModule was doing, but this was deemed unnecessary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77111 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/TargetRegistry.cpp')
-rw-r--r--lib/Support/TargetRegistry.cpp102
1 files changed, 17 insertions, 85 deletions
diff --git a/lib/Support/TargetRegistry.cpp b/lib/Support/TargetRegistry.cpp
index f9026f12af..4558d2d215 100644
--- a/lib/Support/TargetRegistry.cpp
+++ b/lib/Support/TargetRegistry.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Module.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/System/Host.h"
#include <cassert>
@@ -19,9 +20,10 @@ TargetRegistry::iterator TargetRegistry::begin() {
return iterator(FirstTarget);
}
-const Target *
-TargetRegistry::getClosestStaticTargetForTriple(const std::string &TT,
- std::string &Error) {
+const Target *TargetRegistry::lookupTarget(const std::string &TT,
+ bool FallbackToHost,
+ bool RequireJIT,
+ std::string &Error) {
// Provide special warning when no targets are initialized.
if (begin() == end()) {
Error = "Unable to find target for this triple (no targets are registered)";
@@ -30,45 +32,10 @@ TargetRegistry::getClosestStaticTargetForTriple(const std::string &TT,
const Target *Best = 0, *EquallyBest = 0;
unsigned BestQuality = 0;
for (iterator it = begin(), ie = end(); it != ie; ++it) {
- if (unsigned Qual = it->TripleMatchQualityFn(TT)) {
- if (!Best || Qual > BestQuality) {
- Best = &*it;
- EquallyBest = 0;
- BestQuality = Qual;
- } else if (Qual == BestQuality)
- EquallyBest = &*it;
- }
- }
-
- if (!Best) {
- Error = "No available targets are compatible with this triple";
- return 0;
- }
-
- // Otherwise, take the best target, but make sure we don't have two equally
- // good best targets.
- if (EquallyBest) {
- Error = std::string("Cannot choose between targets \"") +
- Best->Name + "\" and \"" + EquallyBest->Name + "\"";
- return 0;
- }
-
- return Best;
-}
-
-const Target *
-TargetRegistry::getClosestStaticTargetForModule(const Module &M,
- std::string &Error) {
- // Provide special warning when no targets are initialized.
- if (begin() == end()) {
- Error = "Unable to find target for this module (no targets are registered)";
- return 0;
- }
+ if (RequireJIT && !it->hasJIT())
+ continue;
- const Target *Best = 0, *EquallyBest = 0;
- unsigned BestQuality = 0;
- for (iterator it = begin(), ie = end(); it != ie; ++it) {
- if (unsigned Qual = it->ModuleMatchQualityFn(M)) {
+ if (unsigned Qual = it->TripleMatchQualityFn(TT)) {
if (!Best || Qual > BestQuality) {
Best = &*it;
EquallyBest = 0;
@@ -78,18 +45,18 @@ TargetRegistry::getClosestStaticTargetForModule(const Module &M,
}
}
- // FIXME: This is a hack to ignore super weak matches like msil, etc. and look
- // by host instead. They will be found again via the triple.
- if (Best && BestQuality == 1)
- Best = EquallyBest = 0;
+ // FIXME: Hack. If we only have an extremely weak match and the client
+ // requested to fall back to the host, then ignore it and try again.
+ if (BestQuality == 1 && FallbackToHost)
+ Best = 0;
- // If that failed, try looking up the host triple.
- if (!Best)
- Best = getClosestStaticTargetForTriple(sys::getHostTriple(), Error);
+ // Fallback to the host triple if we didn't find anything.
+ if (!Best && FallbackToHost)
+ return lookupTarget(sys::getHostTriple(), false, RequireJIT, Error);
if (!Best) {
- Error = "No available targets are compatible with this module";
- return Best;
+ Error = "No available targets are compatible with this triple";
+ return 0;
}
// Otherwise, take the best target, but make sure we don't have two equally
@@ -103,41 +70,6 @@ TargetRegistry::getClosestStaticTargetForModule(const Module &M,
return Best;
}
-const Target *
-TargetRegistry::getClosestTargetForJIT(std::string &Error) {
- std::string Triple = sys::getHostTriple();
-
- // Provide special warning when no targets are initialized.
- if (begin() == end()) {
- Error = "No JIT is available for this host (no targets are registered)";
- return 0;
- }
-
- const Target *Best = 0, *EquallyBest = 0;
- unsigned BestQuality = 0;
- for (iterator it = begin(), ie = end(); it != ie; ++it) {
- if (!it->hasJIT())
- continue;
-
- if (unsigned Qual = it->TripleMatchQualityFn(Triple)) {
- if (!Best || Qual > BestQuality) {
- Best = &*it;
- EquallyBest = 0;
- BestQuality = Qual;
- } else if (Qual == BestQuality)
- EquallyBest = &*it;
- }
- }
-
- if (!Best) {
- Error = "No JIT is available for this host";
- return 0;
- }
-
- // Return the best, ignoring ties.
- return Best;
-}
-
void TargetRegistry::RegisterTarget(Target &T,
const char *Name,
const char *ShortDesc,