static iterator end() { return iterator(); }
- /// getClosestStaticTargetForTriple - Given a target triple, pick the most
- /// capable target for that triple.
- static const Target *getClosestStaticTargetForTriple(const std::string &TT,
- std::string &Error);
-
- /// getClosestStaticTargetForModule - Given an LLVM module, pick the best
- /// target that is compatible with the module. If no close target can be
- /// found, this returns null and sets the Error string to a reason.
- static const Target *getClosestStaticTargetForModule(const Module &M,
- std::string &Error);
+ /// lookupTarget - Lookup a target based on a target triple.
+ ///
+ /// \param Triple - The triple to use for finding a target.
+ /// \param FallbackToHost - If true and no target is found for the given
+ /// \arg Triple, then the host's triple will be used.
+ /// \param RequireJIT - Require the target to support JIT compilation.
+ /// \param Error - On failure, an error string describing why no target was
+ /// found.
+ static const Target *lookupTarget(const std::string &Triple,
+ bool FallbackToHost,
+ bool RequireJIT,
+ std::string &Error);
/// getClosestTargetForJIT - Pick the best target that is compatible with
/// the current host. If no close target can be found, this returns null
/// and sets the Error string to a reason.
- //
- // FIXME: Do we still need this interface, clients can always look for the
- // match for the host triple.
- static const Target *getClosestTargetForJIT(std::string &Error);
+ ///
+ /// Mainted for compatibility through 2.6.
+ static const Target *getClosestTargetForJIT(std::string &Error) {
+ return lookupTarget("", true, true, Error);
+ }
/// @}
/// @name Target Registration
//
//===----------------------------------------------------------------------===//
+#include "llvm/Module.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/System/Host.h"
#include <cassert>
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)";
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;
}
}
- // 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
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,