@@ -108,6 +108,28 @@ class OpState {
108
108
// / Return the operation that this refers to.
109
109
Operation *getOperation () { return state; }
110
110
111
+ // / Return the dialect that this refers to.
112
+ Dialect *getDialect () { return getOperation ()->getDialect (); }
113
+
114
+ // / Return the parent Region of this operation.
115
+ Region *getParentRegion () { return getOperation ()->getParentRegion (); }
116
+
117
+ // / Returns the closest surrounding operation that contains this operation
118
+ // / or nullptr if this is a top-level operation.
119
+ Operation *getParentOp () { return getOperation ()->getParentOp (); }
120
+
121
+ // / Return the closest surrounding parent operation that is of type 'OpTy'.
122
+ template <typename OpTy>
123
+ OpTy getParentOfType () {
124
+ return getOperation ()->getParentOfType <OpTy>();
125
+ }
126
+
127
+ // / Returns the closest surrounding parent operation with trait `Trait`.
128
+ template <template <typename T> class Trait >
129
+ Operation *getParentWithTrait () {
130
+ return getOperation ()->getParentWithTrait <Trait>();
131
+ }
132
+
111
133
// / Return the context this operation belongs to.
112
134
MLIRContext *getContext () { return getOperation ()->getContext (); }
113
135
@@ -134,6 +156,37 @@ class OpState {
134
156
using dialect_attr_iterator = Operation::dialect_attr_iterator;
135
157
using dialect_attr_range = Operation::dialect_attr_range;
136
158
159
+ // / Return a range corresponding to the dialect attributes for this operation.
160
+ dialect_attr_range getDialectAttrs () { return state->getDialectAttrs (); }
161
+ dialect_attr_iterator dialect_attr_begin () {
162
+ return state->dialect_attr_begin ();
163
+ }
164
+ dialect_attr_iterator dialect_attr_end () { return state->dialect_attr_end (); }
165
+
166
+ // / Return an attribute with the specified name.
167
+ Attribute getAttr (StringRef name) { return state->getAttr (name); }
168
+
169
+ // / If the operation has an attribute of the specified type, return it.
170
+ template <typename AttrClass>
171
+ AttrClass getAttrOfType (StringRef name) {
172
+ return getAttr (name).dyn_cast_or_null <AttrClass>();
173
+ }
174
+
175
+ // / If the an attribute exists with the specified name, change it to the new
176
+ // / value. Otherwise, add a new attribute with the specified name/value.
177
+ void setAttr (Identifier name, Attribute value) {
178
+ state->setAttr (name, value);
179
+ }
180
+ void setAttr (StringRef name, Attribute value) {
181
+ setAttr (Identifier::get (name, getContext ()), value);
182
+ }
183
+
184
+ // / Set the attributes held by this operation.
185
+ void setAttrs (ArrayRef<NamedAttribute> attributes) {
186
+ state->setAttrs (attributes);
187
+ }
188
+ void setAttrs (MutableDictionaryAttr newAttrs) { state->setAttrs (newAttrs); }
189
+
137
190
// / Set the dialect attributes for this operation, and preserve all dependent.
138
191
template <typename DialectAttrs> void setDialectAttrs (DialectAttrs &&attrs) {
139
192
state->setDialectAttrs (std::move (attrs));
0 commit comments