diff options
Diffstat (limited to 'include/llvm/Target/TargetMachineRegistry.h')
-rw-r--r-- | include/llvm/Target/TargetMachineRegistry.h | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/include/llvm/Target/TargetMachineRegistry.h b/include/llvm/Target/TargetMachineRegistry.h index 6b78a58..b7ea448 100644 --- a/include/llvm/Target/TargetMachineRegistry.h +++ b/include/llvm/Target/TargetMachineRegistry.h @@ -19,21 +19,25 @@ #include "llvm/Module.h" #include "llvm/Support/Registry.h" -#include "llvm/Target/TargetRegistry.h" namespace llvm { class Module; - class Target; class TargetMachine; struct TargetMachineRegistryEntry { - const Target &TheTarget; const char *Name; const char *ShortDesc; + TargetMachine *(*CtorFn)(const Module &, const std::string &); + unsigned (*ModuleMatchQualityFn)(const Module &M); + unsigned (*JITMatchQualityFn)(); public: - TargetMachineRegistryEntry(const Target &T, const char *N, const char *SD) - : TheTarget(T), Name(N), ShortDesc(SD) {} + 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<> @@ -46,15 +50,24 @@ namespace llvm { }; struct TargetMachineRegistry : public Registry<TargetMachine> { + /// 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, + 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); }; //===--------------------------------------------------------------------===// /// RegisterTarget - This class is used to make targets automatically register - /// themselves with the tools they are linked with. Targets should define an - /// single global Target instance and register it using the TargetRegistry - /// interfaces. Targets must also include a static instance of this class. - /// + /// themselves with the tool they are linked. Targets should define an + /// instance of this and implement the static methods described in the + /// TargetMachine comments. /// The type 'TargetMachineImpl' should provide a constructor with two /// parameters: /// - const Module& M: the module that is being compiled: @@ -63,19 +76,19 @@ namespace llvm { template<class TargetMachineImpl> struct RegisterTarget { - RegisterTarget(Target &T, const char *Name, const char *ShortDesc) - : Entry(T, Name, ShortDesc), - Node(Entry) { - TargetRegistry::RegisterTargetMachine(T, &Allocator); - } + 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 Target &T, const Module &M, - const std::string &FS) { - return new TargetMachineImpl(T, M, FS); + static TargetMachine *Allocator(const Module &M, const std::string &FS) { + return new TargetMachineImpl(M, FS); } }; |