[llvm-commits] [llvm] r49475 - in /llvm/branches/ggreif/use-diet: include/llvm/InstrTypes.h include/llvm/Instructions.h include/llvm/User.h lib/VMCore/Instructions.cpp
Gabor Greif
ggreif at gmail.com
Thu Apr 10 04:13:32 PDT 2008
Author: ggreif
Date: Thu Apr 10 06:13:26 2008
New Revision: 49475
URL: http://llvm.org/viewvc/llvm-project?rev=49475&view=rev
Log:
expand functionality of *_TRANSPARENT_OPERAND_ACCESSORS, cleanups, convert GetResultInst
Modified:
llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h
llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
llvm/branches/ggreif/use-diet/include/llvm/User.h
llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
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=49475&r1=49474&r2=49475&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/InstrTypes.h Thu Apr 10 06:13:26 2008
@@ -106,13 +106,15 @@
static inline void *allocate(unsigned); // FIXME
};
-
+/// Macro for generating in-class operand accessor declarations
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS) \
inline VALUECLASS *getOperand(unsigned) const; \
inline void setOperand(unsigned, VALUECLASS*); \
- inline unsigned getNumOperands() const
-
+ inline unsigned getNumOperands() const; \
+ template <unsigned Idx> inline Use &Op(); \
+ template <unsigned Idx> inline const Use &Op() const
+/// Macro for generating out-of-class operand accessor definitions
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
VALUECLASS *CLASS::getOperand(unsigned i) const { \
assert(i < OperandTraits<CLASS>::operands(this) && "getOperand() out of range!"); \
@@ -122,7 +124,13 @@
assert(i < OperandTraits<CLASS>::operands(this) && "setOperand() out of range!"); \
OperandTraits<CLASS>::op_begin(this)[i] = Val; \
} \
-unsigned CLASS::getNumOperands() const { return OperandTraits<CLASS>::operands(this); }
+unsigned CLASS::getNumOperands() const { return OperandTraits<CLASS>::operands(this); } \
+template <unsigned Idx> Use &CLASS::Op() { \
+ return OperandTraits<CLASS>::op_begin(this)[Idx]; \
+} \
+template <unsigned Idx> const Use &CLASS::Op() const { \
+ return OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[Idx]; \
+}
//===----------------------------------------------------------------------===//
@@ -152,15 +160,6 @@
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-/* Value *getOperand(unsigned i) const {
- assert(i == 0 && "getOperand() out of range!");
- return Op<0>();
- }
- void setOperand(unsigned i, Value *Val) {
- assert(i == 0 && "setOperand() out of range!");
- Op<0>() = Val;
- }
- unsigned getNumOperands() const { return 1; }*/
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const UnaryInstruction *) { return true; }
@@ -203,9 +202,6 @@
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-/* inline Value *getOperand(unsigned i) const;
- inline void setOperand(unsigned i, Value *Val);
- inline unsigned getNumOperands() const;*/
/// create() - Construct a binary instruction, given the opcode and the two
/// operands. Optionally (if InstBefore is specified) insert the instruction
@@ -603,17 +599,6 @@
/// @brief Provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-/* 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;
- }
-
- /// @brief CmpInst instructions always have 2 operands.
- unsigned getNumOperands() const { return 2; }*/
/// This is just a convenience that dispatches to the subclasses.
/// @brief Swap the operands and adjust predicate accordingly to retain
Modified: llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Instructions.h?rev=49475&r1=49474&r2=49475&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Instructions.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Instructions.h Thu Apr 10 06:13:26 2008
@@ -2578,7 +2578,8 @@
return Idx;
}
- unsigned getNumOperands() const { return 1; }
+ /// Provide fast operand accessors
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GetResultInst *) { return true; }
@@ -2590,6 +2591,14 @@
}
};
+// FIXME: these are redundant if GetResultInst < UnaryInstruction
+template <>
+struct OperandTraits<GetResultInst> : FixedNumOperandTraits<1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetResultInst, Value)
+
+
} // End llvm namespace
#endif
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=49475&r1=49474&r2=49475&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/User.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/User.h Thu Apr 10 06:13:26 2008
@@ -235,7 +235,7 @@
return Obj;
}
User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps)
- : Value(Ty, vty)/*, OperandList(OpList), NumOperands(NumOps)*/ {}
+ : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {}
public:
void operator delete(void *Usr) {
User *Start = static_cast<User*>(Usr);
Modified: llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp?rev=49475&r1=49474&r2=49475&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp Thu Apr 10 06:13:26 2008
@@ -2253,7 +2253,10 @@
CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
const std::string &Name, Instruction *InsertBefore)
- : Instruction(Type::Int1Ty, op, /*Ops*/NULL, 2, InsertBefore) {
+ : Instruction(Type::Int1Ty, op,
+ OperandTraits<CmpInst>::op_begin(this),
+ OperandTraits<CmpInst>::operands(this),
+ InsertBefore) {
Op<0>().init(LHS, this);
Op<1>().init(RHS, this);
SubclassData = predicate;
@@ -2282,10 +2285,13 @@
assert(Op0Ty->isFloatingPoint() &&
"Invalid operand types for FCmp instruction");
}
-
+
CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
const std::string &Name, BasicBlock *InsertAtEnd)
- : Instruction(Type::Int1Ty, op, /*Ops*/NULL, 2, InsertAtEnd) {
+ : Instruction(Type::Int1Ty, op,
+ OperandTraits<CmpInst>::op_begin(this),
+ OperandTraits<CmpInst>::operands(this),
+ InsertAtEnd) {
Op<0>().init(LHS, this);
Op<1>().init(RHS, this);
SubclassData = predicate;
@@ -2677,7 +2683,10 @@
const std::string &Name,
Instruction *InsertBef)
: Instruction(cast<StructType>(Aggregate->getType())->getElementType(Index),
- GetResult, /*&Aggr*/NULL, 1, InsertBef) {
+ GetResult,
+ OperandTraits<GetResultInst>::op_begin(this),
+ OperandTraits<GetResultInst>::operands(this),
+ InsertBef) {
assert(isValidOperands(Aggregate, Index) && "Invalid GetResultInst operands!");
Op<0>().init(Aggregate, this);
Idx = Index;
More information about the llvm-commits
mailing list