Skip to content

Commit 585b75e

Browse files
committed
[VPlan] Simplify matching recipe ty and opcode in pattern match (NFC).
Use parameter pack fold to simplify matching of recipe types and opcodes for RecipeTys parameter pack.
1 parent 113534d commit 585b75e

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,32 +128,6 @@ inline bind_ty<VPValue> m_VPValue(VPValue *&V) { return V; }
128128

129129
namespace detail {
130130

131-
/// A helper to match an opcode against multiple recipe types.
132-
template <unsigned Opcode, typename...> struct MatchRecipeAndOpcode {};
133-
134-
template <unsigned Opcode, typename RecipeTy>
135-
struct MatchRecipeAndOpcode<Opcode, RecipeTy> {
136-
static bool match(const VPRecipeBase *R) {
137-
auto *DefR = dyn_cast<RecipeTy>(R);
138-
// Check for recipes that do not have opcodes.
139-
if constexpr (std::is_same<RecipeTy, VPScalarIVStepsRecipe>::value ||
140-
std::is_same<RecipeTy, VPCanonicalIVPHIRecipe>::value ||
141-
std::is_same<RecipeTy, VPWidenSelectRecipe>::value ||
142-
std::is_same<RecipeTy, VPDerivedIVRecipe>::value ||
143-
std::is_same<RecipeTy, VPWidenGEPRecipe>::value)
144-
return DefR;
145-
else
146-
return DefR && DefR->getOpcode() == Opcode;
147-
}
148-
};
149-
150-
template <unsigned Opcode, typename RecipeTy, typename... RecipeTys>
151-
struct MatchRecipeAndOpcode<Opcode, RecipeTy, RecipeTys...> {
152-
static bool match(const VPRecipeBase *R) {
153-
return MatchRecipeAndOpcode<Opcode, RecipeTy>::match(R) ||
154-
MatchRecipeAndOpcode<Opcode, RecipeTys...>::match(R);
155-
}
156-
};
157131
template <typename TupleTy, typename Fn, std::size_t... Is>
158132
bool CheckTupleElements(const TupleTy &Ops, Fn P, std::index_sequence<Is...>) {
159133
return (P(std::get<Is>(Ops), Is) && ...);
@@ -193,8 +167,9 @@ struct Recipe_match {
193167
}
194168

195169
bool match(const VPRecipeBase *R) const {
196-
if (!detail::MatchRecipeAndOpcode<Opcode, RecipeTys...>::match(R))
170+
if ((!matchRecipeAndOpcode<RecipeTys>(R) && ...))
197171
return false;
172+
198173
assert(R->getNumOperands() == std::tuple_size<Ops_t>::value &&
199174
"recipe with matched opcode the expected number of operands");
200175

@@ -208,6 +183,21 @@ struct Recipe_match {
208183
return Op.match(R->getOperand(R->getNumOperands() - Idx - 1));
209184
});
210185
}
186+
187+
private:
188+
template <typename RecipeTy>
189+
static bool matchRecipeAndOpcode(const VPRecipeBase *R) {
190+
auto *DefR = dyn_cast<RecipeTy>(R);
191+
// Check for recipes that do not have opcodes.
192+
if constexpr (std::is_same<RecipeTy, VPScalarIVStepsRecipe>::value ||
193+
std::is_same<RecipeTy, VPCanonicalIVPHIRecipe>::value ||
194+
std::is_same<RecipeTy, VPWidenSelectRecipe>::value ||
195+
std::is_same<RecipeTy, VPDerivedIVRecipe>::value ||
196+
std::is_same<RecipeTy, VPWidenGEPRecipe>::value)
197+
return DefR;
198+
else
199+
return DefR && DefR->getOpcode() == Opcode;
200+
}
211201
};
212202

213203
template <typename Op0_t, unsigned Opcode, typename... RecipeTys>

0 commit comments

Comments
 (0)