LLVM: include/llvm/IR/OperandTraits.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_IR_OPERANDTRAITS_H
15#define LLVM_IR_OPERANDTRAITS_H
16
18
19namespace llvm {
20
21
22
23
24
25
26
27
28
29template <typename SubClass, unsigned ARITY>
32 static_assert(
33 !std::is_polymorphic::value,
34 "adding virtual methods to subclasses of User breaks use lists");
35 return reinterpret_cast<Use*>(U) - ARITY;
36 }
38 return reinterpret_cast<Use*>(U);
39 }
43};
44
45
46
47
48
49
50
51
52template <typename SubClass, unsigned ARITY = 1>
55 return U->getNumOperands();
56 }
57};
58
59
60
61
62
63
64
65
66
69 static_assert(
70 !std::is_polymorphic::value,
71 "adding virtual methods to subclasses of User breaks use lists");
73 }
75 return reinterpret_cast<Use*>(U);
76 }
78 return U->getNumOperands();
79 }
80};
81
82
83
84
85
86
87
88
89
90
91
92
95 return U->getHungOffOperands();
96 }
98 return U->getHungOffOperands() + U->getNumOperands();
99 }
101 return U->getNumOperands();
102 }
103};
104
105
106
107
108#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS) \
109 public: \
110 inline VALUECLASS *getOperand(unsigned) const; \
111 inline void setOperand(unsigned, VALUECLASS*); \
112 inline op_iterator op_begin(); \
113 inline const_op_iterator op_begin() const; \
114 inline op_iterator op_end(); \
115 inline const_op_iterator op_end() const; \
116 protected: \
117 template inline Use &Op(); \
118 template inline const Use &Op() const; \
119 public: \
120 inline unsigned getNumOperands() const
121
122
123#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
124CLASS::op_iterator CLASS::op_begin() { \
125 return OperandTraits::op_begin(this); \
126} \
127CLASS::const_op_iterator CLASS::op_begin() const { \
128 return OperandTraits::op_begin(const_cast<CLASS*>(this)); \
129} \
130CLASS::op_iterator CLASS::op_end() { \
131 return OperandTraits::op_end(this); \
132} \
133CLASS::const_op_iterator CLASS::op_end() const { \
134 return OperandTraits::op_end(const_cast<CLASS*>(this)); \
135} \
136VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \
137 assert(i_nocapture < OperandTraits::operands(this) \
138 && "getOperand() out of range!"); \
139 return cast_or_null( \
140 OperandTraits::op_begin(const_cast<CLASS*>(this))[i_nocapture].get()); \
141} \
142void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \
143 assert(i_nocapture < OperandTraits::operands(this) \
144 && "setOperand() out of range!"); \
145 OperandTraits::op_begin(this)[i_nocapture] = Val_nocapture; \
146} \
147unsigned CLASS::getNumOperands() const { \
148 return OperandTraits::operands(this); \
149} \
150template <int Idx_nocapture> Use &CLASS::Op() { \
151 return this->OpFrom<Idx_nocapture>(this); \
152} \
153template <int Idx_nocapture> const Use &CLASS::Op() const { \
154 return this->OpFrom<Idx_nocapture>(this); \
155}
156
157
158}
159
160#endif
A Use represents the edge between a Value definition and its users.
unsigned getNumOperands() const
This is an optimization pass for GlobalISel generic memory operations.
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition OperandTraits.h:30
static unsigned operands(const User *)
Definition OperandTraits.h:40
static Use * op_begin(SubClass *U)
Definition OperandTraits.h:31
static Use * op_end(SubClass *U)
Definition OperandTraits.h:37
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
Definition OperandTraits.h:93
static Use * op_end(User *U)
Definition OperandTraits.h:97
static Use * op_begin(User *U)
Definition OperandTraits.h:94
static unsigned operands(const User *U)
Definition OperandTraits.h:100
OptionalOperandTraits - when the number of operands may change at runtime.
Definition OperandTraits.h:53
static unsigned operands(const User *U)
Definition OperandTraits.h:54
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition OperandTraits.h:67
static Use * op_begin(SubClass *U)
Definition OperandTraits.h:68
static Use * op_end(SubClass *U)
Definition OperandTraits.h:74
static unsigned operands(const User *U)
Definition OperandTraits.h:77