[llvm] r253832 - [TableGen] Use std::any_of and std::find instead of manual loops. NFC

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 22 12:14:13 PST 2015


On Sun, Nov 22, 2015 at 11:27 AM, Craig Topper via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: ctopper
> Date: Sun Nov 22 13:27:02 2015
> New Revision: 253832
>
> URL: http://llvm.org/viewvc/llvm-project?rev=253832&view=rev
> Log:
> [TableGen] Use std::any_of and std::find instead of manual loops. NFC
>
> Modified:
>     llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
>
> Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=253832&r1=253831&r2=253832&view=diff
>
> ==============================================================================
> --- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
> +++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Sun Nov 22 13:27:02
> 2015
> @@ -107,36 +107,36 @@ bool EEVT::TypeSet::FillWithPossibleType
>  /// hasIntegerTypes - Return true if this TypeSet contains iAny or an
>  /// integer value type.
>  bool EEVT::TypeSet::hasIntegerTypes() const {
> -  for (unsigned i = 0, e = TypeVec.size(); i != e; ++i)
> -    if (isInteger(TypeVec[i]))
> -      return true;
> -  return false;
> +  return std::any_of(TypeVec.begin(), TypeVec.end(),
> +                     [](MVT::SimpleValueType VT) {
> +                       return isInteger(VT);
> +                     });
>

Simplified these ^ a bit further by just passing isFoo directly to
std::any_of in r253833.


>  }
>
>  /// hasFloatingPointTypes - Return true if this TypeSet contains an fAny
> or
>  /// a floating point value type.
>  bool EEVT::TypeSet::hasFloatingPointTypes() const {
> -  for (unsigned i = 0, e = TypeVec.size(); i != e; ++i)
> -    if (isFloatingPoint(TypeVec[i]))
> -      return true;
> -  return false;
> +  return std::any_of(TypeVec.begin(), TypeVec.end(),
> +                     [](MVT::SimpleValueType VT) {
> +                       return isFloatingPoint(VT);
> +                     });
>  }
>
>  /// hasScalarTypes - Return true if this TypeSet contains a scalar value
> type.
>  bool EEVT::TypeSet::hasScalarTypes() const {
> -  for (unsigned i = 0, e = TypeVec.size(); i != e; ++i)
> -    if (isScalar(TypeVec[i]))
> -      return true;
> -  return false;
> +  return std::any_of(TypeVec.begin(), TypeVec.end(),
> +                     [](MVT::SimpleValueType VT) {
> +                       return isScalar(VT);
> +                     });
>  }
>
>  /// hasVectorTypes - Return true if this TypeSet contains a vAny or a
> vector
>  /// value type.
>  bool EEVT::TypeSet::hasVectorTypes() const {
> -  for (unsigned i = 0, e = TypeVec.size(); i != e; ++i)
> -    if (isVector(TypeVec[i]))
> -      return true;
> -  return false;
> +  return std::any_of(TypeVec.begin(), TypeVec.end(),
> +                     [](MVT::SimpleValueType VT) {
> +                       return isVector(VT);
> +                     });
>  }
>
>
> @@ -220,14 +220,10 @@ bool EEVT::TypeSet::MergeInTypeInfo(cons
>    TypeSet InputSet(*this);
>
>    for (unsigned i = 0; i != TypeVec.size(); ++i) {
> -    bool InInVT = false;
> -    for (unsigned j = 0, e = InVT.TypeVec.size(); j != e; ++j)
> -      if (TypeVec[i] == InVT.TypeVec[j]) {
> -        InInVT = true;
> -        break;
> -      }
> +    if (std::find(InVT.TypeVec.begin(), InVT.TypeVec.end(), TypeVec[i]) !=
> +        InVT.TypeVec.end())
> +      continue;
>
> -    if (InInVT) continue;
>      TypeVec.erase(TypeVec.begin()+i--);
>      MadeChange = true;
>    }
> @@ -3554,19 +3550,14 @@ static void CombineChildVariants(TreePat
>      if (!R->canPatternMatch(ErrString, CDP)) {
>        delete R;
>      } else {
> -      bool AlreadyExists = false;
> -
>        // Scan to see if this pattern has already been emitted.  We can get
>        // duplication due to things like commuting:
>        //   (and GPRC:$a, GPRC:$b) -> (and GPRC:$b, GPRC:$a)
>        // which are the same pattern.  Ignore the dups.
> -      for (unsigned i = 0, e = OutVariants.size(); i != e; ++i)
> -        if (R->isIsomorphicTo(OutVariants[i], DepVars)) {
> -          AlreadyExists = true;
> -          break;
> -        }
> -
> -      if (AlreadyExists)
> +      if (std::any_of(OutVariants.begin(), OutVariants.end(),
> +                      [=](TreePatternNode *Variant) {
> +                        return R->isIsomorphicTo(Variant, DepVars);
> +                      }))
>

& simplified some code around here further in r253834


>          delete R;
>        else
>          OutVariants.push_back(R);
>
>
> _______________________________________________
> 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/20151122/159c7cf2/attachment.html>


More information about the llvm-commits mailing list