[clang] [CIR][NFC] Do not copy CIRGenBuilderTy per vtable component (PR #232509)
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 15 14:53:18 PDT 2026
https://github.com/bcardosolopes created https://github.com/llvm/llvm-project/pull/232509
CIRGenBuilderTy carries two StringMaps by value (record name and global versioning maps), which grow to tens of thousands of entries over a translation unit. getVTableComponent copied the builder on every call, deep-copying both maps per vtable component: quadratic work that cost ~12.5s while selfhosting clang/unittests/AST/ASTImporterTest.cpp.
Take the builder by reference instead, matching every other call site. Also take it by reference in genVscaleTimesFactor, the only other by-value use.
ASTImporterTest -fclangir wall time goes from 87.4s to 75.0s; output is unchanged.
>From 2094d22708eb4fc7f8a048d9e3371b4bc562b586 Mon Sep 17 00:00:00 2001
From: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
Date: Wed, 7 Oct 2026 17:51:56 -0700
Subject: [PATCH] [CIR][NFC] Do not copy CIRGenBuilderTy per vtable component
CIRGenBuilderTy carries two StringMaps by value (record name and global
versioning maps), which grow to tens of thousands of entries over a
translation unit. getVTableComponent copied the builder on every call,
deep-copying both maps per vtable component: quadratic work that cost
~12.5s on clang/unittests/AST/ASTImporterTest.cpp.
Take the builder by reference instead, matching every other call site.
Also take it by reference in genVscaleTimesFactor, the only other
by-value use.
ASTImporterTest -fclangir wall time goes from 87.4s to 75.0s; output is
unchanged.
Assisted-by: Muse Code (Muse).
---
clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp | 2 +-
clang/lib/CIR/CodeGen/CIRGenVTables.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
index ba7355cffbaf04..30438d5288608a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
@@ -37,7 +37,7 @@ using namespace clang::aarch64;
// Generate vscale * scalingFactor
static mlir::Value genVscaleTimesFactor(mlir::Location loc,
- CIRGenBuilderTy builder,
+ CIRGenBuilderTy &builder,
mlir::Type cirTy,
int32_t scalingFactor) {
mlir::Value vscale = builder.emitIntrinsicCallOp(loc, "vscale", cirTy);
diff --git a/clang/lib/CIR/CodeGen/CIRGenVTables.cpp b/clang/lib/CIR/CodeGen/CIRGenVTables.cpp
index 270b8a6a539ba9..ca7a8a74a9e211 100644
--- a/clang/lib/CIR/CodeGen/CIRGenVTables.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenVTables.cpp
@@ -141,7 +141,7 @@ mlir::Attribute CIRGenVTables::getVTableComponent(
bool vtableHasLocalLinkage) {
const VTableComponent &component = layout.vtable_components()[componentIndex];
- CIRGenBuilderTy builder = cgm.getBuilder();
+ CIRGenBuilderTy &builder = cgm.getBuilder();
assert(!cir::MissingFeatures::vtableRelativeLayout());
More information about the cfe-commits
mailing list