Skip to content

Commit 2c6aa67

Browse files
committed
[SDPatternMatch] Do not use std::forward and rvalue references (NFC)
The m_ZExtOrSelf() family of matchers currently incorrect calls std::forward twice on the value. However, just removing those causes other complications, because then template arguments get incorrectly inferred to const references instead of the underlying value types. Things become a mess. Instead, just completely remove the use of std::forward and rvalue references from SDPatternMatch, aligning it with normal IR PatternMatch.
1 parent b2bd024 commit 2c6aa67

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

llvm/include/llvm/CodeGen/SDPatternMatch.h

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ template <typename... Preds> struct And {
330330
template <typename Pred, typename... Preds>
331331
struct And<Pred, Preds...> : And<Preds...> {
332332
Pred P;
333-
And(Pred &&p, Preds &&...preds)
334-
: And<Preds...>(std::forward<Preds>(preds)...), P(std::forward<Pred>(p)) {
335-
}
333+
And(const Pred &p, const Preds &...preds) : And<Preds...>(preds...), P(p) {}
336334

337335
template <typename MatchContext>
338336
bool match(const MatchContext &Ctx, SDValue N) {
@@ -349,8 +347,7 @@ template <typename... Preds> struct Or {
349347
template <typename Pred, typename... Preds>
350348
struct Or<Pred, Preds...> : Or<Preds...> {
351349
Pred P;
352-
Or(Pred &&p, Preds &&...preds)
353-
: Or<Preds...>(std::forward<Preds>(preds)...), P(std::forward<Pred>(p)) {}
350+
Or(const Pred &p, const Preds &...preds) : Or<Preds...>(preds...), P(p) {}
354351

355352
template <typename MatchContext>
356353
bool match(const MatchContext &Ctx, SDValue N) {
@@ -376,16 +373,16 @@ template <typename Pred> inline Not<Pred> m_Unless(const Pred &P) {
376373
return Not{P};
377374
}
378375

379-
template <typename... Preds> And<Preds...> m_AllOf(Preds &&...preds) {
380-
return And<Preds...>(std::forward<Preds>(preds)...);
376+
template <typename... Preds> And<Preds...> m_AllOf(const Preds &...preds) {
377+
return And<Preds...>(preds...);
381378
}
382379

383-
template <typename... Preds> Or<Preds...> m_AnyOf(Preds &&...preds) {
384-
return Or<Preds...>(std::forward<Preds>(preds)...);
380+
template <typename... Preds> Or<Preds...> m_AnyOf(const Preds &...preds) {
381+
return Or<Preds...>(preds...);
385382
}
386383

387-
template <typename... Preds> auto m_NoneOf(Preds &&...preds) {
388-
return m_Unless(m_AnyOf(std::forward<Preds>(preds)...));
384+
template <typename... Preds> auto m_NoneOf(const Preds &...preds) {
385+
return m_Unless(m_AnyOf(preds...));
389386
}
390387

391388
// === Generic node matching ===
@@ -402,10 +399,8 @@ struct Operands_match<OpIdx, OpndPred, OpndPreds...>
402399
: Operands_match<OpIdx + 1, OpndPreds...> {
403400
OpndPred P;
404401

405-
Operands_match(OpndPred &&p, OpndPreds &&...preds)
406-
: Operands_match<OpIdx + 1, OpndPreds...>(
407-
std::forward<OpndPreds>(preds)...),
408-
P(std::forward<OpndPred>(p)) {}
402+
Operands_match(const OpndPred &p, const OpndPreds &...preds)
403+
: Operands_match<OpIdx + 1, OpndPreds...>(preds...), P(p) {}
409404

410405
template <typename MatchContext>
411406
bool match(const MatchContext &Ctx, SDValue N) {
@@ -419,9 +414,8 @@ struct Operands_match<OpIdx, OpndPred, OpndPreds...>
419414
};
420415

421416
template <typename... OpndPreds>
422-
auto m_Node(unsigned Opcode, OpndPreds &&...preds) {
423-
return m_AllOf(m_Opc(Opcode), Operands_match<0, OpndPreds...>(
424-
std::forward<OpndPreds>(preds)...));
417+
auto m_Node(unsigned Opcode, const OpndPreds &...preds) {
418+
return m_AllOf(m_Opc(Opcode), Operands_match<0, OpndPreds...>(preds...));
425419
}
426420

427421
/// Provide number of operands that are not chain or glue, as well as the first
@@ -647,10 +641,9 @@ template <typename Opnd> inline UnaryOpc_match<Opnd> m_ZExt(const Opnd &Op) {
647641
return UnaryOpc_match<Opnd>(ISD::ZERO_EXTEND, Op);
648642
}
649643

650-
template <typename Opnd> inline auto m_SExt(Opnd &&Op) {
651-
return m_AnyOf(
652-
UnaryOpc_match<Opnd>(ISD::SIGN_EXTEND, Op),
653-
m_Node(ISD::SIGN_EXTEND_INREG, std::forward<Opnd>(Op), m_Value()));
644+
template <typename Opnd> inline auto m_SExt(const Opnd &Op) {
645+
return m_AnyOf(UnaryOpc_match<Opnd>(ISD::SIGN_EXTEND, Op),
646+
m_Node(ISD::SIGN_EXTEND_INREG, Op, m_Value()));
654647
}
655648

656649
template <typename Opnd> inline UnaryOpc_match<Opnd> m_AnyExt(const Opnd &Op) {
@@ -663,30 +656,28 @@ template <typename Opnd> inline UnaryOpc_match<Opnd> m_Trunc(const Opnd &Op) {
663656

664657
/// Match a zext or identity
665658
/// Allows to peek through optional extensions
666-
template <typename Opnd> inline auto m_ZExtOrSelf(Opnd &&Op) {
667-
return m_AnyOf(m_ZExt(std::forward<Opnd>(Op)), std::forward<Opnd>(Op));
659+
template <typename Opnd> inline auto m_ZExtOrSelf(const Opnd &Op) {
660+
return m_AnyOf(m_ZExt(Op), Op);
668661
}
669662

670663
/// Match a sext or identity
671664
/// Allows to peek through optional extensions
672-
template <typename Opnd> inline auto m_SExtOrSelf(Opnd &&Op) {
673-
return m_AnyOf(m_SExt(std::forward<Opnd>(Op)), std::forward<Opnd>(Op));
665+
template <typename Opnd> inline auto m_SExtOrSelf(const Opnd &Op) {
666+
return m_AnyOf(m_SExt(Op), Op);
674667
}
675668

676669
/// Match a aext or identity
677670
/// Allows to peek through optional extensions
678671
template <typename Opnd>
679-
inline Or<UnaryOpc_match<Opnd>, Opnd> m_AExtOrSelf(Opnd &&Op) {
680-
return Or<UnaryOpc_match<Opnd>, Opnd>(m_AnyExt(std::forward<Opnd>(Op)),
681-
std::forward<Opnd>(Op));
672+
inline Or<UnaryOpc_match<Opnd>, Opnd> m_AExtOrSelf(const Opnd &Op) {
673+
return Or<UnaryOpc_match<Opnd>, Opnd>(m_AnyExt(Op), Op);
682674
}
683675

684676
/// Match a trunc or identity
685677
/// Allows to peek through optional truncations
686678
template <typename Opnd>
687-
inline Or<UnaryOpc_match<Opnd>, Opnd> m_TruncOrSelf(Opnd &&Op) {
688-
return Or<UnaryOpc_match<Opnd>, Opnd>(m_Trunc(std::forward<Opnd>(Op)),
689-
std::forward<Opnd>(Op));
679+
inline Or<UnaryOpc_match<Opnd>, Opnd> m_TruncOrSelf(const Opnd &Op) {
680+
return Or<UnaryOpc_match<Opnd>, Opnd>(m_Trunc(Op), Op);
690681
}
691682

692683
// === Constants ===

0 commit comments

Comments
 (0)