[llvm] [VPlan] Add vputils::recipesOnly that returns a downcasted range (NFC) (PR #222770)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 20:14:57 PDT 2026


================
@@ -166,6 +166,15 @@ inline VPRecipeBase *findRecipe(VPValue *Start, PredT Pred) {
   return nullptr;
 }
 
+/// Returns an iterator range over \p Range which only includes \p RecipeTy
+/// recipes. The accesses are casted to \p RecipeTy.
+template <typename RecipeTy, typename T> auto recipesOnly(T &&Range) {
+  auto Filter = make_filter_range(std::forward<T>(Range),
+                                  [](auto &R) { return isa<RecipeTy>(R); });
+  return map_range(Filter,
+                   [](auto &R) -> RecipeTy & { return cast<RecipeTy>(R); });
+}
----------------
lukel97 wrote:

Can we use the functors so we propagate const correctly

```suggestion
template <typename RecipeTy, typename T> auto recipesOnly(T &&Range) {
  return map_range(
      make_filter_range(std::forward<T>(Range), IsaPred<RecipeTy>),
      CastTo<RecipeTy>);
}
```

https://github.com/llvm/llvm-project/pull/222770


More information about the llvm-commits mailing list