[clang] [CIR] CXXABI and target lowering without pattern rollback (PR #238691)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 22:19:30 PST 2026


https://github.com/bcardosolopes updated https://github.com/llvm/llvm-project/pull/238691

>From dc5c862fceec4e6b0ed7841434b8612875e42289 Mon Sep 17 00:00:00 2001
From: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
Date: Tue, 3 Nov 2026 11:57:41 -0800
Subject: [PATCH] [CIR] Convert CXXABI and target lowering without pattern
 rollback

Flip CXXABILowering and TargetLowering to one-shot dialect conversion
(allowPatternRollback=false). Rewrites materialize immediately,
skipping the IR rewrite and value mapping bookkeeping the rollback
driver keeps for every pattern application. One-shot is a
per-conversion driver mode, so it applies identically to these
CIR-to-CIR conversions. Both passes lower CIR to CIR with total
patterns, so no supporting changes are needed; the full suite passes
with no test changes.

Failure semantics change, but only on paths these passes cannot hit.
If a pattern fires and its own output then fails to legalize, the
driver can no longer roll back: a rewrite of arith.addi to an
unlegalizable arith.muli fails gracefully today with

  error: failed to legalize operation 'arith.addi' ...

and aborts one-shot with

  LLVM ERROR: pattern '...' produced IR that could not be legalized.

Every failure() return in both passes precedes the first rewriter
call and the converters never return null, so no pattern here can
fire and then fail. The only failure left is an unmatched illegal
op, which keeps the graceful diagnostic in both modes.

First of the one-shot split; ConvertCIRToLLVM follows separately.

Assisted-by: Muse Code (Muse)
---
 clang/lib/CIR/Dialect/Transforms/CXXABILowering.cpp | 10 +++++++---
 clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp | 10 +++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CIR/Dialect/Transforms/CXXABILowering.cpp b/clang/lib/CIR/Dialect/Transforms/CXXABILowering.cpp
index c1ce076fa8944..3342ca66f1d72 100644
--- a/clang/lib/CIR/Dialect/Transforms/CXXABILowering.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CXXABILowering.cpp
@@ -590,8 +590,7 @@ mlir::LogicalResult CIRFuncOpABILowering::matchAndRewrite(
       cir::FuncType::get(signatureConversion.getConvertedTypes(),
                          loweredResultType, /*isVarArg=*/opFuncType.isVarArg());
 
-  // Convert the body types before moving it: a failure here leaves the
-  // body unmoved for the driver to report.
+  // Convert the body types before moving it.
   if (mlir::failed(rewriter.convertRegionTypes(
           &op.getBody(), *getTypeConverter(), &signatureConversion)))
     return mlir::failure();
@@ -983,7 +982,12 @@ void CXXABILoweringPass::runOnOperation() {
   ops.push_back(mod);
   cir::collectUnreachable(mod, ops);
 
-  if (failed(mlir::applyPartialConversion(ops, target, std::move(patterns))))
+  // One-shot conversion (no pattern rollback): rewrites materialize
+  // immediately, skipping the IRRewrite/value-mapping bookkeeping.
+  mlir::ConversionConfig config;
+  config.allowPatternRollback = false;
+  if (failed(mlir::applyPartialConversion(ops, target, std::move(patterns),
+                                          config)))
     signalPassFailure();
 
   typeConverter.restoreRecordTypeNames();
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp
index d2fa36972605b..e88a376b6ff24 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp
@@ -243,8 +243,7 @@ class CIRFuncOpTargetLowering : public mlir::OpConversionPattern<cir::FuncOp> {
     if (loweredFuncType == opFuncType)
       return mlir::failure();
 
-    // Convert the body types before moving it: a failure here leaves the
-    // body unmoved for the driver to report.
+    // Convert the body types before moving it.
     if (mlir::failed(rewriter.convertRegionTypes(
             &op.getBody(), *getTypeConverter(), &signatureConversion)))
       return mlir::failure();
@@ -333,7 +332,12 @@ void TargetLoweringPass::runOnOperation() {
   ops.push_back(mod);
   cir::collectUnreachable(mod, ops);
 
-  if (failed(mlir::applyPartialConversion(ops, target, std::move(patterns))))
+  // One-shot conversion (no pattern rollback): rewrites materialize
+  // immediately, skipping the IRRewrite/value-mapping bookkeeping.
+  mlir::ConversionConfig config;
+  config.allowPatternRollback = false;
+  if (failed(mlir::applyPartialConversion(ops, target, std::move(patterns),
+                                          config)))
     signalPassFailure();
 
   typeConverter.restoreRecordTypeNames();



More information about the cfe-commits mailing list