diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/ApplyPatterns.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/ApplyPatterns.cpp index be84cd148e64..9c050630ad26 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/ApplyPatterns.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/ApplyPatterns.cpp @@ -8,6 +8,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilDialect.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "iree/compiler/Dialect/Util/Transforms/Patterns.h" #include "mlir/Dialect/Func/IR/FuncOps.h" @@ -20,15 +21,8 @@ namespace iree_compiler { namespace IREE { namespace Util { -class ApplyPatternsPass - : public PassWrapper> { +class ApplyPatternsPass : public ApplyPatternsBase { public: - StringRef getArgument() const override { return "iree-util-apply-patterns"; } - - StringRef getDescription() const override { - return "Applies some risky/IREE-specific canonicalization patterns."; - } - void getDependentDialects(DialectRegistry ®istry) const override { registry .insert(); @@ -60,8 +54,6 @@ std::unique_ptr> createApplyPatternsPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/BUILD b/compiler/src/iree/compiler/Dialect/Util/Transforms/BUILD index 8c0d1bbbfe15..5a17443e70a0 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/BUILD +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/BUILD @@ -5,6 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library") +load("//build_tools/bazel:iree_tablegen.bzl", "iree_gentbl_cc_library") package( default_visibility = ["//visibility:public"], @@ -23,8 +24,10 @@ iree_compiler_cc_library( "FoldGlobals.cpp", "FuseGlobals.cpp", "HoistIntoGlobals.cpp", + "PassDetail.h", + "Passes.cpp", "Patterns.cpp", - "PropagateSubrange.cpp", + "PropagateSubranges.cpp", "SimplifyGlobalAccesses.cpp", "StripDebugOps.cpp", "TestConversion.cpp", @@ -32,9 +35,11 @@ iree_compiler_cc_library( ], hdrs = [ "Passes.h", + "Passes.h.inc", "Patterns.h", ], deps = [ + ":PassesIncGen", "//compiler/src/iree/compiler/Dialect/Util/Analysis", "//compiler/src/iree/compiler/Dialect/Util/Analysis/Attributes", "//compiler/src/iree/compiler/Dialect/Util/Analysis/Constant", @@ -59,3 +64,18 @@ iree_compiler_cc_library( "@llvm-project//mlir:Transforms", ], ) + +iree_gentbl_cc_library( + name = "PassesIncGen", + tbl_outs = [ + ( + ["--gen-pass-decls"], + "Passes.h.inc", + ), + ], + tblgen = "@llvm-project//mlir:mlir-tblgen", + td_file = "Passes.td", + deps = [ + "@llvm-project//mlir:PassBaseTdFiles", + ], +) diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/CMakeLists.txt b/compiler/src/iree/compiler/Dialect/Util/Transforms/CMakeLists.txt index 15f1ac5a47c8..8f54c6c77e5a 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/CMakeLists.txt +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/CMakeLists.txt @@ -15,6 +15,7 @@ iree_cc_library( Transforms HDRS "Passes.h" + "Passes.h.inc" "Patterns.h" SRCS "ApplyPatterns.cpp" @@ -25,13 +26,16 @@ iree_cc_library( "FoldGlobals.cpp" "FuseGlobals.cpp" "HoistIntoGlobals.cpp" + "PassDetail.h" + "Passes.cpp" "Patterns.cpp" - "PropagateSubrange.cpp" + "PropagateSubranges.cpp" "SimplifyGlobalAccesses.cpp" "StripDebugOps.cpp" "TestConversion.cpp" "TestFloatRangeAnalysis.cpp" DEPS + ::PassesIncGen LLVMSupport MLIRAffineDialect MLIRAnalysis @@ -57,4 +61,13 @@ iree_cc_library( PUBLIC ) +iree_tablegen_library( + NAME + PassesIncGen + TD_FILE + "Passes.td" + OUTS + --gen-pass-decls Passes.h.inc +) + ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ### diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/CombineInitializers.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/CombineInitializers.cpp index dd7462feaf3a..be7366a9164f 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/CombineInitializers.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/CombineInitializers.cpp @@ -10,6 +10,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilDialect.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" #include "iree/compiler/Dialect/Util/IR/UtilTraits.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Debug.h" @@ -30,19 +31,8 @@ namespace Util { namespace { class CombineInitializersPass - : public PassWrapper> { + : public CombineInitializersBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CombineInitializersPass) - - StringRef getArgument() const override { - return "iree-util-combine-initializers"; - } - - StringRef getDescription() const override { - return "Combines global initializers into one."; - } - void getDependentDialects(DialectRegistry ®istry) const override { registry.insert(); } @@ -92,8 +82,6 @@ std::unique_ptr> createCombineInitializersPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/ConvertPrimitiveType.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/ConvertPrimitiveType.cpp index 069467f2d9d7..28a38d4d175f 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/ConvertPrimitiveType.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/ConvertPrimitiveType.cpp @@ -9,6 +9,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilOps.h" #include "iree/compiler/Dialect/Util/IR/UtilTypes.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" @@ -215,8 +216,8 @@ struct ConvertTypeSensitiveArithCastOp : public OpConversionPattern { } }; -template -struct ConvertTypesPass : public PassWrapper> { +template +struct ConvertTypesPass : public Base { void runOnOperation() override { MLIRContext *context = &this->getContext(); RewritePatternSet patterns(context); @@ -285,22 +286,13 @@ struct DemoteI64ToI32Converter } }; struct DemoteI64ToI32Pass - : public ConvertTypesPass { - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DemoteI64ToI32Pass) - - StringRef getArgument() const override { - return "iree-util-demote-i64-to-i32"; - } - StringRef getDescription() const override { - return "Demotes i64 types to i32 types."; - } -}; + : public ConvertTypesPass, + DemoteI64ToI32Converter> {}; } // namespace std::unique_ptr> createDemoteI64ToI32Pass() { return std::make_unique(); } -static PassRegistration demoteI64ToI32Pass; namespace { struct DemoteF32ToF16Converter @@ -310,22 +302,13 @@ struct DemoteF32ToF16Converter } }; struct DemoteF32ToF16Pass - : public ConvertTypesPass { - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DemoteF32ToF16Pass) - - StringRef getArgument() const override { - return "iree-util-demote-f32-to-f16"; - } - StringRef getDescription() const override { - return "Demotes f32 types to f16 types."; - } -}; + : public ConvertTypesPass, + DemoteF32ToF16Converter> {}; } // namespace std::unique_ptr> createDemoteF32ToF16Pass() { return std::make_unique(); } -static PassRegistration demoteF32ToF16Pass; namespace { struct PromoteF16ToF32Converter @@ -335,22 +318,13 @@ struct PromoteF16ToF32Converter } }; struct PromoteF16ToF32Pass - : public ConvertTypesPass { - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(PromoteF16ToF32Pass) - - StringRef getArgument() const override { - return "iree-util-promote-f16-to-f32"; - } - StringRef getDescription() const override { - return "Promotes f16 types to f32 types."; - } -}; + : public ConvertTypesPass, + PromoteF16ToF32Converter> {}; } // namespace std::unique_ptr> createPromoteF16ToF32Pass() { return std::make_unique(); } -static PassRegistration promoteF16ToF32Pass; namespace { struct DemoteF64ToF32Converter @@ -360,22 +334,13 @@ struct DemoteF64ToF32Converter } }; struct DemoteF64ToF32Pass - : public ConvertTypesPass { - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DemoteF64ToF32Pass) - - StringRef getArgument() const override { - return "iree-util-demote-f64-to-f32"; - } - StringRef getDescription() const override { - return "Demotes f64 types to f32 types."; - } -}; + : public ConvertTypesPass, + DemoteF64ToF32Converter> {}; } // namespace std::unique_ptr> createDemoteF64ToF32Pass() { return std::make_unique(); } -static PassRegistration demoteF64ToF32Pass; } // namespace Util } // namespace IREE diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/DropCompilerHints.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/DropCompilerHints.cpp index c18a62bff6cc..68538304123e 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/DropCompilerHints.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/DropCompilerHints.cpp @@ -7,6 +7,7 @@ #include #include "iree/compiler/Dialect/Util/IR/UtilOps.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "mlir/Pass/Pass.h" @@ -16,18 +17,8 @@ namespace IREE { namespace Util { class DropCompilerHintsPass - : public PassWrapper> { + : public DropCompilerHintsBase { public: - StringRef getArgument() const override { - return "iree-util-drop-compiler-hints"; - } - - StringRef getDescription() const override { - return "Deletes operations that have no runtime equivalent and are only " - "used in the compiler. This should be performed after all other " - "compiler passes."; - } - void runOnOperation() override { // We can't use patterns and applyPatternsAndFoldGreedily because that // automatically does canonicalization. @@ -42,8 +33,6 @@ std::unique_ptr> createDropCompilerHintsPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/FixedPointIterator.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/FixedPointIterator.cpp index e79b5baa10e4..b75f3ba11313 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/FixedPointIterator.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/FixedPointIterator.cpp @@ -4,6 +4,8 @@ // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" +#include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" @@ -24,25 +26,16 @@ namespace { // iteration terminates. If a sub-pass removes it, then iteration will // continue. class FixedPointIteratorPass - : public PassWrapper> { + : public FixedPointIteratorBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(FixedPointIteratorPass) - FixedPointIteratorPass() = default; FixedPointIteratorPass(const FixedPointIteratorPass &other) - : PassWrapper(other) {} + : FixedPointIteratorBase(other) {} FixedPointIteratorPass(OpPassManager pipeline); private: LogicalResult initializeOptions(StringRef options) override; void getDependentDialects(DialectRegistry ®istry) const override; - StringRef getArgument() const override { - return "iree-util-fixed-point-iterator"; - } - StringRef getDescription() const override { - return "Iterates a sub-pipeline to a fixed point"; - } - void runOnOperation() override; Optional pipeline; @@ -125,7 +118,6 @@ void FixedPointIteratorPass::runOnOperation() { std::unique_ptr> createFixedPointIteratorPass( OpPassManager pipeline) { - static PassRegistration pass; return std::make_unique(std::move(pipeline)); } diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/FoldGlobals.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/FoldGlobals.cpp index 3b10ee0d8139..e1b37fe21edc 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/FoldGlobals.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/FoldGlobals.cpp @@ -11,6 +11,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilOps.h" #include "iree/compiler/Dialect/Util/IR/UtilTraits.h" #include "iree/compiler/Dialect/Util/IR/UtilTypes.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/EquivalenceClasses.h" @@ -390,20 +391,11 @@ static bool deduplicateConstantGlobals(GlobalTable &globalTable) { return didChange; } -class FoldGlobalsPass - : public PassWrapper> { +class FoldGlobalsPass : public FoldGlobalsBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(FoldGlobalsPass) - explicit FoldGlobalsPass() = default; FoldGlobalsPass(const FoldGlobalsPass &pass) {} - StringRef getArgument() const override { return "iree-util-fold-globals"; } - - StringRef getDescription() const override { - return "Folds duplicate globals and propagates constants."; - } - void getDependentDialects(DialectRegistry ®istry) const override { registry.insert(); registry.insert(); @@ -491,8 +483,6 @@ std::unique_ptr> createFoldGlobalsPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/FuseGlobals.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/FuseGlobals.cpp index bf20f74a5da2..8aded7f0e6c4 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/FuseGlobals.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/FuseGlobals.cpp @@ -10,6 +10,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilDialect.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" #include "iree/compiler/Dialect/Util/IR/UtilTraits.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/EquivalenceClasses.h" @@ -98,17 +99,8 @@ static llvm::raw_ostream &operator<<(llvm::raw_ostream &os, // util.global mutable @fused : i32 // builtin.func @foo(%arg0: i32) { // util.global.store %arg0, @fused : i32 -class FuseGlobalsPass - : public PassWrapper> { +class FuseGlobalsPass : public FuseGlobalsBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(FuseGlobalsPass) - - StringRef getArgument() const override { return "iree-util-fuse-globals"; } - - StringRef getDescription() const override { - return "Fuses correlated globals together."; - } - void getDependentDialects(DialectRegistry ®istry) const override { registry.insert(); } @@ -289,8 +281,6 @@ std::unique_ptr> createFuseGlobalsPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/HoistIntoGlobals.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/HoistIntoGlobals.cpp index deaa0e53a0ba..89016c3da3c3 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/HoistIntoGlobals.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/HoistIntoGlobals.cpp @@ -7,6 +7,7 @@ #include "iree/compiler/Dialect/Util/Analysis/Constant/ConstExpr.h" #include "iree/compiler/Dialect/Util/Analysis/Constant/OpOracle.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "llvm/Support/Debug.h" #include "mlir/Analysis/SliceAnalysis.h" @@ -33,19 +34,8 @@ using HoistedValueMap = llvm::DenseMap; // necessary. Either this algorithm can be made smarter or a follow-on pass // can sink globals into the program where it is profitable to reduce // working set size. -class HoistIntoGlobalsPass - : public PassWrapper> { +class HoistIntoGlobalsPass : public HoistIntoGlobalsBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(HoistIntoGlobalsPass) - - StringRef getArgument() const override { - return "iree-util-hoist-into-globals"; - } - - StringRef getDescription() const override { - return "Greedily hoists eligible constant expressions into globals"; - } - void getDependentDialects(DialectRegistry ®istry) const override { registerConstExprDependentDialects(registry); } @@ -242,8 +232,6 @@ std::unique_ptr> createHoistIntoGlobalsPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/PassDetail.h b/compiler/src/iree/compiler/Dialect/Util/Transforms/PassDetail.h new file mode 100644 index 000000000000..8a5ae9ccd2b4 --- /dev/null +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/PassDetail.h @@ -0,0 +1,27 @@ +// Copyright 2022 The IREE Authors +// +// Licensed 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 + +#ifndef IREE_COMPILER_DIALECT_UTIL_TRANSFORMS_PASS_DETAIL_H_ +#define IREE_COMPILER_DIALECT_UTIL_TRANSFORMS_PASS_DETAIL_H_ + +#include "mlir/IR/BuiltinOps.h" +#include "mlir/Interfaces/CallInterfaces.h" +#include "mlir/Pass/Pass.h" + +namespace mlir { +namespace iree_compiler { +namespace IREE { +namespace Util { + +#define GEN_PASS_CLASSES +#include "iree/compiler/Dialect/Util/Transforms/Passes.h.inc" // IWYU pragma: keep + +} // namespace Util +} // namespace IREE +} // namespace iree_compiler +} // namespace mlir + +#endif // IREE_COMPILER_DIALECT_UTIL_TRANSFORMS_PASS_DETAIL_H_ diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.cpp new file mode 100644 index 000000000000..40d0d4ef2880 --- /dev/null +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.cpp @@ -0,0 +1,27 @@ +// Copyright 2022 The IREE Authors +// +// Licensed 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 "iree/compiler/Dialect/Util/Transforms/Passes.h" + +namespace mlir { +namespace iree_compiler { +namespace IREE { +namespace Util { + +namespace { +#define GEN_PASS_REGISTRATION +#include "iree/compiler/Dialect/Util/Transforms/Passes.h.inc" // IWYU pragma: export +} // namespace + +void registerTransformPasses() { + // Generated. + registerPasses(); +} + +} // namespace Util +} // namespace IREE +} // namespace iree_compiler +} // namespace mlir diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.h b/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.h index c3bb1e8e531d..c084254bb90a 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.h +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.h @@ -7,6 +7,7 @@ #ifndef IREE_COMPILER_DIALECT_IREE_TRANSFORMS_PASSES_H_ #define IREE_COMPILER_DIALECT_IREE_TRANSFORMS_PASSES_H_ +#include "mlir/IR/BuiltinOps.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" @@ -38,27 +39,7 @@ std::unique_ptr> createTestConversionPass(); std::unique_ptr> createTestFloatRangeAnalysisPass(); // Register all Passes -// TODO: Switch this directory to declarative registration. -inline void registerTransformPasses() { - createApplyPatternsPass(); - createCombineInitializersPass(); - createDropCompilerHintsPass(); - createFixedPointIteratorPass(OpPassManager("dummy_op")); - createFoldGlobalsPass(); - createFuseGlobalsPass(); - createHoistIntoGlobalsPass(); - createPropagateSubrangesPass(); - createSimplifyGlobalAccessesPass(); - createStripDebugOpsPass(); - - createDemoteI64ToI32Pass(); - createDemoteF32ToF16Pass(); - createDemoteF64ToF32Pass(); - createPromoteF16ToF32Pass(); - - createTestConversionPass(); - createTestFloatRangeAnalysisPass(); -} +void registerTransformPasses(); } // namespace Util } // namespace IREE diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.td b/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.td new file mode 100644 index 000000000000..178b0f4db5db --- /dev/null +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/Passes.td @@ -0,0 +1,147 @@ +// Copyright 2022 The IREE Authors +// +// Licensed 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 + +#ifndef IREE_DIALECT_UTIL_PASSES +#define IREE_DIALECT_UTIL_PASSES + +include "mlir/Pass/PassBase.td" + +def ApplyPatterns : Pass<"iree-util-apply-patterns", ""> { + let summary = "Applies some risky/IREE-specific canonicalization patterns."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createApplyPatternsPass() + }]; +} + +def CombineInitializers : Pass<"iree-util-combine-initializers", "mlir::ModuleOp"> { + let summary = "Combines global initializers into one."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createCombineInitializersPass() + }]; +} + +def DropCompilerHints : Pass<"iree-util-drop-compiler-hints", ""> { + let summary = "Deletes operations that have no runtime equivalent."; + let description = [{ + Deletes operations that have no runtime equivalent and are only + used in the compiler. This should be performed after all other + compiler passes. + }]; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createDropCompilerHintsPass() + }]; +} + +def FixedPointIterator : Pass<"iree-util-fixed-point-iterator", ""> { + let summary = "Iterates a sub-pipeline to a fixed point."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createFixedPointIteratorPass( + mlir::OpPassManager("dummy_op")) + }]; +} + +def PropagateSubranges : Pass<"iree-util-propagate-subranges", "mlir::ModuleOp"> { + let summary = "Propagates resource subranges across the program."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createPropagateSubrangesPass() + }]; +} + +def StripDebugOps : Pass<"iree-util-strip-debug-ops", ""> { + let summary = "Strips debug ops, like assertions."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createStripDebugOpsPass() + }]; +} + +//===----------------------------------------------------------------------===// +// Globals +//===----------------------------------------------------------------------===// + +def FoldGlobals : Pass<"iree-util-fold-globals", "mlir::ModuleOp"> { + let summary = "Folds duplicate globals and propagates constants."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createFoldGlobalsPass() + }]; +} + +def FuseGlobals : Pass<"iree-util-fuse-globals", "mlir::ModuleOp"> { + let summary = "Fuses correlated globals together."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createFuseGlobalsPass() + }]; +} + +def HoistIntoGlobals : Pass<"iree-util-hoist-into-globals", "mlir::ModuleOp"> { + let summary = "Greedily hoists eligible constant expressions into globals."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createHoistIntoGlobalsPass() + }]; +} + +def SimplifyGlobalAccesses : + InterfacePass<"iree-util-simplify-global-accesses", "mlir::CallableOpInterface"> { + let summary = "Hoists loads and sinks stores to variables to decrease data dependency regions."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createSimplifyGlobalAccessesPass() + }]; +} + +//===----------------------------------------------------------------------===// +// Type Conversion +//===----------------------------------------------------------------------===// + +def DemoteI64ToI32 : Pass<"iree-util-demote-i64-to-i32", "mlir::ModuleOp"> { + let summary = "Demotes i64 types to i32 types."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createDemoteI64ToI32Pass() + }]; +} + +def DemoteF32ToF16 : Pass<"iree-util-demote-f32-to-f16", "mlir::ModuleOp"> { + let summary = "Demotes f32 types to f16 types."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createDemoteF32ToF16Pass() + }]; +} + +def DemoteF64ToF32 : Pass<"iree-util-demote-f64-to-f32", "mlir::ModuleOp"> { + let summary = "Demotes f64 types to f32 types."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createDemoteF64ToF32Pass() + }]; +} + +def PromoteF16ToF32 : Pass<"iree-util-promote-f16-to-f32", "mlir::ModuleOp"> { + let summary = "Promotes f16 types to f32 types."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createPromoteF16ToF32Pass() + }]; +} + +//===----------------------------------------------------------------------===// +// Test passes +//===----------------------------------------------------------------------===// + +def TestConversion : Pass<"iree-util-test-conversion", "mlir::ModuleOp"> { + let summary = "Tests util dialect conversion patterns."; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createTestConversionPass() + }]; +} + +def TestFloatRangeAnalysis : Pass<"iree-util-test-float-range-analysis", ""> { + let summary = "Tests floating point range analysis."; + let description = [{ + Tests floating point range analysis by evaluating any + 'iree_unregistered.test_fprange' op and setting the results on an attribute. + }]; + let constructor = [{ + mlir::iree_compiler::IREE::Util::createTestFloatRangeAnalysisPass() + }]; +} + +#endif // IREE_DIALECT_UTIL_PASSES diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/PropagateSubrange.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/PropagateSubranges.cpp similarity index 98% rename from compiler/src/iree/compiler/Dialect/Util/Transforms/PropagateSubrange.cpp rename to compiler/src/iree/compiler/Dialect/Util/Transforms/PropagateSubranges.cpp index 0868347e4c6d..161ca3e20b28 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/PropagateSubrange.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/PropagateSubranges.cpp @@ -8,6 +8,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilDialect.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "iree/compiler/Dialect/Util/Transforms/Patterns.h" #include "iree/compiler/Utils/IndexSet.h" @@ -597,19 +598,8 @@ static void expandSubranges(Operation *op, ExpandedGlobalMap &globalMap, // are always wrapped in a subrange op, with the elision/deduplication/etc left // until cleanup. class PropagateSubrangesPass - : public PassWrapper> { + : public PropagateSubrangesBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(PropagateSubrangesPass) - - StringRef getArgument() const override { - return "iree-util-propagate-subranges"; - } - - StringRef getDescription() const override { - return "Propagates resource subranges across the program."; - } - void getDependentDialects(DialectRegistry ®istry) const override { registry.insert(); registry.insert(); @@ -646,8 +636,6 @@ std::unique_ptr> createPropagateSubrangesPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/SimplifyGlobalAccesses.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/SimplifyGlobalAccesses.cpp index 1a099a517d1e..f47188409e65 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/SimplifyGlobalAccesses.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/SimplifyGlobalAccesses.cpp @@ -10,6 +10,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilDialect.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" #include "iree/compiler/Dialect/Util/IR/UtilTraits.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Debug.h" @@ -230,20 +231,8 @@ static bool rearrangeBlockGlobalAccesses( namespace { class SimplifyGlobalAccessesPass - : public PassWrapper> { + : public SimplifyGlobalAccessesBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SimplifyGlobalAccessesPass) - - StringRef getArgument() const override { - return "iree-util-simplify-global-accesses"; - } - - StringRef getDescription() const override { - return "Hoists loads and sinks stores to variables to decrease data " - "dependency regions."; - } - void runOnOperation() override { auto callableOp = getOperation(); if (!callableOp.getCallableRegion() || @@ -302,8 +291,6 @@ std::unique_ptr> createSimplifyGlobalAccessesPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/StripDebugOps.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/StripDebugOps.cpp index 234ef0ee5dc7..b180bed3400f 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/StripDebugOps.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/StripDebugOps.cpp @@ -7,6 +7,7 @@ #include "iree/compiler/Dialect/Util/IR/UtilDialect.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" #include "iree/compiler/Dialect/Util/IR/UtilTraits.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" #include "mlir/Pass/Pass.h" @@ -19,17 +20,8 @@ namespace Util { namespace { -class StripDebugOpsPass - : public PassWrapper> { +class StripDebugOpsPass : public StripDebugOpsBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(StripDebugOpsPass) - - StringRef getArgument() const override { return "iree-util-strip-debug-ops"; } - - StringRef getDescription() const override { - return "Strips debug ops, like assertions."; - } - void runOnOperation() override { getOperation()->walk([](Operation *op) { if (isa(op) || @@ -46,8 +38,6 @@ std::unique_ptr> createStripDebugOpsPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/TestConversion.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/TestConversion.cpp index 7c2d7dc4d52e..0057de2b9ec8 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/TestConversion.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/TestConversion.cpp @@ -8,6 +8,7 @@ #include "iree/compiler/Dialect/Util/Conversion/MemRefToUtil/ConvertMemRefToUtil.h" #include "iree/compiler/Dialect/Util/IR/UtilDialect.h" #include "iree/compiler/Dialect/Util/IR/UtilOps.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arithmetic/Transforms/Passes.h" @@ -23,19 +24,10 @@ namespace Util { namespace { -class TestConversionPass - : public PassWrapper> { +class TestConversionPass : public TestConversionBase { public: TestConversionPass() = default; TestConversionPass(const TestConversionPass &) {} - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestConversionPass) - - StringRef getArgument() const override { return "iree-util-test-conversion"; } - - StringRef getDescription() const override { - return "Tests util dialect conversion patterns"; - } - void getDependentDialects(DialectRegistry ®istry) const override { registry.insert> createTestConversionPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/TestFloatRangeAnalysis.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/TestFloatRangeAnalysis.cpp index f9a00094c1a4..e4d53b904824 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/TestFloatRangeAnalysis.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/TestFloatRangeAnalysis.cpp @@ -8,6 +8,7 @@ #include "iree/compiler/Dialect/Util/Analysis/DFX/Solver.h" #include "iree/compiler/Dialect/Util/Analysis/DFX/State.h" #include "iree/compiler/Dialect/Util/Analysis/Explorer.h" +#include "iree/compiler/Dialect/Util/Transforms/PassDetail.h" #include "iree/compiler/Dialect/Util/Transforms/Passes.h" namespace mlir { @@ -18,20 +19,8 @@ namespace Util { namespace { class TestFloatRangeAnalysisPass - : public PassWrapper> { + : public TestFloatRangeAnalysisBase { public: - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFloatRangeAnalysisPass) - - StringRef getArgument() const override { - return "iree-util-test-float-range-analysis"; - } - - StringRef getDescription() const override { - return "Tests floating point range analysis by evaluating any " - "'iree_unregistered.test_fprange' op and setting the results on an " - "attribute"; - } - void runOnOperation() override { Explorer explorer(getOperation(), TraversalAction::SHALLOW); llvm::BumpPtrAllocator allocator; @@ -72,8 +61,6 @@ std::unique_ptr> createTestFloatRangeAnalysisPass() { return std::make_unique(); } -static PassRegistration pass; - } // namespace Util } // namespace IREE } // namespace iree_compiler