Now that we have atomics support properly detected by configure,
[oota-llvm.git] / include / llvm / OperandTraits.h
index 3811927e57b9787aca23e539801fd57cca672c4b..83c1025c07b7ab8d797c2806a123f0f2a10880e3 100644 (file)
@@ -1,4 +1,4 @@
-//===-- llvm/OperandTraits.h - OperandTraits class definition ---------------------*- C++ -*-===//
+//===-- llvm/OperandTraits.h - OperandTraits class definition ---*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -23,6 +23,10 @@ namespace llvm {
 //                          FixedNumOperands Trait Class
 //===----------------------------------------------------------------------===//
 
+/// 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.
+
 template <unsigned ARITY>
 struct FixedNumOperandTraits {
   static Use *op_begin(User* U) {
@@ -62,6 +66,10 @@ struct OptionalOperandTraits : FixedNumOperandTraits<ARITY> {
 //                          VariadicOperand Trait Class
 //===----------------------------------------------------------------------===//
 
+/// 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.
+
 template <unsigned MINARITY = 0>
 struct VariadicOperandTraits {
   static Use *op_begin(User* U) {
@@ -80,6 +88,16 @@ struct VariadicOperandTraits {
 //                          HungoffOperand Trait Class
 //===----------------------------------------------------------------------===//
 
+/// 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.
+
 template <unsigned MINARITY = 1>
 struct HungoffOperandTraits {
   static Use *op_begin(User* U) {
@@ -101,14 +119,30 @@ struct HungoffOperandTraits {
   public: \
   inline VALUECLASS *getOperand(unsigned) const; \
   inline void setOperand(unsigned, VALUECLASS*); \
+  inline op_iterator op_begin(); \
+  inline const_op_iterator op_begin() const; \
+  inline op_iterator op_end(); \
+  inline const_op_iterator op_end() const; \
   protected: \
-  template <unsigned> inline Use &Op(); \
-  template <unsigned> inline const Use &Op() const; \
+  template <int> inline Use &Op(); \
+  template <int> inline const Use &Op() const; \
   public: \
   inline unsigned getNumOperands() const
 
 /// Macro for generating out-of-class operand accessor definitions
 #define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
+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)); \
+} \
 VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \
   assert(i_nocapture < OperandTraits<CLASS>::operands(this) \
          && "getOperand() out of range!"); \
@@ -123,18 +157,29 @@ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \
 unsigned CLASS::getNumOperands() const { \
   return OperandTraits<CLASS>::operands(this);  \
 } \
-template <unsigned Idx_nocapture> Use &CLASS::Op() { \
-  return OperandTraits<CLASS>::op_begin(this)[Idx_nocapture]; \
+template <int Idx_nocapture> Use &CLASS::Op() { \
+  return this->OpFrom<Idx_nocapture>(this); \
 } \
-template <unsigned Idx_nocapture> const Use &CLASS::Op() const { \
-  return OperandTraits<CLASS>::op_begin( \
-    const_cast<CLASS*>(this))[Idx_nocapture]; \
+template <int Idx_nocapture> const Use &CLASS::Op() const { \
+  return this->OpFrom<Idx_nocapture>(this); \
 }
 
 
 /// Macro for generating out-of-class operand accessor
 /// definitions with casted result
 #define DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
+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)); \
+} \
 VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \
   assert(i_nocapture < OperandTraits<CLASS>::operands(this) \
          && "getOperand() out of range!"); \
@@ -149,12 +194,11 @@ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \
 unsigned CLASS::getNumOperands() const { \
   return OperandTraits<CLASS>::operands(this); \
 } \
-template <unsigned Idx_nocapture> Use &CLASS::Op() { \
-  return OperandTraits<CLASS>::op_begin(this)[Idx_nocapture]; \
+template <int Idx_nocapture> Use &CLASS::Op() { \
+  return this->OpFrom<Idx_nocapture>(this); \
 } \
-template <unsigned Idx_nocapture> const Use &CLASS::Op() const { \
-  return OperandTraits<CLASS>::op_begin( \
-    const_cast<CLASS*>(this))[Idx_nocapture]; \
+template <int Idx_nocapture> const Use &CLASS::Op() const { \
+  return this->OpFrom<Idx_nocapture>(this); \
 }