[llvm] [IR] Speed up printing instruction sequences (PR #221460)
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 11:17:45 PDT 2026
https://github.com/yxsamliu updated https://github.com/llvm/llvm-project/pull/221460
>From 7e7b791d1697b746a7fe7db7279af54807b7a772 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" <yaxun.liu at amd.com>
Date: Sat, 15 Aug 2026 00:43:35 -0400
Subject: [PATCH] [IR] Avoid collecting COMDATs for non-module printing
AssemblyWriter currently scans all module global objects in its constructor to collect referenced COMDATs. This is needed only when printing a complete module, but the scan also runs for standalone value and instruction printing.
Move COMDAT collection to printModule so those paths avoid the module-wide scan.
---
llvm/lib/IR/AsmWriter.cpp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 8e57bff1d36c9..7c471d8f4acbe 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -3068,13 +3068,7 @@ AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
ShouldPreserveUseListOrder(
PreserveAssemblyUseListOrder.getNumOccurrences()
? PreserveAssemblyUseListOrder
- : ShouldPreserveUseListOrder) {
- if (!TheModule)
- return;
- for (const GlobalObject &GO : TheModule->global_objects())
- if (const Comdat *C = GO.getComdat())
- Comdats.insert(C);
-}
+ : ShouldPreserveUseListOrder) {}
AssemblyWriter::AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const ModuleSummaryIndex *Index, bool IsForDebug)
@@ -3186,6 +3180,10 @@ void AssemblyWriter::writeOperandBundles(const CallBase *Call) {
void AssemblyWriter::printModule(const Module *M) {
Machine.initializeIfNeeded();
+ for (const GlobalObject &GO : M->global_objects())
+ if (const Comdat *C = GO.getComdat())
+ Comdats.insert(C);
+
if (ShouldPreserveUseListOrder)
UseListOrders = predictUseListOrder(M);
More information about the llvm-commits
mailing list