diff --git a/mlir/examples/toy/Ch5/CMakeLists.txt b/mlir/examples/toy/Ch5/CMakeLists.txt --- a/mlir/examples/toy/Ch5/CMakeLists.txt +++ b/mlir/examples/toy/Ch5/CMakeLists.txt @@ -27,15 +27,10 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) target_link_libraries(toyc-ch5 PRIVATE - MLIRAffineOps + MLIRAllDialects MLIRAnalysis MLIRIR MLIRParser MLIRPass - MLIRStandardOps MLIRTransforms) -whole_archive_link(toyc-ch5 - MLIRAffineOps - MLIRStandardOps - ) diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -18,6 +18,7 @@ #include "mlir/Analysis/Verifier.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Module.h" +#include "mlir/InitAllDialects.h" #include "mlir/Parser.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" @@ -171,6 +172,7 @@ } int main(int argc, char **argv) { + mlir::registerAllDialects(); mlir::registerPassManagerCLOptions(); cl::ParseCommandLineOptions(argc, argv, "toy compiler\n"); diff --git a/mlir/examples/toy/Ch6/CMakeLists.txt b/mlir/examples/toy/Ch6/CMakeLists.txt --- a/mlir/examples/toy/Ch6/CMakeLists.txt +++ b/mlir/examples/toy/Ch6/CMakeLists.txt @@ -29,7 +29,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) target_link_libraries(toyc-ch6 PRIVATE - MLIRAffineOps + MLIRAllDialects MLIRAffineToStandard MLIRAnalysis MLIRExecutionEngine @@ -38,15 +38,8 @@ MLIRLoopToStandard MLIRParser MLIRPass - MLIRStandardOps MLIRStandardToLLVM MLIRTargetLLVMIR MLIRTransforms ) -whole_archive_link(toyc-ch6 - MLIRAffineToStandard - MLIRAffineOps - MLIRLLVMIR - MLIRStandardOps - ) diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp --- a/mlir/examples/toy/Ch6/toyc.cpp +++ b/mlir/examples/toy/Ch6/toyc.cpp @@ -20,6 +20,7 @@ #include "mlir/ExecutionEngine/OptUtils.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Module.h" +#include "mlir/InitAllDialects.h" #include "mlir/Parser.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" @@ -238,6 +239,7 @@ } int main(int argc, char **argv) { + mlir::registerAllDialects(); mlir::registerPassManagerCLOptions(); cl::ParseCommandLineOptions(argc, argv, "toy compiler\n"); diff --git a/mlir/examples/toy/Ch7/CMakeLists.txt b/mlir/examples/toy/Ch7/CMakeLists.txt --- a/mlir/examples/toy/Ch7/CMakeLists.txt +++ b/mlir/examples/toy/Ch7/CMakeLists.txt @@ -29,24 +29,15 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) target_link_libraries(toyc-ch7 PRIVATE - MLIRAffineOps + MLIRAllDialects MLIRAffineToStandard MLIRAnalysis MLIRExecutionEngine MLIRIR - MLIRLLVMIR MLIRLoopToStandard MLIRParser MLIRPass - MLIRStandardOps MLIRStandardToLLVM MLIRTargetLLVMIR MLIRTransforms ) - -whole_archive_link(toyc-ch7 - MLIRAffineToStandard - MLIRAffineOps - MLIRLLVMIR - MLIRStandardOps - ) diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp --- a/mlir/examples/toy/Ch7/toyc.cpp +++ b/mlir/examples/toy/Ch7/toyc.cpp @@ -20,6 +20,7 @@ #include "mlir/ExecutionEngine/OptUtils.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Module.h" +#include "mlir/InitAllDialects.h" #include "mlir/Parser.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" @@ -239,6 +240,7 @@ } int main(int argc, char **argv) { + mlir::registerAllDialects(); mlir::registerPassManagerCLOptions(); cl::ParseCommandLineOptions(argc, argv, "toy compiler\n"); diff --git a/mlir/include/mlir/Analysis/Passes.h b/mlir/include/mlir/Analysis/Passes.h --- a/mlir/include/mlir/Analysis/Passes.h +++ b/mlir/include/mlir/Analysis/Passes.h @@ -28,9 +28,6 @@ /// Creates a pass to check memref access dependences in a Function. std::unique_ptr> createTestMemRefDependenceCheckPass(); -/// Creates a pass to test parallelism detection; emits note for parallel loops. -std::unique_ptr> createParallelismDetectionTestPass(); - } // end namespace mlir #endif // MLIR_ANALYSIS_PASSES_H diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/InitAllDialects.h @@ -0,0 +1,59 @@ +//===- InitAllDialects.h - MLIR Dialects Registration -----------*- C++ -*-===// +// +// 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 helper to trigger the registration of all dialects and +// passes to the system. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_INITALLDIALECTS_H_ +#define MLIR_INITALLDIALECTS_H_ + +#include "mlir/Dialect/AffineOps/AffineOps.h" +#include "mlir/Dialect/FxpMathOps/FxpMathOps.h" +#include "mlir/Dialect/GPU/GPUDialect.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/Dialect/LLVMIR/NVVMDialect.h" +#include "mlir/Dialect/LLVMIR/ROCDLDialect.h" +#include "mlir/Dialect/Linalg/IR/LinalgOps.h" +#include "mlir/Dialect/LoopOps/LoopOps.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/Dialect/QuantOps/QuantOps.h" +#include "mlir/Dialect/SDBM/SDBMDialect.h" +#include "mlir/Dialect/SPIRV/SPIRVDialect.h" +#include "mlir/Dialect/StandardOps/Ops.h" +#include "mlir/Dialect/VectorOps/VectorOps.h" +#include "mlir/IR/Dialect.h" + +namespace mlir { + +// This function should be called before creating any MLIRContext if one expect +// all the possible dialects to be made available to the context automatically. +inline void registerAllDialects() { + static bool init_once = []() { + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + return true; + }(); + (void)init_once; +} +} // namespace mlir + +#endif // MLIR_INITALLDIALECTS_H_ diff --git a/mlir/include/mlir/InitAllPasses.h b/mlir/include/mlir/InitAllPasses.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/InitAllPasses.h @@ -0,0 +1,124 @@ +//===- LinkAllPassesAndDialects.h - MLIR Registration -----------*- C++ -*-===// +// +// 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 helper to trigger the registration of all dialects and +// passes to the system. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_INITALLPASSES_H_ +#define MLIR_INITALLPASSES_H_ + +#include "mlir/Analysis/Passes.h" +#include "mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h" +#include "mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h" +#include "mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h" +#include "mlir/Conversion/GPUToSPIRV/ConvertGPUToSPIRVPass.h" +#include "mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h" +#include "mlir/Conversion/LinalgToSPIRV/LinalgToSPIRVPass.h" +#include "mlir/Conversion/LoopsToGPU/LoopsToGPUPass.h" +#include "mlir/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.h" +#include "mlir/Dialect/FxpMathOps/Passes.h" +#include "mlir/Dialect/GPU/Passes.h" +#include "mlir/Dialect/Linalg/Passes.h" +#include "mlir/Dialect/QuantOps/Passes.h" +#include "mlir/Dialect/SPIRV/Passes.h" +#include "mlir/Quantizer/Transforms/Passes.h" +#include "mlir/Transforms/LocationSnapshot.h" +#include "mlir/Transforms/Passes.h" + +#include + +namespace mlir { + +// This function may be called to register the MLIR passes with the +// global registry. +// If you're building a compiler, you likely don't need this: you would build a +// pipeline programmatically without the need to register with the global +// registry, since it would already be calling the creation routine of the +// individual passes. +// The global registry is interesting to interact with the command-line tools. +inline void registerAllPasses() { + // At the moment we still rely on global initializers for registering passes, + // but we may not do it in the future. + // We must reference the passes in such a way that compilers will not + // delete it all as dead code, even with whole program optimization, + // yet is effectively a NO-OP. As the compiler isn't smart enough + // to know that getenv() never returns -1, this will do the job. + if (std::getenv("bar") != (char *)-1) + return; + + // Init general passes + createCanonicalizerPass(); + createCSEPass(); + createVectorizePass({}); + createLoopUnrollPass(); + createLoopUnrollAndJamPass(); + createSimplifyAffineStructuresPass(); + createLoopFusionPass(); + createLoopInvariantCodeMotionPass(); + createAffineLoopInvariantCodeMotionPass(); + createPipelineDataTransferPass(); + createLowerAffinePass(); + createLoopTilingPass(0); + createLoopCoalescingPass(); + createAffineDataCopyGenerationPass(0, 0); + createMemRefDataFlowOptPass(); + createStripDebugInfoPass(); + createPrintOpStatsPass(); + createInlinerPass(); + createSymbolDCEPass(); + createLocationSnapshotPass({}); + + // GPUtoRODCLPass + createLowerGpuOpsToROCDLOpsPass(); + + // FxpOpsDialect passes + fxpmath::createLowerUniformRealMathPass(); + fxpmath::createLowerUniformCastsPass(); + + // GPU + createGpuKernelOutliningPass(); + createSimpleLoopsToGPUPass(0, 0); + createLoopToGPUPass({}, {}); + + // CUDA + createConvertGpuLaunchFuncToCudaCallsPass(); + createConvertGPUKernelToCubinPass( + [](const std::string &, Location, StringRef) { return nullptr; }); + createLowerGpuOpsToNVVMOpsPass(); + + // Linalg + createLinalgFusionPass(); + createLinalgTilingPass(); + createLinalgTilingToParallelLoopsPass(); + createLinalgPromotionPass(0); + createConvertLinalgToLoopsPass(); + createConvertLinalgToParallelLoopsPass(); + createConvertLinalgToAffineLoopsPass(); + createConvertLinalgToLLVMPass(); + + // QuantOps + quant::createConvertSimulatedQuantPass(); + quant::createConvertConstPass(); + quantizer::createAddDefaultStatsPass(); + quantizer::createRemoveInstrumentationPass(); + quantizer::registerInferQuantizedTypesPass(); + + // SPIR-V + spirv::createDecorateSPIRVCompositeTypeLayoutPass(); + spirv::createLowerABIAttributesPass(); + createConvertGPUToSPIRVPass(); + createConvertStandardToSPIRVPass(); + createLegalizeStdOpsForSPIRVLoweringPass(); + createLinalgToSPIRVPass(); +} + +} // namespace mlir + +#endif // MLIR_INITALLPASSES_H_ diff --git a/mlir/include/mlir/Quantizer/Transforms/Passes.h b/mlir/include/mlir/Quantizer/Transforms/Passes.h --- a/mlir/include/mlir/Quantizer/Transforms/Passes.h +++ b/mlir/include/mlir/Quantizer/Transforms/Passes.h @@ -28,6 +28,9 @@ createInferQuantizedTypesPass(SolverContext &solverContext, const TargetConfiguration &config); +/// Registers the InferQuantizedTypes pass with the global registry. +void registerInferQuantizedTypesPass(); + /// Creates a pass which removes any instrumentation and hint ops which have /// no effect on final runtime. std::unique_ptr> createRemoveInstrumentationPass(); diff --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h --- a/mlir/include/mlir/Transforms/Passes.h +++ b/mlir/include/mlir/Transforms/Passes.h @@ -37,10 +37,6 @@ std::unique_ptr> createVectorizePass(ArrayRef virtualVectorSize); -/// Creates a pass to allow independent testing of vectorizer functionality with -/// FileCheck. -std::unique_ptr> createVectorizerTestPass(); - /// Creates a loop unrolling pass with the provided parameters. /// 'getUnrollFactor' is a function callback for clients to supply a function /// that computes an unroll factor - the callback takes precedence over unroll @@ -91,12 +87,6 @@ std::unique_ptr> createLoopTilingPass(uint64_t cacheSizeBytes); -/// Creates a pass that performs parametric tiling so that the outermost loops -/// have the given fixed number of iterations. Assumes outermost loop nests -/// are permutable. -std::unique_ptr> -createSimpleParametricTilingPass(ArrayRef outerLoopSizes); - /// Creates a pass that transforms perfectly nested loops with independent /// bounds into a single loop. std::unique_ptr> createLoopCoalescingPass(); @@ -116,11 +106,12 @@ /// Creates a pass to strip debug information from a function. std::unique_ptr createStripDebugInfoPass(); -/// Creates a pass which tests loop fusion utilities. -std::unique_ptr> createTestLoopFusionPass(); +/// Creates a pass which prints the list of ops and the number of occurences in +/// the module. +std::unique_ptr> createPrintOpStatsPass(); -/// Creates a pass which inlines calls and callable operations as defined by the -/// CallGraph. +/// Creates a pass which inlines calls and callable operations as defined by +/// the CallGraph. std::unique_ptr createInlinerPass(); /// Creates a pass which delete symbol operations that are unreachable. This diff --git a/mlir/lib/Dialect/AffineOps/CMakeLists.txt b/mlir/lib/Dialect/AffineOps/CMakeLists.txt --- a/mlir/lib/Dialect/AffineOps/CMakeLists.txt +++ b/mlir/lib/Dialect/AffineOps/CMakeLists.txt @@ -1,9 +1,8 @@ add_llvm_library(MLIRAffineOps AffineOps.cpp AffineValueMap.cpp - DialectRegistration.cpp EDSC/Builders.cpp - + ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/AffineOps ) diff --git a/mlir/lib/Dialect/AffineOps/DialectRegistration.cpp b/mlir/lib/Dialect/AffineOps/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/AffineOps/DialectRegistration.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===- DialectRegistration.cpp - Register Affine Op 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/AffineOps/AffineOps.h" -using namespace mlir; - -// Static initialization for Affine op dialect registration. -static DialectRegistration StandardOps; diff --git a/mlir/lib/Dialect/CMakeLists.txt b/mlir/lib/Dialect/CMakeLists.txt --- a/mlir/lib/Dialect/CMakeLists.txt +++ b/mlir/lib/Dialect/CMakeLists.txt @@ -12,6 +12,11 @@ add_subdirectory(StandardOps) add_subdirectory(VectorOps) + +set(LLVM_OPTIONAL_SOURCES + Traits.cpp +) + add_llvm_library(MLIRDialect Traits.cpp @@ -19,3 +24,29 @@ ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect ) target_link_libraries(MLIRDialect MLIRIR) + +# Create a dummy MLIRAllDialects library for the purpose +# of having an easy tracking of all dialects when linking +# them in tools. +# Empty libraries aren't possible with CMake, create a dummy file. +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/all_dialects.c "typedef int make_iso_compilers_happy;\n") +add_llvm_library(MLIRAllDialects + ${CMAKE_CURRENT_BINARY_DIR}/all_dialects.c +) +target_link_libraries(MLIRAllDialects + MLIRAffineOps + MLIRFxpMathOps + MLIRGPU + MLIRLLVMIR + MLIRNVVMIR + MLIRROCDLIR + MLIRLinalgOps + MLIRLoopOps + MLIROpenMP + MLIRQuantOps + MLIRSDBM + MLIRShape + MLIRSPIRV + MLIRStandardOps + MLIRVectorOps +) diff --git a/mlir/lib/Dialect/FxpMathOps/CMakeLists.txt b/mlir/lib/Dialect/FxpMathOps/CMakeLists.txt --- a/mlir/lib/Dialect/FxpMathOps/CMakeLists.txt +++ b/mlir/lib/Dialect/FxpMathOps/CMakeLists.txt @@ -1,6 +1,5 @@ add_llvm_library(MLIRFxpMathOps IR/FxpMathOps.cpp - IR/DialectRegistration.cpp Transforms/LowerUniformRealMath.cpp ADDITIONAL_HEADER_DIRS diff --git a/mlir/lib/Dialect/FxpMathOps/IR/DialectRegistration.cpp b/mlir/lib/Dialect/FxpMathOps/IR/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/FxpMathOps/IR/DialectRegistration.cpp +++ /dev/null @@ -1,15 +0,0 @@ -//===- DialectRegistration.cpp - Register FxpMathOps 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/FxpMathOps/FxpMathOps.h" - -using namespace mlir; -using namespace mlir::fxpmath; - -// Static initialization for the fxpmath ops dialect registration. -static mlir::DialectRegistration FxpMathOps; diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt --- a/mlir/lib/Dialect/GPU/CMakeLists.txt +++ b/mlir/lib/Dialect/GPU/CMakeLists.txt @@ -1,6 +1,5 @@ add_llvm_library(MLIRGPU IR/GPUDialect.cpp - IR/DialectRegistration.cpp Transforms/AllReduceLowering.cpp Transforms/KernelOutlining.cpp Transforms/MemoryPromotion.cpp diff --git a/mlir/lib/Dialect/GPU/IR/DialectRegistration.cpp b/mlir/lib/Dialect/GPU/IR/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/GPU/IR/DialectRegistration.cpp +++ /dev/null @@ -1,12 +0,0 @@ -//===- DialectRegistration.cpp - MLIR GPU dialect registration ------------===// -// -// 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/GPU/GPUDialect.h" - -// Static initialization for GPU dialect registration. -static mlir::DialectRegistration kernelDialect; diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1658,8 +1658,6 @@ return success(); } -static DialectRegistration llvmDialect; - //===----------------------------------------------------------------------===// // LLVMType. //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -159,4 +159,3 @@ } // namespace NVVM } // namespace mlir -static DialectRegistration nvvmDialect; diff --git a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp @@ -52,4 +52,3 @@ } // namespace ROCDL } // namespace mlir -static DialectRegistration rocdlDialect; diff --git a/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt b/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt --- a/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt +++ b/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt @@ -7,7 +7,6 @@ add_llvm_library(MLIRLinalgOps LinalgOps.cpp LinalgTypes.cpp - LinalgRegistration.cpp ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Linalg diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgRegistration.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgRegistration.cpp +++ /dev/null @@ -1,16 +0,0 @@ -//===- LinalgRegistration.cpp - Register the linalg dialect statically ----===// -// -// 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/Linalg/IR/LinalgOps.h" -#include "mlir/Dialect/Linalg/IR/LinalgTypes.h" - -using namespace mlir; -using namespace mlir::linalg; - -// Static initialization for LinalgOps dialect registration. -static DialectRegistration LinalgOps; diff --git a/mlir/lib/Dialect/LoopOps/DialectRegistration.cpp b/mlir/lib/Dialect/LoopOps/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/LoopOps/DialectRegistration.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===- DialectRegistration.cpp - Register loop 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/LoopOps/LoopOps.h" -using namespace mlir; - -// Static initialization for loop dialect registration. -static DialectRegistration LoopOps; diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -30,5 +30,3 @@ #include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" } // namespace omp } // namespace mlir - -static DialectRegistration ompDialect; diff --git a/mlir/lib/Dialect/QuantOps/CMakeLists.txt b/mlir/lib/Dialect/QuantOps/CMakeLists.txt --- a/mlir/lib/Dialect/QuantOps/CMakeLists.txt +++ b/mlir/lib/Dialect/QuantOps/CMakeLists.txt @@ -1,5 +1,4 @@ add_llvm_library(MLIRQuantOps - IR/DialectRegistration.cpp IR/QuantOps.cpp IR/QuantTypes.cpp IR/TypeDetail.h diff --git a/mlir/lib/Dialect/QuantOps/IR/DialectRegistration.cpp b/mlir/lib/Dialect/QuantOps/IR/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/QuantOps/IR/DialectRegistration.cpp +++ /dev/null @@ -1,15 +0,0 @@ -//===- DialectRegistration.cpp - Register Quantization 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/QuantOps/QuantOps.h" - -using namespace mlir; -using namespace mlir::quant; - -// Static initialization for Quantization dialect registration. -static mlir::DialectRegistration QuantizationOps; diff --git a/mlir/lib/Dialect/SDBM/CMakeLists.txt b/mlir/lib/Dialect/SDBM/CMakeLists.txt --- a/mlir/lib/Dialect/SDBM/CMakeLists.txt +++ b/mlir/lib/Dialect/SDBM/CMakeLists.txt @@ -1,7 +1,6 @@ add_llvm_library(MLIRSDBM SDBM.cpp SDBMExpr.cpp - SDBMDialect.cpp ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SDBM diff --git a/mlir/lib/Dialect/SDBM/SDBMDialect.cpp b/mlir/lib/Dialect/SDBM/SDBMDialect.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/SDBM/SDBMDialect.cpp +++ /dev/null @@ -1,11 +0,0 @@ -//===- SDBMDialect.cpp - Dialect for striped difference-bound matrices ----===// -// -// 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/SDBM/SDBMDialect.h" - -static mlir::DialectRegistration SDBMDialect; diff --git a/mlir/lib/Dialect/SPIRV/CMakeLists.txt b/mlir/lib/Dialect/SPIRV/CMakeLists.txt --- a/mlir/lib/Dialect/SPIRV/CMakeLists.txt +++ b/mlir/lib/Dialect/SPIRV/CMakeLists.txt @@ -3,7 +3,6 @@ add_public_tablegen_target(MLIRSPIRVCanonicalizationIncGen) add_llvm_library(MLIRSPIRV - DialectRegistration.cpp LayoutUtils.cpp SPIRVDialect.cpp SPIRVOps.cpp diff --git a/mlir/lib/Dialect/SPIRV/DialectRegistration.cpp b/mlir/lib/Dialect/SPIRV/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/SPIRV/DialectRegistration.cpp +++ /dev/null @@ -1,12 +0,0 @@ -//===- DialectRegistration.cpp - MLIR SPIR-V dialect registration ---------===// -// -// 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/SPIRV/SPIRVDialect.h" - -// Static initialization for SPIR-V dialect registration. -static mlir::DialectRegistration spirvDialect; diff --git a/mlir/lib/Dialect/StandardOps/DialectRegistration.cpp b/mlir/lib/Dialect/StandardOps/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/StandardOps/DialectRegistration.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===- DialectRegistration.cpp - Register standard Op 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/StandardOps/Ops.h" -using namespace mlir; - -// Static initialization for standard op dialect registration. -static DialectRegistration StandardOps; diff --git a/mlir/lib/Dialect/VectorOps/CMakeLists.txt b/mlir/lib/Dialect/VectorOps/CMakeLists.txt --- a/mlir/lib/Dialect/VectorOps/CMakeLists.txt +++ b/mlir/lib/Dialect/VectorOps/CMakeLists.txt @@ -1,5 +1,4 @@ add_llvm_library(MLIRVectorOps - DialectRegistration.cpp VectorOps.cpp VectorTransforms.cpp VectorUtils.cpp diff --git a/mlir/lib/Dialect/VectorOps/DialectRegistration.cpp b/mlir/lib/Dialect/VectorOps/DialectRegistration.cpp deleted file mode 100644 --- a/mlir/lib/Dialect/VectorOps/DialectRegistration.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===- DialectRegistration.cpp - Register super vectorization 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/VectorOps/VectorOps.h" -using namespace mlir; - -// Static initialization for VectorOps dialect registration. -static DialectRegistration VectorOps; diff --git a/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp b/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp --- a/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp +++ b/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp @@ -282,6 +282,11 @@ SolverContext &solverContext, const TargetConfiguration &config) { return std::make_unique(solverContext, config); } +void mlir::quantizer::registerInferQuantizedTypesPass() { + // Do nothing, this will be enough to force link this file and the static + // registration will kick-in. This is temporary while we're refactoring pass + // registration to move away from static constructors. +} static PassRegistration pass("quantizer-infer-quantized-types", diff --git a/mlir/lib/Support/JitRunner.cpp b/mlir/lib/Support/JitRunner.cpp --- a/mlir/lib/Support/JitRunner.cpp +++ b/mlir/lib/Support/JitRunner.cpp @@ -22,6 +22,7 @@ #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Module.h" #include "mlir/IR/StandardTypes.h" +#include "mlir/InitAllDialects.h" #include "mlir/Parser.h" #include "mlir/Support/FileUtilities.h" @@ -209,6 +210,7 @@ int mlir::JitRunnerMain( int argc, char **argv, function_ref mlirTransformer) { + registerAllDialects(); llvm::InitLLVM y(argc, argv); initializeLLVM(); diff --git a/mlir/lib/Transforms/OpStats.cpp b/mlir/lib/Transforms/OpStats.cpp --- a/mlir/lib/Transforms/OpStats.cpp +++ b/mlir/lib/Transforms/OpStats.cpp @@ -10,6 +10,7 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/OperationSupport.h" #include "mlir/Pass/Pass.h" +#include "mlir/Transforms/Passes.h" #include "llvm/ADT/DenseMap.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" @@ -80,5 +81,9 @@ } } +std::unique_ptr> mlir::createPrintOpStatsPass() { + return std::make_unique(); +} + static PassRegistration pass("print-op-stats", "Print statistics of operations"); diff --git a/mlir/test/Dialect/SPIRV/TestAvailability.cpp b/mlir/test/Dialect/SPIRV/TestAvailability.cpp --- a/mlir/test/Dialect/SPIRV/TestAvailability.cpp +++ b/mlir/test/Dialect/SPIRV/TestAvailability.cpp @@ -213,6 +213,9 @@ return matchSuccess(); } -static PassRegistration - convertToTargetEnvPass("test-spirv-target-env", - "Test SPIR-V target environment"); +namespace mlir { +void registerConvertToTargetEnvPass() { + PassRegistration convertToTargetEnvPass( + "test-spirv-target-env", "Test SPIR-V target environment"); +} +} // namespace mlir diff --git a/mlir/test/EDSC/builder-api-test.cpp b/mlir/test/EDSC/builder-api-test.cpp --- a/mlir/test/EDSC/builder-api-test.cpp +++ b/mlir/test/EDSC/builder-api-test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// RUN: mlir-edsc-builder-api-test | FileCheck %s +// RUN: mlir-edsc-builder-api-test | FileCheck %s -dump-input-on-failure #include "mlir/Dialect/AffineOps/EDSC/Intrinsics.h" #include "mlir/Dialect/Linalg/EDSC/Intrinsics.h" @@ -37,6 +37,15 @@ using namespace mlir::edsc::intrinsics; static MLIRContext &globalContext() { + static bool init_once = []() { + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + return true; + }(); + (void)init_once; static thread_local MLIRContext context; return context; } diff --git a/mlir/test/SDBM/sdbm-api-test.cpp b/mlir/test/SDBM/sdbm-api-test.cpp --- a/mlir/test/SDBM/sdbm-api-test.cpp +++ b/mlir/test/SDBM/sdbm-api-test.cpp @@ -19,6 +19,9 @@ using namespace mlir; +// Load the SDBM dialect +static DialectRegistration SDBMRegistration; + static MLIRContext *ctx() { static thread_local MLIRContext context; return &context; 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 @@ -51,8 +51,12 @@ }; } // end anonymous namespace -static PassRegistration pass("test-func-erase-arg", - "Test erasing func args."); - -static PassRegistration pass2("test-func-set-type", - "Test FuncOp::setType."); +namespace mlir { +void registerTestFunc() { + PassRegistration pass("test-func-erase-arg", + "Test erasing func args."); + + PassRegistration pass2("test-func-set-type", + "Test FuncOp::setType."); +} +} // namespace mlir 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 @@ -146,5 +146,8 @@ test2(f); } -static PassRegistration pass("test-matchers", - "Test C++ pattern matchers."); +namespace mlir { +void registerTestMatchers() { + PassRegistration("test-matchers", "Test C++ pattern matchers."); +} +} // namespace mlir diff --git a/mlir/test/lib/IR/TestSymbolUses.cpp b/mlir/test/lib/IR/TestSymbolUses.cpp --- a/mlir/test/lib/IR/TestSymbolUses.cpp +++ b/mlir/test/lib/IR/TestSymbolUses.cpp @@ -103,8 +103,12 @@ }; } // end anonymous namespace -static PassRegistration pass("test-symbol-uses", - "Test detection of symbol uses"); +namespace mlir { +void registerSymbolTestPasses() { + PassRegistration("test-symbol-uses", + "Test detection of symbol uses"); -static PassRegistration - rauwPass("test-symbol-rauw", "Test replacement of symbol uses"); + PassRegistration("test-symbol-rauw", + "Test replacement of symbol uses"); +} +} // namespace mlir diff --git a/mlir/test/lib/Pass/TestPassManager.cpp b/mlir/test/lib/Pass/TestPassManager.cpp --- a/mlir/test/lib/Pass/TestPassManager.cpp +++ b/mlir/test/lib/Pass/TestPassManager.cpp @@ -88,40 +88,43 @@ (void)parsePassPipeline("test-pm-nested-pipeline", pm); } -static PassRegistration - reg("test-options-pass", "Test options parsing capabilities"); - -static PassRegistration - unusedMP("test-module-pass", "Test a module pass in the pass manager"); -static PassRegistration - unusedFP("test-function-pass", "Test a function pass in the pass manager"); - -static PassRegistration - unusedCrashP("test-pass-crash", - "Test a pass in the pass manager that always crashes"); - -static PassRegistration unusedStatP("test-stats-pass", - "Test pass statistics"); - -static PassPipelineRegistration<> - unused("test-pm-nested-pipeline", - "Test a nested pipeline in the pass manager", testNestedPipeline); -static PassPipelineRegistration<> - unusedTextual("test-textual-pm-nested-pipeline", - "Test a nested pipeline in the pass manager", - testNestedPipelineTextual); -static PassPipelineRegistration<> - unusedDump("test-dump-pipeline", - "Dumps the pipeline build so far for debugging purposes", - [](OpPassManager &pm) { - pm.printAsTextualPipeline(llvm::errs()); - llvm::errs() << "\n"; - }); - -static PassPipelineRegistration - registerOptionsPassPipeline( - "test-options-pass-pipeline", - "Parses options using pass pipeline registration", - [](OpPassManager &pm, const TestOptionsPass::Options &options) { - pm.addPass(std::make_unique(options)); - }); +namespace mlir { +void registerPassManagerTestPass() { + PassRegistration("test-options-pass", + "Test options parsing capabilities"); + + PassRegistration("test-module-pass", + "Test a module pass in the pass manager"); + + PassRegistration( + "test-function-pass", "Test a function pass in the pass manager"); + + PassRegistration( + "test-pass-crash", "Test a pass in the pass manager that always crashes"); + + PassRegistration unusedStatP("test-stats-pass", + "Test pass statistics"); + + PassPipelineRegistration<>("test-pm-nested-pipeline", + "Test a nested pipeline in the pass manager", + testNestedPipeline); + PassPipelineRegistration<>("test-textual-pm-nested-pipeline", + "Test a nested pipeline in the pass manager", + testNestedPipelineTextual); + PassPipelineRegistration<>( + "test-dump-pipeline", + "Dumps the pipeline build so far for debugging purposes", + [](OpPassManager &pm) { + pm.printAsTextualPipeline(llvm::errs()); + llvm::errs() << "\n"; + }); + + PassPipelineRegistration + registerOptionsPassPipeline( + "test-options-pass-pipeline", + "Parses options using pass pipeline registration", + [](OpPassManager &pm, const TestOptionsPass::Options &options) { + pm.addPass(std::make_unique(options)); + }); +} +} // namespace mlir diff --git a/mlir/test/lib/TestDialect/TestPatterns.cpp b/mlir/test/lib/TestDialect/TestPatterns.cpp --- a/mlir/test/lib/TestDialect/TestPatterns.cpp +++ b/mlir/test/lib/TestDialect/TestPatterns.cpp @@ -50,9 +50,6 @@ }; } // end anonymous namespace -static mlir::PassRegistration - pass("test-patterns", "Run test dialect patterns"); - //===----------------------------------------------------------------------===// // ReturnType Driver. //===----------------------------------------------------------------------===// @@ -107,9 +104,6 @@ }; } // end anonymous namespace -static mlir::PassRegistration - rt_pass("test-return-type", "Run return type functions"); - //===----------------------------------------------------------------------===// // Legalization Driver. //===----------------------------------------------------------------------===// @@ -440,13 +434,6 @@ clEnumValN(TestLegalizePatternDriver::ConversionMode::Partial, "partial", "Perform a partial conversion"))); -static mlir::PassRegistration - legalizer_pass("test-legalize-patterns", - "Run test dialect legalization patterns", [] { - return std::make_unique( - legalizerConversionMode); - }); - //===----------------------------------------------------------------------===// // ConversionPatternRewriter::getRemappedValue testing. This method is used // to get the remapped value of a original value that was replaced using @@ -505,6 +492,22 @@ }; } // end anonymous namespace -static PassRegistration remapped_value_pass( - "test-remapped-value", - "Test public remapped value mechanism in ConversionPatternRewriter"); +namespace mlir { +void registerPatternsTestPass() { + mlir::PassRegistration("test-return-type", + "Run return type functions"); + + mlir::PassRegistration("test-patterns", + "Run test dialect patterns"); + + mlir::PassRegistration( + "test-legalize-patterns", "Run test dialect legalization patterns", [] { + return std::make_unique( + legalizerConversionMode); + }); + + PassRegistration( + "test-remapped-value", + "Test public remapped value mechanism in ConversionPatternRewriter"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestAllReduceLowering.cpp b/mlir/test/lib/Transforms/TestAllReduceLowering.cpp --- a/mlir/test/lib/Transforms/TestAllReduceLowering.cpp +++ b/mlir/test/lib/Transforms/TestAllReduceLowering.cpp @@ -27,6 +27,10 @@ }; } // namespace -static PassRegistration - pass("test-all-reduce-lowering", - "Lowers gpu.all-reduce ops within the GPU dialect."); +namespace mlir { +void registerTestAllReduceLoweringPass() { + PassRegistration pass( + "test-all-reduce-lowering", + "Lowers gpu.all-reduce ops within the GPU dialect."); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestCallGraph.cpp b/mlir/test/lib/Transforms/TestCallGraph.cpp --- a/mlir/test/lib/Transforms/TestCallGraph.cpp +++ b/mlir/test/lib/Transforms/TestCallGraph.cpp @@ -25,6 +25,9 @@ }; } // end anonymous namespace -static PassRegistration - pass("test-print-callgraph", - "Print the contents of a constructed callgraph."); +namespace mlir { +void registerTestCallGraphPass() { + PassRegistration pass( + "test-print-callgraph", "Print the contents of a constructed callgraph."); +} +} // namespace mlir 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 @@ -64,5 +64,9 @@ } } -static PassRegistration - pass("test-constant-fold", "Test operation constant folding"); +namespace mlir { +void registerTestConstantFold() { + PassRegistration("test-constant-fold", + "Test operation constant folding"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestGpuMemoryPromotion.cpp b/mlir/test/lib/Transforms/TestGpuMemoryPromotion.cpp --- a/mlir/test/lib/Transforms/TestGpuMemoryPromotion.cpp +++ b/mlir/test/lib/Transforms/TestGpuMemoryPromotion.cpp @@ -35,6 +35,10 @@ }; } // end namespace -static PassRegistration registration( - "test-gpu-memory-promotion", - "Promotes the annotated arguments of gpu.func to workgroup memory."); +namespace mlir { +void registerTestGpuMemoryPromotionPass() { + PassRegistration( + "test-gpu-memory-promotion", + "Promotes the annotated arguments of gpu.func to workgroup memory."); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestInlining.cpp b/mlir/test/lib/Transforms/TestInlining.cpp --- a/mlir/test/lib/Transforms/TestInlining.cpp +++ b/mlir/test/lib/Transforms/TestInlining.cpp @@ -60,5 +60,8 @@ }; } // end anonymous namespace -static PassRegistration pass("test-inline", - "Test inlining region calls"); +namespace mlir { +void registerInliner() { + PassRegistration("test-inline", "Test inlining region calls"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLinalgTransforms.cpp b/mlir/test/lib/Transforms/TestLinalgTransforms.cpp --- a/mlir/test/lib/Transforms/TestLinalgTransforms.cpp +++ b/mlir/test/lib/Transforms/TestLinalgTransforms.cpp @@ -47,6 +47,10 @@ }); } -static PassRegistration - pass("test-linalg-transform-patterns", - "Test Linalg transformation patterns by applying them greedily."); +namespace mlir { +void registerTestLinalgTransforms() { + PassRegistration( + "test-linalg-transform-patterns", + "Test Linalg transformation patterns by applying them greedily."); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLiveness.cpp b/mlir/test/lib/Transforms/TestLiveness.cpp --- a/mlir/test/lib/Transforms/TestLiveness.cpp +++ b/mlir/test/lib/Transforms/TestLiveness.cpp @@ -28,6 +28,10 @@ } // end anonymous namespace -static PassRegistration - pass("test-print-liveness", - "Print the contents of a constructed liveness information."); +namespace mlir { +void registerTestLivenessPass() { + PassRegistration( + "test-print-liveness", + "Print the contents of a constructed liveness information."); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLoopFusion.cpp b/mlir/test/lib/Transforms/TestLoopFusion.cpp --- a/mlir/test/lib/Transforms/TestLoopFusion.cpp +++ b/mlir/test/lib/Transforms/TestLoopFusion.cpp @@ -54,10 +54,6 @@ } // end anonymous namespace -std::unique_ptr> mlir::createTestLoopFusionPass() { - return std::make_unique(); -} - // Gathers all AffineForOps in 'block' at 'currLoopDepth' in 'depthToLoops'. static void gatherLoops(Block *block, unsigned currLoopDepth, @@ -218,5 +214,9 @@ iterateLoops(depthToLoops, testSliceComputation); } -static PassRegistration - pass("test-loop-fusion", "Tests loop fusion utility functions."); +namespace mlir { +void registerTestLoopFusion() { + PassRegistration("test-loop-fusion", + "Tests loop fusion utility functions."); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLoopMapping.cpp b/mlir/test/lib/Transforms/TestLoopMapping.cpp --- a/mlir/test/lib/Transforms/TestLoopMapping.cpp +++ b/mlir/test/lib/Transforms/TestLoopMapping.cpp @@ -50,7 +50,10 @@ }; } // end namespace -static PassRegistration - reg("test-mapping-to-processing-elements", - "test mapping a single loop on a virtual processor grid", - [] { return std::make_unique(); }); +namespace mlir { +void registerTestLoopMappingPass() { + PassRegistration( + "test-mapping-to-processing-elements", + "test mapping a single loop on a virtual processor grid"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp b/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp --- a/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp +++ b/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp @@ -48,12 +48,11 @@ }; } // end namespace -std::unique_ptr> -mlir::createSimpleParametricTilingPass(ArrayRef outerLoopSizes) { - return std::make_unique(outerLoopSizes); +namespace mlir { +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"); } - -static PassRegistration - reg("test-extract-fixed-outer-loops", - "test application of parametric tiling to the outer loops so that the " - "ranges of outer loops become static"); +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp b/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp --- a/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp +++ b/mlir/test/lib/Transforms/TestMemRefBoundCheck.cpp @@ -48,6 +48,9 @@ }); } -static PassRegistration - memRefBoundCheck("test-memref-bound-check", - "Check memref access bounds in a Function"); +namespace mlir { +void registerMemRefBoundCheck() { + PassRegistration( + "test-memref-bound-check", "Check memref access bounds in a Function"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp b/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp --- a/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp +++ b/mlir/test/lib/Transforms/TestMemRefDependenceCheck.cpp @@ -116,6 +116,10 @@ checkDependences(loadsAndStores); } -static PassRegistration - pass("test-memref-dependence-check", - "Checks dependences between all pairs of memref accesses."); +namespace mlir { +void registerTestMemRefDependenceCheck() { + PassRegistration pass( + "test-memref-dependence-check", + "Checks dependences between all pairs of memref accesses."); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp b/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp --- a/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp +++ b/mlir/test/lib/Transforms/TestMemRefStrideCalculation.cpp @@ -50,5 +50,9 @@ llvm::outs().flush(); } -static PassRegistration - pass("test-memref-stride-calculation", "Test operation constant folding"); +namespace mlir { +void registerTestMemRefStrideCalculation() { + PassRegistration pass( + "test-memref-stride-calculation", "Test operation constant folding"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestOpaqueLoc.cpp b/mlir/test/lib/Transforms/TestOpaqueLoc.cpp --- a/mlir/test/lib/Transforms/TestOpaqueLoc.cpp +++ b/mlir/test/lib/Transforms/TestOpaqueLoc.cpp @@ -80,5 +80,9 @@ } // end anonymous namespace -static PassRegistration - pass("test-opaque-loc", "Changes all leaf locations to opaque locations"); +namespace mlir { +void registerTestOpaqueLoc() { + PassRegistration pass( + "test-opaque-loc", "Changes all leaf locations to opaque locations"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestParallelismDetection.cpp b/mlir/test/lib/Transforms/TestParallelismDetection.cpp --- a/mlir/test/lib/Transforms/TestParallelismDetection.cpp +++ b/mlir/test/lib/Transforms/TestParallelismDetection.cpp @@ -27,9 +27,6 @@ } // end anonymous namespace -std::unique_ptr> mlir::createParallelismDetectionTestPass() { - return std::make_unique(); -} // Walks the function and emits a note for all 'affine.for' ops detected as // parallel. @@ -44,5 +41,9 @@ }); } -static PassRegistration - pass("test-detect-parallel", "Test parallelism detection "); +namespace mlir { +void registerTestParallelismDetection() { + PassRegistration pass( + "test-detect-parallel", "Test parallelism detection "); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp b/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp --- a/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp +++ b/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp @@ -29,6 +29,10 @@ } // end anonymous namespace -static PassRegistration - pass("test-convert-vector-to-loops", - "Converts vector transfer ops to loops over scalars and vector casts"); +namespace mlir { +void registerTestVectorToLoopsPass() { + PassRegistration pass( + "test-convert-vector-to-loops", + "Converts vector transfer ops to loops over scalars and vector casts"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestVectorTransforms.cpp b/mlir/test/lib/Transforms/TestVectorTransforms.cpp --- a/mlir/test/lib/Transforms/TestVectorTransforms.cpp +++ b/mlir/test/lib/Transforms/TestVectorTransforms.cpp @@ -44,10 +44,14 @@ } // end anonymous namespace -static PassRegistration - pass("test-vector-to-vector-conversion", - "Test conversion patterns between ops in the vector dialect"); - -static PassRegistration slices_pass( - "test-vector-slices-conversion", - "Test conversion patterns that lower slices ops in the vector dialect"); +namespace mlir { +void registerTestVectorConversions() { + PassRegistration pass( + "test-vector-to-vector-conversion", + "Test conversion patterns between ops in the vector dialect"); + + PassRegistration slices_pass( + "test-vector-slices-conversion", + "Test conversion patterns that lower slices ops in the vector dialect"); +} +} // namespace mlir diff --git a/mlir/test/lib/Transforms/TestVectorizationUtils.cpp b/mlir/test/lib/Transforms/TestVectorizationUtils.cpp --- a/mlir/test/lib/Transforms/TestVectorizationUtils.cpp +++ b/mlir/test/lib/Transforms/TestVectorizationUtils.cpp @@ -281,12 +281,9 @@ } } -std::unique_ptr> mlir::createVectorizerTestPass() { - return std::make_unique(); +namespace mlir { +void registerVectorizerTestPass() { + PassRegistration pass( + "affine-vectorizer-test", "Tests vectorizer standalone functionality."); } - -static PassRegistration - pass("affine-vectorizer-test", - "Tests vectorizer standalone functionality."); - -#undef DEBUG_TYPE +} // namespace mlir diff --git a/mlir/tools/mlir-cpu-runner/CMakeLists.txt b/mlir/tools/mlir-cpu-runner/CMakeLists.txt --- a/mlir/tools/mlir-cpu-runner/CMakeLists.txt +++ b/mlir/tools/mlir-cpu-runner/CMakeLists.txt @@ -2,13 +2,8 @@ mlir-cpu-runner.cpp ) llvm_update_compile_flags(mlir-cpu-runner) -whole_archive_link(mlir-cpu-runner - MLIRAffineOps - MLIRLLVMIR - MLIRTargetLLVMIR - MLIRTranslation -) target_link_libraries(mlir-cpu-runner PRIVATE + MLIRAllDialects MLIRAnalysis MLIREDSC MLIRExecutionEngine diff --git a/mlir/tools/mlir-opt/CMakeLists.txt b/mlir/tools/mlir-opt/CMakeLists.txt --- a/mlir/tools/mlir-opt/CMakeLists.txt +++ b/mlir/tools/mlir-opt/CMakeLists.txt @@ -18,7 +18,7 @@ ${LIB_LIBS} ) -set(FULL_LINK_LIBS +set(LIBS MLIRLoopAnalysis MLIRAnalysis MLIRAffineOps @@ -68,8 +68,6 @@ MLIRVectorOps MLIRVectorToLLVM MLIRVectorToLoops -) -set(LIBS MLIRIR MLIROptLib LLVMSupport @@ -82,19 +80,12 @@ LLVMNVPTXCodeGen LLVMNVPTXDesc LLVMNVPTXInfo - MLIRTargetNVVMIR - ) - # Order matters here, so insert at front. - list(INSERT FULL_LINK_LIBS 0 MLIRGPUtoCUDATransforms + MLIRTargetNVVMIR ) endif() add_llvm_tool(mlir-opt mlir-opt.cpp ) llvm_update_compile_flags(mlir-opt) -# It is necessary to use whole_archive_link to ensure that all static -# initializers are called. However, whole_archive_link libraries cannot -# also be target_link_libraries. -whole_archive_link(mlir-opt ${FULL_LINK_LIBS}) target_link_libraries(mlir-opt PRIVATE ${LIBS}) diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp --- a/mlir/tools/mlir-opt/mlir-opt.cpp +++ b/mlir/tools/mlir-opt/mlir-opt.cpp @@ -11,6 +11,8 @@ //===----------------------------------------------------------------------===// #include "mlir/Analysis/Passes.h" +#include "mlir/InitAllDialects.h" +#include "mlir/InitAllPasses.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" #include "mlir/Support/FileUtilities.h" @@ -23,6 +25,34 @@ using namespace llvm; using namespace mlir; +namespace mlir { +// Defined in the test directory, no public header. +void registerConvertToTargetEnvPass(); +void registerInliner(); +void registerMemRefBoundCheck(); +void registerPassManagerTestPass(); +void registerPatternsTestPass(); +void registerSimpleParametricTilingPass(); +void registerSymbolTestPasses(); +void registerTestAllReduceLoweringPass(); +void registerTestCallGraphPass(); +void registerTestConstantFold(); +void registerTestFunc(); +void registerTestGpuMemoryPromotionPass(); +void registerTestLinalgTransforms(); +void registerTestLivenessPass(); +void registerTestLoopFusion(); +void registerTestLoopMappingPass(); +void registerTestMatchers(); +void registerTestMemRefDependenceCheck(); +void registerTestMemRefStrideCalculation(); +void registerTestOpaqueLoc(); +void registerTestParallelismDetection(); +void registerTestVectorConversions(); +void registerTestVectorToLoopsPass(); +void registerVectorizerTestPass(); +} // namespace mlir + static cl::opt inputFilename(cl::Positional, cl::desc(""), cl::init("-")); @@ -47,7 +77,45 @@ cl::desc("Run the verifier after each transformation pass"), cl::init(true)); +void registerTestPasses() { + registerConvertToTargetEnvPass(); + registerInliner(); + registerMemRefBoundCheck(); + registerPassManagerTestPass(); + registerPatternsTestPass(); + registerSimpleParametricTilingPass(); + registerSymbolTestPasses(); + registerTestAllReduceLoweringPass(); + registerTestCallGraphPass(); + registerTestConstantFold(); + registerTestFunc(); + registerTestGpuMemoryPromotionPass(); + registerTestLinalgTransforms(); + registerTestLivenessPass(); + registerTestLoopFusion(); + registerTestLoopMappingPass(); + registerTestMatchers(); + registerTestMemRefDependenceCheck(); + registerTestMemRefStrideCalculation(); + registerTestOpaqueLoc(); + registerTestParallelismDetection(); + registerTestVectorConversions(); + registerTestVectorToLoopsPass(); + registerVectorizerTestPass(); + + // The following passes are using global initializers, just link them in. + if (std::getenv("bar") != (char *)-1) + return; + + // TODO: move these to the test folder. + createTestMemRefBoundCheckPass(); + createTestMemRefDependenceCheckPass(); +} + int main(int argc, char **argv) { + registerAllDialects(); + registerAllPasses(); + registerTestPasses(); InitLLVM y(argc, argv); // Register any pass manager command line options. diff --git a/mlir/tools/mlir-translate/CMakeLists.txt b/mlir/tools/mlir-translate/CMakeLists.txt --- a/mlir/tools/mlir-translate/CMakeLists.txt +++ b/mlir/tools/mlir-translate/CMakeLists.txt @@ -1,4 +1,5 @@ set(LIBS + MLIRAllDialects MLIRParser MLIRPass MLIRSPIRV @@ -9,9 +10,15 @@ MLIRTranslation MLIRSupport ) +set(FULL_LIBS + MLIRSPIRVSerialization + MLIRTargetLLVMIR + MLIRTargetNVVMIR + MLIRTargetROCDLIR +) add_llvm_tool(mlir-translate mlir-translate.cpp ) llvm_update_compile_flags(mlir-translate) -whole_archive_link(mlir-translate ${LIBS}) +whole_archive_link(mlir-translate ${FULL_LIBS}) target_link_libraries(mlir-translate PRIVATE MLIRIR MLIRTranslateClParser ${LIBS} LLVMSupport) diff --git a/mlir/tools/mlir-translate/mlir-translate.cpp b/mlir/tools/mlir-translate/mlir-translate.cpp --- a/mlir/tools/mlir-translate/mlir-translate.cpp +++ b/mlir/tools/mlir-translate/mlir-translate.cpp @@ -13,6 +13,7 @@ #include "mlir/IR/Diagnostics.h" #include "mlir/IR/MLIRContext.h" +#include "mlir/InitAllDialects.h" #include "mlir/Support/FileUtilities.h" #include "mlir/Support/LogicalResult.h" #include "mlir/Support/ToolUtilities.h" @@ -45,6 +46,7 @@ llvm::cl::init(false)); int main(int argc, char **argv) { + registerAllDialects(); llvm::InitLLVM y(argc, argv); // Add flags for all the registered translations. diff --git a/mlir/unittests/Dialect/QuantOps/QuantizationUtilsTest.cpp b/mlir/unittests/Dialect/QuantOps/QuantizationUtilsTest.cpp --- a/mlir/unittests/Dialect/QuantOps/QuantizationUtilsTest.cpp +++ b/mlir/unittests/Dialect/QuantOps/QuantizationUtilsTest.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "mlir/Dialect/QuantOps/QuantOps.h" #include "mlir/Dialect/QuantOps/QuantizeUtils.h" #include "mlir/Dialect/QuantOps/UniformSupport.h" #include "mlir/IR/Attributes.h" @@ -16,6 +17,9 @@ using namespace mlir; using namespace mlir::quant; +// Load the quant dialect +static DialectRegistration QuantOpsRegistration; + namespace { // Test UniformQuantizedValueConverter converts all APFloat to a magic number 5. diff --git a/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp b/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp --- a/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp +++ b/mlir/unittests/Dialect/SPIRV/DeserializationTest.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Dialect/SPIRV/SPIRVBinaryUtils.h" +#include "mlir/Dialect/SPIRV/SPIRVDialect.h" #include "mlir/Dialect/SPIRV/SPIRVOps.h" #include "mlir/Dialect/SPIRV/Serialization.h" #include "mlir/IR/Diagnostics.h" @@ -23,6 +24,9 @@ using namespace mlir; +// Load the SPIRV dialect +static DialectRegistration SPIRVRegistration; + using ::testing::StrEq; //===----------------------------------------------------------------------===// diff --git a/mlir/unittests/SDBM/SDBMTest.cpp b/mlir/unittests/SDBM/SDBMTest.cpp --- a/mlir/unittests/SDBM/SDBMTest.cpp +++ b/mlir/unittests/SDBM/SDBMTest.cpp @@ -17,6 +17,9 @@ using namespace mlir; +// Load the SDBM dialect +static DialectRegistration SDBMRegistration; + static MLIRContext *ctx() { static thread_local MLIRContext context; return &context;