Fix stupid typo
[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 #include <vector>
17
18 class User : public Value {
19   User(const User &);             // Do not implement
20 protected:
21   vector<Use> Operands;
22 public:
23   User(const Type *Ty, ValueTy vty, const string &name = "");
24   virtual ~User() { dropAllReferences(); }
25
26   inline Value *getOperand(unsigned i) { 
27     assert(i < Operands.size() && "getOperand() out of range!");
28     return Operands[i]; 
29   }
30   inline const Value *getOperand(unsigned i) const {
31     assert(i < Operands.size() && "getOperand() const out of range!");
32     return Operands[i]; 
33   }
34   inline void setOperand(unsigned i, Value *Val) {
35     assert(i < Operands.size() && "setOperand() out of range!");
36     Operands[i] = Val;
37   }
38   inline unsigned getNumOperands() const { return Operands.size(); }
39
40   // ---------------------------------------------------------------------------
41   // Operand Iterator interface...
42   //
43   typedef vector<Use>::iterator       op_iterator;
44   typedef vector<Use>::const_iterator op_const_iterator;
45
46   inline op_iterator       op_begin()       { return Operands.begin(); }
47   inline op_const_iterator op_begin() const { return Operands.begin(); }
48   inline op_iterator       op_end()         { return Operands.end(); }
49   inline op_const_iterator op_end()   const { return Operands.end(); }
50
51   // dropAllReferences() - This function is in charge of "letting go" of all
52   // objects that this User refers to.  This allows one to
53   // 'delete' a whole class at a time, even though there may be circular
54   // references... first all references are dropped, and all use counts go to
55   // zero.  Then everything is delete'd for real.  Note that no operations are
56   // valid on an object that has "dropped all references", except operator 
57   // delete.
58   //
59   inline void dropAllReferences() {
60     Operands.clear();
61   }
62
63   // replaceUsesOfWith - Replaces all references to the "From" definition with
64   // references to the "To" definition.  (defined in Value.cpp)
65   //
66   void replaceUsesOfWith(Value *From, Value *To);
67
68   // addOperand - This is a special purpose API that should not be used in most
69   // cases.  It adds an empty (null) operand to the instruction specified.  This
70   // is currently used by the back end as part of the "lowering" process... most
71   // optimizations will not handle instructions that are not in their normal
72   // form, so this method should be used with care.
73   //
74   void addOperand() {
75     Operands.push_back(Use(0, this));
76   }
77 };
78
79 #endif