Initial revision
[oota-llvm.git] / include / llvm / User.h
1 //===-- llvm/User.h - User class definition ----------------------*- C++ -*--=//
2 //
3 // This class defines the interface that one who 'use's a Value must implement.
4 // Each instance of the Value class keeps track of what User's have handles
5 // to it.
6 //
7 //  * Instructions are the largest class of User's.
8 //  * Constants may be users of other constants (think arrays and stuff)
9 //
10 //===----------------------------------------------------------------------===//
11
12 #ifndef LLVM_USER_H
13 #define LLVM_USER_H
14
15 #include "llvm/Value.h"
16
17 class User : public Value {
18   User(const User &);             // Do not implement
19 public:
20   User(const Type *Ty, ValueTy vty, const string &name = "");
21   virtual ~User() {}
22
23   // if i > the number of operands, then getOperand() returns 0, and setOperand
24   // returns false.  setOperand() may also return false if the operand is of
25   // the wrong type.
26   //
27   virtual Value *getOperand(unsigned i) = 0;
28   virtual const Value *getOperand(unsigned i) const = 0;
29   virtual bool setOperand(unsigned i, Value *Val) = 0;
30
31   // dropAllReferences() - This virtual function should be overridden to "let
32   // go" of all references that this user is maintaining.  This allows one to 
33   // 'delete' a whole class at a time, even though there may be circular
34   // references... first all references are dropped, and all use counts go to
35   // zero.  Then everything is delete'd for real.  Note that no operations are
36   // valid on an object that has "dropped all references", except operator 
37   // delete.
38   //
39   virtual void dropAllReferences() = 0;
40
41   // replaceUsesOfWith - Replaces all references to the "From" definition with
42   // references to the "To" definition.  (defined in Value.cpp)
43   //
44   void replaceUsesOfWith(Value *From, Value *To);
45 };
46
47 #endif