From 4b2b9402c5c369b94b35837470a170f1d0e47e1f Mon Sep 17 00:00:00 2001 From: Gordon Henriksen Date: Wed, 17 Oct 2007 21:28:48 +0000 Subject: Switching TargetMachineRegistry to use the new generic Registry. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43094 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/TargetMachineRegistry.h | 111 ++++++++++------------------ 1 file changed, 40 insertions(+), 71 deletions(-) (limited to 'include/llvm/Target') diff --git a/include/llvm/Target/TargetMachineRegistry.h b/include/llvm/Target/TargetMachineRegistry.h index 4c009e1..a8df7b3 100644 --- a/include/llvm/Target/TargetMachineRegistry.h +++ b/include/llvm/Target/TargetMachineRegistry.h @@ -17,52 +17,49 @@ #ifndef LLVM_TARGET_TARGETMACHINEREGISTRY_H #define LLVM_TARGET_TARGETMACHINEREGISTRY_H -#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Registry.h" namespace llvm { class Module; class TargetMachine; + + struct TargetMachineRegistryEntry { + const char *Name; + const char *ShortDesc; + TargetMachine *(*CtorFn)(const Module &, const std::string &); + unsigned (*ModuleMatchQualityFn)(const Module &M); + unsigned (*JITMatchQualityFn)(); + + public: + TargetMachineRegistryEntry(const char *N, const char *SD, + TargetMachine *(*CF)(const Module &, const std::string &), + unsigned (*MMF)(const Module &M), + unsigned (*JMF)()) + : Name(N), ShortDesc(SD), CtorFn(CF), ModuleMatchQualityFn(MMF), + JITMatchQualityFn(JMF) {} + }; + + template<> + class RegistryTraits { + public: + typedef TargetMachineRegistryEntry entry; + + static const char *nameof(const entry &Entry) { return Entry.Name; } + static const char *descof(const entry &Entry) { return Entry.ShortDesc; } + }; - struct TargetMachineRegistry { - struct Entry; - - /// TargetMachineRegistry::getList - This static method returns the list of - /// target machines that are registered with the system. - static const Entry *getList() { return List; } - + struct TargetMachineRegistry : Registry { /// 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. - static const Entry *getClosestStaticTargetForModule(const Module &M, + static const entry *getClosestStaticTargetForModule(const Module &M, std::string &Error); /// 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. - static const Entry *getClosestTargetForJIT(std::string &Error); - - - /// Entry - One instance of this struct is created for each target that is - /// registered. - struct Entry { - const char *Name; - const char *ShortDesc; - TargetMachine *(*CtorFn)(const Module &, const std::string &); - unsigned (*ModuleMatchQualityFn)(const Module &M); - unsigned (*JITMatchQualityFn)(); - - const Entry *getNext() const { return Next; } + static const entry *getClosestTargetForJIT(std::string &Error); - protected: - Entry(const char *N, const char *SD, - TargetMachine *(*CF)(const Module &, const std::string &), - unsigned (*MMF)(const Module &M), unsigned (*JMF)()); - private: - const Entry *Next; // Next entry in the linked list. - }; - - private: - static const Entry *List; }; //===--------------------------------------------------------------------===// @@ -77,51 +74,23 @@ namespace llvm { /// flavour. template - struct RegisterTarget : public TargetMachineRegistry::Entry { - RegisterTarget(const char *Name, const char *ShortDesc) : - TargetMachineRegistry::Entry(Name, ShortDesc, &Allocator, - &TargetMachineImpl::getModuleMatchQuality, - &TargetMachineImpl::getJITMatchQuality) { - } + struct RegisterTarget { + RegisterTarget(const char *Name, const char *ShortDesc) + : Entry(Name, ShortDesc, &Allocator, + &TargetMachineImpl::getModuleMatchQuality, + &TargetMachineImpl::getJITMatchQuality), + Node(Entry) + {} + private: + TargetMachineRegistry::entry Entry; + TargetMachineRegistry::node Node; + static TargetMachine *Allocator(const Module &M, const std::string &FS) { return new TargetMachineImpl(M, FS); } }; - /// TargetRegistrationListener - This class allows code to listen for targets - /// that are dynamically registered, and be notified of it when they are. - class TargetRegistrationListener { - TargetRegistrationListener **Prev, *Next; - public: - TargetRegistrationListener(); - virtual ~TargetRegistrationListener(); - - TargetRegistrationListener *getNext() const { return Next; } - - virtual void targetRegistered(const TargetMachineRegistry::Entry *E) = 0; - }; - - - //===--------------------------------------------------------------------===// - /// TargetNameParser - This option can be used to provide a command line - /// option to choose among the various registered targets (commonly -march). - class TargetNameParser : public TargetRegistrationListener, - public cl::parser { - public: - void initialize(cl::Option &O) { - for (const TargetMachineRegistry::Entry *E = - TargetMachineRegistry::getList(); E; E = E->getNext()) - Values.push_back(std::make_pair(E->Name, - std::make_pair(E, E->ShortDesc))); - cl::parser::initialize(O); - } - - virtual void targetRegistered(const TargetMachineRegistry::Entry *E) { - Values.push_back(std::make_pair(E->Name, - std::make_pair(E, E->ShortDesc))); - } - }; } #endif -- cgit v1.1