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

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Thu Oct 5 10:32:46 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{});
----------------
ftynse wrote:

Would something like the following work here?

```
if constexpr (std::is_same_v<
      typename llvm::function_traits<
          decltype(&OpTy::matchOperation)>::template arg_t<0>,
      Operation *>) {
  return op.matchOperation(nullptr, results, state);
} else {
  return op.matchOperation(nullopt, results, state);
}
```

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


More information about the Mlir-commits mailing list