X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FTargetMachineRegistry.cpp;h=62c76bbc5bf14ed2c93e71a7b1ccf1b2880adad1;hb=963a97f1a365c8d09ca681e922371f9ec3473ee8;hp=f5bd035d03354a334d04c1255528a02695315b21;hpb=b1e1180ca0b32f37aa74d7ad703eeaf91e66c8fa;p=oota-llvm.git diff --git a/lib/Target/TargetMachineRegistry.cpp b/lib/Target/TargetMachineRegistry.cpp index f5bd035d033..62c76bbc5bf 100644 --- a/lib/Target/TargetMachineRegistry.cpp +++ b/lib/Target/TargetMachineRegistry.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -18,45 +18,23 @@ #include using namespace llvm; -/// List - This is the main list of all of the registered target machines. -const TargetMachineRegistry::Entry *TargetMachineRegistry::List = 0; - -/// Listeners - All of the listeners registered to get notified when new targets -/// are loaded. -static TargetRegistrationListener *Listeners = 0; - -TargetMachineRegistry::Entry::Entry(const char *N, const char *SD, - TargetMachine *(*CF)(const Module &, IntrinsicLowering*, - const std::string &), - unsigned (*MMF)(const Module &M), unsigned (*JMF)()) - : Name(N), ShortDesc(SD), CtorFn(CF), ModuleMatchQualityFn(MMF), - JITMatchQualityFn(JMF), Next(List) { - List = this; - for (TargetRegistrationListener *L = Listeners; L; L = L->getNext()) - L->targetRegistered(this); -} - -TargetRegistrationListener::TargetRegistrationListener() { - Next = Listeners; - if (Next) Next->Prev = &Next; - Prev = &Listeners; - Listeners = this; -} - -TargetRegistrationListener::~TargetRegistrationListener() { - *Prev = Next; -} +template<> Registry::node *Registry::Head = 0; +template<> Registry::node *Registry::Tail = 0; +template<> Registry::listener *Registry:: +ListenerHead = 0; +template<> Registry::listener *Registry:: +ListenerTail = 0; /// getClosestStaticTargetForModule - Given an LLVM module, pick the best target /// that is compatible with the module. If no close target can be found, this /// returns null and sets the Error string to a reason. -const TargetMachineRegistry::Entry * +const TargetMachineRegistry::entry * TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M, std::string &Error) { - std::vector > UsableTargets; - for (const Entry *E = getList(); E; E = E->getNext()) - if (unsigned Qual = E->ModuleMatchQualityFn(M)) - UsableTargets.push_back(std::make_pair(Qual, E)); + std::vector > UsableTargets; + for (Registry::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"; @@ -76,16 +54,15 @@ TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M, return UsableTargets.back().second; } -/// getClosestTargetForJIT - Given an LLVM module, pick the best target that -/// is compatible with the current host and the specified module. If no -/// close target can be found, this returns null and sets the Error string -/// to a reason. -const TargetMachineRegistry::Entry * +/// getClosestTargetForJIT - Pick the best target that is compatible with +/// the current host. If no close target can be found, this returns null +/// and sets the Error string to a reason. +const TargetMachineRegistry::entry * TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) { - std::vector > UsableTargets; - for (const Entry *E = getList(); E; E = E->getNext()) - if (unsigned Qual = E->JITMatchQualityFn()) - UsableTargets.push_back(std::make_pair(Qual, E)); + std::vector > UsableTargets; + for (Registry::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"; @@ -95,7 +72,7 @@ TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) { // Otherwise, take the best target. If there is a tie, just pick one. unsigned MaxQual = UsableTargets.front().first; - const Entry *MaxQualTarget = UsableTargets.front().second; + const entry *MaxQualTarget = UsableTargets.front().second; for (unsigned i = 1, e = UsableTargets.size(); i != e; ++i) if (UsableTargets[i].first > MaxQual) {