1 //===-- Target/TargetMachineRegistry.h - Target Registration ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes two classes: the TargetMachineRegistry class, which allows
11 // tools to inspect all of registered targets, and the RegisterTarget class,
12 // which TargetMachine implementations should use to register themselves with
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TARGET_TARGETMACHINEREGISTRY_H
18 #define LLVM_TARGET_TARGETMACHINEREGISTRY_H
23 class IntrinsicLowering;
25 struct TargetMachineRegistry {
26 /// Entry - One instance of this struct is created for each target that is
30 const char *ShortDesc;
31 TargetMachine *(*CtorFn)(const Module &, IntrinsicLowering*);
32 unsigned (*ModuleMatchQualityFn)(const Module &M);
33 unsigned (*JITMatchQualityFn)();
35 const Entry *getNext() const { return Next; }
38 Entry(const char *N, const char *SD,
39 TargetMachine *(*CF)(const Module &, IntrinsicLowering*),
40 unsigned (*MMF)(const Module &M), unsigned (*JMF)())
41 : Name(N), ShortDesc(SD), CtorFn(CF), ModuleMatchQualityFn(MMF),
42 JITMatchQualityFn(JMF), Next(List) {
46 const Entry *Next; // Next entry in the linked list.
49 /// TargetMachineRegistry::getList - This static method returns the list of
50 /// target machines that are registered with the system.
51 static const Entry *getList() { return List; }
54 static const Entry *List;
57 //===--------------------------------------------------------------------===//
58 /// RegisterTarget - This class is used to make targets automatically register
59 /// themselves with the tool they are linked. Targets should define an
60 /// instance of this and implement the static methods described in the
61 /// TargetMachine comments..
62 template<class TargetMachineImpl>
63 struct RegisterTarget : public TargetMachineRegistry::Entry {
64 RegisterTarget(const char *Name, const char *ShortDesc) :
65 TargetMachineRegistry::Entry(Name, ShortDesc, &Allocator,
66 &TargetMachineImpl::getModuleMatchQuality,
67 &TargetMachineImpl::getJITMatchQuality) {
70 static TargetMachine *Allocator(const Module &M, IntrinsicLowering *IL) {
71 return new TargetMachineImpl(M, IL);