<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 13, 2015, at 10:51 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, May 12, 2015 at 6:12 PM, Pete Cooper<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:peter_cooper@apple.com" target="_blank" class="">peter_cooper@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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 class="">Date: Tue May 12 20:12:09 2015<br class="">New Revision: 237224<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=237224&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=237224&view=rev</a><br class="">Log:<br class="">Change a loop in LoopInfo to foreach.  NFC<br class=""><br class="">Modified:<br class="">   <span class="Apple-converted-space"> </span>llvm/trunk/lib/Analysis/LoopInfo.cpp<br class=""><br class="">Modified: llvm/trunk/lib/Analysis/LoopInfo.cpp<br class="">URL:<span class="Apple-converted-space"> </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" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=237224&r1=237223&r2=237224&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)<br class="">+++ llvm/trunk/lib/Analysis/LoopInfo.cpp Tue May 12 20:12:09 2015<br class="">@@ -65,8 +65,8 @@ bool Loop::isLoopInvariant(const Value *<br class=""> /// hasLoopInvariantOperands - Return true if all the operands of the<br class=""> /// specified instruction are loop invariant.<br class=""> bool Loop::hasLoopInvariantOperands(const Instruction *I) const {<br class="">-  for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)<br class="">-    if (!isLoopInvariant(I->getOperand(i)))<br class="">+  for (auto &Op : I->operands())<br class="">+    if (!isLoopInvariant(Op))<br class="">       return false;<br class=""></blockquote><div class=""><br class="">Could be written as:<br class=""><br class="">  return std::all_of(I->operands().begin(), I->operands().end(), [&](Value *V) { return isLoopInvariant(V); );<br class=""><br class="">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 class=""></div></div></div></blockquote>Thanks.  Something like this:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">namespace<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> llvm {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">template</span><<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">typename</span> T, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> UnaryPredicate></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">inline</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">bool</span> all_of(<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">llvm</span>::<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">iterator_range</span><T> Range, UnaryPredicate p) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">std</span>::all_of(Range.begin(), Range.end(), p);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">};</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">bool</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Loop</span>::hasLoopInvariantOperands(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Instruction</span> *I) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> {</div><div style="margin: 0px; line-height: normal;" class="">  <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">all_of</span>(I-><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">operands</span>(), [&](<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Value</span> *V) { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">isLoopInvariant</span>(V); });</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">I chose to constrain is to <span style="color: rgb(112, 61, 170); line-height: normal;" class="">iterator_range for now just to avoid complicating it to require begin/end of any kind of container.  What do you think?</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(112, 61, 170); line-height: normal;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(112, 61, 170); line-height: normal;" class="">Cheers,</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(112, 61, 170); line-height: normal;" class="">Pete</span></div></div><blockquote type="cite" class=""><div class=""><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""> </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 class="">   return true;<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></blockquote></div></div></blockquote></div><br class=""></body></html>