From 72c65b698e3af6d1826dad43cb57d4ec06844fcc Mon Sep 17 00:00:00 2001 From: Alexander Belyaev Date: Wed, 4 Nov 2020 22:18:26 +0100 Subject: [PATCH] [mlir] Move TestDialect and its passes to mlir::test namespace. TestDialect has many operations and they all live in ::mlir namespace. Sometimes it is not clear whether the ops used in the code for the test passes belong to Standard or to Test dialects. Also, with this change it is easier to understand what test passes registered in mlir-opt are actually passes in mlir/test. Differential Revision: https://reviews.llvm.org/D90794 --- mlir/test/lib/Dialect/Test/TestDialect.cpp | 3 +- mlir/test/lib/Dialect/Test/TestDialect.h | 4 +- mlir/test/lib/Dialect/Test/TestOps.td | 6 +- mlir/test/lib/Dialect/Test/TestPatterns.cpp | 3 + mlir/test/lib/Dialect/Test/TestTraits.cpp | 1 + mlir/test/lib/Dialect/Test/TestTypeDefs.td | 4 +- mlir/test/lib/Dialect/Test/TestTypes.cpp | 7 +- mlir/test/lib/Dialect/Test/TestTypes.h | 6 +- mlir/test/lib/IR/TestInterfaces.cpp | 3 + mlir/test/lib/IR/TestTypes.cpp | 7 +- .../Transforms/TestAffineLoopParametricTiling.cpp | 3 +- mlir/test/lib/Transforms/TestCallGraph.cpp | 2 + mlir/test/lib/Transforms/TestConstantFold.cpp | 2 + mlir/test/lib/Transforms/TestConvVectorization.cpp | 2 + mlir/test/lib/Transforms/TestConvertCallOp.cpp | 11 +- .../lib/Transforms/TestConvertGPUKernelToCubin.cpp | 3 + .../lib/Transforms/TestConvertGPUKernelToHsaco.cpp | 3 + mlir/test/lib/Transforms/TestDominance.cpp | 2 + mlir/test/lib/Transforms/TestDynamicPipeline.cpp | 4 +- .../lib/Transforms/TestExpandMemRefReshape.cpp | 2 + mlir/test/lib/Transforms/TestExpandTanh.cpp | 2 + .../lib/Transforms/TestFinalizingBufferize.cpp | 34 +++--- .../lib/Transforms/TestGpuParallelLoopMapping.cpp | 4 +- mlir/test/lib/Transforms/TestInlining.cpp | 3 + .../lib/Transforms/TestLinalgCodegenStrategy.cpp | 2 + .../lib/Transforms/TestLinalgFusionTransforms.cpp | 2 + mlir/test/lib/Transforms/TestLinalgHoisting.cpp | 2 + mlir/test/lib/Transforms/TestLinalgTransforms.cpp | 2 + mlir/test/lib/Transforms/TestLiveness.cpp | 2 + mlir/test/lib/Transforms/TestLoopFusion.cpp | 2 + mlir/test/lib/Transforms/TestLoopMapping.cpp | 4 +- .../lib/Transforms/TestLoopParametricTiling.cpp | 4 +- mlir/test/lib/Transforms/TestLoopUnrolling.cpp | 4 +- mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp | 2 + .../lib/Transforms/TestMemRefDependenceCheck.cpp | 2 + .../lib/Transforms/TestMemRefStrideCalculation.cpp | 2 + mlir/test/lib/Transforms/TestOpaqueLoc.cpp | 2 + mlir/test/lib/Transforms/TestSCFUtils.cpp | 4 +- mlir/test/lib/Transforms/TestVectorTransforms.cpp | 2 + mlir/tools/mlir-opt/mlir-opt.cpp | 124 +++++++++++---------- 40 files changed, 184 insertions(+), 99 deletions(-) diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp index ffc59aa..a14fd0b 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -20,8 +20,9 @@ #include "llvm/ADT/StringSwitch.h" using namespace mlir; +using namespace mlir::test; -void mlir::registerTestDialect(DialectRegistry ®istry) { +void mlir::test::registerTestDialect(DialectRegistry ®istry) { registry.insert(); } diff --git a/mlir/test/lib/Dialect/Test/TestDialect.h b/mlir/test/lib/Dialect/Test/TestDialect.h index 7eb189b..3b9e8c5 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.h +++ b/mlir/test/lib/Dialect/Test/TestDialect.h @@ -38,7 +38,9 @@ #include "TestOps.h.inc" namespace mlir { +namespace test { void registerTestDialect(DialectRegistry ®istry); -} // end namespace mlir +} // namespace test +} // namespace mlir #endif // MLIR_TESTDIALECT_H diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 41a21b5..1ed6c54 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -21,7 +21,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td" def Test_Dialect : Dialect { let name = "test"; - let cppNamespace = "::mlir"; + let cppNamespace = "::mlir::test"; let hasOperationAttrVerify = 1; let hasRegionArgAttrVerify = 1; let hasRegionResultAttrVerify = 1; @@ -89,8 +89,8 @@ def MultiTensorRankOf : TEST_Op<"multi_tensor_rank_of"> { } def TEST_TestType : DialectType()">, "test">, - BuildableType<"$_builder.getType<::mlir::TestType>()">; + CPred<"$_self.isa<::mlir::test::TestType>()">, "test">, + BuildableType<"$_builder.getType<::mlir::test::TestType>()">; //===----------------------------------------------------------------------===// // Test Symbols diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp index 5958105..40ae9ad 100644 --- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp +++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp @@ -16,6 +16,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" using namespace mlir; +using namespace mlir::test; // Native function for testing NativeCodeCall static Value chooseOperand(Value input1, Value input2, BoolAttr choice) { @@ -955,6 +956,7 @@ struct TestMergeBlocksPatternDriver //===----------------------------------------------------------------------===// namespace mlir { +namespace test { void registerPatternsTestPass() { PassRegistration("test-return-type", "Run return type functions"); @@ -987,4 +989,5 @@ void registerPatternsTestPass() { "test-merge-blocks", "Test Merging operation in ConversionPatternRewriter"}; } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Dialect/Test/TestTraits.cpp b/mlir/test/lib/Dialect/Test/TestTraits.cpp index dbd05ae..d398c44 100644 --- a/mlir/test/lib/Dialect/Test/TestTraits.cpp +++ b/mlir/test/lib/Dialect/Test/TestTraits.cpp @@ -11,6 +11,7 @@ #include "mlir/Transforms/GreedyPatternRewriteDriver.h" using namespace mlir; +using namespace mlir::test; //===----------------------------------------------------------------------===// // Trait Folder. diff --git a/mlir/test/lib/Dialect/Test/TestTypeDefs.td b/mlir/test/lib/Dialect/Test/TestTypeDefs.td index d755d91..75fffa1 100644 --- a/mlir/test/lib/Dialect/Test/TestTypeDefs.td +++ b/mlir/test/lib/Dialect/Test/TestTypeDefs.td @@ -55,7 +55,7 @@ def IntegerType : Test_Type<"TestInteger"> { let parameters = ( ins // SignednessSemantics is defined below. - "::mlir::TestIntegerType::SignednessSemantics":$signedness, + "::mlir::test::TestIntegerType::SignednessSemantics":$signedness, "unsigned":$width ); @@ -108,7 +108,7 @@ class FieldInfo_Type : Test_Type { // An ArrayRef of something which requires allocation in the storage // constructor. ArrayRefOfSelfAllocationParameter< - "::mlir::FieldInfo", // FieldInfo is defined/declared in TestTypes.h. + "::mlir::test::FieldInfo", // FieldInfo is defined/declared in TestTypes.h. "Models struct fields">: $fields ); diff --git a/mlir/test/lib/Dialect/Test/TestTypes.cpp b/mlir/test/lib/Dialect/Test/TestTypes.cpp index 1eb5347..0a91be3 100644 --- a/mlir/test/lib/Dialect/Test/TestTypes.cpp +++ b/mlir/test/lib/Dialect/Test/TestTypes.cpp @@ -18,6 +18,7 @@ #include "llvm/ADT/TypeSwitch.h" using namespace mlir; +using namespace mlir::test; // Custom parser for SignednessSemantics. static ParseResult @@ -87,21 +88,23 @@ void CompoundAType::print(DialectAsmPrinter &printer) const { // namespace. Declare them here, then define them immediately below. Separating // the declaration and definition adheres to the LLVM coding standards. namespace mlir { +namespace test { // FieldInfo is used as part of a parameter, so equality comparison is // compulsory. static bool operator==(const FieldInfo &a, const FieldInfo &b); // FieldInfo is used as part of a parameter, so a hash will be computed. static llvm::hash_code hash_value(const FieldInfo &fi); // NOLINT +} // namespace test } // namespace mlir // FieldInfo is used as part of a parameter, so equality comparison is // compulsory. -static bool mlir::operator==(const FieldInfo &a, const FieldInfo &b) { +static bool mlir::test::operator==(const FieldInfo &a, const FieldInfo &b) { return a.name == b.name && a.type == b.type; } // FieldInfo is used as part of a parameter, so a hash will be computed. -static llvm::hash_code mlir::hash_value(const FieldInfo &fi) { // NOLINT +static llvm::hash_code mlir::test::hash_value(const FieldInfo &fi) { // NOLINT return llvm::hash_combine(fi.name, fi.type); } diff --git a/mlir/test/lib/Dialect/Test/TestTypes.h b/mlir/test/lib/Dialect/Test/TestTypes.h index 371171f..fdde7a4 100644 --- a/mlir/test/lib/Dialect/Test/TestTypes.h +++ b/mlir/test/lib/Dialect/Test/TestTypes.h @@ -23,6 +23,7 @@ #include "mlir/IR/Types.h" namespace mlir { +namespace test { /// FieldInfo represents a field in the StructType data type. It is used as a /// parameter in TestTypeDefs.td. @@ -36,12 +37,14 @@ struct FieldInfo { } }; +} // namespace test } // namespace mlir #define GET_TYPEDEF_CLASSES #include "TestTypeDefs.h.inc" namespace mlir { +namespace test { #include "TestTypeInterfaces.h.inc" @@ -104,6 +107,7 @@ public: StringRef getName() { return getImpl()->name; } }; -} // end namespace mlir +} // namespace test +} // namespace mlir #endif // MLIR_TESTTYPES_H diff --git a/mlir/test/lib/IR/TestInterfaces.cpp b/mlir/test/lib/IR/TestInterfaces.cpp index c48d582..369001f 100644 --- a/mlir/test/lib/IR/TestInterfaces.cpp +++ b/mlir/test/lib/IR/TestInterfaces.cpp @@ -10,6 +10,7 @@ #include "mlir/Pass/Pass.h" using namespace mlir; +using namespace mlir::test; namespace { /// This test checks various aspects of Type interface generation and @@ -34,8 +35,10 @@ struct TestTypeInterfaces } // end anonymous namespace namespace mlir { +namespace test { void registerTestInterfaces() { PassRegistration pass("test-type-interfaces", "Test type interface support."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/IR/TestTypes.cpp b/mlir/test/lib/IR/TestTypes.cpp index 43b2c05..0d652a4 100644 --- a/mlir/test/lib/IR/TestTypes.cpp +++ b/mlir/test/lib/IR/TestTypes.cpp @@ -11,6 +11,7 @@ #include "mlir/Pass/Pass.h" using namespace mlir; +using namespace mlir::test; namespace { struct TestRecursiveTypesPass @@ -36,7 +37,7 @@ struct TestRecursiveTypesPass signalPassFailure(); } }; -} // end namespace +} // namespace LogicalResult TestRecursiveTypesPass::createIRWithTypes() { MLIRContext *ctx = &getContext(); @@ -69,10 +70,12 @@ LogicalResult TestRecursiveTypesPass::createIRWithTypes() { } namespace mlir { +namespace test { void registerTestRecursiveTypesPass() { PassRegistration reg( "test-recursive-types", "Test support for recursive types"); } -} // end namespace mlir +} // namespace test +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestAffineLoopParametricTiling.cpp b/mlir/test/lib/Transforms/TestAffineLoopParametricTiling.cpp index 5d369e6..cd4d91f 100644 --- a/mlir/test/lib/Transforms/TestAffineLoopParametricTiling.cpp +++ b/mlir/test/lib/Transforms/TestAffineLoopParametricTiling.cpp @@ -20,7 +20,6 @@ using namespace mlir; #define DEBUG_TYPE "test-affine-parametric-tile" namespace { - struct TestAffineLoopParametricTiling : public PassWrapper { void runOnFunction() override; @@ -82,9 +81,11 @@ void TestAffineLoopParametricTiling::runOnFunction() { } namespace mlir { +namespace test { void registerTestAffineLoopParametricTilingPass() { PassRegistration( "test-affine-parametric-tile", "Tile affine loops using SSA values as tile sizes"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestCallGraph.cpp b/mlir/test/lib/Transforms/TestCallGraph.cpp index bd651a5..56182e2 100644 --- a/mlir/test/lib/Transforms/TestCallGraph.cpp +++ b/mlir/test/lib/Transforms/TestCallGraph.cpp @@ -27,8 +27,10 @@ struct TestCallGraphPass } // end anonymous namespace namespace mlir { +namespace test { void registerTestCallGraphPass() { PassRegistration pass( "test-print-callgraph", "Print the contents of a constructed callgraph."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestConstantFold.cpp b/mlir/test/lib/Transforms/TestConstantFold.cpp index 089d450..d7b062e 100644 --- a/mlir/test/lib/Transforms/TestConstantFold.cpp +++ b/mlir/test/lib/Transforms/TestConstantFold.cpp @@ -65,8 +65,10 @@ void TestConstantFold::runOnFunction() { } namespace mlir { +namespace test { void registerTestConstantFold() { PassRegistration("test-constant-fold", "Test operation constant folding"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestConvVectorization.cpp b/mlir/test/lib/Transforms/TestConvVectorization.cpp index 196f3ad..51c2807 100644 --- a/mlir/test/lib/Transforms/TestConvVectorization.cpp +++ b/mlir/test/lib/Transforms/TestConvVectorization.cpp @@ -124,8 +124,10 @@ void TestConvVectorization::runOnOperation() { } namespace mlir { +namespace test { void registerTestConvVectorization() { PassRegistration testTransformPatternsPass( "test-conv-vectorization", "Test vectorization of convolutions"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestConvertCallOp.cpp b/mlir/test/lib/Transforms/TestConvertCallOp.cpp index 7beba01..a612738 100644 --- a/mlir/test/lib/Transforms/TestConvertCallOp.cpp +++ b/mlir/test/lib/Transforms/TestConvertCallOp.cpp @@ -19,9 +19,10 @@ using namespace mlir; namespace { class TestTypeProducerOpConverter - : public ConvertOpToLLVMPattern { + : public ConvertOpToLLVMPattern { public: - using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern; + using ConvertOpToLLVMPattern< + test::TestTypeProducerOp>::ConvertOpToLLVMPattern; LogicalResult matchAndRewrite(Operation *op, ArrayRef operands, @@ -43,7 +44,7 @@ public: // Populate type conversions. LLVMTypeConverter type_converter(m.getContext()); - type_converter.addConversion([&](TestType type) { + type_converter.addConversion([&](test::TestType type) { return LLVM::LLVMType::getInt8PtrTy(m.getContext()); }); @@ -55,7 +56,7 @@ public: // Set target. ConversionTarget target(getContext()); target.addLegalDialect(); - target.addIllegalDialect(); + target.addIllegalDialect(); target.addIllegalDialect(); if (failed(applyPartialConversion(m, target, std::move(patterns)))) @@ -66,10 +67,12 @@ public: } // namespace namespace mlir { +namespace test { void registerConvertCallOpPass() { PassRegistration( "test-convert-call-op", "Tests conversion of `std.call` to `llvm.call` in " "presence of custom types"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp index a347b2c..ac217a2 100644 --- a/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp +++ b/mlir/test/lib/Transforms/TestConvertGPUKernelToCubin.cpp @@ -11,6 +11,7 @@ #include "mlir/Pass/PassManager.h" #include "mlir/Target/NVVMIR.h" #include "llvm/Support/TargetSelect.h" + using namespace mlir; #if MLIR_CUDA_CONVERSIONS_ENABLED @@ -21,6 +22,7 @@ static OwnedBlob compilePtxToCubinForTesting(const std::string &, Location, } namespace mlir { +namespace test { void registerTestConvertGPUKernelToCubinPass() { PassPipelineRegistration<>( "test-kernel-to-cubin", @@ -37,5 +39,6 @@ void registerTestConvertGPUKernelToCubinPass() { "nvptx64-nvidia-cuda", "sm_35", "+ptx60", "nvvm.cubin")); }); } +} // namespace test } // namespace mlir #endif diff --git a/mlir/test/lib/Transforms/TestConvertGPUKernelToHsaco.cpp b/mlir/test/lib/Transforms/TestConvertGPUKernelToHsaco.cpp index 54293a8..f7036c9 100644 --- a/mlir/test/lib/Transforms/TestConvertGPUKernelToHsaco.cpp +++ b/mlir/test/lib/Transforms/TestConvertGPUKernelToHsaco.cpp @@ -11,6 +11,7 @@ #include "mlir/Pass/PassManager.h" #include "mlir/Target/ROCDLIR.h" #include "llvm/Support/TargetSelect.h" + using namespace mlir; #if MLIR_ROCM_CONVERSIONS_ENABLED @@ -21,6 +22,7 @@ static OwnedBlob compileIsaToHsacoForTesting(const std::string &, Location, } namespace mlir { +namespace test { void registerTestConvertGPUKernelToHsacoPass() { PassPipelineRegistration<>( "test-kernel-to-hsaco", @@ -37,5 +39,6 @@ void registerTestConvertGPUKernelToHsacoPass() { "amdgcn-amd-amdhsa", "gfx900", "-code-object-v3", "rocdl.hsaco")); }); } +} // namespace test } // namespace mlir #endif diff --git a/mlir/test/lib/Transforms/TestDominance.cpp b/mlir/test/lib/Transforms/TestDominance.cpp index fd83e60..a138f88 100644 --- a/mlir/test/lib/Transforms/TestDominance.cpp +++ b/mlir/test/lib/Transforms/TestDominance.cpp @@ -82,9 +82,11 @@ struct TestDominancePass : public PassWrapper { } // end anonymous namespace namespace mlir { +namespace test { void registerTestDominancePass() { PassRegistration( "test-print-dominance", "Print the dominance information for multiple regions."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestDynamicPipeline.cpp b/mlir/test/lib/Transforms/TestDynamicPipeline.cpp index 21e89a3..57c5a59 100644 --- a/mlir/test/lib/Transforms/TestDynamicPipeline.cpp +++ b/mlir/test/lib/Transforms/TestDynamicPipeline.cpp @@ -103,12 +103,14 @@ public: *this, "op-name", llvm::cl::MiscFlags::CommaSeparated, llvm::cl::desc("List of function name to apply the pipeline to")}; }; -} // end namespace +} // namespace namespace mlir { +namespace test { void registerTestDynamicPipelinePass() { PassRegistration( "test-dynamic-pipeline", "Tests the dynamic pipeline feature by applying " "a pipeline on a selected set of functions"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestExpandMemRefReshape.cpp b/mlir/test/lib/Transforms/TestExpandMemRefReshape.cpp index ddb340a..13e13c3 100644 --- a/mlir/test/lib/Transforms/TestExpandMemRefReshape.cpp +++ b/mlir/test/lib/Transforms/TestExpandMemRefReshape.cpp @@ -30,8 +30,10 @@ void TestExpandMemRefReshapePass::runOnFunction() { } namespace mlir { +namespace test { void registerTestExpandMemRefReshapePass() { PassRegistration pass( "test-expand-memref-reshape", "Test expanding memref reshape"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestExpandTanh.cpp b/mlir/test/lib/Transforms/TestExpandTanh.cpp index c33625b..4baffac 100644 --- a/mlir/test/lib/Transforms/TestExpandTanh.cpp +++ b/mlir/test/lib/Transforms/TestExpandTanh.cpp @@ -30,8 +30,10 @@ void TestExpandTanhPass::runOnFunction() { } namespace mlir { +namespace test { void registerTestExpandTanhPass() { PassRegistration pass("test-expand-tanh", "Test expanding tanh"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestFinalizingBufferize.cpp b/mlir/test/lib/Transforms/TestFinalizingBufferize.cpp index b7d48c6..f74f8ae 100644 --- a/mlir/test/lib/Transforms/TestFinalizingBufferize.cpp +++ b/mlir/test/lib/Transforms/TestFinalizingBufferize.cpp @@ -50,15 +50,15 @@ struct TestFinalizingBufferizePass /// Converts tensor based test operations to buffer based ones using /// bufferize. class TensorBasedOpConverter - : public BufferizeOpConversionPattern { + : public BufferizeOpConversionPattern { public: using BufferizeOpConversionPattern< - mlir::TensorBasedOp>::BufferizeOpConversionPattern; + test::TensorBasedOp>::BufferizeOpConversionPattern; LogicalResult - matchAndRewrite(mlir::TensorBasedOp op, ArrayRef operands, + matchAndRewrite(test::TensorBasedOp op, ArrayRef operands, ConversionPatternRewriter &rewriter) const final { - mlir::TensorBasedOpAdaptor adaptor( + mlir::test::TensorBasedOpAdaptor adaptor( operands, op.getOperation()->getAttrDictionary()); // The input needs to be turned into a buffer first. Until then, bail out. @@ -76,9 +76,9 @@ struct TestFinalizingBufferizePass Value newOutputBuffer = rewriter.create(loc, memrefType); // Generate a new test operation that works on buffers. - rewriter.create(loc, - /*input=*/adaptor.input(), - /*output=*/newOutputBuffer); + rewriter.create(loc, + /*input=*/adaptor.input(), + /*output=*/newOutputBuffer); // Replace the results of the old op with the new output buffers. rewriter.replaceOp(op, newOutputBuffer); @@ -87,7 +87,7 @@ struct TestFinalizingBufferizePass }; void getDependentDialects(DialectRegistry ®istry) const override { - registry.insert(); + registry.insert(); } void runOnOperation() override { @@ -97,8 +97,8 @@ struct TestFinalizingBufferizePass // Mark all Standard operations legal. target.addLegalDialect(); - target.addLegalOp(); - target.addLegalOp(); + target.addLegalOp(); + target.addLegalOp(); target.addLegalOp(); target.addLegalOp(); @@ -106,7 +106,7 @@ struct TestFinalizingBufferizePass auto isLegalOperation = [&](Operation *op) { return converter.isLegal(op); }; - target.addDynamicallyLegalDialect(isLegalOperation); + target.addDynamicallyLegalDialect(isLegalOperation); // Mark Standard Return operations illegal as long as one operand is tensor. target.addDynamicallyLegalOp([&](mlir::ReturnOp returnOp) { @@ -144,7 +144,8 @@ struct TestFinalizingBufferizePass TypeRange TypeRange = inputs.getTypes(); SmallVector types(TypeRange.begin(), TypeRange.end()); TupleType tuple = TupleType::get(types, builder.getContext()); - mlir::Value value = builder.create(loc, tuple, inputs); + mlir::Value value = + builder.create(loc, tuple, inputs); return value; }); @@ -152,7 +153,7 @@ struct TestFinalizingBufferizePass TupleType resultType, Value value, SmallVectorImpl &values) { for (unsigned i = 0, e = resultType.size(); i < e; ++i) { - Value res = builder.create( + Value res = builder.create( loc, resultType.getType(i), value, builder.getI32IntegerAttr(i)); values.push_back(res); } @@ -160,8 +161,7 @@ struct TestFinalizingBufferizePass }); OwningRewritePatternList patterns; - populateWithBufferizeOpConversionPatterns( + populateWithBufferizeOpConversionPatterns( &context, converter, patterns); patterns.insert(&context, converter); @@ -173,6 +173,7 @@ struct TestFinalizingBufferizePass } // end anonymous namespace namespace mlir { +namespace test { void registerTestFinalizingBufferizePass() { PassRegistration< TestFinalizingBufferizePass>( @@ -186,4 +187,5 @@ void registerTestPreparationPassWithAllowedMemrefResults() { "Tests finalizing buffierize conversions, allowing functions to have " "memref typed results."); } -} // end namespace mlir +} // namespace test +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestGpuParallelLoopMapping.cpp b/mlir/test/lib/Transforms/TestGpuParallelLoopMapping.cpp index 916b7203..c553be6 100644 --- a/mlir/test/lib/Transforms/TestGpuParallelLoopMapping.cpp +++ b/mlir/test/lib/Transforms/TestGpuParallelLoopMapping.cpp @@ -28,12 +28,14 @@ class TestGpuGreedyParallelLoopMappingPass greedilyMapParallelSCFToGPU(region); } }; -} // end namespace +} // namespace namespace mlir { +namespace test { void registerTestGpuParallelLoopMappingPass() { PassRegistration registration( "test-gpu-greedy-parallel-loop-mapping", "Greedily maps all parallel loops to gpu hardware ids."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestInlining.cpp b/mlir/test/lib/Transforms/TestInlining.cpp index 27c0d08..c56a38e 100644 --- a/mlir/test/lib/Transforms/TestInlining.cpp +++ b/mlir/test/lib/Transforms/TestInlining.cpp @@ -22,6 +22,7 @@ #include "llvm/ADT/StringSet.h" using namespace mlir; +using namespace mlir::test; namespace { struct Inliner : public PassWrapper { @@ -61,7 +62,9 @@ struct Inliner : public PassWrapper { } // end anonymous namespace namespace mlir { +namespace test { void registerInliner() { PassRegistration("test-inline", "Test inlining region calls"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLinalgCodegenStrategy.cpp b/mlir/test/lib/Transforms/TestLinalgCodegenStrategy.cpp index 57500bc..5e8c92c 100644 --- a/mlir/test/lib/Transforms/TestLinalgCodegenStrategy.cpp +++ b/mlir/test/lib/Transforms/TestLinalgCodegenStrategy.cpp @@ -143,8 +143,10 @@ void TestLinalgCodegenStrategy::runOnFunction() { } namespace mlir { +namespace test { void registerTestLinalgCodegenStrategy() { PassRegistration testLinalgCodegenStrategyPass( "test-linalg-codegen-strategy", "Test Linalg Codegen Strategy."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLinalgFusionTransforms.cpp b/mlir/test/lib/Transforms/TestLinalgFusionTransforms.cpp index 33f9429..06ff91e 100644 --- a/mlir/test/lib/Transforms/TestLinalgFusionTransforms.cpp +++ b/mlir/test/lib/Transforms/TestLinalgFusionTransforms.cpp @@ -188,6 +188,7 @@ struct TestLinalgGreedyFusion } // namespace namespace mlir { +namespace test { void registerTestLinalgFusionTransforms() { PassRegistration testFusionTransformsPass( "test-linalg-fusion-transform-patterns", @@ -198,4 +199,5 @@ void registerTestLinalgGreedyFusion() { "test-linalg-greedy-fusion", "Test Linalg fusion by applying a greedy test transformation."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLinalgHoisting.cpp b/mlir/test/lib/Transforms/TestLinalgHoisting.cpp index 5d4031f..d78833e 100644 --- a/mlir/test/lib/Transforms/TestLinalgHoisting.cpp +++ b/mlir/test/lib/Transforms/TestLinalgHoisting.cpp @@ -52,8 +52,10 @@ void TestLinalgHoisting::runOnFunction() { } namespace mlir { +namespace test { void registerTestLinalgHoisting() { PassRegistration testTestLinalgHoistingPass( "test-linalg-hoisting", "Test Linalg hoisting functions."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLinalgTransforms.cpp b/mlir/test/lib/Transforms/TestLinalgTransforms.cpp index a861b19..253d4ad 100644 --- a/mlir/test/lib/Transforms/TestLinalgTransforms.cpp +++ b/mlir/test/lib/Transforms/TestLinalgTransforms.cpp @@ -503,9 +503,11 @@ void TestLinalgTransforms::runOnFunction() { } namespace mlir { +namespace test { void registerTestLinalgTransforms() { PassRegistration testTransformPatternsPass( "test-linalg-transform-patterns", "Test Linalg transformation patterns by applying them greedily."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLiveness.cpp b/mlir/test/lib/Transforms/TestLiveness.cpp index e51ee1b..5efacaf 100644 --- a/mlir/test/lib/Transforms/TestLiveness.cpp +++ b/mlir/test/lib/Transforms/TestLiveness.cpp @@ -29,9 +29,11 @@ struct TestLivenessPass : public PassWrapper { } // end anonymous namespace namespace mlir { +namespace test { void registerTestLivenessPass() { PassRegistration( "test-print-liveness", "Print the contents of a constructed liveness information."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLoopFusion.cpp b/mlir/test/lib/Transforms/TestLoopFusion.cpp index 8e6974d..6cf1ae0 100644 --- a/mlir/test/lib/Transforms/TestLoopFusion.cpp +++ b/mlir/test/lib/Transforms/TestLoopFusion.cpp @@ -192,8 +192,10 @@ void TestLoopFusion::runOnFunction() { } namespace mlir { +namespace test { void registerTestLoopFusion() { PassRegistration("test-loop-fusion", "Tests loop fusion utility functions."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLoopMapping.cpp b/mlir/test/lib/Transforms/TestLoopMapping.cpp index b8039b2..d373b39 100644 --- a/mlir/test/lib/Transforms/TestLoopMapping.cpp +++ b/mlir/test/lib/Transforms/TestLoopMapping.cpp @@ -49,12 +49,14 @@ public: }); } }; -} // end namespace +} // namespace namespace mlir { +namespace test { void registerTestLoopMappingPass() { PassRegistration( "test-mapping-to-processing-elements", "test mapping a single loop on a virtual processor grid"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp b/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp index a49a38a..2649101 100644 --- a/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp +++ b/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp @@ -46,13 +46,15 @@ public: llvm::cl::desc( "fixed number of iterations that the outer loops should have")}; }; -} // end namespace +} // namespace namespace mlir { +namespace test { void registerSimpleParametricTilingPass() { PassRegistration( "test-extract-fixed-outer-loops", "test application of parametric tiling to the outer loops so that the " "ranges of outer loops become static"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLoopUnrolling.cpp b/mlir/test/lib/Transforms/TestLoopUnrolling.cpp index 396f08b..f67be1d 100644 --- a/mlir/test/lib/Transforms/TestLoopUnrolling.cpp +++ b/mlir/test/lib/Transforms/TestLoopUnrolling.cpp @@ -61,11 +61,13 @@ public: Option loopDepth{*this, "loop-depth", llvm::cl::desc("Loop depth."), llvm::cl::init(0)}; }; -} // end namespace +} // namespace namespace mlir { +namespace test { void registerTestLoopUnrollingPass() { PassRegistration( "test-loop-unrolling", "Tests loop unrolling transformation"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp b/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp index b7e84f6..a2df870 100644 --- a/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp +++ b/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp @@ -46,8 +46,10 @@ void TestMemRefBoundCheck::runOnFunction() { } namespace mlir { +namespace test { void registerMemRefBoundCheck() { PassRegistration( "test-memref-bound-check", "Check memref access bounds in a Function"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp b/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp index 787c927..3e96ca6 100644 --- a/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp +++ b/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp @@ -111,9 +111,11 @@ void TestMemRefDependenceCheck::runOnFunction() { } namespace mlir { +namespace test { void registerTestMemRefDependenceCheck() { PassRegistration pass( "test-memref-dependence-check", "Checks dependences between all pairs of memref accesses."); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp b/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp index dccd1ff..e2a67b7 100644 --- a/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp +++ b/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp @@ -50,8 +50,10 @@ void TestMemRefStrideCalculation::runOnFunction() { } namespace mlir { +namespace test { void registerTestMemRefStrideCalculation() { PassRegistration pass( "test-memref-stride-calculation", "Test operation constant folding"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestOpaqueLoc.cpp b/mlir/test/lib/Transforms/TestOpaqueLoc.cpp index 55b181c..1d16ab7 100644 --- a/mlir/test/lib/Transforms/TestOpaqueLoc.cpp +++ b/mlir/test/lib/Transforms/TestOpaqueLoc.cpp @@ -82,8 +82,10 @@ struct TestOpaqueLoc } // end anonymous namespace namespace mlir { +namespace test { void registerTestOpaqueLoc() { PassRegistration pass( "test-opaque-loc", "Changes all leaf locations to opaque locations"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestSCFUtils.cpp b/mlir/test/lib/Transforms/TestSCFUtils.cpp index 4b99f25..c4e2328 100644 --- a/mlir/test/lib/Transforms/TestSCFUtils.cpp +++ b/mlir/test/lib/Transforms/TestSCFUtils.cpp @@ -68,13 +68,15 @@ public: }); } }; -} // end namespace +} // namespace namespace mlir { +namespace test { void registerTestSCFUtilsPass() { PassRegistration("test-scf-for-utils", "test scf.for utils"); PassRegistration("test-scf-if-utils", "test scf.if utils"); } +} // namespace test } // namespace mlir diff --git a/mlir/test/lib/Transforms/TestVectorTransforms.cpp b/mlir/test/lib/Transforms/TestVectorTransforms.cpp index e2a507f..8daed18 100644 --- a/mlir/test/lib/Transforms/TestVectorTransforms.cpp +++ b/mlir/test/lib/Transforms/TestVectorTransforms.cpp @@ -294,6 +294,7 @@ struct TestVectorTransferFullPartialSplitPatterns } // end anonymous namespace namespace mlir { +namespace test { void registerTestVectorConversions() { PassRegistration vectorToVectorPass( "test-vector-to-vector-conversion", @@ -327,4 +328,5 @@ void registerTestVectorConversions() { "test-vector-to-forloop", "Test conversion patterns to break up a vector op into a for loop"); } +} // namespace test } // namespace mlir diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp index 51a72ad..d18cd11 100644 --- a/mlir/tools/mlir-opt/mlir-opt.cpp +++ b/mlir/tools/mlir-opt/mlir-opt.cpp @@ -27,36 +27,47 @@ using namespace llvm; using namespace mlir; -namespace mlir { // Defined in the test directory, no public header. -void registerConvertCallOpPass(); +namespace mlir { void registerConvertToTargetEnvPass(); -void registerInliner(); -void registerMemRefBoundCheck(); void registerPassManagerTestPass(); -void registerPatternsTestPass(); void registerPrintOpAvailabilityPass(); void registerSideEffectTestPasses(); -void registerSimpleParametricTilingPass(); void registerSliceAnalysisTestPass(); void registerSymbolTestPasses(); void registerTestAffineDataCopyPass(); -void registerTestAffineLoopParametricTilingPass(); void registerTestAffineLoopUnswitchingPass(); void registerTestAllReduceLoweringPass(); +void registerTestFunc(); +void registerTestGpuMemoryPromotionPass(); +void registerTestLoopPermutationPass(); +void registerTestMatchers(); +void registerTestPrintDefUsePass(); +void registerTestPrintNestingPass(); +void registerTestReducer(); +void registerTestSpirvEntryPointABIPass(); +void registerTestSpirvModuleCombinerPass(); +void registerTestTraitsPass(); +void registerVectorizerTestPass(); + +namespace test { +void registerConvertCallOpPass(); +void registerInliner(); +void registerMemRefBoundCheck(); +void registerPatternsTestPass(); +void registerSimpleParametricTilingPass(); +void registerTestAffineLoopParametricTilingPass(); void registerTestCallGraphPass(); void registerTestConstantFold(); void registerTestConvVectorization(); void registerTestConvertGPUKernelToCubinPass(); void registerTestConvertGPUKernelToHsacoPass(); -void registerTestDominancePass(); void registerTestDialect(DialectRegistry &); +void registerTestDominancePass(); void registerTestDynamicPipelinePass(); void registerTestExpandMemRefReshapePass(); void registerTestExpandTanhPass(); void registerTestFinalizingBufferizePass(); -void registerTestFunc(); -void registerTestGpuMemoryPromotionPass(); void registerTestGpuParallelLoopMappingPass(); void registerTestInterfaces(); void registerTestLinalgCodegenStrategy(); @@ -67,85 +78,78 @@ void registerTestLinalgTransforms(); void registerTestLivenessPass(); void registerTestLoopFusion(); void registerTestLoopMappingPass(); -void registerTestLoopPermutationPass(); void registerTestLoopUnrollingPass(); -void registerTestMatchers(); void registerTestMemRefDependenceCheck(); void registerTestMemRefStrideCalculation(); void registerTestOpaqueLoc(); void registerTestPreparationPassWithAllowedMemrefResults(); -void registerTestPrintDefUsePass(); -void registerTestPrintNestingPass(); void registerTestRecursiveTypesPass(); -void registerTestReducer(); -void registerTestSpirvEntryPointABIPass(); -void registerTestSpirvModuleCombinerPass(); void registerTestSCFUtilsPass(); -void registerTestTraitsPass(); void registerTestVectorConversions(); -void registerVectorizerTestPass(); +} // namespace test } // namespace mlir #ifdef MLIR_INCLUDE_TESTS void registerTestPasses() { - registerConvertCallOpPass(); registerConvertToTargetEnvPass(); - registerInliner(); - registerMemRefBoundCheck(); registerPassManagerTestPass(); - registerPatternsTestPass(); registerPrintOpAvailabilityPass(); registerSideEffectTestPasses(); - registerSimpleParametricTilingPass(); registerSliceAnalysisTestPass(); registerSymbolTestPasses(); registerTestAffineDataCopyPass(); - registerTestAllReduceLoweringPass(); registerTestAffineLoopUnswitchingPass(); - registerTestLoopPermutationPass(); - registerTestCallGraphPass(); - registerTestConvVectorization(); - registerTestConstantFold(); -#if MLIR_CUDA_CONVERSIONS_ENABLED - registerTestConvertGPUKernelToCubinPass(); -#endif -#if MLIR_ROCM_CONVERSIONS_ENABLED - registerTestConvertGPUKernelToHsacoPass(); -#endif - registerTestAffineLoopParametricTilingPass(); - registerTestDominancePass(); - registerTestDynamicPipelinePass(); - registerTestFinalizingBufferizePass(); + registerTestAllReduceLoweringPass(); registerTestFunc(); - registerTestExpandTanhPass(); - registerTestExpandMemRefReshapePass(); registerTestGpuMemoryPromotionPass(); - registerTestInterfaces(); - registerTestLinalgCodegenStrategy(); - registerTestLinalgFusionTransforms(); - registerTestLinalgGreedyFusion(); - registerTestLinalgHoisting(); - registerTestLinalgTransforms(); - registerTestLivenessPass(); - registerTestLoopFusion(); - registerTestLoopMappingPass(); - registerTestLoopUnrollingPass(); + registerTestLoopPermutationPass(); registerTestMatchers(); - registerTestMemRefDependenceCheck(); - registerTestMemRefStrideCalculation(); - registerTestOpaqueLoc(); - registerTestPreparationPassWithAllowedMemrefResults(); registerTestPrintDefUsePass(); registerTestPrintNestingPass(); - registerTestRecursiveTypesPass(); registerTestReducer(); - registerTestGpuParallelLoopMappingPass(); registerTestSpirvEntryPointABIPass(); registerTestSpirvModuleCombinerPass(); - registerTestSCFUtilsPass(); registerTestTraitsPass(); - registerTestVectorConversions(); registerVectorizerTestPass(); + + test::registerConvertCallOpPass(); + test::registerInliner(); + test::registerMemRefBoundCheck(); + test::registerPatternsTestPass(); + test::registerSimpleParametricTilingPass(); + test::registerTestAffineLoopParametricTilingPass(); + test::registerTestCallGraphPass(); + test::registerTestConstantFold(); +#if MLIR_CUDA_CONVERSIONS_ENABLED + test::registerTestConvertGPUKernelToCubinPass(); +#endif +#if MLIR_ROCM_CONVERSIONS_ENABLED + test::registerTestConvertGPUKernelToHsacoPass(); +#endif + test::registerTestConvVectorization(); + test::registerTestDominancePass(); + test::registerTestDynamicPipelinePass(); + test::registerTestExpandMemRefReshapePass(); + test::registerTestExpandTanhPass(); + test::registerTestFinalizingBufferizePass(); + test::registerTestGpuParallelLoopMappingPass(); + test::registerTestInterfaces(); + test::registerTestLinalgCodegenStrategy(); + test::registerTestLinalgFusionTransforms(); + test::registerTestLinalgGreedyFusion(); + test::registerTestLinalgHoisting(); + test::registerTestLinalgTransforms(); + test::registerTestLivenessPass(); + test::registerTestLoopFusion(); + test::registerTestLoopMappingPass(); + test::registerTestLoopUnrollingPass(); + test::registerTestMemRefDependenceCheck(); + test::registerTestMemRefStrideCalculation(); + test::registerTestOpaqueLoc(); + test::registerTestPreparationPassWithAllowedMemrefResults(); + test::registerTestRecursiveTypesPass(); + test::registerTestSCFUtilsPass(); + test::registerTestVectorConversions(); } #endif @@ -157,7 +161,7 @@ int main(int argc, char **argv) { DialectRegistry registry; registerAllDialects(registry); #ifdef MLIR_INCLUDE_TESTS - registerTestDialect(registry); + test::registerTestDialect(registry); #endif return failed(MlirOptMain(argc, argv, "MLIR modular optimizer driver\n", registry, -- 2.7.4