Initial checkin of ValueHolder helper class
authorChris Lattner <sabre@nondot.org>
Sat, 23 Aug 2003 19:43:18 +0000 (19:43 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 23 Aug 2003 19:43:18 +0000 (19:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8073 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/ValueHolder.h [new file with mode: 0644]

diff --git a/include/llvm/Support/ValueHolder.h b/include/llvm/Support/ValueHolder.h
new file mode 100644 (file)
index 0000000..33fda2c
--- /dev/null
@@ -0,0 +1,36 @@
+//===-- llvm/Support/ValueHolder.h - Wrapper for Value's --------*- C++ -*-===//
+//
+// This class defines a simple subclass of User, which keeps a pointer to a
+// Value, which automatically updates when Value::replaceAllUsesWith is called.
+// This is useful when you have pointers to Value's in your pass, but the
+// pointers get invalidated when some other portion of the algorithm is
+// replacing Values with other Values.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_VALUEHOLDER_H
+#define LLVM_SUPPORT_VALUEHOLDER_H
+
+#include "llvm/User.h"
+
+struct ValueHolder : public User {
+  ValueHolder(Value *V = 0);
+
+  // Getters...
+  const Value *get() const { return getOperand(0); }
+  operator const Value*() const { return getOperand(0); }
+  Value *get() { return getOperand(0); }
+  operator Value*() { return getOperand(0); }
+
+  // Setters...
+  const ValueHolder &operator=(Value *V) {
+    setOperand(0, V);
+    return *this;
+  }
+
+  virtual void print(std::ostream& OS) const {
+    OS << "ValueHolder";
+  }
+};
+
+#endif