mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
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
This commit is contained in:
parent
4883630360
commit
e0bda7df1a
@ -49,6 +49,8 @@ namespace llvm {
|
|||||||
bool);
|
bool);
|
||||||
|
|
||||||
friend struct TargetRegistry;
|
friend struct TargetRegistry;
|
||||||
|
// FIXME: Temporary hack, please remove.
|
||||||
|
friend struct TargetMachineRegistry;
|
||||||
|
|
||||||
/// Next - The next registered target in the linked list, maintained by the
|
/// Next - The next registered target in the linked list, maintained by the
|
||||||
/// TargetRegistry.
|
/// TargetRegistry.
|
||||||
|
@ -24,27 +24,14 @@ using namespace llvm;
|
|||||||
const TargetMachineRegistry::entry *
|
const TargetMachineRegistry::entry *
|
||||||
TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M,
|
TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M,
|
||||||
std::string &Error) {
|
std::string &Error) {
|
||||||
std::vector<std::pair<unsigned, const entry *> > UsableTargets;
|
const Target *T = TargetRegistry::getClosestStaticTargetForModule(M, Error);
|
||||||
for (Registry<TargetMachine>::iterator I = begin(), E = end(); I != E; ++I)
|
if (!T)
|
||||||
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;
|
return 0;
|
||||||
} else if (UsableTargets.size() == 1)
|
// FIXME: Temporary hack, please remove.
|
||||||
return UsableTargets.back().second;
|
return new TargetMachineRegistry::entry(T->Name, T->ShortDesc,
|
||||||
|
T->TargetMachineCtorFn,
|
||||||
// Otherwise, take the best target, but make sure we don't have two equally
|
T->ModuleMatchQualityFn,
|
||||||
// good best targets.
|
T->JITMatchQualityFn);
|
||||||
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) + "\"";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return UsableTargets.back().second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getClosestTargetForJIT - Pick the best target that is compatible with
|
/// 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.
|
/// and sets the Error string to a reason.
|
||||||
const TargetMachineRegistry::entry *
|
const TargetMachineRegistry::entry *
|
||||||
TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) {
|
TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) {
|
||||||
std::vector<std::pair<unsigned, const entry *> > UsableTargets;
|
const Target *T = TargetRegistry::getClosestTargetForJIT(Error);
|
||||||
for (Registry<TargetMachine>::iterator I = begin(), E = end(); I != E; ++I)
|
if (!T)
|
||||||
if (unsigned Qual = I->JITMatchQualityFn())
|
|
||||||
UsableTargets.push_back(std::make_pair(Qual, &*I));
|
|
||||||
|
|
||||||
if (UsableTargets.empty()) {
|
|
||||||
Error = "No JIT is available for this host";
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (UsableTargets.size() == 1)
|
// FIXME: Temporary hack, please remove.
|
||||||
return UsableTargets.back().second;
|
return new TargetMachineRegistry::entry(T->Name, T->ShortDesc,
|
||||||
|
T->TargetMachineCtorFn,
|
||||||
// Otherwise, take the best target. If there is a tie, just pick one.
|
T->ModuleMatchQualityFn,
|
||||||
unsigned MaxQual = UsableTargets.front().first;
|
T->JITMatchQualityFn);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user