X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FOperandTraits.h;h=3d8dc329b39fe0be346fa250b58f87e8e395d93f;hb=b09c146b116359616f6cbd4c8b3328607e00ff42;hp=3811927e57b9787aca23e539801fd57cca672c4b;hpb=efe65369a74871c3140a540a6c95ce5d1f080954;p=oota-llvm.git diff --git a/include/llvm/OperandTraits.h b/include/llvm/OperandTraits.h index 3811927e57b..3d8dc329b39 100644 --- a/include/llvm/OperandTraits.h +++ b/include/llvm/OperandTraits.h @@ -1,4 +1,4 @@ -//===-- llvm/OperandTraits.h - OperandTraits class definition ---------------------*- C++ -*-===// +//===-- llvm/OperandTraits.h - OperandTraits class definition ---*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -20,39 +20,35 @@ namespace llvm { //===----------------------------------------------------------------------===// -// FixedNumOperands Trait Class +// FixedNumOperand Trait Class //===----------------------------------------------------------------------===// -template +/// 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 struct FixedNumOperandTraits { - static Use *op_begin(User* U) { + static Use *op_begin(SubClass* U) { return reinterpret_cast(U) - ARITY; } - static Use *op_end(User* U) { + static Use *op_end(SubClass* U) { return reinterpret_cast(U); } static unsigned operands(const User*) { return ARITY; } - struct prefix { - Use Ops[ARITY]; - prefix(); // DO NOT IMPLEMENT - }; - template - struct Layout { - struct overlay : prefix, U { - overlay(); // DO NOT IMPLEMENT - }; - }; - static inline void *allocate(unsigned); // FIXME }; //===----------------------------------------------------------------------===// -// OptionalOperands Trait Class +// OptionalOperand Trait Class //===----------------------------------------------------------------------===// -template -struct OptionalOperandTraits : FixedNumOperandTraits { +/// OptionalOperandTraits - when the number of operands may change at runtime. +/// Naturally it may only decrease, because the allocations may not change. + +template +struct OptionalOperandTraits : public FixedNumOperandTraits { static unsigned operands(const User *U) { return U->getNumOperands(); } @@ -62,24 +58,37 @@ struct OptionalOperandTraits : FixedNumOperandTraits { // VariadicOperand Trait Class //===----------------------------------------------------------------------===// -template +/// 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 struct VariadicOperandTraits { - static Use *op_begin(User* U) { - return reinterpret_cast(U) - U->getNumOperands(); + static Use *op_begin(SubClass* U) { + return reinterpret_cast(U) - static_cast(U)->getNumOperands(); } - static Use *op_end(User* U) { + static Use *op_end(SubClass* U) { return reinterpret_cast(U); } static unsigned operands(const User *U) { return U->getNumOperands(); } - static inline void *allocate(unsigned); // FIXME }; //===----------------------------------------------------------------------===// // 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 struct HungoffOperandTraits { static Use *op_begin(User* U) { @@ -91,7 +100,6 @@ struct HungoffOperandTraits { static unsigned operands(const User *U) { return U->getNumOperands(); } - static inline void *allocate(unsigned); // FIXME }; /// Macro for generating in-class operand accessor declarations. @@ -101,45 +109,35 @@ 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 inline Use &Op(); \ - template inline const Use &Op() const; \ + template inline Use &Op(); \ + template 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) \ -VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \ - assert(i_nocapture < OperandTraits::operands(this) \ - && "getOperand() out of range!"); \ - return static_cast( \ - OperandTraits::op_begin(const_cast(this))[i_nocapture]); \ +CLASS::op_iterator CLASS::op_begin() { \ + return OperandTraits::op_begin(this); \ } \ -void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ - assert(i_nocapture < OperandTraits::operands(this) \ - && "setOperand() out of range!"); \ - OperandTraits::op_begin(this)[i_nocapture] = Val_nocapture; \ +CLASS::const_op_iterator CLASS::op_begin() const { \ + return OperandTraits::op_begin(const_cast(this)); \ } \ -unsigned CLASS::getNumOperands() const { \ - return OperandTraits::operands(this); \ +CLASS::op_iterator CLASS::op_end() { \ + return OperandTraits::op_end(this); \ } \ -template Use &CLASS::Op() { \ - return OperandTraits::op_begin(this)[Idx_nocapture]; \ +CLASS::const_op_iterator CLASS::op_end() const { \ + return OperandTraits::op_end(const_cast(this)); \ } \ -template const Use &CLASS::Op() const { \ - return OperandTraits::op_begin( \ - const_cast(this))[Idx_nocapture]; \ -} - - -/// Macro for generating out-of-class operand accessor -/// definitions with casted result -#define DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(CLASS, VALUECLASS) \ VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \ assert(i_nocapture < OperandTraits::operands(this) \ && "getOperand() out of range!"); \ - return cast( \ - OperandTraits::op_begin(const_cast(this))[i_nocapture]); \ + return cast_or_null( \ + OperandTraits::op_begin(const_cast(this))[i_nocapture].get()); \ } \ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ assert(i_nocapture < OperandTraits::operands(this) \ @@ -149,12 +147,11 @@ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ unsigned CLASS::getNumOperands() const { \ return OperandTraits::operands(this); \ } \ -template Use &CLASS::Op() { \ - return OperandTraits::op_begin(this)[Idx_nocapture]; \ +template Use &CLASS::Op() { \ + return this->OpFrom(this); \ } \ -template const Use &CLASS::Op() const { \ - return OperandTraits::op_begin( \ - const_cast(this))[Idx_nocapture]; \ +template const Use &CLASS::Op() const { \ + return this->OpFrom(this); \ }