[llvm] e8e499f - [IR] Ignore globals with the `llvm.` prefix when calculating module hash
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 12 08:40:39 PDT 2023
Author: Paul Kirth
Date: 2023-07-12T15:40:31Z
New Revision: e8e499f5f9c4c28c367577c54a1999fac824a727
URL: https://github.com/llvm/llvm-project/commit/e8e499f5f9c4c28c367577c54a1999fac824a727
DIFF: https://github.com/llvm/llvm-project/commit/e8e499f5f9c4c28c367577c54a1999fac824a727.diff
LOG: [IR] Ignore globals with the `llvm.` prefix when calculating module hash
This came up in This came up in
https://reviews.llvm.org/D146776#inline-1489091 and is slightly related
to https://reviews.llvm.org/D153855. In both patches, there is the
observation that some modifications of the module should not invalidate
analysis, such as when adding a declaration or some metadata the won't
be used when compiling the current module.
This patch implements the suggestion that we should ignore globals that have
the `llvm.` prefix when calculating the module hash.
Fixes https://github.com/llvm/llvm-project/issues/63590
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D154019
Added:
Modified:
llvm/lib/IR/StructuralHash.cpp
llvm/unittests/IR/StructuralHashTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/StructuralHash.cpp b/llvm/lib/IR/StructuralHash.cpp
index ca58cf9e718a48..6ea108d831a165 100644
--- a/llvm/lib/IR/StructuralHash.cpp
+++ b/llvm/lib/IR/StructuralHash.cpp
@@ -59,10 +59,9 @@ class StructuralHashImpl {
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());
diff --git a/llvm/unittests/IR/StructuralHashTest.cpp b/llvm/unittests/IR/StructuralHashTest.cpp
index d25198fe307ab0..4c16144a91df9f 100644
--- a/llvm/unittests/IR/StructuralHashTest.cpp
+++ b/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 @@ TEST(StructuralHashTest, InstructionType) {
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
More information about the llvm-commits
mailing list