<div dir="ltr"><div>Why is Name not 'comdatted' ?</div><div><br></div>Multiple copies of counters for comdat functions might actually be a feature instead of a bug. Consider the case when instrumented comdat function gets inlined into the caller.  Keeping different copies of counters allows more context sensitive profiling while de-duping the counters causes the profiles of inline instances to be merged into the out of line instance.<div><br></div><div>This is a moot point for now as there is no profile-use mechanism to take advantage of that context-sensitivity (i.e., using inline instance profile copy during inline profile update). So this patch is fine for now and can be revisited later if we lose perf opportunities).</div><div><br></div><div>thanks,</div><div><br></div><div>David</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 27, 2015 at 9:44 AM, Diego Novillo <span dir="ltr"><<a href="mailto:dnovillo@google.com" target="_blank">dnovillo@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dnovillo<br>
Date: Wed May 27 11:44:47 2015<br>
New Revision: 238335<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238335-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=OOqbyuSMePfUlri3PV9r3WseMVTVUAK7Nu84ItJle44&s=9UQOwDOWgeBbqEDEnVkHwZlGxFTsxh8aUVR19mOcmdA&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=238335&view=rev</a><br>
Log:<br>
Fix PR 23499 - Avoid multiple profile counters for functions in comdat sections.<br>
<br>
Counter symbols created for linkonce functions are not discarded by ELF<br>
linkers unless the symbols are placed in the same comdat section as its<br>
associated function.<br>
<br>
Modified:<br>
    llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Transforms_Instrumentation_InstrProfiling.cpp-3Frev-3D238335-26r1-3D238334-26r2-3D238335-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=OOqbyuSMePfUlri3PV9r3WseMVTVUAK7Nu84ItJle44&s=SQh5QskvQCr7GbwOL1sBrI9AzLf1vkqYwvowM8abdec&e=" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp?rev=238335&r1=238334&r2=238335&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp Wed May 27 11:44:47 2015<br>
@@ -203,6 +203,7 @@ InstrProfiling::getOrCreateRegionCounter<br>
   uint64_t NumCounters = Inc->getNumCounters()->getZExtValue();<br>
   LLVMContext &Ctx = M->getContext();<br>
   ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters);<br>
+  Function *Fn = Inc->getParent()->getParent();<br>
<br>
   // Create the counters variable.<br>
   auto *Counters = new GlobalVariable(*M, CounterTy, false, Name->getLinkage(),<br>
@@ -211,6 +212,10 @@ InstrProfiling::getOrCreateRegionCounter<br>
   Counters->setVisibility(Name->getVisibility());<br>
   Counters->setSection(getCountersSection());<br>
   Counters->setAlignment(8);<br>
+  // Place the counters in the same comdat section as its parent function.<br>
+  // Otherwise, we may get multiple counters for the same function in certain<br>
+  // cases.<br>
+  Counters->setComdat(Fn->getComdat());<br>
<br>
   RegionCounters[Inc->getName()] = Counters;<br>
<br>
@@ -235,6 +240,7 @@ InstrProfiling::getOrCreateRegionCounter<br>
   Data->setVisibility(Name->getVisibility());<br>
   Data->setSection(getDataSection());<br>
   Data->setAlignment(8);<br>
+  Data->setComdat(Fn->getComdat());<br>
<br>
   // Mark the data variable as used so that it isn't stripped out.<br>
   UsedVars.push_back(Data);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>