[llvm] r254391 - Introduce a range version of std::find, and use in SCEV

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 1 10:45:30 PST 2015


On Tue, Dec 1, 2015 at 1:14 AM, James Molloy via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Great idea! I've wanted this for a long time!
>

FWIW, I'm encouraging of adding any/all range-based algorithms in this way.
There was some tension/desire to hold off on these until there was a good
standards proposal to model off, but I think that's taking too long.

There is a slight risk of lifetime issues when using these algorithms on
temporaries, then keeping the result beyond the current full expression -
but I don't think the algorithms we've added so far are /too/ prone to that
particular mis-use (adapter algorithms are more likely to have this
problem, especially in a range-for loop)

- Dave


>
> On Tue, 1 Dec 2015 at 07:52 Sanjoy Das via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: sanjoy
>> Date: Tue Dec  1 01:49:27 2015
>> New Revision: 254391
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=254391&view=rev
>> Log:
>> Introduce a range version of std::find, and use in SCEV
>>
>> Reviewers: dblaikie, pcc
>>
>> Subscribers: llvm-commits
>>
>> Differential Revision: http://reviews.llvm.org/D15064
>>
>> Modified:
>>     llvm/trunk/include/llvm/ADT/STLExtras.h
>>     llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>>
>> Modified: llvm/trunk/include/llvm/ADT/STLExtras.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=254391&r1=254390&r2=254391&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ADT/STLExtras.h (original)
>> +++ llvm/trunk/include/llvm/ADT/STLExtras.h Tue Dec  1 01:49:27 2015
>> @@ -379,6 +379,13 @@ bool any_of(R &&Range, UnaryPredicate &&
>>                       std::forward<UnaryPredicate>(P));
>>  }
>>
>> +/// Provide wrappers to std::find which take ranges instead of having to
>> pass
>> +/// begin/end explicitly.
>> +template<typename R, class T>
>> +auto find(R &&Range, const T &val) -> decltype(Range.begin()) {
>> +  return std::find(Range.begin(), Range.end(), val);
>> +}
>> +
>>
>>  //===----------------------------------------------------------------------===//
>>  //     Extra additions to <memory>
>>
>>  //===----------------------------------------------------------------------===//
>>
>> Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=254391&r1=254390&r2=254391&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
>> +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Tue Dec  1 01:49:27 2015
>> @@ -7964,8 +7964,7 @@ static bool IsMaxConsistingOf(const SCEV
>>    const MaxExprType *MaxExpr = dyn_cast<MaxExprType>(MaybeMaxExpr);
>>    if (!MaxExpr) return false;
>>
>> -  auto It = std::find(MaxExpr->op_begin(), MaxExpr->op_end(), Candidate);
>> -  return It != MaxExpr->op_end();
>> +  return find(MaxExpr->operands(), Candidate) != MaxExpr->op_end();
>>  }
>>
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151201/116eef82/attachment.html>


More information about the llvm-commits mailing list