forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Flow specific canonicalizer pass (iree-org#17836)
Certain patterns that are borderline canonicalizations or better suited as a canonical form for certain phases benefit from having a phase specific canonicalization pass. The only pattern added here for now is consecutive insert/extract slice folding which is always beneficial in Flow, but not in Codegen.
- Loading branch information
Showing
15 changed files
with
100 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
compiler/src/iree/compiler/Dialect/Flow/Transforms/Canonicalizer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2024 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/Flow/Transforms/Passes.h" | ||
|
||
#include "mlir/Dialect/Tensor/Transforms/Transforms.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
|
||
namespace mlir::iree_compiler::IREE::Flow { | ||
|
||
#define GEN_PASS_DEF_CANONICALIZERPASS | ||
#include "iree/compiler/Dialect/Flow/Transforms/Passes.h.inc" | ||
|
||
namespace { | ||
|
||
/// Canonicalize operations in nested regions. | ||
struct CanonicalizerPass | ||
: public impl::CanonicalizerPassBase<CanonicalizerPass> { | ||
using IREE::Flow::impl::CanonicalizerPassBase< | ||
CanonicalizerPass>::CanonicalizerPassBase; | ||
/// Initialize the canonicalizer by building the set of patterns used during | ||
/// execution. | ||
LogicalResult initialize(MLIRContext *context) override { | ||
// Inherit the same config defaults from the upstream canonicalizer pass. | ||
config.useTopDownTraversal = true; | ||
config.enableRegionSimplification = mlir::GreedySimplifyRegionLevel::Normal; | ||
|
||
RewritePatternSet owningPatterns(context); | ||
for (auto *dialect : context->getLoadedDialects()) | ||
dialect->getCanonicalizationPatterns(owningPatterns); | ||
for (RegisteredOperationName op : context->getRegisteredOperations()) | ||
op.getCanonicalizationPatterns(owningPatterns, context); | ||
|
||
// Some Flow specific patterns we want to pull in for common | ||
// canonicalization. | ||
tensor::populateMergeConsecutiveInsertExtractSlicePatterns(owningPatterns); | ||
|
||
patterns = | ||
std::make_shared<FrozenRewritePatternSet>(std::move(owningPatterns)); | ||
return success(); | ||
} | ||
void runOnOperation() override { | ||
// Canonicalization is best-effort. Non-convergence is not a pass failure. | ||
LogicalResult didConverge = | ||
applyPatternsAndFoldGreedily(getOperation(), *patterns, config); | ||
if (this->testConvergence && failed(didConverge)) { | ||
getOperation()->emitError("Canonicalizer failed to converge"); | ||
return signalPassFailure(); | ||
} | ||
} | ||
GreedyRewriteConfig config; | ||
std::shared_ptr<const FrozenRewritePatternSet> patterns; | ||
}; | ||
|
||
} // namespace | ||
|
||
} // namespace mlir::iree_compiler::IREE::Flow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
compiler/src/iree/compiler/Dialect/Flow/Transforms/test/convert_region_to_workgroups.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
compiler/src/iree/compiler/Dialect/Flow/Transforms/test/dispatch_linalg_on_tensors.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...er/src/iree/compiler/Dialect/Flow/Transforms/test/dispatch_linalg_on_tensors_default.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mpiler/Dialect/Flow/Transforms/test/dispatch_linalg_on_tensors_fusion_with_transpose.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ler/src/iree/compiler/Dialect/Flow/Transforms/test/interchange_transpose_generic_ops.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ler/src/iree/compiler/Dialect/Flow/Transforms/test/tensor_pad_to_tensor_insert_slice.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
compiler/src/iree/compiler/GlobalOptimization/test/fuse_dequantization_matmul.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
compiler/src/iree/compiler/GlobalOptimization/test/fuse_silu_horizontal_matmul.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
compiler/src/iree/compiler/GlobalOptimization/test/raise_special_ops.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters