Initial checkin of ValueHolder helper class
[oota-llvm.git] / include / llvm / Support / ValueHolder.h
1 //===-- llvm/Support/ValueHolder.h - Wrapper for Value's --------*- C++ -*-===//
2 //
3 // This class defines a simple subclass of User, which keeps a pointer to a
4 // Value, which automatically updates when Value::replaceAllUsesWith is called.
5 // This is useful when you have pointers to Value's in your pass, but the
6 // pointers get invalidated when some other portion of the algorithm is
7 // replacing Values with other Values.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LLVM_SUPPORT_VALUEHOLDER_H
12 #define LLVM_SUPPORT_VALUEHOLDER_H
13
14 #include "llvm/User.h"
15
16 struct ValueHolder : public User {
17   ValueHolder(Value *V = 0);
18
19   // Getters...
20   const Value *get() const { return getOperand(0); }
21   operator const Value*() const { return getOperand(0); }
22   Value *get() { return getOperand(0); }
23   operator Value*() { return getOperand(0); }
24
25   // Setters...
26   const ValueHolder &operator=(Value *V) {
27     setOperand(0, V);
28     return *this;
29   }
30
31   virtual void print(std::ostream& OS) const {
32     OS << "ValueHolder";
33   }
34 };
35
36 #endif