[all-commits] [llvm/llvm-project] 20a62a: [CIR] Eliminate SymbolTable::lookupSymbolIn hotspo...

Bruno Cardoso Lopes via All-commits all-commits at lists.llvm.org
Mon Apr 27 14:33:14 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 20a62a41c26215b342431c6ab98702ddfb1a6a86
      https://github.com/llvm/llvm-project/commit/20a62a41c26215b342431c6ab98702ddfb1a6a86
  Author: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
  Date:   2026-04-27 (Mon, 27 Apr 2026)

  Changed paths:
    M clang/lib/CIR/CodeGen/CIRGenDecl.cpp
    M clang/lib/CIR/CodeGen/CIRGenExpr.cpp
    M clang/lib/CIR/CodeGen/CIRGenFunction.cpp
    M clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
    M clang/lib/CIR/CodeGen/CIRGenModule.cpp
    M clang/lib/CIR/CodeGen/CIRGenModule.h
    M clang/lib/CIR/CodeGen/CIRGenVTables.cpp

  Log Message:
  -----------
  [CIR] Eliminate SymbolTable::lookupSymbolIn hotspots (#193362)

mlir::SymbolTable::lookupSymbolIn is O(n) per lookup, so cumulative
symbol lookups during CIRGen are O(n^2) in the number of global symbols.
On template-heavy translation units this becomes a significant
compile-time hotspot.

Replace the SymbolTable lookup path with a per-CIRGenModule DenseMap
cache keyed by symbol name, giving O(1) lookups.

On a synthetic template-heavy stress test, end-to-end compile time on
`clang -fclangir -S -emit-llvm -O0` improves by ~11% on a 33K-LOC input
(5.86s -> 5.21s) and ~16% on a 67K-LOC input (16.09s -> 13.52s). The
super-linear growth of the win with input size confirms the O(n^2) ->
O(n) effect.

Similar to previous compile time fix, repro shape (scale records and
template instantiations into the hundreds/thousands to amplify):

  template <typename T, int N> struct Box { T head; Box<T, N-1> tail; };
  template <typename T> struct Box<T, 0> { T head; };
  struct R0; struct R1;
  struct R0 { int v; Box<int, 4> b; R1* next; };
  struct R1 { long v; Box<long, 4> b; R0* next; };
  int f0(R0*); int f1(R1*);
  int f0(R0* r) { return r->v + (r->next ? f1(r->next) : 0); }
  int f1(R1* r) { return (int)r->v + (r->next ? f0(r->next) : 0); }



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list