[llvm-commits] [llvm] r49471 - in /llvm/branches/ggreif/use-diet/include/llvm: InstrTypes.h User.h
Gabor Greif
ggreif at gmail.com
Thu Apr 10 01:38:30 PDT 2008
Author: ggreif
Date: Thu Apr 10 03:38:30 2008
New Revision: 49471
URL: http://llvm.org/viewvc/llvm-project?rev=49471&view=rev
Log:
implement operand accessors in terms of traits (for BinaryOperator now)
Modified:
llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h
llvm/branches/ggreif/use-diet/include/llvm/User.h
Modified: llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h?rev=49471&r1=49470&r2=49471&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h Thu Apr 10 03:38:30 2008
@@ -90,7 +90,7 @@
static Use *op_end(User* U) {
return reinterpret_cast<Use*>(U);
}
- static unsigned operands(User*) {
+ static unsigned operands(const User*) {
return ARITY;
}
struct prefix {
@@ -182,15 +182,15 @@
}
/// Transparently provide more efficient getOperand methods.
- Value *getOperand(unsigned i) const {
- assert(i < 2 && "getOperand() out of range!");
- return OperandList[i];
- }
- void setOperand(unsigned i, Value *Val) {
- assert(i < 2 && "setOperand() out of range!");
- OperandList[i] = Val;
- }
- unsigned getNumOperands() const { return 2; }
+ Value *getOperand(unsigned i) const; /*{
+ assert(i < OperandTraits<BinaryOperator>::operands && "getOperand() out of range!");
+ return OperandTraits<BinaryOperator>::op_begin(this)[i];
+ }*/
+ void setOperand(unsigned i, Value *Val); /*{
+ assert(i < OperandTraits<BinaryOperator>::operands && "setOperand() out of range!");
+ OperandTraits<BinaryOperator>::op_begin(this)[i] = Val;
+ }*/
+ unsigned getNumOperands() const;// { return OperandTraits<BinaryOperator>::operands; }
/// create() - Construct a binary instruction, given the opcode and the two
/// operands. Optionally (if InstBefore is specified) insert the instruction
@@ -289,6 +289,17 @@
struct OperandTraits<BinaryOperator> : FixedNumOperandTraits<2> {
};
+Value *BinaryOperator::getOperand(unsigned i) const {
+ assert(i < OperandTraits<BinaryOperator>::operands(this) && "getOperand() out of range!");
+ return OperandTraits<BinaryOperator>::op_begin(const_cast<BinaryOperator*>(this))[i];
+}
+void BinaryOperator::setOperand(unsigned i, Value *Val) {
+ assert(i < OperandTraits<BinaryOperator>::operands(this) && "setOperand() out of range!");
+ OperandTraits<BinaryOperator>::op_begin(this)[i] = Val;
+}
+unsigned BinaryOperator::getNumOperands() const { return OperandTraits<BinaryOperator>::operands(this); }
+
+
//===----------------------------------------------------------------------===//
// CastInst Class
//===----------------------------------------------------------------------===//
Modified: llvm/branches/ggreif/use-diet/include/llvm/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/User.h?rev=49471&r1=49470&r2=49471&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/User.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/User.h Thu Apr 10 03:38:30 2008
@@ -200,7 +200,7 @@
struct OperandTraits<User> {
static inline Use *op_begin(User*);
static inline Use *op_end(User*);
- static inline unsigned operands(User*);
+ static inline unsigned operands(const User*);
template <class U>
struct Layout {
typedef U overlay;
@@ -308,7 +308,7 @@
return U->op_end();
}
-inline unsigned OperandTraits<User>::operands(User *U) {
+inline unsigned OperandTraits<User>::operands(const User *U) {
return U->getNumOperands();
}
/*
More information about the llvm-commits
mailing list