[Mlir-commits] [mlir] a5b9316 - [MLIR][NFC] applyPatternsGreedily -> applyPatternsAndFoldGreedily
Uday Bondhugula
llvmlistbot at llvm.org
Fri Apr 10 00:26:44 PDT 2020
Author: Uday Bondhugula
Date: 2020-04-10T12:55:21+05:30
New Revision: a5b9316b24ce1de54ae3ab7a5254f0219fee12ac
URL: https://github.com/llvm/llvm-project/commit/a5b9316b24ce1de54ae3ab7a5254f0219fee12ac
DIFF: https://github.com/llvm/llvm-project/commit/a5b9316b24ce1de54ae3ab7a5254f0219fee12ac.diff
LOG: [MLIR][NFC] applyPatternsGreedily -> applyPatternsAndFoldGreedily
Rename mlir::applyPatternsGreedily -> applyPatternsAndFoldGreedily. The
new name is a more accurate description of the method - it performs
both, application of the specified patterns and folding of all ops in
the op's region irrespective of whether any patterns have been supplied.
Differential Revision: https://reviews.llvm.org/D77478
Added:
Modified:
mlir/include/mlir/IR/PatternMatch.h
mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
mlir/lib/Conversion/StandardToSPIRV/LegalizeStandardForSPIRV.cpp
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp
mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp
mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
mlir/lib/Dialect/Quant/Transforms/ConvertConst.cpp
mlir/lib/Dialect/Quant/Transforms/ConvertSimQuant.cpp
mlir/lib/Transforms/Canonicalizer.cpp
mlir/lib/Transforms/Inliner.cpp
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
mlir/test/lib/Dialect/Test/TestPatterns.cpp
mlir/test/lib/Transforms/TestAllReduceLowering.cpp
mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp
mlir/test/lib/Transforms/TestLinalgTransforms.cpp
mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp
mlir/test/lib/Transforms/TestVectorTransforms.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h
index 457a4b11d816..4679d9871922 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -450,11 +450,11 @@ class RewritePatternMatcher {
/// Note: These methods also perform folding and simple dead-code elimination
/// before attempting to match any of the provided patterns.
///
-bool applyPatternsGreedily(Operation *op,
- const OwningRewritePatternList &patterns);
+bool applyPatternsAndFoldGreedily(Operation *op,
+ const OwningRewritePatternList &patterns);
/// Rewrite the given regions, which must be isolated from above.
-bool applyPatternsGreedily(MutableArrayRef<Region> regions,
- const OwningRewritePatternList &patterns);
+bool applyPatternsAndFoldGreedily(MutableArrayRef<Region> regions,
+ const OwningRewritePatternList &patterns);
} // end namespace mlir
#endif // MLIR_PATTERN_MATCH_H
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index c3f3c04d9196..9391466ffdc9 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -268,7 +268,7 @@ class LowerGpuOpsToNVVMOpsPass
// which need to be lowered further, which is not supported by a single
// conversion pass.
populateGpuRewritePatterns(m.getContext(), patterns);
- applyPatternsGreedily(m, patterns);
+ applyPatternsAndFoldGreedily(m, patterns);
patterns.clear();
populateStdToLLVMConversionPatterns(converter, patterns);
diff --git a/mlir/lib/Conversion/StandardToSPIRV/LegalizeStandardForSPIRV.cpp b/mlir/lib/Conversion/StandardToSPIRV/LegalizeStandardForSPIRV.cpp
index 1312e0c36f80..6d9974233a9f 100644
--- a/mlir/lib/Conversion/StandardToSPIRV/LegalizeStandardForSPIRV.cpp
+++ b/mlir/lib/Conversion/StandardToSPIRV/LegalizeStandardForSPIRV.cpp
@@ -170,7 +170,7 @@ void SPIRVLegalization::runOnOperation() {
OwningRewritePatternList patterns;
auto *context = &getContext();
populateStdLegalizationPatternsForSPIRVLowering(context, patterns);
- applyPatternsGreedily(getOperation()->getRegions(), patterns);
+ applyPatternsAndFoldGreedily(getOperation()->getRegions(), patterns);
}
std::unique_ptr<Pass> mlir::createLegalizeStdOpsForSPIRVLoweringPass() {
diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index 38822fa79458..b7c4a57a78ba 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -1244,7 +1244,7 @@ void LowerVectorToLLVMPass::runOnOperation() {
OwningRewritePatternList patterns;
populateVectorSlicesLoweringPatterns(patterns, &getContext());
populateVectorContractLoweringPatterns(patterns, &getContext());
- applyPatternsGreedily(getOperation(), patterns);
+ applyPatternsAndFoldGreedily(getOperation(), patterns);
}
// Convert to the LLVM IR dialect.
diff --git a/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp b/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp
index bff60f417082..c861b214d3b3 100644
--- a/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp
@@ -225,6 +225,6 @@ void AffineDataCopyGeneration::runOnFunction() {
OwningRewritePatternList patterns;
AffineLoadOp::getCanonicalizationPatterns(patterns, &getContext());
AffineStoreOp::getCanonicalizationPatterns(patterns, &getContext());
- applyPatternsGreedily(f, std::move(patterns));
+ applyPatternsAndFoldGreedily(f, std::move(patterns));
}
}
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp
index ee9996b28708..97f684cd16ab 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp
@@ -572,7 +572,7 @@ struct FusionOfTensorOpsPass
OwningRewritePatternList patterns;
Operation *op = getOperation();
patterns.insert<FuseGenericTensorOps>(op->getContext());
- applyPatternsGreedily(op->getRegions(), patterns);
+ applyPatternsAndFoldGreedily(op->getRegions(), patterns);
};
};
diff --git a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
index e85a67a9f7eb..48df0ac3ea2a 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
@@ -688,7 +688,7 @@ static void lowerLinalgToLoopsImpl(Operation *op, MLIRContext *context) {
AffineApplyOp::getCanonicalizationPatterns(patterns, context);
patterns.insert<FoldAffineOp>(context);
// Just apply the patterns greedily.
- applyPatternsGreedily(op, patterns);
+ applyPatternsAndFoldGreedily(op, patterns);
}
namespace {
diff --git a/mlir/lib/Dialect/Quant/Transforms/ConvertConst.cpp b/mlir/lib/Dialect/Quant/Transforms/ConvertConst.cpp
index 8f9f55d175a9..2ff23123b474 100644
--- a/mlir/lib/Dialect/Quant/Transforms/ConvertConst.cpp
+++ b/mlir/lib/Dialect/Quant/Transforms/ConvertConst.cpp
@@ -98,7 +98,7 @@ void ConvertConstPass::runOnFunction() {
auto func = getFunction();
auto *context = &getContext();
patterns.insert<QuantizedConstRewrite>(context);
- applyPatternsGreedily(func, patterns);
+ applyPatternsAndFoldGreedily(func, patterns);
}
std::unique_ptr<OperationPass<FuncOp>> mlir::quant::createConvertConstPass() {
diff --git a/mlir/lib/Dialect/Quant/Transforms/ConvertSimQuant.cpp b/mlir/lib/Dialect/Quant/Transforms/ConvertSimQuant.cpp
index 2cb077a25bb1..bafc48e11ff0 100644
--- a/mlir/lib/Dialect/Quant/Transforms/ConvertSimQuant.cpp
+++ b/mlir/lib/Dialect/Quant/Transforms/ConvertSimQuant.cpp
@@ -131,7 +131,7 @@ void ConvertSimulatedQuantPass::runOnFunction() {
auto ctx = func.getContext();
patterns.insert<ConstFakeQuantRewrite, ConstFakeQuantPerAxisRewrite>(
ctx, &hadFailure);
- applyPatternsGreedily(func, patterns);
+ applyPatternsAndFoldGreedily(func, patterns);
if (hadFailure)
signalPassFailure();
}
diff --git a/mlir/lib/Transforms/Canonicalizer.cpp b/mlir/lib/Transforms/Canonicalizer.cpp
index c46a8b9fa31e..9b028bfa2525 100644
--- a/mlir/lib/Transforms/Canonicalizer.cpp
+++ b/mlir/lib/Transforms/Canonicalizer.cpp
@@ -32,7 +32,7 @@ struct Canonicalizer : public CanonicalizerBase<Canonicalizer> {
op->getCanonicalizationPatterns(patterns, context);
Operation *op = getOperation();
- applyPatternsGreedily(op->getRegions(), patterns);
+ applyPatternsAndFoldGreedily(op->getRegions(), patterns);
}
};
} // end anonymous namespace
diff --git a/mlir/lib/Transforms/Inliner.cpp b/mlir/lib/Transforms/Inliner.cpp
index 8ee4996bd03f..f797ca8f6484 100644
--- a/mlir/lib/Transforms/Inliner.cpp
+++ b/mlir/lib/Transforms/Inliner.cpp
@@ -541,7 +541,7 @@ static void canonicalizeSCC(CallGraph &cg, CGUseList &useList,
// Apply the canonicalization patterns to this region.
auto *node = nodesToCanonicalize[index];
- applyPatternsGreedily(*node->getCallableRegion(), canonPatterns);
+ applyPatternsAndFoldGreedily(*node->getCallableRegion(), canonPatterns);
// Make sure to reset the order ID for the diagnostic handler, as this
// thread may be used in a
diff erent context.
diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index 258df35d9b4d..80ad143ce0d3 100644
--- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -37,8 +37,8 @@ class GreedyPatternRewriteDriver : public PatternRewriter {
worklist.reserve(64);
}
- /// Perform the rewrites. Return true if the rewrite converges in
- /// `maxIterations`.
+ /// Perform the rewrites while folding and erasing any dead ops. Return true
+ /// if the rewrite converges in `maxIterations`.
bool simplify(MutableArrayRef<Region> regions, int maxIterations);
void addToWorklist(Operation *op) {
@@ -133,7 +133,7 @@ class GreedyPatternRewriteDriver : public PatternRewriter {
};
} // end anonymous namespace
-/// Perform the rewrites.
+/// Perform the rewrites while folding and erasing any dead ops.
bool GreedyPatternRewriteDriver::simplify(MutableArrayRef<Region> regions,
int maxIterations) {
// Add the given operation to the worklist.
@@ -213,14 +213,14 @@ bool GreedyPatternRewriteDriver::simplify(MutableArrayRef<Region> regions,
/// the result operation regions.
/// Note: This does not apply patterns to the top-level operation itself.
///
-bool mlir::applyPatternsGreedily(Operation *op,
- const OwningRewritePatternList &patterns) {
- return applyPatternsGreedily(op->getRegions(), patterns);
+bool mlir::applyPatternsAndFoldGreedily(
+ Operation *op, const OwningRewritePatternList &patterns) {
+ return applyPatternsAndFoldGreedily(op->getRegions(), patterns);
}
/// Rewrite the given regions, which must be isolated from above.
-bool mlir::applyPatternsGreedily(MutableArrayRef<Region> regions,
- const OwningRewritePatternList &patterns) {
+bool mlir::applyPatternsAndFoldGreedily(
+ MutableArrayRef<Region> regions, const OwningRewritePatternList &patterns) {
if (regions.empty())
return true;
diff --git a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
index 7c0052dd9e68..6c8b546e6aef 100644
--- a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
@@ -97,7 +97,7 @@ void TestAffineDataCopy::runOnFunction() {
OwningRewritePatternList patterns;
AffineLoadOp::getCanonicalizationPatterns(patterns, &getContext());
AffineStoreOp::getCanonicalizationPatterns(patterns, &getContext());
- applyPatternsGreedily(getFunction(), std::move(patterns));
+ applyPatternsAndFoldGreedily(getFunction(), std::move(patterns));
}
namespace mlir {
diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
index 90b34d9fe70f..d36eb985512a 100644
--- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp
+++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
@@ -46,7 +46,7 @@ struct TestPatternDriver : public PassWrapper<TestPatternDriver, FunctionPass> {
// Verify named pattern is generated with expected name.
patterns.insert<TestNamedPatternRule>(&getContext());
- applyPatternsGreedily(getFunction(), patterns);
+ applyPatternsAndFoldGreedily(getFunction(), patterns);
}
};
} // end anonymous namespace
diff --git a/mlir/test/lib/Transforms/TestAllReduceLowering.cpp b/mlir/test/lib/Transforms/TestAllReduceLowering.cpp
index 9a2bcc292379..c043d0f02f8d 100644
--- a/mlir/test/lib/Transforms/TestAllReduceLowering.cpp
+++ b/mlir/test/lib/Transforms/TestAllReduceLowering.cpp
@@ -22,7 +22,7 @@ struct TestAllReduceLoweringPass
void runOnOperation() override {
OwningRewritePatternList patterns;
populateGpuRewritePatterns(&getContext(), patterns);
- applyPatternsGreedily(getOperation(), patterns);
+ applyPatternsAndFoldGreedily(getOperation(), patterns);
}
};
} // namespace
diff --git a/mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp b/mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp
index 6f49fabc192a..e32f4d3dd6c5 100644
--- a/mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp
+++ b/mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp
@@ -36,7 +36,7 @@ struct DeclarativeTransforms
SubViewOp::getCanonicalizationPatterns(patterns, context);
ViewOp::getCanonicalizationPatterns(patterns, context);
populateWithGenerated(context, &patterns);
- applyPatternsGreedily(getFunction(), patterns);
+ applyPatternsAndFoldGreedily(getFunction(), patterns);
}
};
} // end anonymous namespace
diff --git a/mlir/test/lib/Transforms/TestLinalgTransforms.cpp b/mlir/test/lib/Transforms/TestLinalgTransforms.cpp
index 85300f981f1e..7fc1138ff8d4 100644
--- a/mlir/test/lib/Transforms/TestLinalgTransforms.cpp
+++ b/mlir/test/lib/Transforms/TestLinalgTransforms.cpp
@@ -40,7 +40,7 @@ void TestLinalgTransforms::runOnFunction() {
// Add the generated patterns to the list.
linalg::populateWithGenerated(&getContext(), &patterns);
- applyPatternsGreedily(funcOp, patterns);
+ applyPatternsAndFoldGreedily(funcOp, patterns);
// Drop the marker.
funcOp.walk([](LinalgOp op) {
diff --git a/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp b/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp
index b1c02bdd0adf..dc9b5c8d66cd 100644
--- a/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp
+++ b/mlir/test/lib/Transforms/TestVectorToLoopsConversion.cpp
@@ -23,7 +23,7 @@ struct TestVectorToLoopsPass
OwningRewritePatternList patterns;
auto *context = &getContext();
populateVectorToAffineLoopsConversionPatterns(context, patterns);
- applyPatternsGreedily(getFunction(), patterns);
+ applyPatternsAndFoldGreedily(getFunction(), patterns);
}
};
diff --git a/mlir/test/lib/Transforms/TestVectorTransforms.cpp b/mlir/test/lib/Transforms/TestVectorTransforms.cpp
index 808fcd21d331..c57540bc2ef7 100644
--- a/mlir/test/lib/Transforms/TestVectorTransforms.cpp
+++ b/mlir/test/lib/Transforms/TestVectorTransforms.cpp
@@ -28,7 +28,7 @@ struct TestVectorToVectorConversion
populateWithGenerated(context, &patterns);
populateVectorToVectorCanonicalizationPatterns(patterns, context);
populateVectorToVectorTransformationPatterns(patterns, context);
- applyPatternsGreedily(getFunction(), patterns);
+ applyPatternsAndFoldGreedily(getFunction(), patterns);
}
};
@@ -37,7 +37,7 @@ struct TestVectorSlicesConversion
void runOnFunction() override {
OwningRewritePatternList patterns;
populateVectorSlicesLoweringPatterns(patterns, &getContext());
- applyPatternsGreedily(getFunction(), patterns);
+ applyPatternsAndFoldGreedily(getFunction(), patterns);
}
};
@@ -57,7 +57,7 @@ struct TestVectorContractionConversion
VectorTransformsOptions options{
/*lowerToLLVMMatrixIntrinsics=*/lowerToLLVMMatrixIntrinsics};
populateVectorContractLoweringPatterns(patterns, &getContext(), options);
- applyPatternsGreedily(getFunction(), patterns);
+ applyPatternsAndFoldGreedily(getFunction(), patterns);
}
};
More information about the Mlir-commits
mailing list