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
102 lines
3.6 KiB
C++
102 lines
3.6 KiB
C++
//===- TestPassStateExtensionCommunication.cpp ----------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines a test pass that showcases how communication can be
|
|
// conducted between a regular mlir pass and transform ops through the
|
|
// transform state extension stateInitializer and stateExporter mechanism.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "TestTransformStateExtension.h"
|
|
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
|
|
#include "mlir/IR/BuiltinOps.h"
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
using namespace llvm;
|
|
using namespace mlir;
|
|
using namespace mlir::test;
|
|
|
|
namespace {
|
|
template <typename Derived>
|
|
class OpPassWrapper : public PassWrapper<Derived, OperationPass<>> {};
|
|
|
|
struct TestPassStateExtensionCommunication
|
|
: public PassWrapper<TestPassStateExtensionCommunication,
|
|
OperationPass<ModuleOp>> {
|
|
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
|
|
TestPassStateExtensionCommunication)
|
|
|
|
StringRef getArgument() const final {
|
|
return "test-pass-state-extension-communication";
|
|
}
|
|
|
|
StringRef getDescription() const final {
|
|
return "test state communciation between a mlir pass and transform ops";
|
|
}
|
|
|
|
static void printVector(const SmallVector<std::string> &opCollection,
|
|
const std::string &extraMessage = {}) {
|
|
outs() << "Printing opCollection" << extraMessage
|
|
<< ", size: " << opCollection.size() << "\n";
|
|
for (const auto &subVector : opCollection) {
|
|
outs() << subVector << " ";
|
|
}
|
|
outs() << "\n";
|
|
}
|
|
|
|
void runOnOperation() override {
|
|
ModuleOp module = getOperation();
|
|
|
|
// Create an opCollection vector.
|
|
SmallVector<std::string> opCollection = {"PASS-TRANSFORMOP-PASS "};
|
|
printVector(opCollection, " before processing transform ops");
|
|
|
|
auto stateInitializer =
|
|
[&opCollection](mlir::transform::TransformState &state) -> void {
|
|
TransformStateInitializerExtension *ext =
|
|
state.getExtension<TransformStateInitializerExtension>();
|
|
if (!ext)
|
|
state.addExtension<TransformStateInitializerExtension>(0, opCollection);
|
|
};
|
|
|
|
auto stateExporter =
|
|
[&opCollection](
|
|
mlir::transform::TransformState &state) -> LogicalResult {
|
|
TransformStateInitializerExtension *ext =
|
|
state.getExtension<TransformStateInitializerExtension>();
|
|
if (!ext) {
|
|
errs() << "Target transform state extension not found!\n";
|
|
return failure();
|
|
}
|
|
opCollection.clear();
|
|
opCollection = ext->getRegisteredOps();
|
|
return success();
|
|
};
|
|
|
|
// Process transform ops with stateInitializer and stateExporter.
|
|
for (auto op : module.getBody()->getOps<transform::TransformOpInterface>())
|
|
if (failed(transform::applyTransforms(
|
|
module, op, {}, mlir::transform::TransformOptions(), false,
|
|
stateInitializer, stateExporter)))
|
|
return signalPassFailure();
|
|
|
|
// Print the opCollection vector after processing transform ops.
|
|
printVector(opCollection, " after processing transform ops");
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
namespace mlir {
|
|
namespace test {
|
|
/// Registers the test pass here.
|
|
void registerTestPassStateExtensionCommunication() {
|
|
PassRegistration<TestPassStateExtensionCommunication> reg;
|
|
}
|
|
} // namespace test
|
|
} // namespace mlir
|