[llvm-commits] [llvm] r144527 - in /llvm/trunk: include/llvm/CodeGen/MachineBranchProbabilityInfo.h lib/CodeGen/MachineBranchProbabilityInfo.cpp
Benjamin Kramer
benny.kra at googlemail.com
Mon Nov 14 01:11:50 PST 2011
On 14.11.2011, at 10:00, Chandler Carruth <chandlerc at gmail.com> wrote:
> Author: chandlerc
> Date: Mon Nov 14 02:55:59 2011
> New Revision: 144527
>
> URL: http://llvm.org/viewvc/llvm-project?rev=144527&view=rev
> Log:
> Reuse the logic in getEdgeProbability within getHotSucc in order to
> correctly handle blocks whose successor weights sum to more than
> UINT32_MAX. This is slightly less efficient, but the entire thing is
> already linear on the number of successors. Calling it within any hot
> routine is a mistake, and indeed no one is calling it. It also
> simplifies the code.
Does this problem also exist in the non-machine BPI version of getHotSucc?
>
> Modified:
> llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h
> llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h?rev=144527&r1=144526&r2=144527&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h Mon Nov 14 02:55:59 2011
> @@ -59,6 +59,7 @@
> bool isEdgeHot(MachineBasicBlock *Src, MachineBasicBlock *Dst) const;
>
> // Return a hot successor for the block BB or null if there isn't one.
> + // NB: This routine's complexity is linear on the number of successors.
> MachineBasicBlock *getHotSucc(MachineBasicBlock *MBB) const;
>
> // Return a probability as a fraction between 0 (0% probability) and
>
> Modified: llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp?rev=144527&r1=144526&r2=144527&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp Mon Nov 14 02:55:59 2011
> @@ -76,26 +76,18 @@
>
> MachineBasicBlock *
> MachineBranchProbabilityInfo::getHotSucc(MachineBasicBlock *MBB) const {
> - uint32_t Sum = 0;
> uint32_t MaxWeight = 0;
> MachineBasicBlock *MaxSucc = 0;
> -
> for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(),
> E = MBB->succ_end(); I != E; ++I) {
> - MachineBasicBlock *Succ = *I;
> - uint32_t Weight = getEdgeWeight(MBB, Succ);
> - uint32_t PrevSum = Sum;
> -
> - Sum += Weight;
> - assert(Sum > PrevSum); (void) PrevSum;
> -
> + uint32_t Weight = getEdgeWeight(MBB, *I);
> if (Weight > MaxWeight) {
> MaxWeight = Weight;
> - MaxSucc = Succ;
> + MaxSucc = *I;
> }
> }
>
> - if (BranchProbability(MaxWeight, Sum) >= BranchProbability(4, 5))
> + if (getEdgeProbability(MBB, MaxSucc) >= BranchProbability(4, 5))
> return MaxSucc;
>
> return 0;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list