diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-07-25 10:09:50 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-07-25 10:09:50 +0000 |
commit | 691a4784db7a1319571e84fc4cfc4cd63a3b82dd (patch) | |
tree | 44f3402afe41eceac7db022418d5ffd4e128a3d9 /llvm/lib/Support/TargetRegistry.cpp | |
parent | 3c2da2bb7ed6c55f9960fb2779cf09382a95b1ac (diff) | |
download | bcm5719-llvm-691a4784db7a1319571e84fc4cfc4cd63a3b82dd.tar.gz bcm5719-llvm-691a4784db7a1319571e84fc4cfc4cd63a3b82dd.zip |
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.
llvm-svn: 77060
Diffstat (limited to 'llvm/lib/Support/TargetRegistry.cpp')
-rw-r--r-- | llvm/lib/Support/TargetRegistry.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/llvm/lib/Support/TargetRegistry.cpp b/llvm/lib/Support/TargetRegistry.cpp index b3446e61092..f9026f12afd 100644 --- a/llvm/lib/Support/TargetRegistry.cpp +++ b/llvm/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 @@ 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; + + // 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 @@ TargetRegistry::getClosestStaticTargetForModule(const Module &M, 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 @@ TargetRegistry::getClosestTargetForJIT(std::string &Error) { 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 @@ void TargetRegistry::RegisterTarget(Target &T, 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 @@ void TargetRegistry::RegisterTarget(Target &T, T.ShortDesc = ShortDesc; T.TripleMatchQualityFn = TQualityFn; T.ModuleMatchQualityFn = MQualityFn; - T.JITMatchQualityFn = JITQualityFn; + T.HasJIT = HasJIT; } |