comparison include/llvm/IR/User.h @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children 60c9769439b8
comparison
equal deleted inserted replaced
34:e874dbf0ad9d 77:54457678186b
17 //===----------------------------------------------------------------------===// 17 //===----------------------------------------------------------------------===//
18 18
19 #ifndef LLVM_IR_USER_H 19 #ifndef LLVM_IR_USER_H
20 #define LLVM_IR_USER_H 20 #define LLVM_IR_USER_H
21 21
22 #include "llvm/ADT/iterator.h"
23 #include "llvm/ADT/iterator_range.h"
22 #include "llvm/IR/Value.h" 24 #include "llvm/IR/Value.h"
23 #include "llvm/Support/ErrorHandling.h" 25 #include "llvm/Support/ErrorHandling.h"
24 26
25 namespace llvm { 27 namespace llvm {
26 28
35 void *operator new(size_t) LLVM_DELETED_FUNCTION; 37 void *operator new(size_t) LLVM_DELETED_FUNCTION;
36 template <unsigned> 38 template <unsigned>
37 friend struct HungoffOperandTraits; 39 friend struct HungoffOperandTraits;
38 virtual void anchor(); 40 virtual void anchor();
39 protected: 41 protected:
42 /// NumOperands - The number of values used by this User.
43 ///
44 unsigned NumOperands;
45
40 /// OperandList - This is a pointer to the array of Uses for this User. 46 /// OperandList - This is a pointer to the array of Uses for this User.
41 /// For nodes of fixed arity (e.g. a binary operator) this array will live 47 /// For nodes of fixed arity (e.g. a binary operator) this array will live
42 /// prefixed to some derived class instance. For nodes of resizable variable 48 /// prefixed to some derived class instance. For nodes of resizable variable
43 /// arity (e.g. PHINodes, SwitchInst etc.), this memory will be dynamically 49 /// arity (e.g. PHINodes, SwitchInst etc.), this memory will be dynamically
44 /// allocated and should be destroyed by the classes' virtual dtor. 50 /// allocated and should be destroyed by the classes' virtual dtor.
45 Use *OperandList; 51 Use *OperandList;
46 52
47 /// NumOperands - The number of values used by this User.
48 ///
49 unsigned NumOperands;
50
51 void *operator new(size_t s, unsigned Us); 53 void *operator new(size_t s, unsigned Us);
52 User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps) 54 User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
53 : Value(ty, vty), OperandList(OpList), NumOperands(NumOps) {} 55 : Value(ty, vty), NumOperands(NumOps), OperandList(OpList) {}
54 Use *allocHungoffUses(unsigned) const; 56 Use *allocHungoffUses(unsigned) const;
55 void dropHungoffUses() { 57 void dropHungoffUses() {
56 Use::zap(OperandList, OperandList + NumOperands, true); 58 Use::zap(OperandList, OperandList + NumOperands, true);
57 OperandList = 0; 59 OperandList = nullptr;
58 // Reset NumOperands so User::operator delete() does the right thing. 60 // Reset NumOperands so User::operator delete() does the right thing.
59 NumOperands = 0; 61 NumOperands = 0;
60 } 62 }
61 public: 63 public:
62 ~User() { 64 ~User() {
110 // --------------------------------------------------------------------------- 112 // ---------------------------------------------------------------------------
111 // Operand Iterator interface... 113 // Operand Iterator interface...
112 // 114 //
113 typedef Use* op_iterator; 115 typedef Use* op_iterator;
114 typedef const Use* const_op_iterator; 116 typedef const Use* const_op_iterator;
117 typedef iterator_range<op_iterator> op_range;
118 typedef iterator_range<const_op_iterator> const_op_range;
115 119
116 inline op_iterator op_begin() { return OperandList; } 120 inline op_iterator op_begin() { return OperandList; }
117 inline const_op_iterator op_begin() const { return OperandList; } 121 inline const_op_iterator op_begin() const { return OperandList; }
118 inline op_iterator op_end() { return OperandList+NumOperands; } 122 inline op_iterator op_end() { return OperandList+NumOperands; }
119 inline const_op_iterator op_end() const { return OperandList+NumOperands; } 123 inline const_op_iterator op_end() const { return OperandList+NumOperands; }
124 inline op_range operands() {
125 return op_range(op_begin(), op_end());
126 }
127 inline const_op_range operands() const {
128 return const_op_range(op_begin(), op_end());
129 }
120 130
121 /// Convenience iterator for directly iterating over the Values in the 131 /// Convenience iterator for directly iterating over the Values in the
122 /// OperandList 132 /// OperandList
123 class value_op_iterator : public std::iterator<std::forward_iterator_tag, 133 struct value_op_iterator
124 Value*> { 134 : iterator_adaptor_base<value_op_iterator, op_iterator,
125 op_iterator OI; 135 std::random_access_iterator_tag, Value *,
126 public: 136 ptrdiff_t, Value *, Value *> {
127 explicit value_op_iterator(Use *U) : OI(U) {} 137 explicit value_op_iterator(Use *U = nullptr) : iterator_adaptor_base(U) {}
128 138
129 bool operator==(const value_op_iterator &x) const { 139 Value *operator*() const { return *I; }
130 return OI == x.OI;
131 }
132 bool operator!=(const value_op_iterator &x) const {
133 return !operator==(x);
134 }
135
136 /// Iterator traversal: forward iteration only
137 value_op_iterator &operator++() { // Preincrement
138 ++OI;
139 return *this;
140 }
141 value_op_iterator operator++(int) { // Postincrement
142 value_op_iterator tmp = *this; ++*this; return tmp;
143 }
144
145 /// Retrieve a pointer to the current Value.
146 Value *operator*() const {
147 return *OI;
148 }
149
150 Value *operator->() const { return operator*(); } 140 Value *operator->() const { return operator*(); }
151 }; 141 };
152 142
153 inline value_op_iterator value_op_begin() { 143 inline value_op_iterator value_op_begin() {
154 return value_op_iterator(op_begin()); 144 return value_op_iterator(op_begin());
155 } 145 }
156 inline value_op_iterator value_op_end() { 146 inline value_op_iterator value_op_end() {
157 return value_op_iterator(op_end()); 147 return value_op_iterator(op_end());
148 }
149 inline iterator_range<value_op_iterator> operand_values() {
150 return iterator_range<value_op_iterator>(value_op_begin(), value_op_end());
158 } 151 }
159 152
160 // dropAllReferences() - This function is in charge of "letting go" of all 153 // dropAllReferences() - This function is in charge of "letting go" of all
161 // objects that this User refers to. This allows one to 154 // objects that this User refers to. This allows one to
162 // 'delete' a whole class at a time, even though there may be circular 155 // 'delete' a whole class at a time, even though there may be circular
164 // zero. Then everything is deleted for real. Note that no operations are 157 // zero. Then everything is deleted for real. Note that no operations are
165 // valid on an object that has "dropped all references", except operator 158 // valid on an object that has "dropped all references", except operator
166 // delete. 159 // delete.
167 // 160 //
168 void dropAllReferences() { 161 void dropAllReferences() {
169 for (op_iterator i = op_begin(), e = op_end(); i != e; ++i) 162 for (Use &U : operands())
170 i->set(0); 163 U.set(nullptr);
171 } 164 }
172 165
173 /// replaceUsesOfWith - Replaces all references to the "From" definition with 166 /// replaceUsesOfWith - Replaces all references to the "From" definition with
174 /// references to the "To" definition. 167 /// references to the "To" definition.
175 /// 168 ///
192 static SimpleType getSimplifiedValue(User::const_op_iterator &Val) { 185 static SimpleType getSimplifiedValue(User::const_op_iterator &Val) {
193 return Val->get(); 186 return Val->get();
194 } 187 }
195 }; 188 };
196 189
197 // value_use_iterator::getOperandNo - Requires the definition of the User class.
198 template<typename UserTy>
199 unsigned value_use_iterator<UserTy>::getOperandNo() const {
200 return U - U->getUser()->op_begin();
201 }
202
203 } // End llvm namespace 190 } // End llvm namespace
204 191
205 #endif 192 #endif