Simplify JIT target selection.
- Instead of requiring targets to define a JIT quality match function, we just
have them specify if they support a JIT.
- Target selection for the JIT just gets the host triple and looks for the best
target which matches the triple and has a JIT.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77060 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/TargetRegistry.cpp b/lib/Support/TargetRegistry.cpp
index b3446e6..f9026f1 100644
--- a/lib/Support/TargetRegistry.cpp
+++ b/lib/Support/TargetRegistry.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Target/TargetRegistry.h"
+#include "llvm/System/Host.h"
#include <cassert>
using namespace llvm;
@@ -77,9 +78,18 @@
}
}
+ // 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;
+
+ // If that failed, try looking up the host triple.
+ if (!Best)
+ Best = getClosestStaticTargetForTriple(sys::getHostTriple(), Error);
+
if (!Best) {
Error = "No available targets are compatible with this module";
- return 0;
+ return Best;
}
// Otherwise, take the best target, but make sure we don't have two equally
@@ -95,6 +105,8 @@
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)";
@@ -104,7 +116,10 @@
const Target *Best = 0, *EquallyBest = 0;
unsigned BestQuality = 0;
for (iterator it = begin(), ie = end(); it != ie; ++it) {
- if (unsigned Qual = it->JITMatchQualityFn()) {
+ if (!it->hasJIT())
+ continue;
+
+ if (unsigned Qual = it->TripleMatchQualityFn(Triple)) {
if (!Best || Qual > BestQuality) {
Best = &*it;
EquallyBest = 0;
@@ -128,8 +143,8 @@
const char *ShortDesc,
Target::TripleMatchQualityFnTy TQualityFn,
Target::ModuleMatchQualityFnTy MQualityFn,
- Target::JITMatchQualityFnTy JITQualityFn) {
- assert(Name && ShortDesc && TQualityFn && MQualityFn && JITQualityFn &&
+ bool HasJIT) {
+ assert(Name && ShortDesc && TQualityFn && MQualityFn &&
"Missing required target information!");
// Check if this target has already been initialized, we allow this as a
@@ -145,6 +160,6 @@
T.ShortDesc = ShortDesc;
T.TripleMatchQualityFn = TQualityFn;
T.ModuleMatchQualityFn = MQualityFn;
- T.JITMatchQualityFn = JITQualityFn;
+ T.HasJIT = HasJIT;
}