CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
85 lines
3.2 KiB
C++
85 lines
3.2 KiB
C++
//===- IRDLExtensionOps.cpp - IRDL extension for the Transform dialect ----===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/Transform/IRDLExtension/IRDLExtensionOps.h"
|
|
#include "mlir/Dialect/IRDL/IR/IRDL.h"
|
|
#include "mlir/Dialect/IRDL/IRDLVerifiers.h"
|
|
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
|
|
#include "mlir/IR/Diagnostics.h"
|
|
#include "mlir/IR/ExtensibleDialect.h"
|
|
#include "mlir/Interfaces/SideEffectInterfaces.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
using namespace mlir;
|
|
|
|
#define GET_OP_CLASSES
|
|
#include "mlir/Dialect/Transform/IRDLExtension/IRDLExtensionOps.cpp.inc"
|
|
|
|
namespace mlir::transform {
|
|
|
|
DiagnosedSilenceableFailure
|
|
IRDLCollectMatchingOp::apply(TransformRewriter &rewriter,
|
|
TransformResults &results, TransformState &state) {
|
|
auto dialect = cast<irdl::DialectOp>(getBody().front().front());
|
|
Block &body = dialect.getBody().front();
|
|
irdl::OperationOp operation = *body.getOps<irdl::OperationOp>().begin();
|
|
auto verifier = irdl::createVerifier(
|
|
operation,
|
|
DenseMap<irdl::TypeOp, std::unique_ptr<DynamicTypeDefinition>>(),
|
|
DenseMap<irdl::AttributeOp, std::unique_ptr<DynamicAttrDefinition>>());
|
|
|
|
auto handlerID = getContext()->getDiagEngine().registerHandler(
|
|
[](Diagnostic &) { return success(); });
|
|
SmallVector<Operation *> matched;
|
|
for (Operation *payload : state.getPayloadOps(getRoot())) {
|
|
payload->walk([&](Operation *target) {
|
|
if (succeeded(verifier(target))) {
|
|
matched.push_back(target);
|
|
}
|
|
});
|
|
}
|
|
getContext()->getDiagEngine().eraseHandler(handlerID);
|
|
results.set(cast<OpResult>(getMatched()), matched);
|
|
return DiagnosedSilenceableFailure::success();
|
|
}
|
|
|
|
void IRDLCollectMatchingOp::getEffects(
|
|
SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {
|
|
onlyReadsHandle(getRootMutable(), effects);
|
|
producesHandle(getOperation()->getOpResults(), effects);
|
|
onlyReadsPayload(effects);
|
|
}
|
|
|
|
LogicalResult IRDLCollectMatchingOp::verify() {
|
|
Block &bodyBlock = getBody().front();
|
|
if (!llvm::hasSingleElement(bodyBlock))
|
|
return emitOpError() << "expects a single operation in the body";
|
|
|
|
auto dialect = dyn_cast<irdl::DialectOp>(bodyBlock.front());
|
|
if (!dialect) {
|
|
return emitOpError() << "expects the body operation to be "
|
|
<< irdl::DialectOp::getOperationName();
|
|
}
|
|
|
|
// TODO: relax this by taking a symbol name of the operation to match, note
|
|
// that symbol name is also the name of the operation and we may want to
|
|
// divert from that to have constraints on-the-fly using IRDL.
|
|
auto irdlOperations = dialect.getOps<irdl::OperationOp>();
|
|
if (!llvm::hasSingleElement(irdlOperations))
|
|
return emitOpError() << "expects IRDL to contain exactly one operation";
|
|
|
|
if (!dialect.getOps<irdl::TypeOp>().empty() ||
|
|
!dialect.getOps<irdl::AttributeOp>().empty()) {
|
|
return emitOpError() << "IRDL types and attributes are not yet supported";
|
|
}
|
|
|
|
return success();
|
|
}
|
|
|
|
} // namespace mlir::transform
|