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

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 22:17:32 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangir

Author: Bruno Cardoso Lopes (bcardosolopes)

<details>
<summary>Changes</summary>

Small build time win. 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. First of the one-shot split, ConvertCIRToLLVM will come next.

Worth noticing that this changes failure from:

```
  error: failed to legalize operation '<op>' ...
```

and aborts one-shot with

```
  LLVM ERROR: pattern '<NameOfPattern>' produced IR that could not be legalized.
```

Unmatched illegal op still keeps the original diagnostic. 

---
Full diff: https://github.com/llvm/llvm-project/pull/238691.diff


2 Files Affected:

- (modified) clang/lib/CIR/Dialect/Transforms/CXXABILowering.cpp (+7-3) 
- (modified) clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp (+7-3) 


``````````diff
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();

``````````

</details>


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


More information about the cfe-commits mailing list