Add more methods to be more value-like
[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   ValueHolder(const ValueHolder &VH) : User(VH.getType(), Value::TypeVal) {}
19
20   // Getters...
21   const Value *get() const { return getOperand(0); }
22   operator const Value*() const { return getOperand(0); }
23   Value *get() { return getOperand(0); }
24   operator Value*() { return getOperand(0); }
25
26   // Setters...
27   const ValueHolder &operator=(Value *V) {
28     setOperand(0, V);
29     return *this;
30   }
31
32   const ValueHolder &operator=(ValueHolder &VH) {
33     setOperand(0, VH);
34     return *this;
35   }
36
37   virtual void print(std::ostream& OS) const {
38     OS << "ValueHolder";
39   }
40 };
41
42 #endif