<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 22, 2014 at 10:21 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"><br>
On 10/22/14 13:19, David Blaikie wrote:<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
On Wed, Oct 22, 2014 at 9:51 AM, Diego Novillo <<a href="mailto:dnovillo@google.com" target="_blank">dnovillo@google.com</a> <mailto:<a href="mailto:dnovillo@google.com" target="_blank">dnovillo@google.com</a>>> wrote:<br>
<br>
    Author: dnovillo<br>
    Date: Wed Oct 22 11:51:50 2014<br>
    New Revision: 220394<br>
<br>
    URL: <a href="http://llvm.org/viewvc/llvm-project?rev=220394&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=220394&view=rev</a><br>
    Log:<br>
    Use auto iteration in lib/Transforms/Scalar/<u></u>SampleProfile.cpp. No<br>
    functional changes.<br>
<br>
    Modified:<br>
        llvm/trunk/lib/Transforms/<u></u>Scalar/SampleProfile.cpp<br>
<br>
    Modified: llvm/trunk/lib/Transforms/<u></u>Scalar/SampleProfile.cpp<br>
    URL:<br>
    <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp?rev=220394&r1=220393&r2=220394&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/lib/<u></u>Transforms/Scalar/<u></u>SampleProfile.cpp?rev=220394&<u></u>r1=220393&r2=220394&view=diff</a><br>
    ==============================<u></u>==============================<u></u>==================<br>
    --- llvm/trunk/lib/Transforms/<u></u>Scalar/SampleProfile.cpp (original)<br>
    +++ llvm/trunk/lib/Transforms/<u></u>Scalar/SampleProfile.cpp Wed Oct 22<br>
    11:51:50 2014<br>
    @@ -249,8 +249,8 @@ unsigned SampleProfileLoader::<u></u>getBlockWe<br>
<br>
       // Otherwise, compute and cache B's weight.<br>
       unsigned Weight = 0;<br>
    -  for (BasicBlock::iterator I = B->begin(), E = B->end(); I != E;<br>
    ++I) {<br>
    -    unsigned InstWeight = getInstWeight(*I);<br>
    +  for (auto &I : B->getInstList()) {<br>
    +    unsigned InstWeight = getInstWeight(I);<br>
         if (InstWeight > Weight)<br>
           Weight = InstWeight;<br>
       }<br>
    @@ -267,7 +267,7 @@ unsigned SampleProfileLoader::<u></u>getBlockWe<br>
     bool SampleProfileLoader::<u></u>computeBlockWeights(Function &F) {<br>
       bool Changed = false;<br>
       DEBUG(dbgs() << "Block weights\n");<br>
    -  for (Function::iterator B = F.begin(), E = F.end(); B != E; ++B) {<br>
    +  for (auto B = F.begin(), E = F.end(); B != E; ++B) {<br>
<br>
<br>
for (auto &B : F) {<br>
<br>
         unsigned Weight = getBlockWeight(B);<br>
<br>
<br>
& you could change getBlockWeight to take a (possibly const?) BasicBlock& instead of a BasicBlock*<br>
<br>
         Changed |= (Weight > 0);<br>
         DEBUG(printBlockWeight(dbgs(), B));<br>
<br>
<br>
& similarly here for printBlockWeight (pass by ref instead of pointer)<br>
</blockquote>
<br></div></div>
The problem here are the maps. I'm using block pointers as keys into the maps. I don't think I can use blocks themselves as keys.</blockquote><div><br>Yep - you can just take the address of the reference where necessary (or, if it's often enough, just introduce a local pointer variable as mentioned below - my personal preference is to leave the named variable as a reference and just use '&' wherever necessary - saves having two names for a thing and wondering where the pointers come from/when they might be null/etc)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    @@ -302,9 +302,7 @@ bool SampleProfileLoader::<u></u>computeBlockWe<br>
     void SampleProfileLoader::<u></u>findEquivalencesFor(<br>
         BasicBlock *BB1, SmallVector<BasicBlock *, 8> Descendants,<br>
         DominatorTreeBase<BasicBlock> *DomTree) {<br>
    -  for (SmallVectorImpl<BasicBlock *>::iterator I =<br>
    Descendants.begin(),<br>
    -                                               E = Descendants.end();<br>
    -       I != E; ++I) {<br>
    +  for (auto I = Descendants.begin(), E = Descendants.end(); I !=<br>
    E; ++I) {<br>
         BasicBlock *BB2 = *I;<br>
<br>
<br>
for (auto *BB2 : Descendants) {<br>
<br>
         bool IsDomParent = DomTree->dominates(BB2, BB1);<br>
         bool IsInSameLoop = LI->getLoopFor(BB1) == LI->getLoopFor(BB2);<br>
    @@ -340,7 +338,7 @@ void SampleProfileLoader::<u></u>findEquivalenc<br>
       SmallVector<BasicBlock *, 8> DominatedBBs;<br>
       DEBUG(dbgs() << "\nBlock equivalence classes\n");<br>
       // Find equivalence sets based on dominance and post-dominance<br>
    information.<br>
    -  for (Function::iterator B = F.begin(), E = F.end(); B != E; ++B) {<br>
    +  for (auto B = F.begin(), E = F.end(); B != E; ++B) {<br>
         BasicBlock *BB1 = B; <br>
<br>
for (auto &BB1 : F) {<br>
<br>
Or, if there are lots of pointer uses you don't want to add '&' to:<br>
<br>
for (auto &B : F) {<br>
  auto *BB1 = &B;<br>
</blockquote>
<br></div></div>
Won't this give me the wrong pointer when accessing the map?</blockquote><div><br>Nope - the address of a reference is the thing the reference refers to. The reference itself has no storage as far as the language is concerned (there's no such thing as a "pointer to reference" - you just get a pointer to the thing the reference refers to).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888"><br>
<br>
Diego.<br>
</font></span></blockquote></div><br></div></div>