2004-07-11 02:43:43 +00:00
|
|
|
//===-- Target/TargetMachineRegistry.h - Target Registration ----*- C++ -*-===//
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2004-07-11 02:43:43 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2004-07-11 02:43:43 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file exposes two classes: the TargetMachineRegistry class, which allows
|
|
|
|
// tools to inspect all of registered targets, and the RegisterTarget class,
|
|
|
|
// which TargetMachine implementations should use to register themselves with
|
|
|
|
// the system.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_TARGETMACHINEREGISTRY_H
|
|
|
|
#define LLVM_TARGET_TARGETMACHINEREGISTRY_H
|
|
|
|
|
2009-01-16 07:02:28 +00:00
|
|
|
#include "llvm/Module.h"
|
2007-10-17 21:28:48 +00:00
|
|
|
#include "llvm/Support/Registry.h"
|
2004-07-11 03:59:46 +00:00
|
|
|
|
2004-07-11 02:43:43 +00:00
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
|
|
|
class TargetMachine;
|
2009-01-16 06:53:46 +00:00
|
|
|
|
2007-10-17 21:28:48 +00:00
|
|
|
struct TargetMachineRegistryEntry {
|
|
|
|
const char *Name;
|
|
|
|
const char *ShortDesc;
|
|
|
|
TargetMachine *(*CtorFn)(const Module &, const std::string &);
|
|
|
|
unsigned (*ModuleMatchQualityFn)(const Module &M);
|
|
|
|
unsigned (*JITMatchQualityFn)();
|
2009-01-16 06:53:46 +00:00
|
|
|
|
2007-10-17 21:28:48 +00:00
|
|
|
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) {}
|
|
|
|
};
|
2009-01-16 06:53:46 +00:00
|
|
|
|
2007-10-17 21:28:48 +00:00
|
|
|
template<>
|
|
|
|
class RegistryTraits<TargetMachine> {
|
|
|
|
public:
|
|
|
|
typedef TargetMachineRegistryEntry entry;
|
2009-01-16 06:53:46 +00:00
|
|
|
|
2007-10-17 21:28:48 +00:00
|
|
|
static const char *nameof(const entry &Entry) { return Entry.Name; }
|
|
|
|
static const char *descof(const entry &Entry) { return Entry.ShortDesc; }
|
|
|
|
};
|
2004-07-11 02:43:43 +00:00
|
|
|
|
2007-10-18 11:31:21 +00:00
|
|
|
struct TargetMachineRegistry : public Registry<TargetMachine> {
|
2004-07-11 03:59:46 +00:00
|
|
|
/// 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.
|
2007-10-17 21:28:48 +00:00
|
|
|
static const entry *getClosestStaticTargetForModule(const Module &M,
|
2004-07-11 03:59:46 +00:00
|
|
|
std::string &Error);
|
|
|
|
|
2007-07-30 14:58:59 +00:00
|
|
|
/// 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.
|
2007-10-17 21:28:48 +00:00
|
|
|
static const entry *getClosestTargetForJIT(std::string &Error);
|
2004-07-11 02:43:43 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// RegisterTarget - This class is used to make targets automatically register
|
|
|
|
/// themselves with the tool they are linked. Targets should define an
|
|
|
|
/// instance of this and implement the static methods described in the
|
2006-05-15 17:25:05 +00:00
|
|
|
/// TargetMachine comments.
|
2009-01-16 06:53:46 +00:00
|
|
|
/// The type 'TargetMachineImpl' should provide a constructor with two
|
2006-05-15 17:25:05 +00:00
|
|
|
/// parameters:
|
|
|
|
/// - const Module& M: the module that is being compiled:
|
2009-01-16 06:53:46 +00:00
|
|
|
/// - const std::string& FS: target-specific string describing target
|
2006-05-15 17:25:05 +00:00
|
|
|
/// flavour.
|
2009-01-16 06:53:46 +00:00
|
|
|
|
2004-07-11 02:43:43 +00:00
|
|
|
template<class TargetMachineImpl>
|
2007-10-17 21:28:48 +00:00
|
|
|
struct RegisterTarget {
|
|
|
|
RegisterTarget(const char *Name, const char *ShortDesc)
|
|
|
|
: Entry(Name, ShortDesc, &Allocator,
|
|
|
|
&TargetMachineImpl::getModuleMatchQuality,
|
|
|
|
&TargetMachineImpl::getJITMatchQuality),
|
|
|
|
Node(Entry)
|
|
|
|
{}
|
|
|
|
|
2004-07-11 02:43:43 +00:00
|
|
|
private:
|
2007-10-17 21:28:48 +00:00
|
|
|
TargetMachineRegistry::entry Entry;
|
|
|
|
TargetMachineRegistry::node Node;
|
2009-01-16 06:53:46 +00:00
|
|
|
|
2008-05-30 22:47:19 +00:00
|
|
|
static TargetMachine *Allocator(const Module &M, const std::string &FS) {
|
|
|
|
return new TargetMachineImpl(M, FS);
|
2004-07-11 02:43:43 +00:00
|
|
|
}
|
|
|
|
};
|
2004-07-11 03:59:46 +00:00
|
|
|
|
2004-07-11 02:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|