diff --git a/mlir/include/mlir/IR/FunctionInterfaces.h b/mlir/include/mlir/IR/FunctionInterfaces.h --- a/mlir/include/mlir/IR/FunctionInterfaces.h +++ b/mlir/include/mlir/IR/FunctionInterfaces.h @@ -16,6 +16,7 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/OpDefinition.h" +#include "mlir/IR/SymbolTable.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/SmallString.h" diff --git a/mlir/include/mlir/IR/FunctionInterfaces.td b/mlir/include/mlir/IR/FunctionInterfaces.td --- a/mlir/include/mlir/IR/FunctionInterfaces.td +++ b/mlir/include/mlir/IR/FunctionInterfaces.td @@ -100,6 +100,14 @@ "::mlir::LogicalResult", "verifyType">, ]; + let extraClassDeclaration = [{ + //===------------------------------------------------------------------===// + // Name + //===------------------------------------------------------------------===// + + /// Return the name of the function. + StringRef getName() { return SymbolTable::getSymbolName(*this); } + }]; let extraSharedClassDeclaration = [{ /// Block list iterator types. using BlockListType = Region::BlockListType; diff --git a/mlir/test/Analysis/test-dominance.mlir b/mlir/test/Analysis/test-dominance.mlir --- a/mlir/test/Analysis/test-dominance.mlir +++ b/mlir/test/Analysis/test-dominance.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -test-print-dominance -split-input-file 2>&1 | FileCheck %s +// RUN: mlir-opt %s -pass-pipeline="builtin.func(test-print-dominance)" -split-input-file 2>&1 | FileCheck %s // CHECK-LABEL: Testing : func_condBranch func @func_condBranch(%cond : i1) { diff --git a/mlir/test/Analysis/test-liveness.mlir b/mlir/test/Analysis/test-liveness.mlir --- a/mlir/test/Analysis/test-liveness.mlir +++ b/mlir/test/Analysis/test-liveness.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -test-print-liveness -split-input-file 2>&1 | FileCheck %s +// RUN: mlir-opt %s -pass-pipeline="builtin.func(test-print-liveness)" -split-input-file 2>&1 | FileCheck %s // CHECK-LABEL: Testing : func_empty func @func_empty() { diff --git a/mlir/test/Analysis/test-match-reduction.mlir b/mlir/test/Analysis/test-match-reduction.mlir --- a/mlir/test/Analysis/test-match-reduction.mlir +++ b/mlir/test/Analysis/test-match-reduction.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -test-match-reduction -verify-diagnostics -split-input-file +// RUN: mlir-opt %s -pass-pipeline="builtin.func(test-match-reduction)" -verify-diagnostics -split-input-file // Verify that the generic reduction detection utility works on different // dialects. diff --git a/mlir/test/Analysis/test-topoligical-sort.mlir b/mlir/test/Analysis/test-topoligical-sort.mlir --- a/mlir/test/Analysis/test-topoligical-sort.mlir +++ b/mlir/test/Analysis/test-topoligical-sort.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -test-print-topological-sort 2>&1 | FileCheck %s +// RUN: mlir-opt %s -pass-pipeline="builtin.func(test-print-topological-sort)" 2>&1 | FileCheck %s // CHECK-LABEL: Testing : region // CHECK: arith.addi {{.*}} : index diff --git a/mlir/test/Dialect/Affine/loop-unswitch.mlir b/mlir/test/Dialect/Affine/loop-unswitch.mlir --- a/mlir/test/Dialect/Affine/loop-unswitch.mlir +++ b/mlir/test/Dialect/Affine/loop-unswitch.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -split-input-file -test-affine-loop-unswitch | FileCheck %s +// RUN: mlir-opt %s -split-input-file -pass-pipeline="builtin.func(test-affine-loop-unswitch)" | FileCheck %s // CHECK-DAG: #[[$SET:.*]] = affine_set<(d0) : (d0 - 2 >= 0)> diff --git a/mlir/test/Dialect/Affine/memref-stride-calculation.mlir b/mlir/test/Dialect/Affine/memref-stride-calculation.mlir --- a/mlir/test/Dialect/Affine/memref-stride-calculation.mlir +++ b/mlir/test/Dialect/Affine/memref-stride-calculation.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -test-memref-stride-calculation -o /dev/null | FileCheck %s +// RUN: mlir-opt %s -pass-pipeline="builtin.func(test-memref-stride-calculation)" -o /dev/null | FileCheck %s func @f(%0: index) { // CHECK-LABEL: Testing: f diff --git a/mlir/test/IR/diagnostic-handler-filter.mlir b/mlir/test/IR/diagnostic-handler-filter.mlir --- a/mlir/test/IR/diagnostic-handler-filter.mlir +++ b/mlir/test/IR/diagnostic-handler-filter.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -test-diagnostic-filter='filters=mysource1' -split-input-file -o - 2>&1 | FileCheck %s +// RUN: mlir-opt %s -pass-pipeline="builtin.func(test-diagnostic-filter{filters=mysource1})" -split-input-file -o - 2>&1 | FileCheck %s // This test verifies that diagnostic handler can emit the call stack successfully. // CHECK-LABEL: Test 'test1' diff --git a/mlir/test/IR/test-matchers.mlir b/mlir/test/IR/test-matchers.mlir --- a/mlir/test/IR/test-matchers.mlir +++ b/mlir/test/IR/test-matchers.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt %s -mlir-disable-threading=true -test-matchers -o /dev/null 2>&1 | FileCheck %s +// RUN: mlir-opt %s -mlir-disable-threading=true -pass-pipeline="builtin.func(test-matchers)" -o /dev/null 2>&1 | FileCheck %s func @test1(%a: f32, %b: f32, %c: f32) { %0 = arith.addf %a, %b: f32 diff --git a/mlir/test/Transforms/parametric-mapping.mlir b/mlir/test/Transforms/parametric-mapping.mlir --- a/mlir/test/Transforms/parametric-mapping.mlir +++ b/mlir/test/Transforms/parametric-mapping.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt -allow-unregistered-dialect -test-mapping-to-processing-elements %s | FileCheck %s +// RUN: mlir-opt -allow-unregistered-dialect -pass-pipeline="builtin.func(test-mapping-to-processing-elements)" %s | FileCheck %s // CHECK: #[[mul_map:.+]] = affine_map<()[s0, s1] -> (s0 * s1)> // CHECK: #[[add_map:.+]] = affine_map<()[s0, s1] -> (s0 + s1)> diff --git a/mlir/test/lib/Analysis/TestLiveness.cpp b/mlir/test/lib/Analysis/TestLiveness.cpp --- a/mlir/test/lib/Analysis/TestLiveness.cpp +++ b/mlir/test/lib/Analysis/TestLiveness.cpp @@ -1,5 +1,4 @@ -//===- TestLiveness.cpp - Test liveness construction and information -//-------===// +//===- TestLiveness.cpp - Test liveness construction and information ------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -20,7 +19,7 @@ namespace { struct TestLivenessPass - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-print-liveness"; } StringRef getDescription() const final { return "Print the contents of a constructed liveness information."; diff --git a/mlir/test/lib/Analysis/TestMatchReduction.cpp b/mlir/test/lib/Analysis/TestMatchReduction.cpp --- a/mlir/test/lib/Analysis/TestMatchReduction.cpp +++ b/mlir/test/lib/Analysis/TestMatchReduction.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Analysis/SliceAnalysis.h" +#include "mlir/IR/FunctionInterfaces.h" #include "mlir/Pass/Pass.h" using namespace mlir; @@ -34,18 +35,19 @@ } struct TestMatchReductionPass - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-match-reduction"; } StringRef getDescription() const final { return "Test the match reduction utility."; } void runOnOperation() override { - FuncOp func = getOperation(); + FunctionOpInterface func = getOperation(); func->emitRemark("Testing function"); func.walk([](Operation *op) { - if (isa(op)) + if (isa(op)) return; // Limit testing to ops with only one region. diff --git a/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp b/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp --- a/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp +++ b/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp @@ -28,10 +28,10 @@ /// Checks for out of bound memref access subscripts.. struct TestMemRefBoundCheck - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-memref-bound-check"; } StringRef getDescription() const final { - return "Check memref access bounds in a Function"; + return "Check memref access bounds"; } void runOnOperation() override; }; @@ -39,7 +39,7 @@ } // namespace void TestMemRefBoundCheck::runOnOperation() { - getOperation().walk([](Operation *opInst) { + getOperation()->walk([](Operation *opInst) { TypeSwitch(opInst) .Case( [](auto op) { (void)boundCheckLoadOrStoreOp(op); }); diff --git a/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp b/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp --- a/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp +++ b/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp @@ -27,7 +27,7 @@ // TODO: Add common surrounding loop depth-wise dependence checks. /// Checks dependences between all pairs of memref accesses in a Function. struct TestMemRefDependenceCheck - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-memref-dependence-check"; } StringRef getDescription() const final { return "Checks dependences between all pairs of memref accesses."; @@ -100,12 +100,12 @@ } } -// Walks the Function 'f' adding load and store ops to 'loadsAndStores'. -// Runs pair-wise dependence checks. +/// Walks the operation adding load and store ops to 'loadsAndStores'. Runs +/// pair-wise dependence checks. void TestMemRefDependenceCheck::runOnOperation() { // Collect the loads and stores within the function. loadsAndStores.clear(); - getOperation().walk([&](Operation *op) { + getOperation()->walk([&](Operation *op) { if (isa(op)) loadsAndStores.push_back(op); }); diff --git a/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp b/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp --- a/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp +++ b/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp @@ -14,7 +14,8 @@ namespace { struct TestMemRefStrideCalculation - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-memref-stride-calculation"; } diff --git a/mlir/test/lib/Analysis/TestSlice.cpp b/mlir/test/lib/Analysis/TestSlice.cpp --- a/mlir/test/lib/Analysis/TestSlice.cpp +++ b/mlir/test/lib/Analysis/TestSlice.cpp @@ -16,7 +16,8 @@ namespace { struct TestTopologicalSortPass - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-print-topological-sort"; } StringRef getDescription() const final { return "Print operations in topological order"; diff --git a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp --- a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp +++ b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp @@ -14,6 +14,7 @@ #include "mlir/Dialect/Affine/Analysis/Utils.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/LoopUtils.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Pass/Pass.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" diff --git a/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp b/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp --- a/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp +++ b/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp @@ -24,7 +24,7 @@ /// This pass applies the permutation on the first maximal perfect nest. struct TestAffineLoopUnswitching - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return PASS_NAME; } StringRef getDescription() const final { return "Tests affine loop unswitching / if/else hoisting"; @@ -44,14 +44,14 @@ // Each hoisting invalidates a lot of IR around. Just stop the walk after the // first if/else hoisting, and repeat until no more hoisting can be done, or // the maximum number of iterations have been run. - auto func = getOperation(); + Operation *op = getOperation(); unsigned i = 0; do { auto walkFn = [](AffineIfOp op) { return succeeded(hoistAffineIfOp(op)) ? WalkResult::interrupt() : WalkResult::advance(); }; - if (func.walk(walkFn).wasInterrupted()) + if (op->walk(walkFn).wasInterrupted()) break; } while (++i < kMaxIterations); } diff --git a/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp b/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp --- a/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp +++ b/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp @@ -23,7 +23,7 @@ namespace { class TestLoopMappingPass - : public PassWrapper> { + : public PassWrapper> { public: StringRef getArgument() const final { return "test-mapping-to-processing-elements"; @@ -38,20 +38,18 @@ } void runOnOperation() override { - FuncOp func = getOperation(); - // SSA values for the transformation are created out of thin air by // unregistered "new_processor_id_and_range" operations. This is enough to // emulate mapping conditions. SmallVector processorIds, numProcessors; - func.walk([&processorIds, &numProcessors](Operation *op) { + getOperation()->walk([&processorIds, &numProcessors](Operation *op) { if (op->getName().getStringRef() != "new_processor_id_and_range") return; processorIds.push_back(op->getResult(0)); numProcessors.push_back(op->getResult(1)); }); - func.walk([&processorIds, &numProcessors](scf::ForOp op) { + getOperation()->walk([&processorIds, &numProcessors](scf::ForOp op) { // Ignore nested loops. if (op->getParentRegion()->getParentOfType()) return; diff --git a/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp b/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp --- a/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp +++ b/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp @@ -19,13 +19,11 @@ using namespace mlir; -static llvm::cl::OptionCategory clOptionsCategory(PASS_NAME " options"); - namespace { /// This pass applies the permutation on the first maximal perfect nest. struct TestLoopPermutation - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return PASS_NAME; } StringRef getDescription() const final { return "Tests affine loop permutation utility"; @@ -50,7 +48,7 @@ SmallVector permMap(permList.begin(), permList.end()); SmallVector forOps; - getOperation().walk([&](AffineForOp forOp) { forOps.push_back(forOp); }); + getOperation()->walk([&](AffineForOp forOp) { forOps.push_back(forOp); }); for (auto forOp : forOps) { SmallVector nest; diff --git a/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp b/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp --- a/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp +++ b/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp @@ -21,7 +21,7 @@ /// a greedy mapping strategy. class TestGpuGreedyParallelLoopMappingPass : public PassWrapper> { + OperationPass<>> { StringRef getArgument() const final { return "test-gpu-greedy-parallel-loop-mapping"; } @@ -29,8 +29,7 @@ return "Greedily maps all parallel loops to gpu hardware ids."; } void runOnOperation() override { - Operation *op = getOperation(); - for (Region ®ion : op->getRegions()) + for (Region ®ion : getOperation()->getRegions()) greedilyMapParallelSCFToGPU(region); } }; diff --git a/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp b/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp --- a/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp +++ b/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp @@ -20,7 +20,7 @@ namespace { struct TestPadFusionPass - : public PassWrapper> { + : public PassWrapper> { void getDependentDialects(DialectRegistry ®istry) const override { registry @@ -32,11 +32,10 @@ void runOnOperation() override { MLIRContext *context = &getContext(); - FuncOp funcOp = getOperation(); RewritePatternSet patterns(context); linalg::populateFuseTensorPadWithProducerLinalgOpPatterns(patterns); - if (failed(applyPatternsAndFoldGreedily(funcOp.getBody(), - std::move(patterns)))) + if (failed( + applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)))) return signalPassFailure(); } }; diff --git a/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp b/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp --- a/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp +++ b/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp @@ -20,8 +20,7 @@ namespace { struct TestMathAlgebraicSimplificationPass - : public PassWrapper> { + : public PassWrapper> { void runOnOperation() override; void getDependentDialects(DialectRegistry ®istry) const override { registry.insert(); diff --git a/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp b/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp --- a/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp +++ b/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp @@ -18,7 +18,7 @@ namespace { struct TestExpandTanhPass - : public PassWrapper> { + : public PassWrapper> { void runOnOperation() override; StringRef getArgument() const final { return "test-expand-tanh"; } StringRef getDescription() const final { return "Test expanding tanh"; } diff --git a/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp b/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp --- a/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp +++ b/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp @@ -23,8 +23,7 @@ namespace { struct TestMathPolynomialApproximationPass - : public PassWrapper> { + : public PassWrapper> { TestMathPolynomialApproximationPass() = default; TestMathPolynomialApproximationPass( const TestMathPolynomialApproximationPass &pass) diff --git a/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp b/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp --- a/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp +++ b/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp @@ -19,7 +19,7 @@ namespace { struct TestComposeSubViewPass - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-compose-subview"; } StringRef getDescription() const final { return "Test combining composed subviews"; diff --git a/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp b/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp --- a/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp +++ b/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp @@ -16,7 +16,7 @@ namespace { struct TestMultiBufferingPass - : public PassWrapper> { + : public PassWrapper> { TestMultiBufferingPass() = default; TestMultiBufferingPass(const TestMultiBufferingPass &pass) : PassWrapper(pass) {} @@ -37,7 +37,7 @@ void TestMultiBufferingPass::runOnOperation() { SmallVector allocs; - getOperation().walk( + getOperation()->walk( [&allocs](memref::AllocOp alloc) { allocs.push_back(alloc); }); for (memref::AllocOp alloc : allocs) (void)multiBuffer(alloc, multiplier); diff --git a/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp b/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp --- a/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp +++ b/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp @@ -22,8 +22,7 @@ // Extracts fixed-range loops for top-level loop nests with ranges defined in // the pass constructor. Assumes loops are permutable. class SimpleParametricLoopTilingPass - : public PassWrapper> { + : public PassWrapper> { public: StringRef getArgument() const final { return "test-extract-fixed-outer-loops"; @@ -39,8 +38,7 @@ } void runOnOperation() override { - FuncOp func = getOperation(); - func.walk([this](scf::ForOp op) { + getOperation()->walk([this](scf::ForOp op) { // Ignore nested loops. if (op->getParentRegion()->getParentOfType()) return; diff --git a/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp b/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp --- a/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp +++ b/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp @@ -31,7 +31,7 @@ } class TestLoopUnrollingPass - : public PassWrapper> { + : public PassWrapper> { public: StringRef getArgument() const final { return "test-loop-unrolling"; } StringRef getDescription() const final { @@ -52,9 +52,8 @@ } void runOnOperation() override { - FuncOp func = getOperation(); SmallVector loops; - func.walk([&](scf::ForOp forOp) { + getOperation()->walk([&](scf::ForOp forOp) { if (getNestingDepth(forOp) == loopDepth) loops.push_back(forOp); }); diff --git a/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp b/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp --- a/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp +++ b/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp @@ -21,7 +21,7 @@ namespace { struct TestTensorTransforms - : public PassWrapper> { + : public PassWrapper> { TestTensorTransforms() = default; TestTensorTransforms(const TestTensorTransforms &pass) : PassWrapper(pass) {} @@ -50,14 +50,14 @@ }; } // namespace -static void applySplitPaddingPatterns(FuncOp funcOp) { - RewritePatternSet patterns(funcOp.getContext()); +static void applySplitPaddingPatterns(Operation *rootOp) { + RewritePatternSet patterns(rootOp->getContext()); tensor::populateSplitPaddingPatterns(patterns); - (void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns)); + (void)applyPatternsAndFoldGreedily(rootOp, std::move(patterns)); } -static void applyFoldConstantExtractSlicePatterns(FuncOp funcOp) { - RewritePatternSet patterns(funcOp.getContext()); +static void applyFoldConstantExtractSlicePatterns(Operation *rootOp) { + RewritePatternSet patterns(rootOp->getContext()); tensor::ControlConstantExtractSliceFusionFn controlFn = [](tensor::ExtractSliceOp op) { if (!op.source().hasOneUse()) @@ -69,15 +69,15 @@ }; tensor::populateFoldConstantExtractSlicePatterns(patterns, controlFn); - (void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns)); + (void)applyPatternsAndFoldGreedily(rootOp, std::move(patterns)); } void TestTensorTransforms::runOnOperation() { - FuncOp func = getOperation(); + Operation *rootOp = getOperation(); if (testSplitPaddingPatterns) - applySplitPaddingPatterns(func); + applySplitPaddingPatterns(rootOp); if (testFoldConstantExtractSlice) - applyFoldConstantExtractSlicePatterns(func); + applyFoldConstantExtractSlicePatterns(rootOp); } namespace mlir { diff --git a/mlir/test/lib/IR/TestDiagnostics.cpp b/mlir/test/lib/IR/TestDiagnostics.cpp --- a/mlir/test/lib/IR/TestDiagnostics.cpp +++ b/mlir/test/lib/IR/TestDiagnostics.cpp @@ -18,7 +18,8 @@ namespace { struct TestDiagnosticFilterPass - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-diagnostic-filter"; } StringRef getDescription() const final { return "Test diagnostic filtering support."; diff --git a/mlir/test/lib/IR/TestDominance.cpp b/mlir/test/lib/IR/TestDominance.cpp --- a/mlir/test/lib/IR/TestDominance.cpp +++ b/mlir/test/lib/IR/TestDominance.cpp @@ -91,7 +91,7 @@ }; struct TestDominancePass - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-print-dominance"; } StringRef getDescription() const final { return "Print the dominance information for multiple regions."; diff --git a/mlir/test/lib/IR/TestFunc.cpp b/mlir/test/lib/IR/TestFunc.cpp --- a/mlir/test/lib/IR/TestFunc.cpp +++ b/mlir/test/lib/IR/TestFunc.cpp @@ -7,12 +7,14 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/FunctionInterfaces.h" #include "mlir/Pass/Pass.h" using namespace mlir; namespace { -/// This is a test pass for verifying FuncOp's insertArgument method. +/// This is a test pass for verifying FunctionOpInterface's insertArgument +/// method. struct TestFuncInsertArg : public PassWrapper> { StringRef getArgument() const final { return "test-func-insert-arg"; } @@ -21,7 +23,7 @@ auto module = getOperation(); UnknownLoc unknownLoc = UnknownLoc::get(module.getContext()); - for (FuncOp func : module.getOps()) { + for (auto func : module.getOps()) { auto inserts = func->getAttrOfType("test.insert_args"); if (!inserts || inserts.empty()) continue; @@ -47,7 +49,7 @@ } }; -/// This is a test pass for verifying FuncOp's insertResult method. +/// This is a test pass for verifying FunctionOpInterface's insertResult method. struct TestFuncInsertResult : public PassWrapper> { StringRef getArgument() const final { return "test-func-insert-result"; } @@ -57,7 +59,7 @@ void runOnOperation() override { auto module = getOperation(); - for (FuncOp func : module.getOps()) { + for (auto func : module.getOps()) { auto inserts = func->getAttrOfType("test.insert_results"); if (!inserts || inserts.empty()) continue; @@ -78,7 +80,8 @@ } }; -/// This is a test pass for verifying FuncOp's eraseArgument method. +/// This is a test pass for verifying FunctionOpInterface's eraseArgument +/// method. struct TestFuncEraseArg : public PassWrapper> { StringRef getArgument() const final { return "test-func-erase-arg"; } @@ -86,7 +89,7 @@ void runOnOperation() override { auto module = getOperation(); - for (FuncOp func : module.getOps()) { + for (auto func : module.getOps()) { BitVector indicesToErase(func.getNumArguments()); for (auto argIndex : llvm::seq(0, func.getNumArguments())) if (func.getArgAttr(argIndex, "test.erase_this_arg")) @@ -96,7 +99,7 @@ } }; -/// This is a test pass for verifying FuncOp's eraseResult method. +/// This is a test pass for verifying FunctionOpInterface's eraseResult method. struct TestFuncEraseResult : public PassWrapper> { StringRef getArgument() const final { return "test-func-erase-result"; } @@ -106,7 +109,7 @@ void runOnOperation() override { auto module = getOperation(); - for (FuncOp func : module.getOps()) { + for (auto func : module.getOps()) { BitVector indicesToErase(func.getNumResults()); for (auto resultIndex : llvm::seq(0, func.getNumResults())) if (func.getResultAttr(resultIndex, "test.erase_this_result")) @@ -116,20 +119,23 @@ } }; -/// This is a test pass for verifying FuncOp's setType method. +/// This is a test pass for verifying FunctionOpInterface's setType method. struct TestFuncSetType : public PassWrapper> { StringRef getArgument() const final { return "test-func-set-type"; } - StringRef getDescription() const final { return "Test FuncOp::setType."; } + StringRef getDescription() const final { + return "Test FunctionOpInterface::setType."; + } void runOnOperation() override { auto module = getOperation(); SymbolTable symbolTable(module); - for (FuncOp func : module.getOps()) { + for (auto func : module.getOps()) { auto sym = func->getAttrOfType("test.set_type_from"); if (!sym) continue; - func.setType(symbolTable.lookup(sym.getValue()).getType()); + func.setType( + symbolTable.lookup(sym.getValue()).getType()); } } }; diff --git a/mlir/test/lib/IR/TestMatchers.cpp b/mlir/test/lib/IR/TestMatchers.cpp --- a/mlir/test/lib/IR/TestMatchers.cpp +++ b/mlir/test/lib/IR/TestMatchers.cpp @@ -8,6 +8,7 @@ #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/FunctionInterfaces.h" #include "mlir/IR/Matchers.h" #include "mlir/Pass/Pass.h" @@ -15,7 +16,8 @@ namespace { /// This is a test pass for verifying matchers. -struct TestMatchers : public PassWrapper> { +struct TestMatchers + : public PassWrapper> { void runOnOperation() override; StringRef getArgument() const final { return "test-matchers"; } StringRef getDescription() const final { @@ -26,7 +28,7 @@ // This could be done better but is not worth the variadic template trouble. template -static unsigned countMatches(FuncOp f, Matcher &matcher) { +static unsigned countMatches(FunctionOpInterface f, Matcher &matcher) { unsigned count = 0; f.walk([&count, &matcher](Operation *op) { if (matcher.match(op)) @@ -37,7 +39,7 @@ using mlir::matchers::m_Any; using mlir::matchers::m_Val; -static void test1(FuncOp f) { +static void test1(FunctionOpInterface f) { assert(f.getNumArguments() == 3 && "matcher test funcs must have 3 args"); auto a = m_Val(f.getArgument(0)); @@ -128,7 +130,7 @@ << countMatches(f, p17) << " times\n"; } -void test2(FuncOp f) { +void test2(FunctionOpInterface f) { auto a = m_Val(f.getArgument(0)); FloatAttr floatAttr; auto p = diff --git a/mlir/test/lib/IR/TestOpaqueLoc.cpp b/mlir/test/lib/IR/TestOpaqueLoc.cpp --- a/mlir/test/lib/IR/TestOpaqueLoc.cpp +++ b/mlir/test/lib/IR/TestOpaqueLoc.cpp @@ -47,7 +47,8 @@ op->setLoc( OpaqueLoc::get(myLocs.back().get(), &getContext())); - if (isa(op) || op->hasTrait()) + if (isa(op->getParentOp()) || + op->hasTrait()) return; OpBuilder builder(op); diff --git a/mlir/test/lib/IR/TestVisitors.cpp b/mlir/test/lib/IR/TestVisitors.cpp --- a/mlir/test/lib/IR/TestVisitors.cpp +++ b/mlir/test/lib/IR/TestVisitors.cpp @@ -68,9 +68,9 @@ /// Tests erasure callbacks that skip the walk. static void testSkipErasureCallbacks(Operation *op) { auto skipOpErasure = [](Operation *op) { - // Do not erase module and function op. Otherwise there wouldn't be too - // much to test in pre-order. - if (isa(op) || isa(op)) + // Do not erase module and module children operations. Otherwise, there + // wouldn't be too much to test in pre-order. + if (isa(op) || isa(op->getParentOp())) return WalkResult::advance(); llvm::outs() << "Erasing "; @@ -81,10 +81,10 @@ return WalkResult::skip(); }; auto skipBlockErasure = [](Block *block) { - // Do not erase module and function blocks. Otherwise there wouldn't be - // too much to test in pre-order. + // Do not erase module and module children blocks. Otherwise there wouldn't + // be too much to test in pre-order. Operation *parentOp = block->getParentOp(); - if (isa(parentOp) || isa(parentOp)) + if (isa(parentOp) || isa(parentOp->getParentOp())) return WalkResult::advance(); llvm::outs() << "Erasing "; diff --git a/mlir/test/lib/Transforms/TestConstantFold.cpp b/mlir/test/lib/Transforms/TestConstantFold.cpp --- a/mlir/test/lib/Transforms/TestConstantFold.cpp +++ b/mlir/test/lib/Transforms/TestConstantFold.cpp @@ -14,13 +14,13 @@ namespace { /// Simple constant folding pass. struct TestConstantFold - : public PassWrapper> { + : public PassWrapper> { StringRef getArgument() const final { return "test-constant-fold"; } StringRef getDescription() const final { return "Test operation constant folding"; } - // All constants in the function post folding. - SmallVector existingConstants; + // All constants in the operation post folding. + SmallVector existingConstants; void foldOperation(Operation *op, OperationFolder &helper); void runOnOperation() override; @@ -37,15 +37,12 @@ (void)helper.tryToFold(op, processGeneratedConstants); } -// For now, we do a simple top-down pass over a function folding constants. We -// don't handle conditional control flow, block arguments, folding conditional -// branches, or anything else fancy. void TestConstantFold::runOnOperation() { existingConstants.clear(); - // Collect and fold the operations within the function. + // Collect and fold the operations within the operation. SmallVector ops; - getOperation().walk([&](Operation *op) { ops.push_back(op); }); + getOperation()->walk([&](Operation *op) { ops.push_back(op); }); // Fold the constants in reverse so that the last generated constants from // folding are at the beginning. This creates somewhat of a linear ordering to @@ -56,7 +53,7 @@ foldOperation(op, helper); // By the time we are done, we may have simplified a bunch of code, leaving - // around dead constants. Check for them now and remove them. + // around dead constants. Check for them now and remove them. for (auto *cst : existingConstants) { if (cst->use_empty()) cst->erase();