LLVM API Documentation
00001 //===-- Target/TargetMachineRegistry.h - Target Registration ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file exposes two classes: the TargetMachineRegistry class, which allows 00011 // tools to inspect all of registered targets, and the RegisterTarget class, 00012 // which TargetMachine implementations should use to register themselves with 00013 // the system. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #ifndef LLVM_TARGET_TARGETMACHINEREGISTRY_H 00018 #define LLVM_TARGET_TARGETMACHINEREGISTRY_H 00019 00020 #include "llvm/Support/Registry.h" 00021 00022 namespace llvm { 00023 class Module; 00024 class TargetMachine; 00025 00026 struct TargetMachineRegistryEntry { 00027 const char *Name; 00028 const char *ShortDesc; 00029 TargetMachine *(*CtorFn)(const Module &, const std::string &); 00030 unsigned (*ModuleMatchQualityFn)(const Module &M); 00031 unsigned (*JITMatchQualityFn)(); 00032 00033 public: 00034 TargetMachineRegistryEntry(const char *N, const char *SD, 00035 TargetMachine *(*CF)(const Module &, const std::string &), 00036 unsigned (*MMF)(const Module &M), 00037 unsigned (*JMF)()) 00038 : Name(N), ShortDesc(SD), CtorFn(CF), ModuleMatchQualityFn(MMF), 00039 JITMatchQualityFn(JMF) {} 00040 }; 00041 00042 template<> 00043 class RegistryTraits<TargetMachine> { 00044 public: 00045 typedef TargetMachineRegistryEntry entry; 00046 00047 static const char *nameof(const entry &Entry) { return Entry.Name; } 00048 static const char *descof(const entry &Entry) { return Entry.ShortDesc; } 00049 }; 00050 00051 struct TargetMachineRegistry : public Registry<TargetMachine> { 00052 /// getClosestStaticTargetForModule - Given an LLVM module, pick the best 00053 /// target that is compatible with the module. If no close target can be 00054 /// found, this returns null and sets the Error string to a reason. 00055 static const entry *getClosestStaticTargetForModule(const Module &M, 00056 std::string &Error); 00057 00058 /// getClosestTargetForJIT - Pick the best target that is compatible with 00059 /// the current host. If no close target can be found, this returns null 00060 /// and sets the Error string to a reason. 00061 static const entry *getClosestTargetForJIT(std::string &Error); 00062 00063 }; 00064 00065 //===--------------------------------------------------------------------===// 00066 /// RegisterTarget - This class is used to make targets automatically register 00067 /// themselves with the tool they are linked. Targets should define an 00068 /// instance of this and implement the static methods described in the 00069 /// TargetMachine comments. 00070 /// The type 'TargetMachineImpl' should provide a constructor with two 00071 /// parameters: 00072 /// - const Module& M: the module that is being compiled: 00073 /// - const std::string& FS: target-specific string describing target 00074 /// flavour. 00075 00076 template<class TargetMachineImpl> 00077 struct RegisterTarget { 00078 RegisterTarget(const char *Name, const char *ShortDesc) 00079 : Entry(Name, ShortDesc, &Allocator, 00080 &TargetMachineImpl::getModuleMatchQuality, 00081 &TargetMachineImpl::getJITMatchQuality), 00082 Node(Entry) 00083 {} 00084 00085 private: 00086 TargetMachineRegistry::entry Entry; 00087 TargetMachineRegistry::node Node; 00088 00089 static TargetMachine *Allocator(const Module &M, const std::string &FS) { 00090 return new TargetMachineImpl(M, FS); 00091 } 00092 }; 00093 00094 } 00095 00096 #endif
This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.