clarify comments
[oota-llvm.git] / include / llvm / Support / ValueHolder.h
1 //===-- llvm/Support/ValueHolder.h - Wrapper for Value's --------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
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.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_SUPPORT_VALUEHOLDER_H
19 #define LLVM_SUPPORT_VALUEHOLDER_H
20
21 #include "llvm/User.h"
22
23 namespace llvm {
24
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));
29   }
30
31   // Getters...
32   Value *get() const { return (Value*)getOperand(0); }
33   operator Value*() const { return (Value*)getOperand(0); }
34
35   // Setters...
36   const ValueHolder &operator=(Value *V) {
37     setOperand(0, V);
38     return *this;
39   }
40
41   const ValueHolder &operator=(ValueHolder &VH) {
42     setOperand(0, VH);
43     return *this;
44   }
45
46   virtual void print(std::ostream& OS) const {
47     OS << "ValueHolder";
48   }
49 };
50
51 } // End llvm namespace
52
53 #endif