<div dir="ltr">On Fri, Jul 19, 2013 at 8:47 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank" class="cremed">benny.kra@gmail.com</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On 19.07.2013, at 12:57, Chandler Carruth <<a href="mailto:chandlerc@gmail.com" class="cremed">chandlerc@gmail.com</a>> wrote:<br>
<br>
> Author: chandlerc<br>
> Date: Fri Jul 19 05:57:36 2013<br>
> New Revision: 186667<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=186667&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=186667&view=rev</a><br>
> Log:<br>
> Cleanup the stats counters for the new implementation. These actually<br>
> count the right things and have the right names.<br>
><br>
> Modified:<br>
>    llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=186667&r1=186666&r2=186667&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=186667&r1=186666&r2=186667&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Fri Jul 19 05:57:36 2013<br>
> @@ -59,9 +59,9 @@ using namespace llvm;<br>
><br>
> STATISTIC(NumAllocasAnalyzed, "Number of allocas analyzed for replacement");<br>
> STATISTIC(NumAllocaPartitions, "Number of alloca partitions formed");<br>
> -STATISTIC(MaxPartitionsPerAlloca, "Maximum number of partitions");<br>
> -STATISTIC(NumAllocaPartitionUses, "Number of alloca partition uses found");<br>
> -STATISTIC(MaxPartitionUsesPerAlloca, "Maximum number of partition uses");<br>
> +STATISTIC(MaxPartitionsPerAlloca, "Maximum number of partitions per alloca");<br>
> +STATISTIC(NumAllocaPartitionUses, "Number of alloca partition uses rewritten");<br>
> +STATISTIC(MaxUsesPerAllocaPartition, "Maximum number of uses of a partition");<br>
> STATISTIC(NumNewAllocas, "Number of new, smaller allocas introduced");<br>
> STATISTIC(NumPromoted, "Number of allocas promoted to SSA values");<br>
> STATISTIC(NumLoadsSpeculated, "Number of loads speculated to allow promotion");<br>
> @@ -682,15 +682,6 @@ AllocaSlices::AllocaSlices(const DataLay<br>
><br>
>   Slices.erase(std::remove_if(Slices.begin(), Slices.end(), IsSliceDead()),<br>
>                Slices.end());<br>
> -<br>
> -  // Record how many slices we end up with.<br>
> -  NumAllocaPartitions += Slices.size();<br>
> -  MaxPartitionsPerAlloca =<br>
> -      std::max<unsigned>(Slices.size(), MaxPartitionsPerAlloca);<br>
> -<br>
> -  NumAllocaPartitionUses += Slices.size();<br>
> -  MaxPartitionUsesPerAlloca =<br>
> -      std::max<unsigned>(Slices.size(), MaxPartitionUsesPerAlloca);<br>
> }<br>
><br>
> #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)<br>
> @@ -3045,6 +3036,10 @@ bool SROA::rewritePartition(AllocaInst &<br>
>   unsigned SPOldSize = SpeculatablePHIs.size();<br>
>   unsigned SSOldSize = SpeculatableSelects.size();<br>
><br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +  unsigned NumUses = 0;<br>
> +#endif<br>
> +<br>
>   AllocaSliceRewriter Rewriter(*DL, S, *this, AI, *NewAI, BeginOffset,<br>
>                                EndOffset, IsVectorPromotable,<br>
>                                IsIntegerPromotable);<br>
> @@ -3055,13 +3050,25 @@ bool SROA::rewritePartition(AllocaInst &<br>
>     DEBUG(dbgs() << "  rewriting split ");<br>
>     DEBUG(S.printSlice(dbgs(), *SUI, ""));<br>
>     Promotable &= Rewriter.visit(*SUI);<br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +    ++NumUses;<br>
> +#endif<br>
>   }<br>
>   for (AllocaSlices::iterator I = B; I != E; ++I) {<br>
>     DEBUG(dbgs() << "  rewriting ");<br>
>     DEBUG(S.printSlice(dbgs(), I, ""));<br>
>     Promotable &= Rewriter.visit(I);<br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +    ++NumUses;<br>
> +#endif<br>
>   }<br>
><br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +  NumAllocaPartitionUses += NumUses;<br>
> +  MaxUsesPerAllocaPartition =<br>
> +      std::max<unsigned>(NumUses, MaxUsesPerAllocaPartition);<br>
> +#endif<br>
> +<br>
>   if (Promotable && (SpeculatablePHIs.size() > SPOldSize ||<br>
>                      SpeculatableSelects.size() > SSOldSize)) {<br>
>     // If we have a promotable alloca except for some unspeculated loads below<br>
> @@ -3135,6 +3142,10 @@ bool SROA::splitAlloca(AllocaInst &AI, A<br>
>   if (S.begin() == S.end())<br>
>     return false;<br>
><br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +  unsigned NumPartitions = 0;<br>
> +#endif<br>
> +<br>
>   bool Changed = false;<br>
>   SmallVector<AllocaSlices::iterator, 4> SplitUses;<br>
>   uint64_t MaxSplitUseEndOffset = 0;<br>
> @@ -3181,6 +3192,9 @@ bool SROA::splitAlloca(AllocaInst &AI, A<br>
>       // Rewrite a sequence of overlapping slices.<br>
>       Changed |=<br>
>           rewritePartition(AI, S, SI, SJ, BeginOffset, MaxEndOffset, SplitUses);<br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +      ++NumPartitions;<br>
> +#endif<br>
><br>
>       removeFinishedSplitUses(SplitUses, MaxSplitUseEndOffset, MaxEndOffset);<br>
>     }<br>
> @@ -3220,6 +3234,10 @@ bool SROA::splitAlloca(AllocaInst &AI, A<br>
><br>
>     Changed |= rewritePartition(AI, S, SJ, SJ, MaxEndOffset, PostSplitEndOffset,<br>
>                                 SplitUses);<br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +    ++NumPartitions;<br>
> +#endif<br>
> +<br>
>     if (SJ == SE)<br>
>       break; // Skip the rest, we don't need to do any cleanup.<br>
><br>
> @@ -3230,6 +3248,12 @@ bool SROA::splitAlloca(AllocaInst &AI, A<br>
>     BeginOffset = SJ->beginOffset();<br>
>   }<br>
><br>
> +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS)<br>
> +  NumAllocaPartitions += NumPartitions;<br>
> +  MaxPartitionsPerAlloca =<br>
> +      std::max<unsigned>(NumPartitions, MaxPartitionsPerAlloca);<br>
> +#endif<br>
<br>
</div></div>Is all this #ifdefing necessary? Operations on llvm::Statistic are all nops when those conditions are met and the optimizer should kill the remaining dead code.<br></blockquote><div><br></div><div>Yea, it should. That said, I'm a worrier so I just made the preprocessor do it. I may rip all this out as it will also prevent bugs like the one Nick hit.</div>
</div></div></div>