<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 13, 2015 at 11:48 AM, Pete Cooper <span dir="ltr"><<a href="mailto:peter_cooper@apple.com" target="_blank">peter_cooper@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div class="h5"><blockquote type="cite"><div>On May 13, 2015, at 10:51 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><br><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:14px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:14px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Tue, May 12, 2015 at 6:12 PM, Pete Cooper<span> </span><span dir="ltr"><<a href="mailto:peter_cooper@apple.com" target="_blank">peter_cooper@apple.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: pete<br>Date: Tue May 12 20:12:09 2015<br>New Revision: 237224<br><br>URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project?rev=237224&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=237224&view=rev</a><br>Log:<br>Change a loop in LoopInfo to foreach.  NFC<br><br>Modified:<br>   <span> </span>llvm/trunk/lib/Analysis/LoopInfo.cpp<br><br>Modified: llvm/trunk/lib/Analysis/LoopInfo.cpp<br>URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=237224&r1=237223&r2=237224&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=237224&r1=237223&r2=237224&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)<br>+++ llvm/trunk/lib/Analysis/LoopInfo.cpp Tue May 12 20:12:09 2015<br>@@ -65,8 +65,8 @@ bool Loop::isLoopInvariant(const Value *<br> /// hasLoopInvariantOperands - Return true if all the operands of the<br> /// specified instruction are loop invariant.<br> bool Loop::hasLoopInvariantOperands(const Instruction *I) const {<br>-  for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)<br>-    if (!isLoopInvariant(I->getOperand(i)))<br>+  for (auto &Op : I->operands())<br>+    if (!isLoopInvariant(Op))<br>       return false;<br></blockquote><div><br>Could be written as:<br><br>  return std::all_of(I->operands().begin(), I->operands().end(), [&](Value *V) { return isLoopInvariant(V); );<br><br>If you like. (but the range-based-ness does make that a bit inconvenient, though std::all_of adds a little readability improvement, I think - at some point we'll just write range-based versions of algorithms like this so we don't have to pass begin/end everywhere)<br></div></div></div></blockquote></div></div>Thanks.  Something like this:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">namespace<span style="color:rgb(0,0,0)"> llvm {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">template</span><<span style="color:rgb(187,44,162)">typename</span> T, <span style="color:rgb(187,44,162)">class</span> UnaryPredicate></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  <span style="color:rgb(187,44,162)">static</span> <span style="color:rgb(187,44,162)">inline</span> <span style="color:rgb(187,44,162)">bool</span> all_of(<span style="color:rgb(79,129,135)">llvm</span>::<span style="color:rgb(112,61,170)">iterator_range</span><T> Range, UnaryPredicate p) {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(112,61,170)">std</span>::all_of(Range.begin(), Range.end(), p);</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">};</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class=""><div style="margin:0px;line-height:normal"><span style="color:rgb(187,44,162)">bool</span> <span style="color:rgb(79,129,135)">Loop</span>::hasLoopInvariantOperands(<span style="color:rgb(187,44,162)">const</span> <span style="color:rgb(79,129,135)">Instruction</span> *I) <span style="color:rgb(187,44,162)">const</span> {</div></span><div style="margin:0px;line-height:normal">  <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(49,89,93)">all_of</span>(I-><span style="color:rgb(49,89,93)">operands</span>(), [&](<span style="color:rgb(79,129,135)">Value</span> *V) { <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(49,89,93)">isLoopInvariant</span>(V); });</div><div style="margin:0px;line-height:normal">}</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">I chose to constrain is to <span style="color:rgb(112,61,170);line-height:normal">iterator_range for now just to avoid complicating it to require begin/end of any kind of container. </span></div></div></div></div></blockquote><div><br>I wouldn't bother with the constraint - I'd just start with a generic ref range R:<br><br><div style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(187,44,162)">template</span><<span style="color:rgb(187,44,162)">typename</span> R, <font color="#bb2ca2">typename</font> UnaryPredicate></div><div style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(187,44,162)">bool</span> all_of(<font color="#4f8187">R &</font>Range, UnaryPredicate p) {</div><div style="margin:0px;font-size:11px;font-family:Menlo">  <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(112,61,170)">std</span>::all_of(Range.begin(), Range.end(), p);</div><div style="margin:0px;font-size:11px;font-family:Menlo">}<br><br>And if we one day need to, we can SFINAE this as appropriate. (heh, now I'm imagining writing this as an adaptor... but of course it wouldn't work because we need template argument deduction, etc... but it'd be fun to "rangify(std::all_of, Range, Predicate)" ;))</div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><div style="margin:0px;line-height:normal"><span style="color:rgb(112,61,170);line-height:normal"> What do you think?</span></div><div style="margin:0px;line-height:normal"><span style="color:rgb(112,61,170);line-height:normal"><br></span></div><div style="margin:0px;line-height:normal"><span style="color:rgb(112,61,170);line-height:normal">Cheers,</span></div><div style="margin:0px;line-height:normal"><span style="color:rgb(112,61,170);line-height:normal">Pete</span></div></div><span class=""><blockquote type="cite"><div><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:14px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>   return true;<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">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></blockquote></div></div></blockquote></span></div><br></div></blockquote></div><br></div></div>