llvm.org GIT mirror llvm / 88e1eef
Initial checkin of ValueHolder helper class git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8073 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
1 changed file(s) with 36 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===-- llvm/Support/ValueHolder.h - Wrapper for Value's --------*- C++ -*-===//
1 //
2 // This class defines a simple subclass of User, which keeps a pointer to a
3 // Value, which automatically updates when Value::replaceAllUsesWith is called.
4 // This is useful when you have pointers to Value's in your pass, but the
5 // pointers get invalidated when some other portion of the algorithm is
6 // replacing Values with other Values.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_SUPPORT_VALUEHOLDER_H
11 #define LLVM_SUPPORT_VALUEHOLDER_H
12
13 #include "llvm/User.h"
14
15 struct ValueHolder : public User {
16 ValueHolder(Value *V = 0);
17
18 // Getters...
19 const Value *get() const { return getOperand(0); }
20 operator const Value*() const { return getOperand(0); }
21 Value *get() { return getOperand(0); }
22 operator Value*() { return getOperand(0); }
23
24 // Setters...
25 const ValueHolder &operator=(Value *V) {
26 setOperand(0, V);
27 return *this;
28 }
29
30 virtual void print(std::ostream& OS) const {
31 OS << "ValueHolder";
32 }
33 };
34
35 #endif