[llvm] 72d20b9 - [LLVM] Change isa<> to a variadic function template
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 15 11:47:19 PDT 2020
Author: Rahul Joshi
Date: 2020-06-15T18:46:57Z
New Revision: 72d20b9604f65e35eedb3d00098a2c9412953946
URL: https://github.com/llvm/llvm-project/commit/72d20b9604f65e35eedb3d00098a2c9412953946
DIFF: https://github.com/llvm/llvm-project/commit/72d20b9604f65e35eedb3d00098a2c9412953946.diff
LOG: [LLVM] Change isa<> to a variadic function template
Change isa<> to a variadic function template, so that it can be used to test against one of multiple types as follows:
isa<Type0, Type1, Type2>(Val)
Differential Revision: https://reviews.llvm.org/D81045
Added:
Modified:
clang/include/clang/AST/DeclBase.h
llvm/include/llvm/Support/Casting.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index f66c5d0f8cd7..ba84f27617f5 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -518,7 +518,7 @@ class alignas(8) Decl {
if (!HasAttrs) return;
AttrVec &Vec = getAttrs();
- Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa<T, Attr*>), Vec.end());
+ llvm::erase_if(Vec, [](Attr *A) { return isa<T>(A); });
if (Vec.empty())
HasAttrs = false;
diff --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 41f1b6740c6f..d6f7793d5df0 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -132,24 +132,30 @@ struct isa_impl_wrap<To, FromTy, FromTy> {
}
};
-// isa<X> - Return true if the parameter to the template is an instance of the
-// template type argument. Used like this:
+// isa<X> - Return true if the parameter to the template is an instance of one
+// of the template type arguments. Used like this:
//
// if (isa<Type>(myVal)) { ... }
+// if (isa<Type0, Type1, Type2>(myVal)) { ... }
//
template <class X, class Y> LLVM_NODISCARD inline bool isa(const Y &Val) {
return isa_impl_wrap<X, const Y,
typename simplify_type<const Y>::SimpleType>::doit(Val);
}
+template <typename First, typename Second, typename... Rest, typename Y>
+LLVM_NODISCARD inline bool isa(const Y &Val) {
+ return isa<First>(Val) || isa<Second, Rest...>(Val);
+}
+
// isa_and_nonnull<X> - Functionally identical to isa, except that a null value
// is accepted.
//
-template <class X, class Y>
+template <typename... X, class Y>
LLVM_NODISCARD inline bool isa_and_nonnull(const Y &Val) {
if (!Val)
return false;
- return isa<X>(Val);
+ return isa<X...>(Val);
}
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 85f9794aa8d8..3625b5e4203f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3860,7 +3860,8 @@ bool ScalarEvolution::containsAddRecurrence(const SCEV *S) {
if (I != HasRecMap.end())
return I->second;
- bool FoundAddRec = SCEVExprContains(S, isa<SCEVAddRecExpr, const SCEV *>);
+ bool FoundAddRec =
+ SCEVExprContains(S, [](const SCEV *S) { return isa<SCEVAddRecExpr>(S); });
HasRecMap.insert({S, FoundAddRec});
return FoundAddRec;
}
@@ -11201,8 +11202,9 @@ static bool findArrayDimensionsRec(ScalarEvolution &SE,
// Returns true when one of the SCEVs of Terms contains a SCEVUnknown parameter.
static inline bool containsParameters(SmallVectorImpl<const SCEV *> &Terms) {
for (const SCEV *T : Terms)
- if (SCEVExprContains(T, isa<SCEVUnknown, const SCEV *>))
+ if (SCEVExprContains(T, [](const SCEV *S) { return isa<SCEVUnknown>(S); }))
return true;
+
return false;
}
diff --git a/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp b/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
index 104cf2ba3c00..2259a29f838a 100644
--- a/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
+++ b/llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp
@@ -220,7 +220,7 @@ class PPCBoolRetToInt : public FunctionPass {
auto Defs = findAllDefs(U);
// If the values are all Constants or Arguments, don't bother
- if (llvm::none_of(Defs, isa<Instruction, Value *>))
+ if (llvm::none_of(Defs, [](Value *V) { return isa<Instruction>(V); }))
return false;
// Presently, we only know how to handle PHINode, Constant, Arguments and
More information about the llvm-commits
mailing list