[PATCH] D81045: [LLVM] Change isa<> to a variadic function template
This revision was automatically updated to reflect the committed changes. Closed by commit rG72d20b9604f6: [LLVM] Change isa<> to a variadic function template (authored by jurahul, committed by mehdi_amini). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81045/new/ https://reviews.llvm.org/D81045 Files: clang/include/clang/AST/DeclBase.h llvm/include/llvm/Support/Casting.h llvm/lib/Analysis/ScalarEvolution.cpp llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp === --- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp @@ -220,7 +220,7 @@ 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 Index: llvm/lib/Analysis/ScalarEvolution.cpp === --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -3860,7 +3860,8 @@ 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 @@ // 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; } Index: llvm/include/llvm/Support/Casting.h === --- llvm/include/llvm/Support/Casting.h +++ llvm/include/llvm/Support/Casting.h @@ -132,24 +132,30 @@ } }; -// 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); } //===--===// Index: clang/include/clang/AST/DeclBase.h === --- clang/include/clang/AST/DeclBase.h +++ clang/include/clang/AST/DeclBase.h @@ -518,7 +518,7 @@ if (!HasAttrs) return; AttrVec &Vec = getAttrs(); -Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa), Vec.end()); +llvm::erase_if(Vec, [](Attr *A) { return isa(A); }); if (Vec.empty()) HasAttrs = false; Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp === --- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp @@ -220,7 +220,7 @@ 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 Index: llvm/lib/Analysis/ScalarEvolution.cpp === --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -3860,7 +3860,8 @@ 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 @@ // 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; } Index: llvm/include/llvm/Support/Casting.h === --- llvm/include/llvm/Support/Casting.h +++ llvm/include/llvm/Support/Casting.h @@ -132,24 +132,30 @@
[PATCH] D81045: [LLVM] Change isa<> to a variadic function template
jurahul added a comment. Yes, I'd appreciate if someone can land this change. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81045/new/ https://reviews.llvm.org/D81045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D81045: [LLVM] Change isa<> to a variadic function template
mehdi_amini added a comment. Do you need someone to land this for you? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81045/new/ https://reviews.llvm.org/D81045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D81045: [LLVM] Change isa<> to a variadic function template
jurahul updated this revision to Diff 270015. jurahul edited the summary of this revision. jurahul added a comment. Address review comments Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81045/new/ https://reviews.llvm.org/D81045 Files: clang/include/clang/AST/DeclBase.h llvm/include/llvm/Support/Casting.h llvm/lib/Analysis/ScalarEvolution.cpp llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp === --- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp @@ -220,7 +220,7 @@ 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 Index: llvm/lib/Analysis/ScalarEvolution.cpp === --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -3860,7 +3860,8 @@ 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 @@ // 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; } Index: llvm/include/llvm/Support/Casting.h === --- llvm/include/llvm/Support/Casting.h +++ llvm/include/llvm/Support/Casting.h @@ -132,24 +132,30 @@ } }; -// 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); } //===--===// Index: clang/include/clang/AST/DeclBase.h === --- clang/include/clang/AST/DeclBase.h +++ clang/include/clang/AST/DeclBase.h @@ -518,7 +518,7 @@ if (!HasAttrs) return; AttrVec &Vec = getAttrs(); -Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa), Vec.end()); +llvm::erase_if(Vec, [](Attr *A) { return isa(A); }); if (Vec.empty()) HasAttrs = false; Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp === --- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp @@ -220,7 +220,7 @@ 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 Index: llvm/lib/Analysis/ScalarEvolution.cpp === --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -3860,7 +3860,8 @@ 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 @@ // 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; } Index: llvm/include/llvm/Support/Casting.h === --- llvm/include/llvm/Support/Casting.h +++ llvm/include/llvm/Support/Casting.h @@ -132,24 +132,30 @@ } }; -// isa - Return true if the parameter to the template is a
[PATCH] D81045: [LLVM] Change isa<> to a variadic function template
rriddle accepted this revision. rriddle marked an inline comment as done. rriddle added a comment. This revision is now accepted and ready to land. I have run into the desire to have this on many occasions, so LGTM for me. Comment at: clang/include/clang/AST/DeclBase.h:521 AttrVec &Vec = getAttrs(); -Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa), Vec.end()); +Vec.erase(std::remove_if(Vec.begin(), Vec.end(), + [](Attr *A) { return isa(A); }), nit: We could also update this to use `llvm::erase_if`, but fine to leave as is. Comment at: llvm/include/llvm/Support/Casting.h:147 +template +LLVM_NODISCARD inline typename std::enable_if::type +isa(const Y &Val) { nit: I would remove the enable_if and just add an additional type to the template. ``` template ... isa(const Y &val) { return isa(Val) || isa(Val); } ``` Comment at: llvm/include/llvm/Support/Casting.h:136 +// isa - Return true if the parameter to the template is an instance of one +// of the template type argument. Used like this: // nit: arguments Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81045/new/ https://reviews.llvm.org/D81045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D81045: [LLVM] Change isa<> to a variadic function template
jurahul updated this revision to Diff 269870. jurahul added a comment. Split isa<> changes into its own change Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81045/new/ https://reviews.llvm.org/D81045 Files: clang/include/clang/AST/DeclBase.h llvm/include/llvm/Support/Casting.h llvm/lib/Analysis/ScalarEvolution.cpp llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp === --- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp @@ -220,7 +220,7 @@ 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 Index: llvm/lib/Analysis/ScalarEvolution.cpp === --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -3860,7 +3860,8 @@ 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 @@ // 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; } Index: llvm/include/llvm/Support/Casting.h === --- llvm/include/llvm/Support/Casting.h +++ llvm/include/llvm/Support/Casting.h @@ -132,24 +132,31 @@ } }; -// 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 argument. 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 typename std::enable_if::type +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); } //===--===// Index: clang/include/clang/AST/DeclBase.h === --- clang/include/clang/AST/DeclBase.h +++ clang/include/clang/AST/DeclBase.h @@ -518,7 +518,9 @@ if (!HasAttrs) return; AttrVec &Vec = getAttrs(); -Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa), Vec.end()); +Vec.erase(std::remove_if(Vec.begin(), Vec.end(), + [](Attr *A) { return isa(A); }), + Vec.end()); if (Vec.empty()) HasAttrs = false; Index: llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp === --- llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp @@ -220,7 +220,7 @@ 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 Index: llvm/lib/Analysis/ScalarEvolution.cpp === --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -3860,7 +3860,8 @@ 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 @@ // 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; } Index: llvm/include/llvm/Support/Casting.h === --- llvm/include/llvm/Support/Casting.h +++ llvm/include/llvm/Support/Casting.h @@ -132,24