diff options
-rw-r--r-- | llvm/include/llvm/Target/TargetRegistry.h | 2 | ||||
-rw-r--r-- | llvm/lib/Target/TargetMachineRegistry.cpp | 55 |
2 files changed, 16 insertions, 41 deletions
diff --git a/llvm/include/llvm/Target/TargetRegistry.h b/llvm/include/llvm/Target/TargetRegistry.h index 0e46526f5f8..8417fef1864 100644 --- a/llvm/include/llvm/Target/TargetRegistry.h +++ b/llvm/include/llvm/Target/TargetRegistry.h @@ -49,6 +49,8 @@ namespace llvm { bool); friend struct TargetRegistry; + // FIXME: Temporary hack, please remove. + friend struct TargetMachineRegistry; /// Next - The next registered target in the linked list, maintained by the /// TargetRegistry. diff --git a/llvm/lib/Target/TargetMachineRegistry.cpp b/llvm/lib/Target/TargetMachineRegistry.cpp index c1a4777c631..4d4652604f0 100644 --- a/llvm/lib/Target/TargetMachineRegistry.cpp +++ b/llvm/lib/Target/TargetMachineRegistry.cpp @@ -24,27 +24,14 @@ using namespace llvm; const TargetMachineRegistry::entry * TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M, std::string &Error) { - std::vector<std::pair<unsigned, const entry *> > UsableTargets; - for (Registry<TargetMachine>::iterator I = begin(), E = end(); I != E; ++I) - if (unsigned Qual = I->ModuleMatchQualityFn(M)) - UsableTargets.push_back(std::make_pair(Qual, &*I)); - - if (UsableTargets.empty()) { - Error = "No available targets are compatible with this module"; - return 0; - } else if (UsableTargets.size() == 1) - return UsableTargets.back().second; - - // Otherwise, take the best target, but make sure we don't have two equally - // good best targets. - std::sort(UsableTargets.begin(), UsableTargets.end()); - if (UsableTargets.back().first ==UsableTargets[UsableTargets.size()-2].first){ - Error = "Cannot choose between targets \"" + - std::string(UsableTargets.back().second->Name) + "\" and \"" + - std::string(UsableTargets[UsableTargets.size()-2].second->Name) + "\""; + const Target *T = TargetRegistry::getClosestStaticTargetForModule(M, Error); + if (!T) return 0; - } - return UsableTargets.back().second; + // FIXME: Temporary hack, please remove. + return new TargetMachineRegistry::entry(T->Name, T->ShortDesc, + T->TargetMachineCtorFn, + T->ModuleMatchQualityFn, + T->JITMatchQualityFn); } /// getClosestTargetForJIT - Pick the best target that is compatible with @@ -52,27 +39,13 @@ TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M, /// and sets the Error string to a reason. const TargetMachineRegistry::entry * TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) { - std::vector<std::pair<unsigned, const entry *> > UsableTargets; - for (Registry<TargetMachine>::iterator I = begin(), E = end(); I != E; ++I) - if (unsigned Qual = I->JITMatchQualityFn()) - UsableTargets.push_back(std::make_pair(Qual, &*I)); - - if (UsableTargets.empty()) { - Error = "No JIT is available for this host"; + const Target *T = TargetRegistry::getClosestTargetForJIT(Error); + if (!T) return 0; - } else if (UsableTargets.size() == 1) - return UsableTargets.back().second; - - // Otherwise, take the best target. If there is a tie, just pick one. - unsigned MaxQual = UsableTargets.front().first; - const entry *MaxQualTarget = UsableTargets.front().second; - - for (unsigned i = 1, e = UsableTargets.size(); i != e; ++i) - if (UsableTargets[i].first > MaxQual) { - MaxQual = UsableTargets[i].first; - MaxQualTarget = UsableTargets[i].second; - } - - return MaxQualTarget; + // FIXME: Temporary hack, please remove. + return new TargetMachineRegistry::entry(T->Name, T->ShortDesc, + T->TargetMachineCtorFn, + T->ModuleMatchQualityFn, + T->JITMatchQualityFn); } |