X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FTargetMachineRegistry.cpp;h=f5bd035d03354a334d04c1255528a02695315b21;hb=89fad2c3b27f62c53a807839c752626f2b11142f;hp=ecbfc82932b35862d89c54bc0c0e6c0b5a718eaa;hpb=d7099bc608421321c0933120baac7d1032e5fc1c;p=oota-llvm.git diff --git a/lib/Target/TargetMachineRegistry.cpp b/lib/Target/TargetMachineRegistry.cpp index ecbfc82932b..f5bd035d033 100644 --- a/lib/Target/TargetMachineRegistry.cpp +++ b/lib/Target/TargetMachineRegistry.cpp @@ -1,10 +1,10 @@ //===-- TargetMachineRegistry.cpp - Target Auto Registration Impl ---------===// -// +// // 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 exposes the RegisterTarget class, which TargetMachine @@ -18,8 +18,35 @@ #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; +} + /// 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. @@ -36,7 +63,7 @@ TargetMachineRegistry::getClosestStaticTargetForModule(const Module &M, return 0; } else if (UsableTargets.size() == 1) return UsableTargets.back().second; - + // Otherwise, take the best target, but make sure we don't have to equally // good best targets. std::sort(UsableTargets.begin(), UsableTargets.end()); @@ -65,7 +92,7 @@ TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) { 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; @@ -75,7 +102,7 @@ TargetMachineRegistry::getClosestTargetForJIT(std::string &Error) { MaxQual = UsableTargets[i].first; MaxQualTarget = UsableTargets[i].second; } - + return MaxQualTarget; } - +