[llvm] ca23b7c - [AsmPrinter] .addrsig_sym: remove isTransitiveUsedByMetadataOnly

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 11:05:49 PST 2022


Author: Fangrui Song
Date: 2022-12-02T19:05:43Z
New Revision: ca23b7ca476fb66771d1c6d02c6837938fde6c7e

URL: https://github.com/llvm/llvm-project/commit/ca23b7ca476fb66771d1c6d02c6837938fde6c7e
DIFF: https://github.com/llvm/llvm-project/commit/ca23b7ca476fb66771d1c6d02c6837938fde6c7e.diff

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/IR/Value.h
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/lib/IR/Value.cpp
    llvm/test/CodeGen/X86/addrsig.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Value.h b/llvm/include/llvm/IR/Value.h
index fc2ed00d770f..d0cd83bec89d 100644
--- a/llvm/include/llvm/IR/Value.h
+++ b/llvm/include/llvm/IR/Value.h
@@ -556,9 +556,6 @@ class Value {
   /// 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
index 1d148cd7b11b..b4b3128db306 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -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));
     }
   }

diff  --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 0fc7f5fe9172..4faf1abf7480 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -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
 //===----------------------------------------------------------------------===//

diff  --git a/llvm/test/CodeGen/X86/addrsig.ll b/llvm/test/CodeGen/X86/addrsig.ll
index f028e0a6b190..5b15c86955f8 100644
--- 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 @@ 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


        


More information about the llvm-commits mailing list