[llvm] [IR] Use SmallDenseSet in dropUnknownNonDebugMetadata (NFC) (PR #98853)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 14 19:18:46 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/98853

SmallSet here often ends up allocating memory via std::set inside
SmallSet because KnownIDs.size() goes up to 17 on an x86 host.  This
patch switches to SmallDenseSet<unsigned, 32> to avoid memory
allocations.

The use of SmallDenseSet here saves 0.57% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.


>From 2988b8f2d4598d0e13c54f6dfb58b8402c773875 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 14 Jul 2024 17:52:13 -0700
Subject: [PATCH] [IR] Use SmallDenseSet in dropUnknownNonDebugMetadata (NFC)

SmallSet here often ends up allocating memory via std::set inside
SmallSet because KnownIDs.size() goes up to 17 on an x86 host.  This
patch switches to SmallDenseSet<unsigned, 32> to avoid memory
allocations.

The use of SmallDenseSet here saves 0.57% of heap allocations during
the compilation of X86ISelLowering.cpp.ii, a preprocessed version of
X86ISelLowering.cpp.
---
 llvm/lib/IR/Metadata.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 5f42ce22f72fe..a1bae38b07ab6 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -20,7 +20,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -1590,7 +1589,7 @@ void Instruction::dropUnknownNonDebugMetadata(ArrayRef<unsigned> KnownIDs) {
   if (!Value::hasMetadata())
     return; // Nothing to remove!
 
-  SmallSet<unsigned, 4> KnownSet;
+  SmallDenseSet<unsigned, 32> KnownSet;
   KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
 
   // A DIAssignID attachment is debug metadata, don't drop it.



More information about the llvm-commits mailing list