[flang-commits] [flang] [flang] disable cf canonicalization patterns at O0 to preserve line location (PR #227770)
Abid Qadeer via flang-commits
flang-commits at lists.llvm.org
Wed Sep 30 10:53:05 PDT 2026
================
@@ -0,0 +1,59 @@
+//===-- O0CanonicalizerPass.cpp -- Canonicalization for O0 ----------------===//
+//
+// 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 "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+
+namespace fir {
+#define GEN_PASS_DEF_O0CANONICALIZERPASS
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+void fir::populateCanonicalizationPatterns(
+ mlir::RewritePatternSet &patterns, bool includeCFPatterns,
+ llvm::function_ref<bool(mlir::RegisteredOperationName)> shouldCollect) {
+ mlir::MLIRContext *context = patterns.getContext();
+ auto includeDialect = [&](mlir::Dialect *dialect) {
+ return includeCFPatterns ||
+ !mlir::isa<mlir::cf::ControlFlowDialect>(dialect);
+ };
+ for (mlir::Dialect *dialect : context->getLoadedDialects())
+ if (includeDialect(dialect))
+ dialect->getCanonicalizationPatterns(patterns);
+ for (mlir::RegisteredOperationName op : context->getRegisteredOperations())
+ if (includeDialect(&op.getDialect()) &&
+ (!shouldCollect || shouldCollect(op)))
+ op.getCanonicalizationPatterns(patterns, context);
+}
----------------
abidh wrote:
nit: The function mirrors some logic from Canonicalizer::initialize and a small comment may help a future reader.
https://github.com/llvm/llvm-project/pull/227770
More information about the flang-commits
mailing list