aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-07-15 09:53:37 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-07-15 09:53:37 +0000
commit41d9c0a616ba5154491435ddc94074575405d031 (patch)
tree7a82aef902469f1228260b7f1604528056524d53 /lib
parentd289bface30164c6cbf3b1bb48c517cca636d01c (diff)
downloadexternal_llvm-41d9c0a616ba5154491435ddc94074575405d031.zip
external_llvm-41d9c0a616ba5154491435ddc94074575405d031.tar.gz
external_llvm-41d9c0a616ba5154491435ddc94074575405d031.tar.bz2
Reimplement TargetMachineRegistry in terms of TargetRegistry.
- This is a temporary hack to aid in incremental refactoring, for now we allocate a new TargetMachineRegistryEntry on every getClosest... call. - No intended functionality change, other than the leaked memory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75766 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/TargetMachineRegistry.cpp55
1 files changed, 14 insertions, 41 deletions
diff --git a/lib/Target/TargetMachineRegistry.cpp b/lib/Target/TargetMachineRegistry.cpp
index c1a4777..4d46526 100644
--- a/lib/Target/TargetMachineRegistry.cpp
+++ b/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);
}