[llvm] r328991 - [DeadArgumentElim] Clone function level metadatas
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 2 10:27:39 PDT 2018
Author: xur
Date: Mon Apr 2 10:27:38 2018
New Revision: 328991
URL: http://llvm.org/viewvc/llvm-project?rev=328991&view=rev
Log:
[DeadArgumentElim] Clone function level metadatas
Some Function level metadatas, such as function entry count, are not cloned in
DeadArgumentElim. This happens a lot in lto/thinlto because of DeadArgumentElim
after internalization.
This patch clones the metadatas in the original function to the new function.
Differential Revision: https://reviews.llvm.org/D44127
Added:
llvm/trunk/test/Transforms/DeadArgElim/func_metadata.ll
Modified:
llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
Modified: llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=328991&r1=328990&r2=328991&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp Mon Apr 2 10:27:38 2018
@@ -240,8 +240,11 @@ bool DeadArgumentEliminationPass::Delete
I2->takeName(&*I);
}
- // Patch the pointer to LLVM function in debug info descriptor.
- NF->setSubprogram(Fn.getSubprogram());
+ // Clone metadatas from the old function, including debug info descriptor.
+ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
+ Fn.getAllMetadata(MDs);
+ for (auto MD : MDs)
+ NF->addMetadata(MD.first, *MD.second);
// Fix up any BlockAddresses that refer to the function.
Fn.replaceAllUsesWith(ConstantExpr::getBitCast(NF, Fn.getType()));
@@ -863,9 +866,6 @@ bool DeadArgumentEliminationPass::Remove
F->getParent()->getFunctionList().insert(F->getIterator(), NF);
NF->takeName(F);
- // Patch the pointer to LLVM function in debug info descriptor.
- NF->setSubprogram(F->getSubprogram());
-
// Loop over all of the callers of the function, transforming the call sites
// to pass in a smaller number of arguments into the new function.
std::vector<Value*> Args;
@@ -1058,6 +1058,12 @@ bool DeadArgumentEliminationPass::Remove
BB.getInstList().erase(RI);
}
+ // Clone metadatas from the old function, including debug info descriptor.
+ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
+ F->getAllMetadata(MDs);
+ for (auto MD : MDs)
+ NF->addMetadata(MD.first, *MD.second);
+
// Now that the old function is dead, delete it.
F->eraseFromParent();
Added: llvm/trunk/test/Transforms/DeadArgElim/func_metadata.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadArgElim/func_metadata.ll?rev=328991&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/DeadArgElim/func_metadata.ll (added)
+++ llvm/trunk/test/Transforms/DeadArgElim/func_metadata.ll Mon Apr 2 10:27:38 2018
@@ -0,0 +1,67 @@
+; RUN: opt -deadargelim -S < %s | FileCheck %s
+
+; Check if function level metadatas are properly cloned.
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at s = common dso_local local_unnamed_addr global i32 0, align 4
+
+define internal i32 @va_func(i32 %num, ...) !prof !28 !PGOFuncName !29{
+; CHECK: define internal void @va_func(i32 %num) !prof ![[ENTRYCOUNT:[0-9]+]] !PGOFuncName ![[PGOFUNCNAME1:[0-9]+]] {
+entry:
+ %0 = load i32, i32* @s, align 4, !tbaa !31
+ %add = add nsw i32 %0, %num
+ store i32 %add, i32* @s, align 4, !tbaa !31
+ ret i32 0
+}
+
+define internal fastcc i32 @foo() unnamed_addr !prof !28 !PGOFuncName !30 {
+; CHECK: define internal fastcc void @foo() unnamed_addr !prof ![[ENTRYCOUNT:[0-9]+]] !PGOFuncName ![[PGOFUNCNAME2:[0-9]+]] {
+entry:
+ %0 = load i32, i32* @s, align 4, !tbaa !31
+ %add = add nsw i32 %0, 8
+ store i32 %add, i32* @s, align 4, !tbaa !31
+ ret i32 0
+}
+
+!llvm.module.flags = !{!0, !1}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 1, !"ProfileSummary", !2}
+!2 = !{!3, !4, !5, !6, !7, !8, !9, !10}
+!3 = !{!"ProfileFormat", !"InstrProf"}
+!4 = !{!"TotalCount", i64 2}
+!5 = !{!"MaxCount", i64 1}
+!6 = !{!"MaxInternalCount", i64 0}
+!7 = !{!"MaxFunctionCount", i64 1}
+!8 = !{!"NumCounts", i64 2}
+!9 = !{!"NumFunctions", i64 2}
+!10 = !{!"DetailedSummary", !11}
+!11 = !{!12, !13, !14, !15, !16, !17, !17, !18, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27}
+!12 = !{i32 10000, i64 0, i32 0}
+!13 = !{i32 100000, i64 0, i32 0}
+!14 = !{i32 200000, i64 0, i32 0}
+!15 = !{i32 300000, i64 0, i32 0}
+!16 = !{i32 400000, i64 0, i32 0}
+!17 = !{i32 500000, i64 1, i32 2}
+!18 = !{i32 600000, i64 1, i32 2}
+!19 = !{i32 700000, i64 1, i32 2}
+!20 = !{i32 800000, i64 1, i32 2}
+!21 = !{i32 900000, i64 1, i32 2}
+!22 = !{i32 950000, i64 1, i32 2}
+!23 = !{i32 990000, i64 1, i32 2}
+!24 = !{i32 999000, i64 1, i32 2}
+!25 = !{i32 999900, i64 1, i32 2}
+!26 = !{i32 999990, i64 1, i32 2}
+!27 = !{i32 999999, i64 1, i32 2}
+!28 = !{!"function_entry_count", i64 1}
+; CHECK: ![[ENTRYCOUNT]] = !{!"function_entry_count", i64 1}
+!29 = !{!"foo.c:va_func"}
+; CHECK: ![[PGOFUNCNAME1]] = !{!"foo.c:va_func"}
+!30 = !{!"foo.c:foo"}
+; CHECK: ![[PGOFUNCNAME2]] = !{!"foo.c:foo"}
+!31 = !{!32, !32, i64 0}
+!32 = !{!"int", !33, i64 0}
+!33 = !{!"omnipotent char", !34, i64 0}
+!34 = !{!"Simple C/C++ TBAA"}
More information about the llvm-commits
mailing list