1 //===-- llvm/Support/ValueHolder.h - Wrapper for Value's --------*- C++ -*-===//
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.
9 //===----------------------------------------------------------------------===//
11 #ifndef LLVM_SUPPORT_VALUEHOLDER_H
12 #define LLVM_SUPPORT_VALUEHOLDER_H
14 #include "llvm/User.h"
16 struct ValueHolder : public User {
17 ValueHolder(Value *V = 0);
18 ValueHolder(const ValueHolder &VH) : User(VH.getType(), Value::TypeVal) {
19 Operands.push_back(Use(VH.get(), this));
23 Value *get() const { return (Value*)getOperand(0); }
24 operator Value*() const { return (Value*)getOperand(0); }
27 const ValueHolder &operator=(Value *V) {
32 const ValueHolder &operator=(ValueHolder &VH) {
37 virtual void print(std::ostream& OS) const {