Mercurial > hg > CbC > CbC_llvm
comparison include/llvm/IR/User.h @ 83:60c9769439b8 LLVM3.7
LLVM 3.7
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Feb 2015 14:55:36 +0900 |
parents | 54457678186b |
children | afa8332a0e37 |
comparison
equal
deleted
inserted
replaced
78:af83660cff7b | 83:60c9769439b8 |
---|---|
24 #include "llvm/IR/Value.h" | 24 #include "llvm/IR/Value.h" |
25 #include "llvm/Support/ErrorHandling.h" | 25 #include "llvm/Support/ErrorHandling.h" |
26 | 26 |
27 namespace llvm { | 27 namespace llvm { |
28 | 28 |
29 /// OperandTraits - Compile-time customization of | 29 /// \brief Compile-time customization of User operands. |
30 /// operand-related allocators and accessors | 30 /// |
31 /// for use of the User class | 31 /// Customizes operand-related allocators and accessors. |
32 template <class> | 32 template <class> |
33 struct OperandTraits; | 33 struct OperandTraits; |
34 | 34 |
35 class User : public Value { | 35 class User : public Value { |
36 User(const User &) LLVM_DELETED_FUNCTION; | 36 User(const User &) = delete; |
37 void *operator new(size_t) LLVM_DELETED_FUNCTION; | 37 void *operator new(size_t) = delete; |
38 template <unsigned> | 38 template <unsigned> |
39 friend struct HungoffOperandTraits; | 39 friend struct HungoffOperandTraits; |
40 virtual void anchor(); | 40 virtual void anchor(); |
41 protected: | 41 protected: |
42 /// NumOperands - The number of values used by this User. | 42 /// \brief This is a pointer to the array of Uses for this User. |
43 /// | 43 /// |
44 unsigned NumOperands; | |
45 | |
46 /// OperandList - This is a pointer to the array of Uses for this User. | |
47 /// For nodes of fixed arity (e.g. a binary operator) this array will live | 44 /// For nodes of fixed arity (e.g. a binary operator) this array will live |
48 /// prefixed to some derived class instance. For nodes of resizable variable | 45 /// prefixed to some derived class instance. For nodes of resizable variable |
49 /// arity (e.g. PHINodes, SwitchInst etc.), this memory will be dynamically | 46 /// arity (e.g. PHINodes, SwitchInst etc.), this memory will be dynamically |
50 /// allocated and should be destroyed by the classes' virtual dtor. | 47 /// allocated and should be destroyed by the classes' virtual dtor. |
51 Use *OperandList; | 48 Use *OperandList; |
52 | 49 |
53 void *operator new(size_t s, unsigned Us); | 50 void *operator new(size_t s, unsigned Us); |
54 User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps) | 51 User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps) |
55 : Value(ty, vty), NumOperands(NumOps), OperandList(OpList) {} | 52 : Value(ty, vty), OperandList(OpList) { |
53 NumOperands = NumOps; | |
54 } | |
56 Use *allocHungoffUses(unsigned) const; | 55 Use *allocHungoffUses(unsigned) const; |
57 void dropHungoffUses() { | 56 void dropHungoffUses() { |
58 Use::zap(OperandList, OperandList + NumOperands, true); | 57 Use::zap(OperandList, OperandList + NumOperands, true); |
59 OperandList = nullptr; | 58 OperandList = nullptr; |
60 // Reset NumOperands so User::operator delete() does the right thing. | 59 // Reset NumOperands so User::operator delete() does the right thing. |
62 } | 61 } |
63 public: | 62 public: |
64 ~User() { | 63 ~User() { |
65 Use::zap(OperandList, OperandList + NumOperands); | 64 Use::zap(OperandList, OperandList + NumOperands); |
66 } | 65 } |
67 /// operator delete - free memory allocated for User and Use objects | 66 /// \brief Free memory allocated for User and Use objects. |
68 void operator delete(void *Usr); | 67 void operator delete(void *Usr); |
69 /// placement delete - required by std, but never called. | 68 /// \brief Placement delete - required by std, but never called. |
70 void operator delete(void*, unsigned) { | 69 void operator delete(void*, unsigned) { |
71 llvm_unreachable("Constructor throws?"); | 70 llvm_unreachable("Constructor throws?"); |
72 } | 71 } |
73 /// placement delete - required by std, but never called. | 72 /// \brief Placement delete - required by std, but never called. |
74 void operator delete(void*, unsigned, bool) { | 73 void operator delete(void*, unsigned, bool) { |
75 llvm_unreachable("Constructor throws?"); | 74 llvm_unreachable("Constructor throws?"); |
76 } | 75 } |
77 protected: | 76 protected: |
78 template <int Idx, typename U> static Use &OpFrom(const U *that) { | 77 template <int Idx, typename U> static Use &OpFrom(const U *that) { |
126 } | 125 } |
127 inline const_op_range operands() const { | 126 inline const_op_range operands() const { |
128 return const_op_range(op_begin(), op_end()); | 127 return const_op_range(op_begin(), op_end()); |
129 } | 128 } |
130 | 129 |
131 /// Convenience iterator for directly iterating over the Values in the | 130 /// \brief Iterator for directly iterating over the operand Values. |
132 /// OperandList | |
133 struct value_op_iterator | 131 struct value_op_iterator |
134 : iterator_adaptor_base<value_op_iterator, op_iterator, | 132 : iterator_adaptor_base<value_op_iterator, op_iterator, |
135 std::random_access_iterator_tag, Value *, | 133 std::random_access_iterator_tag, Value *, |
136 ptrdiff_t, Value *, Value *> { | 134 ptrdiff_t, Value *, Value *> { |
137 explicit value_op_iterator(Use *U = nullptr) : iterator_adaptor_base(U) {} | 135 explicit value_op_iterator(Use *U = nullptr) : iterator_adaptor_base(U) {} |
148 } | 146 } |
149 inline iterator_range<value_op_iterator> operand_values() { | 147 inline iterator_range<value_op_iterator> operand_values() { |
150 return iterator_range<value_op_iterator>(value_op_begin(), value_op_end()); | 148 return iterator_range<value_op_iterator>(value_op_begin(), value_op_end()); |
151 } | 149 } |
152 | 150 |
153 // dropAllReferences() - This function is in charge of "letting go" of all | 151 /// \brief Drop all references to operands. |
154 // objects that this User refers to. This allows one to | 152 /// |
155 // 'delete' a whole class at a time, even though there may be circular | 153 /// This function is in charge of "letting go" of all objects that this User |
156 // references... First all references are dropped, and all use counts go to | 154 /// refers to. This allows one to 'delete' a whole class at a time, even |
157 // zero. Then everything is deleted for real. Note that no operations are | 155 /// though there may be circular references... First all references are |
158 // valid on an object that has "dropped all references", except operator | 156 /// dropped, and all use counts go to zero. Then everything is deleted for |
159 // delete. | 157 /// real. Note that no operations are valid on an object that has "dropped |
160 // | 158 /// all references", except operator delete. |
161 void dropAllReferences() { | 159 void dropAllReferences() { |
162 for (Use &U : operands()) | 160 for (Use &U : operands()) |
163 U.set(nullptr); | 161 U.set(nullptr); |
164 } | 162 } |
165 | 163 |
166 /// replaceUsesOfWith - Replaces all references to the "From" definition with | 164 /// \brief Replace uses of one Value with another. |
167 /// references to the "To" definition. | |
168 /// | 165 /// |
166 /// Replaces all references to the "From" definition with references to the | |
167 /// "To" definition. | |
169 void replaceUsesOfWith(Value *From, Value *To); | 168 void replaceUsesOfWith(Value *From, Value *To); |
170 | 169 |
171 // Methods for support type inquiry through isa, cast, and dyn_cast: | 170 // Methods for support type inquiry through isa, cast, and dyn_cast: |
172 static inline bool classof(const Value *V) { | 171 static inline bool classof(const Value *V) { |
173 return isa<Instruction>(V) || isa<Constant>(V); | 172 return isa<Instruction>(V) || isa<Constant>(V); |