[llvm-commits] [llvm] r49451 - /llvm/branches/ggreif/use-diet/include/llvm/User.h

Gabor Greif ggreif at gmail.com
Wed Apr 9 14:28:25 PDT 2008


Author: ggreif
Date: Wed Apr  9 16:28:25 2008
New Revision: 49451

URL: http://llvm.org/viewvc/llvm-project?rev=49451&view=rev
Log:
implement Op<Indx> functions using trait redirection

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

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=49451&r1=49450&r2=49451&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/User.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/User.h Wed Apr  9 16:28:25 2008
@@ -188,6 +188,26 @@
 
 ==============================================================================*/
 
+/// OperandTraits - Compile-time customization of
+/// operand-related allocators and accessors
+/// for use of the User class
+template <class>
+struct OperandTraits;
+
+class User;
+
+template <>
+struct OperandTraits<User> {
+  static inline Use *op_begin(User*);
+  static inline Use *op_end(User*);
+	static inline unsigned operands(User*);
+  template <class U>
+	struct Layout {
+		typedef U overlay;
+	};
+	static inline void *allocate(unsigned);
+};
+
 class User : public Value {
   User(const User &);             // Do not implement
   void *operator new(size_t);     // Do not implement
@@ -225,8 +245,12 @@
     else ::operator delete(Usr);
   }
 public:
-  template <unsigned> Use &Op();
-  template <unsigned> const Use &Op() const;
+  template <unsigned Idx> Use &Op() {
+		return OperandTraits<User>::op_begin(this)[Idx];
+	}
+  template <unsigned Idx> const Use &Op() const {
+		return OperandTraits<User>::op_begin(const_cast<User*>(this))[Idx];
+	}
   Use *allocHangoffUses(unsigned) const;
 
   Value *getOperand(unsigned i) const {
@@ -276,6 +300,26 @@
   }
 };
 
+inline Use *OperandTraits<User>::op_begin(User *U) {
+	return U->op_begin();
+}
+
+inline Use *OperandTraits<User>::op_end(User *U) {
+	return U->op_end();
+}
+
+inline unsigned OperandTraits<User>::operands(User *U) {
+	return U->getNumOperands();
+}
+	/*
+  template <class U>
+	struct Layout {
+		typedef U overlay;
+	};
+	static inline void *allocate(unsigned);
+};
+	*/
+
 template<> struct simplify_type<User::op_iterator> {
   typedef Value* SimpleType;
 





More information about the llvm-commits mailing list