Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Commit 4b3e543

Browse files
authored
[CIR][CodeGen] Use MapVector instead of StringMap for Replacements (#2116)
Fix #1938 Minimized benchmark: ```cpp #include <vector> class my_class { public: std::vector<void*> my_vec; }; my_class inst; ``` When using `llvm::StringMap` transitive replacements may be out of order. So use `llvm::MapVector` which is also used in clang's CodeGen. https://github.com/llvm/clangir/blob/0c130cda66d792752fa52f57aabdf561a49482fd/clang/lib/CodeGen/CodeGenModule.h#L439 I couldn't reproduce the MRE with `#include "std-cxx.h"`, any other way to add the test?
1 parent 0c130cd commit 4b3e543

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

β€Žclang/lib/CIR/CodeGen/CIRGenModule.cppβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4268,7 +4268,7 @@ void CIRGenModule::replacePointerTypeArgs(cir::FuncOp oldF, cir::FuncOp newF) {
42684268

42694269
void CIRGenModule::applyReplacements() {
42704270
for (auto &i : Replacements) {
4271-
StringRef mangledName = i.first();
4271+
StringRef mangledName = i.first;
42724272
mlir::Operation *replacement = i.second;
42734273
auto *entry = getGlobalValue(mangledName);
42744274
if (!entry)

β€Žclang/lib/CIR/CodeGen/CIRGenModule.hβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,7 @@ class CIRGenModule : public CIRGenTypeCache {
10221022
llvm::StringMap<clang::GlobalDecl, llvm::BumpPtrAllocator> Manglings;
10231023

10241024
// FIXME: should we use llvm::TrackingVH<mlir::Operation> here?
1025-
typedef llvm::StringMap<mlir::Operation *> ReplacementsTy;
1026-
ReplacementsTy Replacements;
1025+
llvm::MapVector<StringRef, mlir::Operation *> Replacements;
10271026
/// Call replaceAllUsesWith on all pairs in Replacements.
10281027
void applyReplacements();
10291028

0 commit comments

Comments
Β (0)