Skip to content

Commit 0cf7e4b

Browse files
committed
Revert "[mlir] Remove methods from mlir::OpState that just forward to mlir::Operation."
This reverts commit 6f271e9. Differential Revision: https://reviews.llvm.org/D93242
1 parent 3b3eb7f commit 0cf7e4b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

mlir/include/mlir/IR/OpDefinition.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ class OpState {
108108
/// Return the operation that this refers to.
109109
Operation *getOperation() { return state; }
110110

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+
111133
/// Return the context this operation belongs to.
112134
MLIRContext *getContext() { return getOperation()->getContext(); }
113135

@@ -134,6 +156,37 @@ class OpState {
134156
using dialect_attr_iterator = Operation::dialect_attr_iterator;
135157
using dialect_attr_range = Operation::dialect_attr_range;
136158

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+
137190
/// Set the dialect attributes for this operation, and preserve all dependent.
138191
template <typename DialectAttrs> void setDialectAttrs(DialectAttrs &&attrs) {
139192
state->setDialectAttrs(std::move(attrs));

0 commit comments

Comments
 (0)