/// super-registers of the specific register, e.g. RAX, EAX, are super-registers
/// of AX.
///
-struct TargetRegisterDesc {
+struct MCRegisterDesc {
const char *Name; // Printable name for the reg (for debugging)
const unsigned *Overlaps; // Overlapping registers, described above
const unsigned *SubRegs; // Sub-register set, described above
/// to this array so that we can turn register number into a register
/// descriptor.
///
+/// Note this class is designed to be a base class of TargetRegisterInfo, which
+/// is the interface used by codegen. However, specific targets *should never*
+/// specialize this class. MCRegisterInfo should only contain getters to access
+/// TableGen generated physical register data. It must not be extended with
+/// virtual methods.
+///
class MCRegisterInfo {
private:
- const TargetRegisterDesc *Desc; // Pointer to the descriptor array
+ const MCRegisterDesc *Desc; // Pointer to the descriptor array
unsigned NumRegs; // Number of entries in the array
public:
/// InitMCRegisterInfo - Initialize MCRegisterInfo, called by TableGen
/// auto-generated routines. *DO NOT USE*.
- void InitMCRegisterInfo(const TargetRegisterDesc *D, unsigned NR) {
+ void InitMCRegisterInfo(const MCRegisterDesc *D, unsigned NR) {
Desc = D;
NumRegs = NR;
}
- const TargetRegisterDesc &operator[](unsigned RegNo) const {
+ const MCRegisterDesc &operator[](unsigned RegNo) const {
assert(RegNo < NumRegs &&
"Attempting to access record for invalid register number!");
return Desc[RegNo];
/// Provide a get method, equivalent to [], but more useful if we have a
/// pointer to this object.
///
- const TargetRegisterDesc &get(unsigned RegNo) const {
+ const MCRegisterDesc &get(unsigned RegNo) const {
return operator[](RegNo);
}
typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
StringRef TT);
- typedef MCRegisterInfo *(*RegInfoCtorFnTy)(const Target &T,
- StringRef TT);
+ typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(void);
typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
const std::string &TT,
const std::string &Features);
/// registered.
AsmInfoCtorFnTy AsmInfoCtorFn;
- /// RegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
+ /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
/// if registered.
- RegInfoCtorFnTy RegInfoCtorFn;
+ MCRegInfoCtorFnTy MCRegInfoCtorFn;
/// TargetMachineCtorFn - Construction function for this target's
/// TargetMachine, if registered.
return AsmInfoCtorFn(*this, Triple);
}
- /// createRegInfo - Create a MCRegisterInfo implementation for the specified
- /// target triple.
+ /// createMCRegInfo - Create a MCRegisterInfo implementation.
///
- /// \arg Triple - This argument is used to determine the target machine
- /// feature set; it should always be provided. Generally this should be
- /// either the target triple from the module, or the target triple of the
- /// host if that does not exist.
- MCRegisterInfo *createRegInfo(StringRef Triple) const {
- if (!RegInfoCtorFn)
+ MCRegisterInfo *createMCRegInfo() const {
+ if (!MCRegInfoCtorFn)
return 0;
- return RegInfoCtorFn(*this, Triple);
+ return MCRegInfoCtorFn();
}
/// createTargetMachine - Create a target specific machine implementation
T.AsmInfoCtorFn = Fn;
}
- /// RegisterRegInfo - Register a MCRegisterInfo implementation for the
+ /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
/// given target.
///
/// Clients are responsible for ensuring that registration doesn't occur
///
/// @param T - The target being registered.
/// @param Fn - A function to construct a MCRegisterInfo for the target.
- static void RegisterRegInfo(Target &T, Target::RegInfoCtorFnTy Fn) {
+ static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
// Ignore duplicate registration.
- if (!T.RegInfoCtorFn)
- T.RegInfoCtorFn = Fn;
+ if (!T.MCRegInfoCtorFn)
+ T.MCRegInfoCtorFn = Fn;
}
/// RegisterTargetMachine - Register a TargetMachine implementation for the
}
};
+ /// RegisterMCRegInfo - Helper template for registering a target register info
+ /// implementation. This invokes the static "Create" method on the class to
+ /// actually do the construction. Usage:
+ ///
+ /// extern "C" void LLVMInitializeFooTarget() {
+ /// extern Target TheFooTarget;
+ /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
+ /// }
+ template<class MCRegisterInfoImpl>
+ struct RegisterMCRegInfo {
+ RegisterMCRegInfo(Target &T) {
+ TargetRegistry::RegisterMCRegInfo(T, &Allocator);
+ }
+ private:
+ static MCRegisterInfo *Allocator() {
+ return new MCRegisterInfoImpl();
+ }
+ };
+
+ /// RegisterMCRegInfoFn - Helper template for registering a target register
+ /// info implementation. This invokes the specified function to do the
+ /// construction. Usage:
+ ///
+ /// extern "C" void LLVMInitializeFooTarget() {
+ /// extern Target TheFooTarget;
+ /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
+ /// }
+ struct RegisterMCRegInfoFn {
+ RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
+ TargetRegistry::RegisterMCRegInfo(T, Fn);
+ }
+ };
/// RegisterTargetMachine - Helper template for registering a target machine
/// implementation, for use in the target machine initialization