[Mlir-commits] [mlir] [mlir][Transform] Add a transform.match.operation_empty op to allow s… (PR #68319)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 5 08:09:37 PDT 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 18933c6d7e06d162c17b6ec08a5e7c508236265f e36eeea35d32a80cefeb196f42cad5e4aa335f9f -- mlir/include/mlir/Dialect/Transform/IR/MatchInterfaces.h mlir/lib/Dialect/Transform/IR/TransformOps.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/include/mlir/Dialect/Transform/IR/MatchInterfaces.h b/mlir/include/mlir/Dialect/Transform/IR/MatchInterfaces.h
index 2cf008a91..c9bad79a5 100644
--- a/mlir/include/mlir/Dialect/Transform/IR/MatchInterfaces.h
+++ b/mlir/include/mlir/Dialect/Transform/IR/MatchInterfaces.h
@@ -22,8 +22,9 @@ class MatchOpInterface;
namespace detail {
template <typename OpTy>
-DiagnosedSilenceableFailure matchOptionalOperationImpl(
- OpTy op, TransformResults &results, TransformState &state, std::false_type) {
+DiagnosedSilenceableFailure
+matchOptionalOperationImpl(OpTy op, TransformResults &results,
+ TransformState &state, std::false_type) {
return op.matchOperation(std::nullopt, results, state);
}
@@ -37,13 +38,13 @@ matchOptionalOperationImpl(OpTy op, TransformResults &results,
/// 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*>;
+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{});
}
} // namespace detail
@@ -62,7 +63,8 @@ class AtMostOneOpMatcherOpTrait
public:
static LogicalResult verifyTrait(Operation *op) {
static_assert(llvm::is_detected<has_get_operand_handle, OpTy>::value,
- "AtMostOneOpMatcherOpTrait/SingleOpMatcherOpTrait expects operation type to have the "
+ "AtMostOneOpMatcherOpTrait/SingleOpMatcherOpTrait expects "
+ "operation type to have the "
"getOperandHandle() method");
static_assert(llvm::is_detected<has_match_operation, OpTy>::value,
"AtMostOneOpMatcherOpTrait/SingleOpMatcherOpTrait expected "
@@ -71,13 +73,15 @@ public:
"TransformState &) method");
// This must be a dynamic assert because interface registration is dynamic.
- assert(isa<MatchOpInterface>(op) &&
- "AtMostOneOpMatcherOpTrait/SingleOpMatchOpTrait is only available on "
- "operations with "
- "MatchOpInterface");
+ assert(
+ isa<MatchOpInterface>(op) &&
+ "AtMostOneOpMatcherOpTrait/SingleOpMatchOpTrait is only available on "
+ "operations with "
+ "MatchOpInterface");
Value operandHandle = cast<OpTy>(op).getOperandHandle();
if (!isa<TransformHandleTypeInterface>(operandHandle.getType())) {
- return op->emitError() << "AtMostOneOpMatcherOpTrait/SingleOpMatchOpTrait requires the op handle "
+ return op->emitError() << "AtMostOneOpMatcherOpTrait/"
+ "SingleOpMatchOpTrait requires the op handle "
"to be of TransformHandleTypeInterface";
}
@@ -96,8 +100,8 @@ public:
"at most one payload op";
}
if (payload.empty()) {
- return detail::matchOptionalOperation(cast<OpTy>(this->getOperation()), results,
- state);
+ return detail::matchOptionalOperation(cast<OpTy>(this->getOperation()),
+ results, state);
}
return cast<OpTy>(this->getOperation())
.matchOperation(*payload.begin(), results, state);
@@ -111,10 +115,9 @@ public:
};
template <typename OpTy>
-class SingleOpMatcherOpTrait
- : public AtMostOneOpMatcherOpTrait<OpTy> {
+class SingleOpMatcherOpTrait : public AtMostOneOpMatcherOpTrait<OpTy> {
- public:
+public:
DiagnosedSilenceableFailure apply(TransformRewriter &rewriter,
TransformResults &results,
TransformState &state) {
@@ -131,47 +134,47 @@ class SingleOpMatcherOpTrait
};
template <typename OpTy>
- class SingleValueMatcherOpTrait
- : public OpTrait::TraitBase<OpTy, SingleValueMatcherOpTrait> {
- public:
- static LogicalResult verifyTrait(Operation *op) {
- // This must be a dynamic assert because interface registration is
- // dynamic.
- assert(isa<MatchOpInterface>(op) &&
- "SingleValueMatchOpTrait is only available on operations with "
- "MatchOpInterface");
-
- Value operandHandle = cast<OpTy>(op).getOperandHandle();
- if (!isa<TransformValueHandleTypeInterface>(operandHandle.getType())) {
- return op->emitError() << "SingleValueMatchOpTrait requires an operand "
- "of TransformValueHandleTypeInterface";
- }
-
- return success();
- }
+class SingleValueMatcherOpTrait
+ : public OpTrait::TraitBase<OpTy, SingleValueMatcherOpTrait> {
+public:
+ static LogicalResult verifyTrait(Operation *op) {
+ // This must be a dynamic assert because interface registration is
+ // dynamic.
+ assert(isa<MatchOpInterface>(op) &&
+ "SingleValueMatchOpTrait is only available on operations with "
+ "MatchOpInterface");
- DiagnosedSilenceableFailure apply(TransformRewriter &rewriter,
- TransformResults &results,
- TransformState &state) {
- Value operandHandle = cast<OpTy>(this->getOperation()).getOperandHandle();
- auto payload = state.getPayloadValues(operandHandle);
- if (!llvm::hasSingleElement(payload)) {
- return emitDefiniteFailure(this->getOperation()->getLoc())
- << "SingleValueMatchOpTrait requires the value handle to point "
- "to "
- "a single payload value";
- }
-
- return cast<OpTy>(this->getOperation())
- .matchValue(*payload.begin(), results, state);
+ Value operandHandle = cast<OpTy>(op).getOperandHandle();
+ if (!isa<TransformValueHandleTypeInterface>(operandHandle.getType())) {
+ return op->emitError() << "SingleValueMatchOpTrait requires an operand "
+ "of TransformValueHandleTypeInterface";
}
- void getEffects(SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {
- onlyReadsHandle(this->getOperation()->getOperands(), effects);
- producesHandle(this->getOperation()->getResults(), effects);
- onlyReadsPayload(effects);
+ return success();
+ }
+
+ DiagnosedSilenceableFailure apply(TransformRewriter &rewriter,
+ TransformResults &results,
+ TransformState &state) {
+ Value operandHandle = cast<OpTy>(this->getOperation()).getOperandHandle();
+ auto payload = state.getPayloadValues(operandHandle);
+ if (!llvm::hasSingleElement(payload)) {
+ return emitDefiniteFailure(this->getOperation()->getLoc())
+ << "SingleValueMatchOpTrait requires the value handle to point "
+ "to "
+ "a single payload value";
}
- };
+
+ return cast<OpTy>(this->getOperation())
+ .matchValue(*payload.begin(), results, state);
+ }
+
+ void getEffects(SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {
+ onlyReadsHandle(this->getOperation()->getOperands(), effects);
+ producesHandle(this->getOperation()->getResults(), effects);
+ onlyReadsPayload(effects);
+ }
+};
} // namespace transform
} // namespace mlir
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 2dff1bf3d..aa1048415 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -1555,7 +1555,7 @@ transform::IncludeOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
//===----------------------------------------------------------------------===//
DiagnosedSilenceableFailure transform::MatchOperationEmptyOp::matchOperation(
- ::std::optional<::mlir::Operation *> maybeCurrent,
+ ::std::optional<::mlir::Operation *> maybeCurrent,
transform::TransformResults &results, transform::TransformState &state) {
if (!maybeCurrent.has_value()) {
DBGS_MATCHER() << "MatchOperationEmptyOp success\n";
``````````
</details>
https://github.com/llvm/llvm-project/pull/68319
More information about the Mlir-commits
mailing list