[llvm-commits] [llvm] r75766 - in /llvm/trunk: include/llvm/Target/TargetRegistry.h lib/Target/TargetMachineRegistry.cpp
Daniel Dunbar
daniel at zuster.org
Wed Jul 15 02:54:01 PDT 2009
Author: ddunbar
Date: Wed Jul 15 04:53:37 2009
New Revision: 75766
URL: http://llvm.org/viewvc/llvm-project?rev=75766&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Target/TargetRegistry.h
llvm/trunk/lib/Target/TargetMachineRegistry.cpp
Modified: llvm/trunk/include/llvm/Target/TargetRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegistry.h?rev=75766&r1=75765&r2=75766&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetRegistry.h (original)
+++ llvm/trunk/include/llvm/Target/TargetRegistry.h Wed Jul 15 04:53:37 2009
@@ -49,6 +49,8 @@
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.
Modified: llvm/trunk/lib/Target/TargetMachineRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineRegistry.cpp?rev=75766&r1=75765&r2=75766&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineRegistry.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineRegistry.cpp Wed Jul 15 04:53:37 2009
@@ -24,27 +24,14 @@
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 @@
/// 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);
}
More information about the llvm-commits
mailing list