[llvm-branch-commits] [mlir] 0cf7e4b - Revert "[mlir] Remove methods from mlir::OpState that just forward to mlir::Operation."
Christian Sigg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 14 13:52:14 PST 2020
Author: Christian Sigg
Date: 2020-12-14T22:47:17+01:00
New Revision: 0cf7e4b252fe1458fddb8e3dbfcae43450e9c04c
URL: https://github.com/llvm/llvm-project/commit/0cf7e4b252fe1458fddb8e3dbfcae43450e9c04c
DIFF: https://github.com/llvm/llvm-project/commit/0cf7e4b252fe1458fddb8e3dbfcae43450e9c04c.diff
LOG: Revert "[mlir] Remove methods from mlir::OpState that just forward to mlir::Operation."
This reverts commit 6f271e921ba48f4c4fa54bbd2c7a4c548ca5e59e.
Differential Revision: https://reviews.llvm.org/D93242
Added:
Modified:
mlir/include/mlir/IR/OpDefinition.h
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 2edc48dd099e..9e4da63c3618 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -108,6 +108,28 @@ class OpState {
/// 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(); }
@@ -134,6 +156,37 @@ class OpState {
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));
More information about the llvm-branch-commits
mailing list