1 //===-- llvm/Support/ValueHolder.h - Wrapper for Value's --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class defines a simple subclass of User, which keeps a pointer to a
11 // Value, which automatically updates when Value::replaceAllUsesWith is called.
12 // This is useful when you have pointers to Value's in your pass, but the
13 // pointers get invalidated when some other portion of the algorithm is
14 // replacing Values with other Values.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_SUPPORT_VALUEHOLDER_H
19 #define LLVM_SUPPORT_VALUEHOLDER_H
21 #include "llvm/User.h"
25 struct ValueHolder : public User {
26 ValueHolder(Value *V = 0);
27 ValueHolder(const ValueHolder &VH) : User(VH.getType(), Value::TypeVal) {
28 Operands.push_back(Use(VH.get(), this));
32 Value *get() const { return (Value*)getOperand(0); }
33 operator Value*() const { return (Value*)getOperand(0); }
36 const ValueHolder &operator=(Value *V) {
41 const ValueHolder &operator=(ValueHolder &VH) {
46 virtual void print(std::ostream& OS) const {
51 } // End llvm namespace