[Mlir-commits] [mlir] [mlir][Transform] Add a transform.match.operation_empty op to allow s… (PR #68319)

Nicolas Vasilache llvmlistbot at llvm.org
Fri Oct 6 00:11:06 PDT 2023


================
@@ -11,14 +11,46 @@
 
 #include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
 #include "mlir/IR/OpDefinition.h"
+#include "llvm/ADT/STLExtras.h"
+#include <optional>
+#include <type_traits>
 
 namespace mlir {
 namespace transform {
 class MatchOpInterface;
 
+namespace detail {
 template <typename OpTy>
-class SingleOpMatcherOpTrait
-    : public OpTrait::TraitBase<OpTy, SingleOpMatcherOpTrait> {
+DiagnosedSilenceableFailure
+matchOptionalOperationImpl(OpTy op, TransformResults &results,
+                           TransformState &state, std::false_type) {
+  return op.matchOperation(std::nullopt, results, state);
+}
+
+template <typename OpTy>
+DiagnosedSilenceableFailure
+matchOptionalOperationImpl(OpTy op, TransformResults &results,
+                           TransformState &state, std::true_type) {
+  return op.matchOperation(nullptr, results, state);
+}
+
+/// Dispatch `matchOperation` based on Operation* or std::optional<Operation*>
+/// first operand.
+template <typename OpTy, typename... Args>
+DiagnosedSilenceableFailure matchOptionalOperation(OpTy op,
+                                                   TransformResults &results,
+                                                   TransformState &state) {
+  using uses_operation_ptr_t = typename std::is_same<
+      typename llvm::function_traits<
+          decltype(&OpTy::matchOperation)>::template arg_t<0>,
+      Operation *>;
+  return matchOptionalOperationImpl(op, results, state, uses_operation_ptr_t{});
----------------
nicolasvasilache wrote:

`if constexpr``, fancy :) I always forget about this feature and end up with chasing the right incantations to get sfinae working every 6 months or so.. thanks!

https://github.com/llvm/llvm-project/pull/68319


More information about the Mlir-commits mailing list