From b474372d7b052b50f24dea13719673711c677c7d Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Mon, 15 Jun 2020 18:25:14 +0000 Subject: [PATCH] [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(Val) Differential Revision: https://reviews.llvm.org/D81045 --- include/llvm/Support/Casting.h | 14 ++++++++++---- lib/Analysis/ScalarEvolution.cpp | 6 ++++-- lib/Target/PowerPC/PPCBoolRetToInt.cpp | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/llvm/Support/Casting.h b/include/llvm/Support/Casting.h index 41f1b6740c6..d6f7793d5df 100644 --- a/include/llvm/Support/Casting.h +++ b/include/llvm/Support/Casting.h @@ -132,24 +132,30 @@ struct isa_impl_wrap { } }; -// isa - Return true if the parameter to the template is an instance of the -// template type argument. Used like this: +// isa - Return true if the parameter to the template is an instance of one +// of the template type arguments. Used like this: // // if (isa(myVal)) { ... } +// if (isa(myVal)) { ... } // template LLVM_NODISCARD inline bool isa(const Y &Val) { return isa_impl_wrap::SimpleType>::doit(Val); } +template +LLVM_NODISCARD inline bool isa(const Y &Val) { + return isa(Val) || isa(Val); +} + // isa_and_nonnull - Functionally identical to isa, except that a null value // is accepted. // -template +template LLVM_NODISCARD inline bool isa_and_nonnull(const Y &Val) { if (!Val) return false; - return isa(Val); + return isa(Val); } //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 85f9794aa8d..3625b5e4203 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/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); + bool FoundAddRec = + SCEVExprContains(S, [](const SCEV *S) { return isa(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 &Terms) { for (const SCEV *T : Terms) - if (SCEVExprContains(T, isa)) + if (SCEVExprContains(T, [](const SCEV *S) { return isa(S); })) return true; + return false; } diff --git a/lib/Target/PowerPC/PPCBoolRetToInt.cpp b/lib/Target/PowerPC/PPCBoolRetToInt.cpp index 104cf2ba3c0..2259a29f838 100644 --- a/lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ b/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)) + if (llvm::none_of(Defs, [](Value *V) { return isa(V); })) return false; // Presently, we only know how to handle PHINode, Constant, Arguments and