[AsmPrinter] .addrsig_sym: remove isTransitiveUsedByMetadataOnly

With D135642 ignoring unregistered symbols, isTransitiveUsedByMetadataOnly added
by D101512 is no longer needed (the operation is potentially slow). There is a
`.addrsig_sym` directive for an only-used-by-metadata symbol but it does not
emit an entry.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D138362
This commit is contained in:
Fangrui Song 2022-12-02 19:05:43 +00:00
parent 9f07256a51
commit ca23b7ca47
4 changed files with 15 additions and 23 deletions

View File

@ -556,9 +556,6 @@ public:
/// 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.
///

View File

@ -2280,9 +2280,9 @@ bool AsmPrinter::doFinalization(Module &M) {
// 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));
}
}

View File

@ -1022,22 +1022,6 @@ bool Value::isSwiftError() const {
return Alloca->isSwiftError();
}
bool Value::isTransitiveUsedByMetadataOnly() const {
SmallVector<const User *, 32> WorkList(user_begin(), user_end());
SmallPtrSet<const User *, 32> 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<Constant>(U) || isa<GlobalValue>(U))
return false;
for (const User *UU : U->users())
if (Visited.insert(UU).second)
WorkList.push_back(UU);
}
return true;
}
//===----------------------------------------------------------------------===//
// ValueHandleBase Class
//===----------------------------------------------------------------------===//

View File

@ -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 @@ define void()* @f1() {
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