[llvm] 6b13cfe - [ArgumentPromotion]: Copy function metadata after promoting arguments

Ettore Tiotto via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 10:10:15 PDT 2020


Author: Ettore Tiotto
Date: 2020-09-10T13:08:57-04:00
New Revision: 6b13cfe7399b0aba726873f807ddfcdd9f967563

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

LOG: [ArgumentPromotion]: Copy function metadata after promoting arguments

The argument promotion pass currently fails to copy function annotations
over to the modified function after promoting arguments.
This patch copies the original function annotation to the new function.

Reviewed By: fhann

Differential Revision: https://reviews.llvm.org/D86630

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
    llvm/test/Transforms/ArgumentPromotion/profile.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index d511ad2729ab..348717ec5618 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -215,9 +215,11 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
   Function *NF = Function::Create(NFTy, F->getLinkage(), F->getAddressSpace(),
                                   F->getName());
   NF->copyAttributesFrom(F);
+  NF->copyMetadata(F, 0);
 
-  // Patch the pointer to LLVM function in debug info descriptor.
-  NF->setSubprogram(F->getSubprogram());
+  // The new function will have the !dbg metadata copied from the original
+  // function. The original function may not be deleted, and dbg metadata need
+  // to be unique so we need to drop it.
   F->setSubprogram(nullptr);
 
   LLVM_DEBUG(dbgs() << "ARG PROMOTION:  Promoting to:" << *NF << "\n"

diff  --git a/llvm/test/Transforms/ArgumentPromotion/profile.ll b/llvm/test/Transforms/ArgumentPromotion/profile.ll
index f4bceb3eb913..941eafad1af3 100644
--- a/llvm/test/Transforms/ArgumentPromotion/profile.ll
+++ b/llvm/test/Transforms/ArgumentPromotion/profile.ll
@@ -15,9 +15,9 @@ define void @caller() #0 {
   ret void
 }
 
-define internal void @promote_i32_ptr(i32* %xp) {
+define internal void @promote_i32_ptr(i32* %xp) !prof !1 {
 ; CHECK-LABEL: define {{[^@]+}}@promote_i32_ptr
-; CHECK-SAME: (i32 [[XP_VAL:%.*]])
+; CHECK-SAME: (i32 [[XP_VAL:%.*]]) !prof !1
 ; CHECK-NEXT:    call void @use_i32(i32 [[XP_VAL]])
 ; CHECK-NEXT:    ret void
 ;
@@ -29,3 +29,4 @@ define internal void @promote_i32_ptr(i32* %xp) {
 declare void @use_i32(i32)
 
 !0 = !{!"branch_weights", i32 30}
+!1 = !{!"function_entry_count", i64 100}


        


More information about the llvm-commits mailing list