<p dir="ltr">Can you send me a test case for the quadratic behavior? I'm happy to help with fixing it</p>
<div class="gmail_quote">On Aug 7, 2012 6:12 PM, "Jakob Stoklund Olesen" <<a href="mailto:stoklund@2pi.dk">stoklund@2pi.dk</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: stoklund<br>
Date: Tue Aug 7 20:10:31 2012<br>
New Revision: 161463<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=161463&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=161463&view=rev</a><br>
Log:<br>
Revert "Fix a quadratic algorithm in MachineBranchProbabilityInfo."<br>
<br>
It caused an assertion failure when compiling consumer-typeset.<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h<br>
llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h<br>
llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp<br>
llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=161463&r1=161462&r2=161463&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=161463&r1=161462&r2=161463&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Tue Aug 7 20:10:31 2012<br>
@@ -572,7 +572,7 @@<br>
/// getSuccWeight - Return weight of the edge from this block to MBB. This<br>
/// method should NOT be called directly, but by using getEdgeWeight method<br>
/// from MachineBranchProbabilityInfo class.<br>
- uint32_t getSuccWeight(const_succ_iterator Succ) const;<br>
+ uint32_t getSuccWeight(const MachineBasicBlock *succ) const;<br>
<br>
<br>
// Methods used to maintain doubly linked list of blocks...<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h?rev=161463&r1=161462&r2=161463&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h?rev=161463&r1=161462&r2=161463&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/MachineBranchProbabilityInfo.h Tue Aug 7 20:10:31 2012<br>
@@ -16,12 +16,14 @@<br>
#define LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H<br>
<br>
#include "llvm/Pass.h"<br>
-#include "llvm/CodeGen/MachineBasicBlock.h"<br>
#include "llvm/Support/BranchProbability.h"<br>
#include <climits><br>
<br>
namespace llvm {<br>
<br>
+class raw_ostream;<br>
+class MachineBasicBlock;<br>
+<br>
class MachineBranchProbabilityInfo : public ImmutablePass {<br>
virtual void anchor();<br>
<br>
@@ -50,11 +52,6 @@<br>
uint32_t getEdgeWeight(const MachineBasicBlock *Src,<br>
const MachineBasicBlock *Dst) const;<br>
<br>
- // Same thing, but using a const_succ_iterator from Src. This is faster when<br>
- // the iterator is already available.<br>
- uint32_t getEdgeWeight(const MachineBasicBlock *Src,<br>
- MachineBasicBlock::const_succ_iterator Dst) const;<br>
-<br>
// Get sum of the block successors' weights, potentially scaling them to fit<br>
// within 32-bits. If scaling is required, sets Scale based on the necessary<br>
// adjustment. Any edge weights used with the sum should be divided by Scale.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=161463&r1=161462&r2=161463&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=161463&r1=161462&r2=161463&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Tue Aug 7 20:10:31 2012<br>
@@ -912,11 +912,12 @@<br>
<br>
/// getSuccWeight - Return weight of the edge from this block to MBB.<br>
///<br>
-uint32_t MachineBasicBlock::getSuccWeight(const_succ_iterator Succ) const {<br>
+uint32_t MachineBasicBlock::getSuccWeight(const MachineBasicBlock *succ) const {<br>
if (Weights.empty())<br>
return 0;<br>
<br>
- return *getWeightIterator(Succ);<br>
+ const_succ_iterator I = std::find(Successors.begin(), Successors.end(), succ);<br>
+ return *getWeightIterator(I);<br>
}<br>
<br>
/// getWeightIterator - Return wight iterator corresonding to the I successor<br>
<br>
Modified: llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp?rev=161463&r1=161462&r2=161463&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp?rev=161463&r1=161462&r2=161463&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp Tue Aug 7 20:10:31 2012<br>
@@ -38,7 +38,7 @@<br>
Scale = 1;<br>
for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(),<br>
E = MBB->succ_end(); I != E; ++I) {<br>
- uint32_t Weight = getEdgeWeight(MBB, I);<br>
+ uint32_t Weight = getEdgeWeight(MBB, *I);<br>
Sum += Weight;<br>
}<br>
<br>
@@ -53,30 +53,22 @@<br>
Sum = 0;<br>
for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(),<br>
E = MBB->succ_end(); I != E; ++I) {<br>
- uint32_t Weight = getEdgeWeight(MBB, I);<br>
+ uint32_t Weight = getEdgeWeight(MBB, *I);<br>
Sum += Weight / Scale;<br>
}<br>
assert(Sum <= UINT32_MAX);<br>
return Sum;<br>
}<br>
<br>
-uint32_t MachineBranchProbabilityInfo::<br>
-getEdgeWeight(const MachineBasicBlock *Src,<br>
- MachineBasicBlock::const_succ_iterator Dst) const {<br>
+uint32_t<br>
+MachineBranchProbabilityInfo::getEdgeWeight(const MachineBasicBlock *Src,<br>
+ const MachineBasicBlock *Dst) const {<br>
uint32_t Weight = Src->getSuccWeight(Dst);<br>
if (!Weight)<br>
return DEFAULT_WEIGHT;<br>
return Weight;<br>
}<br>
<br>
-uint32_t MachineBranchProbabilityInfo::<br>
-getEdgeWeight(const MachineBasicBlock *Src,<br>
- const MachineBasicBlock *Dst) const {<br>
- // This is a linear search. Try to use the const_succ_iterator version when<br>
- // possible.<br>
- return getEdgeWeight(Src, std::find(Src->succ_begin(), Src->succ_end(), Dst));<br>
-}<br>
-<br>
bool MachineBranchProbabilityInfo::isEdgeHot(MachineBasicBlock *Src,<br>
MachineBasicBlock *Dst) const {<br>
// Hot probability is at least 4/5 = 80%<br>
@@ -90,7 +82,7 @@<br>
MachineBasicBlock *MaxSucc = 0;<br>
for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(),<br>
E = MBB->succ_end(); I != E; ++I) {<br>
- uint32_t Weight = getEdgeWeight(MBB, I);<br>
+ uint32_t Weight = getEdgeWeight(MBB, *I);<br>
if (Weight > MaxWeight) {<br>
MaxWeight = Weight;<br>
MaxSucc = *I;<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>