[PATCH] D154019: [IR] Ignore globals with the `llvm.` prefix when calculating module hash

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 08:40:46 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe8e499f5f9c4: [IR] Ignore globals with the `llvm.` prefix when calculating module hash (authored by paulkirth).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154019/new/

https://reviews.llvm.org/D154019

Files:
  llvm/lib/IR/StructuralHash.cpp
  llvm/unittests/IR/StructuralHashTest.cpp


Index: llvm/unittests/IR/StructuralHashTest.cpp
===================================================================
--- llvm/unittests/IR/StructuralHashTest.cpp
+++ llvm/unittests/IR/StructuralHashTest.cpp
@@ -12,6 +12,8 @@
 #include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
 
+#include <memory>
+
 using namespace llvm;
 
 namespace {
@@ -121,4 +123,21 @@
   EXPECT_EQ(StructuralHash(*M1), StructuralHash(*M2));
 }
 
+TEST(StructuralHashTest, IgnoredMetadata) {
+  LLVMContext Ctx;
+  std::unique_ptr<Module> M1 = parseIR(Ctx, "@a = global i32 1\n");
+  // clang-format off
+  std::unique_ptr<Module> M2 = parseIR(
+      Ctx, R"(
+        @a = global i32 1
+        @llvm.embedded.object = private constant [4 x i8] c"BC\C0\00", section ".llvm.lto", align 1, !exclude !0
+        @llvm.compiler.used = appending global [1 x ptr] [ptr @llvm.embedded.object], section "llvm.metadata"
+
+        !llvm.embedded.objects = !{!1}
+
+        !0 = !{}
+        !1 = !{ptr @llvm.embedded.object, !".llvm.lto"}
+        )");
+  EXPECT_EQ(StructuralHash(*M1), StructuralHash(*M2));
+}
 } // end anonymous namespace
Index: llvm/lib/IR/StructuralHash.cpp
===================================================================
--- llvm/lib/IR/StructuralHash.cpp
+++ llvm/lib/IR/StructuralHash.cpp
@@ -59,10 +59,9 @@
 
   void update(const GlobalVariable &GV) {
     // Declarations and used/compiler.used don't affect analyses.
-    // Same for llvm.embedded.object, which is always a metadata section.
-    if (GV.isDeclaration() ||
-        GV.getName() == "llvm.compiler.used" || GV.getName() == "llvm.used" ||
-        GV.getName() == "llvm.embedded.object")
+    // Since there are several `llvm.*` metadata, like `llvm.embedded.object`,
+    // we ignore anything with the `.llvm` prefix
+    if (GV.isDeclaration() || GV.getName().starts_with("llvm."))
       return;
     hash(23456); // Global header
     hash(GV.getValueType()->getTypeID());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154019.539585.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230712/33cb33bb/attachment.bin>


More information about the llvm-commits mailing list