From bc22b5c9a2f729460ffdf7627b3534a8d9f3f767 Mon Sep 17 00:00:00 2001 From: bzcheeseman <12992886+bzcheeseman@users.noreply.github.com> Date: Wed, 11 May 2022 15:25:04 -0400 Subject: [PATCH] [MLIR][Operation] Simplify Operation casting, NFC We can simplify the code needed to implement dyn_cast/cast/isa support for MLIR operations with documented interfaces via the CastInfo structures. This will also provide an example of how to use CastInfo. Depends on D123901 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D124963 --- mlir/include/mlir/IR/Operation.h | 58 +++++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index 4594cb6b219b..86b5a94cb211 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -172,7 +172,8 @@ public: Operation *getParentOp() { return block ? block->getParentOp() : nullptr; } /// Return the closest surrounding parent operation that is of type 'OpTy'. - template OpTy getParentOfType() { + template + OpTy getParentOfType() { auto *op = this; while ((op = op->getParentOp())) if (auto parentOp = dyn_cast(op)) @@ -521,14 +522,16 @@ public: /// Returns true if the operation was registered with a particular trait, e.g. /// hasTrait(). - template