diff --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h --- a/llvm/include/llvm/IR/Value.h +++ b/llvm/include/llvm/IR/Value.h @@ -556,9 +556,6 @@ /// Return true if there is metadata referencing this value. bool isUsedByMetadata() const { return IsUsedByMD; } - // Return true if this value is only transitively referenced by metadata. - bool isTransitiveUsedByMetadataOnly() const; - protected: /// Get the current metadata attachments for the given kind, if any. /// diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2280,9 +2280,9 @@ // Emit address-significance attributes for all globals. OutStreamer->emitAddrsig(); for (const GlobalValue &GV : M.global_values()) { - if (!GV.use_empty() && !GV.isTransitiveUsedByMetadataOnly() && - !GV.isThreadLocal() && !GV.hasDLLImportStorageClass() && - !GV.getName().startswith("llvm.") && !GV.hasAtLeastLocalUnnamedAddr()) + if (!GV.use_empty() && !GV.isThreadLocal() && + !GV.hasDLLImportStorageClass() && !GV.getName().startswith("llvm.") && + !GV.hasAtLeastLocalUnnamedAddr()) OutStreamer->emitAddrsigSym(getSymbol(&GV)); } } diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -1022,22 +1022,6 @@ return Alloca->isSwiftError(); } -bool Value::isTransitiveUsedByMetadataOnly() const { - SmallVector WorkList(user_begin(), user_end()); - SmallPtrSet Visited(user_begin(), user_end()); - while (!WorkList.empty()) { - const User *U = WorkList.pop_back_val(); - // If it is transitively used by a global value or a non-constant value, - // it's obviously not only used by metadata. - if (!isa(U) || isa(U)) - return false; - for (const User *UU : U->users()) - if (Visited.insert(UU).second) - WorkList.push_back(UU); - } - return true; -} - //===----------------------------------------------------------------------===// // ValueHandleBase Class //===----------------------------------------------------------------------===// diff --git a/llvm/test/CodeGen/X86/addrsig.ll b/llvm/test/CodeGen/X86/addrsig.ll --- a/llvm/test/CodeGen/X86/addrsig.ll +++ b/llvm/test/CodeGen/X86/addrsig.ll @@ -1,8 +1,18 @@ ; RUN: llc < %s -mtriple=x86_64-unknown-linux | FileCheck --check-prefix=NO-ADDRSIG %s ; RUN: llc < %s -mtriple=x86_64-unknown-linux -addrsig | FileCheck %s +; RUN: llc %s -filetype=obj -mtriple=x86_64-unknown-linux -addrsig -o %t +; RUN: llvm-readobj --addrsig %t | FileCheck %s --check-prefix=SYM ; NO-ADDRSIG-NOT: .addrsig +; SYM: Addrsig [ +; SYM-NEXT: Sym: f1 +; SYM-NEXT: Sym: metadata_f2 +; SYM-NEXT: Sym: g1 +; SYM-NEXT: Sym: a1 +; SYM-NEXT: Sym: i1 +; SYM-NEXT: ] + ; CHECK: .addrsig ; CHECK: .addrsig_sym f1 @@ -27,7 +37,8 @@ declare void @f4(i8*) unnamed_addr -; CHECK-NOT: .addrsig_sym metadata_f1 +;; f1 is unreferenced, so this directive does not emit an entry. +; CHECK: .addrsig_sym metadata_f1 declare void @metadata_f1() ; CHECK: .addrsig_sym metadata_f2