[llvm-commits] [llvm] r49638 - in /llvm/branches/ggreif/use-diet/include/llvm: Constants.h OperandTraits.h

Gabor Greif ggreif at gmail.com
Mon Apr 14 03:16:54 PDT 2008


Author: ggreif
Date: Mon Apr 14 05:16:54 2008
New Revision: 49638

URL: http://llvm.org/viewvc/llvm-project?rev=49638&view=rev
Log:
introduce (and use) DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS for safe, covariant getOperand()

Modified:
    llvm/branches/ggreif/use-diet/include/llvm/Constants.h
    llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h

Modified: llvm/branches/ggreif/use-diet/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Constants.h?rev=49638&r1=49637&r2=49638&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Constants.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Constants.h Mon Apr 14 05:16:54 2008
@@ -22,6 +22,7 @@
 
 #include "llvm/Constant.h"
 #include "llvm/Type.h"
+#include "llvm/OperandTraits.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/APFloat.h"
 
@@ -332,7 +333,7 @@
   static Constant *get(const std::string &Initializer, bool AddNull = true);
 
   /// Transparently provide more efficient getOperand methods.
-  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 
   /// getType - Specialize the getType() method to always return an ArrayType,
   /// which reduces the amount of casting needed in parts of the compiler.
@@ -376,7 +377,7 @@
 struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
 };
 
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Value)
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
 
 //===----------------------------------------------------------------------===//
 // ConstantStruct - Constant Struct Declarations
@@ -400,7 +401,7 @@
   }
   
   /// Transparently provide more efficient getOperand methods.
-  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 
   /// getType() specialization - Reduce amount of casting...
   ///
@@ -429,7 +430,7 @@
 struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
 };
 
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Value)
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
 
 //===----------------------------------------------------------------------===//
 /// ConstantVector - Constant Vector Declarations
@@ -451,7 +452,7 @@
   }
   
   /// Transparently provide more efficient getOperand methods.
-  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 
   /// getType - Specialize the getType() method to always return a VectorType,
   /// which reduces the amount of casting needed in parts of the compiler.
@@ -494,7 +495,7 @@
 struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
 };
 
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Value)
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
 
 //===----------------------------------------------------------------------===//
 /// ConstantPointerNull - a constant pointer value that points to null
@@ -733,13 +734,13 @@
   virtual void destroyConstant();
   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
 
-  /// Override methods to provide more type information...
+/*  /// Override methods to provide more type information...
   inline Constant *getOperand(unsigned i) {
     return cast<Constant>(User::getOperand(i));
   }
   inline Constant *getOperand(unsigned i) const {
     return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
-  }
+  }*/
 
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -753,7 +754,7 @@
 struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
 };
 
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
+DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
 
 //===----------------------------------------------------------------------===//
 /// UndefValue - 'undef' values are things that do not have specified contents.

Modified: llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h?rev=49638&r1=49637&r2=49638&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h Mon Apr 14 05:16:54 2008
@@ -106,7 +106,27 @@
 #define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
 VALUECLASS *CLASS::getOperand(unsigned i) const { \
   assert(i < OperandTraits<CLASS>::operands(this) && "getOperand() out of range!"); \
-  return OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[i]; \
+  return static_cast<VALUECLASS*>(OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[i]); \
+} \
+void CLASS::setOperand(unsigned i, VALUECLASS *Val) { \
+  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); } \
+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]; \
+}
+
+
+/// 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) const { \
+  assert(i < OperandTraits<CLASS>::operands(this) && "getOperand() out of range!"); \
+  return cast<VALUECLASS>(OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[i]); \
 } \
 void CLASS::setOperand(unsigned i, VALUECLASS *Val) { \
   assert(i < OperandTraits<CLASS>::operands(this) && "setOperand() out of range!"); \





More information about the llvm-commits mailing list