[PATCH] D153855: [StructuralHash] Ignore global variable declarations
Mikael Holmén via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 03:55:06 PDT 2023
uabelho created this revision.
uabelho added reviewers: aeubanks, nikic.
Herald added subscribers: StephenFan, bjope, hiraditya.
Herald added a project: All.
uabelho requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Ignore declarations of global variables, just as we do with declarations
of functions.
Done as a follow up to the comments in https://reviews.llvm.org/D149209.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153855
Files:
llvm/lib/IR/StructuralHash.cpp
llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll
Index: llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/StripDeadPrototypes/remove-global-variable-declaration.ll
@@ -0,0 +1,38 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -passes=strip-dead-prototypes -S -verify-analysis-invalidation < %s | FileCheck %s
+
+; The declaration of the unused global variable @.str should be removed without
+; getting any error from -verify-analysis-invalidation.
+
+; CHECK-NOT: @.str
+
+ at .str = external constant [15 x i16]
+
+define i16 @_Z7test_itv() {
+; CHECK-LABEL: define i16 @_Z7test_itv() {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 0, ptr null)
+; CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr null, metadata [[META3:![0-9]+]], metadata !DIExpression()), !dbg [[DBG5:![0-9]+]]
+; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 0, ptr null)
+; CHECK-NEXT: ret i16 0
+;
+entry:
+ call void @llvm.lifetime.start.p0(i64 0, ptr null)
+ call void @llvm.dbg.declare(metadata ptr null, metadata !3, metadata !DIExpression()), !dbg !5
+ call void @llvm.lifetime.end.p0(i64 0, ptr null)
+ ret i16 0
+}
+
+declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1)
+!1 = !DIFile(filename: "t.C", directory: "/")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !DILocalVariable(scope: !4)
+!4 = distinct !DISubprogram(unit: !0)
+!5 = !DILocation(scope: !4)
Index: llvm/lib/IR/StructuralHash.cpp
===================================================================
--- llvm/lib/IR/StructuralHash.cpp
+++ llvm/lib/IR/StructuralHash.cpp
@@ -58,8 +58,9 @@
}
void update(const GlobalVariable &GV) {
- // used/compiler.used don't affect analyses.
- if (GV.getName() == "llvm.compiler.used" || GV.getName() == "llvm.used")
+ // Declarations and used/compiler.used don't affect analyses.
+ if (GV.isDeclaration() || GV.getName() == "llvm.compiler.used" ||
+ GV.getName() == "llvm.used")
return;
hash(23456); // Global header
hash(GV.getValueType()->getTypeID());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153855.534902.patch
Type: text/x-patch
Size: 2452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230627/afbcec39/attachment.bin>
More information about the llvm-commits
mailing list