Files
TheRock/compiler/amd-llvm/mlir/test/lib/Pass/TestDynamicPipeline.cpp
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

117 lines
3.9 KiB
C++

//===------ TestDynamicPipeline.cpp --- dynamic pipeline test pass --------===//
//
// 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 implements a pass to test the dynamic pipeline feature.
//
//===----------------------------------------------------------------------===//
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
using namespace mlir;
namespace {
class TestDynamicPipelinePass
: public PassWrapper<TestDynamicPipelinePass, OperationPass<>> {
public:
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDynamicPipelinePass)
StringRef getArgument() const final { return "test-dynamic-pipeline"; }
StringRef getDescription() const final {
return "Tests the dynamic pipeline feature by applying "
"a pipeline on a selected set of functions";
}
void getDependentDialects(DialectRegistry &registry) const override {
OpPassManager pm(ModuleOp::getOperationName(),
OpPassManager::Nesting::Implicit);
(void)parsePassPipeline(pipeline, pm, llvm::errs());
pm.getDependentDialects(registry);
}
TestDynamicPipelinePass() = default;
TestDynamicPipelinePass(const TestDynamicPipelinePass &) {}
void runOnOperation() override {
Operation *currentOp = getOperation();
llvm::errs() << "Dynamic execute '" << pipeline << "' on "
<< currentOp->getName() << "\n";
if (pipeline.empty()) {
llvm::errs() << "Empty pipeline\n";
return;
}
auto symbolOp = dyn_cast<SymbolOpInterface>(currentOp);
if (!symbolOp) {
currentOp->emitWarning()
<< "Ignoring because not implementing SymbolOpInterface\n";
return;
}
auto opName = symbolOp.getName();
if (!opNames.empty() && !llvm::is_contained(opNames, opName)) {
llvm::errs() << "dynamic-pipeline skip op name: " << opName << "\n";
return;
}
OpPassManager pm(currentOp->getName().getIdentifier(),
OpPassManager::Nesting::Implicit);
(void)parsePassPipeline(pipeline, pm, llvm::errs());
// Check that running on the parent operation always immediately fails.
if (runOnParent) {
if (currentOp->getParentOp())
if (!failed(runPipeline(pm, currentOp->getParentOp())))
signalPassFailure();
return;
}
if (runOnNestedOp) {
llvm::errs() << "Run on nested op\n";
currentOp->walk([&](Operation *op) {
if (op == currentOp || !op->hasTrait<OpTrait::IsIsolatedFromAbove>() ||
op->getName() != currentOp->getName())
return;
llvm::errs() << "Run on " << *op << "\n";
// Run on the current operation
if (failed(runPipeline(pm, op)))
signalPassFailure();
});
} else {
// Run on the current operation
if (failed(runPipeline(pm, currentOp)))
signalPassFailure();
}
}
Option<bool> runOnNestedOp{
*this, "run-on-nested-operations",
llvm::cl::desc("This will apply the pipeline on nested operations under "
"the visited operation.")};
Option<bool> runOnParent{
*this, "run-on-parent",
llvm::cl::desc("This will apply the pipeline on the parent operation if "
"it exist, this is expected to fail.")};
Option<std::string> pipeline{
*this, "dynamic-pipeline",
llvm::cl::desc("The pipeline description that "
"will run on the filtered function.")};
ListOption<std::string> opNames{
*this, "op-name",
llvm::cl::desc("List of function name to apply the pipeline to")};
};
} // namespace
namespace mlir {
namespace test {
void registerTestDynamicPipelinePass() {
PassRegistration<TestDynamicPipelinePass>();
}
} // namespace test
} // namespace mlir