2008-07-05 22:41:37 +00:00
|
|
|
//===-- llvm/OperandTraits.h - OperandTraits class definition ---*- C++ -*-===//
|
2008-05-10 08:32:32 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the traits classes that are handy for enforcing the correct
|
|
|
|
// layout of various User subclasses. It also provides the means for accessing
|
|
|
|
// the operands in the most efficient manner.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LLVM_OPERAND_TRAITS_H
|
|
|
|
#define LLVM_OPERAND_TRAITS_H
|
|
|
|
|
|
|
|
#include "llvm/User.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-03-16 10:59:48 +00:00
|
|
|
// FixedNumOperand Trait Class
|
2008-05-10 08:32:32 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-29 22:58:33 +00:00
|
|
|
/// FixedNumOperandTraits - determine the allocation regime of the Use array
|
|
|
|
/// when it is a prefix to the User object, and the number of Use objects is
|
|
|
|
/// known at compile time.
|
|
|
|
|
2011-01-11 15:07:38 +00:00
|
|
|
template <typename SubClass, unsigned ARITY>
|
2008-05-10 08:32:32 +00:00
|
|
|
struct FixedNumOperandTraits {
|
2011-01-11 15:07:38 +00:00
|
|
|
static Use *op_begin(SubClass* U) {
|
2008-05-10 08:32:32 +00:00
|
|
|
return reinterpret_cast<Use*>(U) - ARITY;
|
|
|
|
}
|
2011-01-11 15:07:38 +00:00
|
|
|
static Use *op_end(SubClass* U) {
|
2008-05-10 08:32:32 +00:00
|
|
|
return reinterpret_cast<Use*>(U);
|
|
|
|
}
|
|
|
|
static unsigned operands(const User*) {
|
|
|
|
return ARITY;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-03-16 10:59:48 +00:00
|
|
|
// OptionalOperand Trait Class
|
2008-05-10 08:32:32 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-03-16 10:59:48 +00:00
|
|
|
/// OptionalOperandTraits - when the number of operands may change at runtime.
|
|
|
|
/// Naturally it may only decrease, because the allocations may not change.
|
|
|
|
|
2011-01-11 15:07:38 +00:00
|
|
|
template <typename SubClass, unsigned ARITY = 1>
|
|
|
|
struct OptionalOperandTraits : public FixedNumOperandTraits<SubClass, ARITY> {
|
2008-05-10 08:32:32 +00:00
|
|
|
static unsigned operands(const User *U) {
|
|
|
|
return U->getNumOperands();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VariadicOperand Trait Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-29 22:58:33 +00:00
|
|
|
/// VariadicOperandTraits - determine the allocation regime of the Use array
|
|
|
|
/// when it is a prefix to the User object, and the number of Use objects is
|
|
|
|
/// only known at allocation time.
|
|
|
|
|
2011-01-11 15:07:38 +00:00
|
|
|
template <typename SubClass, unsigned MINARITY = 0>
|
2008-05-10 08:32:32 +00:00
|
|
|
struct VariadicOperandTraits {
|
2011-01-11 15:07:38 +00:00
|
|
|
static Use *op_begin(SubClass* U) {
|
|
|
|
return reinterpret_cast<Use*>(U) - static_cast<User*>(U)->getNumOperands();
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
2011-01-11 15:07:38 +00:00
|
|
|
static Use *op_end(SubClass* U) {
|
2008-05-10 08:32:32 +00:00
|
|
|
return reinterpret_cast<Use*>(U);
|
|
|
|
}
|
|
|
|
static unsigned operands(const User *U) {
|
|
|
|
return U->getNumOperands();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// HungoffOperand Trait Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-29 22:58:33 +00:00
|
|
|
/// HungoffOperandTraits - determine the allocation regime of the Use array
|
|
|
|
/// when it is not a prefix to the User object, but allocated at an unrelated
|
|
|
|
/// heap address.
|
|
|
|
/// Assumes that the User subclass that is determined by this traits class
|
|
|
|
/// has an OperandList member of type User::op_iterator. [Note: this is now
|
|
|
|
/// trivially satisfied, because User has that member for historic reasons.]
|
|
|
|
///
|
|
|
|
/// This is the traits class that is needed when the Use array must be
|
|
|
|
/// resizable.
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <unsigned MINARITY = 1>
|
|
|
|
struct HungoffOperandTraits {
|
|
|
|
static Use *op_begin(User* U) {
|
|
|
|
return U->OperandList;
|
|
|
|
}
|
|
|
|
static Use *op_end(User* U) {
|
|
|
|
return U->OperandList + U->getNumOperands();
|
|
|
|
}
|
|
|
|
static unsigned operands(const User *U) {
|
|
|
|
return U->getNumOperands();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Macro for generating in-class operand accessor declarations.
|
|
|
|
/// It should only be called in the public section of the interface.
|
|
|
|
///
|
|
|
|
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS) \
|
|
|
|
public: \
|
|
|
|
inline VALUECLASS *getOperand(unsigned) const; \
|
|
|
|
inline void setOperand(unsigned, VALUECLASS*); \
|
2009-02-11 22:09:00 +00:00
|
|
|
inline op_iterator op_begin(); \
|
|
|
|
inline const_op_iterator op_begin() const; \
|
|
|
|
inline op_iterator op_end(); \
|
|
|
|
inline const_op_iterator op_end() const; \
|
2008-05-10 08:32:32 +00:00
|
|
|
protected: \
|
2009-03-10 23:02:13 +00:00
|
|
|
template <int> inline Use &Op(); \
|
|
|
|
template <int> inline const Use &Op() const; \
|
2008-05-10 08:32:32 +00:00
|
|
|
public: \
|
|
|
|
inline unsigned getNumOperands() const
|
|
|
|
|
|
|
|
/// Macro for generating out-of-class operand accessor definitions
|
|
|
|
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
|
2009-02-11 22:09:00 +00:00
|
|
|
CLASS::op_iterator CLASS::op_begin() { \
|
|
|
|
return OperandTraits<CLASS>::op_begin(this); \
|
|
|
|
} \
|
|
|
|
CLASS::const_op_iterator CLASS::op_begin() const { \
|
|
|
|
return OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this)); \
|
|
|
|
} \
|
|
|
|
CLASS::op_iterator CLASS::op_end() { \
|
|
|
|
return OperandTraits<CLASS>::op_end(this); \
|
|
|
|
} \
|
|
|
|
CLASS::const_op_iterator CLASS::op_end() const { \
|
|
|
|
return OperandTraits<CLASS>::op_end(const_cast<CLASS*>(this)); \
|
|
|
|
} \
|
2008-05-10 08:32:32 +00:00
|
|
|
VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \
|
|
|
|
assert(i_nocapture < OperandTraits<CLASS>::operands(this) \
|
|
|
|
&& "getOperand() out of range!"); \
|
|
|
|
return static_cast<VALUECLASS*>( \
|
|
|
|
OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[i_nocapture]); \
|
|
|
|
} \
|
|
|
|
void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \
|
|
|
|
assert(i_nocapture < OperandTraits<CLASS>::operands(this) \
|
|
|
|
&& "setOperand() out of range!"); \
|
|
|
|
OperandTraits<CLASS>::op_begin(this)[i_nocapture] = Val_nocapture; \
|
|
|
|
} \
|
|
|
|
unsigned CLASS::getNumOperands() const { \
|
|
|
|
return OperandTraits<CLASS>::operands(this); \
|
|
|
|
} \
|
2009-03-10 23:02:13 +00:00
|
|
|
template <int Idx_nocapture> Use &CLASS::Op() { \
|
|
|
|
return this->OpFrom<Idx_nocapture>(this); \
|
2008-05-10 08:32:32 +00:00
|
|
|
} \
|
2009-03-10 23:02:13 +00:00
|
|
|
template <int Idx_nocapture> const Use &CLASS::Op() const { \
|
|
|
|
return this->OpFrom<Idx_nocapture>(this); \
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Macro for generating out-of-class operand accessor
|
|
|
|
/// definitions with casted result
|
|
|
|
#define DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
|
2009-02-11 22:09:00 +00:00
|
|
|
CLASS::op_iterator CLASS::op_begin() { \
|
|
|
|
return OperandTraits<CLASS>::op_begin(this); \
|
|
|
|
} \
|
|
|
|
CLASS::const_op_iterator CLASS::op_begin() const { \
|
|
|
|
return OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this)); \
|
|
|
|
} \
|
|
|
|
CLASS::op_iterator CLASS::op_end() { \
|
|
|
|
return OperandTraits<CLASS>::op_end(this); \
|
|
|
|
} \
|
|
|
|
CLASS::const_op_iterator CLASS::op_end() const { \
|
|
|
|
return OperandTraits<CLASS>::op_end(const_cast<CLASS*>(this)); \
|
|
|
|
} \
|
2008-05-10 08:32:32 +00:00
|
|
|
VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \
|
|
|
|
assert(i_nocapture < OperandTraits<CLASS>::operands(this) \
|
|
|
|
&& "getOperand() out of range!"); \
|
|
|
|
return cast<VALUECLASS>( \
|
|
|
|
OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[i_nocapture]); \
|
|
|
|
} \
|
|
|
|
void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \
|
|
|
|
assert(i_nocapture < OperandTraits<CLASS>::operands(this) \
|
|
|
|
&& "setOperand() out of range!"); \
|
|
|
|
OperandTraits<CLASS>::op_begin(this)[i_nocapture] = Val_nocapture; \
|
|
|
|
} \
|
|
|
|
unsigned CLASS::getNumOperands() const { \
|
|
|
|
return OperandTraits<CLASS>::operands(this); \
|
|
|
|
} \
|
2009-03-10 23:02:13 +00:00
|
|
|
template <int Idx_nocapture> Use &CLASS::Op() { \
|
|
|
|
return this->OpFrom<Idx_nocapture>(this); \
|
2008-05-10 08:32:32 +00:00
|
|
|
} \
|
2009-03-10 23:02:13 +00:00
|
|
|
template <int Idx_nocapture> const Use &CLASS::Op() const { \
|
|
|
|
return this->OpFrom<Idx_nocapture>(this); \
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|