/// Return the operation that this refers to.
Operation *getOperation() { return state; }
+ /// Return the dialect that this refers to.
+ Dialect *getDialect() { return getOperation()->getDialect(); }
+
+ /// Return the parent Region of this operation.
+ Region *getParentRegion() { return getOperation()->getParentRegion(); }
+
+ /// Returns the closest surrounding operation that contains this operation
+ /// or nullptr if this is a top-level operation.
+ Operation *getParentOp() { return getOperation()->getParentOp(); }
+
+ /// Return the closest surrounding parent operation that is of type 'OpTy'.
+ template <typename OpTy>
+ OpTy getParentOfType() {
+ return getOperation()->getParentOfType<OpTy>();
+ }
+
+ /// Returns the closest surrounding parent operation with trait `Trait`.
+ template <template <typename T> class Trait>
+ Operation *getParentWithTrait() {
+ return getOperation()->getParentWithTrait<Trait>();
+ }
+
/// Return the context this operation belongs to.
MLIRContext *getContext() { return getOperation()->getContext(); }
using dialect_attr_iterator = Operation::dialect_attr_iterator;
using dialect_attr_range = Operation::dialect_attr_range;
+ /// Return a range corresponding to the dialect attributes for this operation.
+ dialect_attr_range getDialectAttrs() { return state->getDialectAttrs(); }
+ dialect_attr_iterator dialect_attr_begin() {
+ return state->dialect_attr_begin();
+ }
+ dialect_attr_iterator dialect_attr_end() { return state->dialect_attr_end(); }
+
+ /// Return an attribute with the specified name.
+ Attribute getAttr(StringRef name) { return state->getAttr(name); }
+
+ /// If the operation has an attribute of the specified type, return it.
+ template <typename AttrClass>
+ AttrClass getAttrOfType(StringRef name) {
+ return getAttr(name).dyn_cast_or_null<AttrClass>();
+ }
+
+ /// If the an attribute exists with the specified name, change it to the new
+ /// value. Otherwise, add a new attribute with the specified name/value.
+ void setAttr(Identifier name, Attribute value) {
+ state->setAttr(name, value);
+ }
+ void setAttr(StringRef name, Attribute value) {
+ setAttr(Identifier::get(name, getContext()), value);
+ }
+
+ /// Set the attributes held by this operation.
+ void setAttrs(ArrayRef<NamedAttribute> attributes) {
+ state->setAttrs(attributes);
+ }
+ void setAttrs(MutableDictionaryAttr newAttrs) { state->setAttrs(newAttrs); }
+
/// Set the dialect attributes for this operation, and preserve all dependent.
template <typename DialectAttrs> void setDialectAttrs(DialectAttrs &&attrs) {
state->setDialectAttrs(std::move(attrs));