[PATCH] D100738: Cache attribute checks

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 18 21:02:02 PDT 2021


nickwasmer created this revision.
nickwasmer added reviewers: dexonsmith, nikic.
nickwasmer added a project: LLVM.
Herald added a subscriber: hiraditya.
nickwasmer requested review of this revision.
Herald added a subscriber: llvm-commits.

As a followup to D99362 <https://reviews.llvm.org/D99362> cache the checks that attributes belong to the same context. Looking for presence in a FoldingSet is slow.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100738

Files:
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -328,6 +328,9 @@
   /// Cache of declarations of the llvm.experimental.deoptimize.<ty> intrinsic.
   SmallVector<const Function *, 4> DeoptimizeDeclarations;
 
+  /// Cache of attribute lists verified.
+  SmallPtrSet<const void *, 32> AttributeListsVisited;
+
   // Verify that this GlobalValue is only used in this module.
   // This map is used to avoid visiting uses twice. We can arrive at a user
   // twice, if they have multiple operands. In particular for very large
@@ -1890,14 +1893,16 @@
   if (Attrs.isEmpty())
     return;
 
-  Assert(Attrs.hasParentContext(Context),
-         "Attribute list does not match Module context!", &Attrs);
-  for (const auto &AttrSet : Attrs) {
-    Assert(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
-           "Attribute set does not match Module context!", &AttrSet);
-    for (const auto &A : AttrSet) {
-      Assert(A.hasParentContext(Context),
-             "Attribute does not match Module context!", &A);
+  if (AttributeListsVisited.insert(Attrs.getRawPointer()).second) {
+    Assert(Attrs.hasParentContext(Context),
+           "Attribute list does not match Module context!", &Attrs);
+    for (const auto &AttrSet : Attrs) {
+      Assert(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
+             "Attribute set does not match Module context!", &AttrSet);
+      for (const auto &A : AttrSet) {
+        Assert(A.hasParentContext(Context),
+               "Attribute does not match Module context!", &A);
+      }
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100738.338424.patch
Type: text/x-patch
Size: 1685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210419/7e855748/attachment.bin>


More information about the llvm-commits mailing list