Commit 3cb4edfe authored by Paul's avatar Paul
Browse files

Try to fix ice on gcc 5

parent 8c8e5fb0
...@@ -190,10 +190,21 @@ auto pop_back_args(Ts&&... xs) ...@@ -190,10 +190,21 @@ auto pop_back_args(Ts&&... xs)
}; };
} }
template<class T>
struct always_f
{
T x;
template<class... Ts>
constexpr T operator()(Ts&&...) const
{
return x;
}
};
template <class T> template <class T>
auto always(T x) auto always(T x)
{ {
return [=](auto&&...) { return x; }; return always_f<T>{x};
} }
} // namespace MIGRAPHX_INLINE_NS } // namespace MIGRAPHX_INLINE_NS
......
...@@ -261,14 +261,21 @@ struct lazy_or ...@@ -261,14 +261,21 @@ struct lazy_or
template <class Op, bool Start, bool Matches> template <class Op, bool Start, bool Matches>
struct folder struct folder
{ {
template <class... Ts> template<class... Ms>
auto operator()(Ts... ms) const static bool fold_match(matcher_context& ctx, instruction_ref ins, Ms... ms)
{ {
return make_bf_matcher([=](matcher_context& ctx, instruction_ref ins) {
Op op; Op op;
auto matched = [&](auto m) { return [&] { return ctx.matched(m, ins); }; }; auto matched = [&](auto m) { return [&] { return ctx.matched(m, ins); }; };
bool matches = return
fold([&](auto x, auto y) { return op(always(x), matched(y)); })(Start, ms...); fold([&](auto x, auto y) { return op(always(x), matched(y)); })(Start, ms...);
}
template <class... Ts>
auto operator()(Ts... ms) const
{
return make_bf_matcher([=](matcher_context& ctx, instruction_ref ins) {
bool matches = folder::fold_match(ctx, ins, ms...);
if(matches == Matches) if(matches == Matches)
return ins; return ins;
return ctx.not_found(); return ctx.not_found();
...@@ -283,12 +290,8 @@ struct folder ...@@ -283,12 +290,8 @@ struct folder
Op op; Op op;
bool matches = Start; bool matches = Start;
select(start, [&](auto ins) { select(start, [&](auto ins) {
auto matched = [&](auto m) { return [&] { return ctx.matched(m, ins); }; }; auto fm = [&] { return folder::fold_match(ctx, ins, ms...); };
auto fold_match = [&] { matches = op(always(matches), fm);
return fold([&](auto x, auto y) { return op(always(x), matched(y)); })(
Start, ms...);
};
matches = op(always(matches), fold_match);
}); });
if(matches == Matches) if(matches == Matches)
return start; return start;
......
...@@ -148,6 +148,20 @@ TEST_CASE(match_arg7) ...@@ -148,6 +148,20 @@ TEST_CASE(match_arg7)
EXPECT(bool{r.result == sum}); EXPECT(bool{r.result == sum});
} }
TEST_CASE(match_arg8)
{
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto sum = p.add_instruction(sum_op{}, one, two);
p.add_instruction(pass_op{}, sum);
auto m = match::name("sum")(match::all_of(match::arg(0)(match::name("@literal")),
match::arg(1)(match::name("@literal"))),
match::standard_shape());
auto r = find_match(p, m);
EXPECT(bool{r.result == sum});
}
TEST_CASE(match_args1) TEST_CASE(match_args1)
{ {
migraphx::program p; migraphx::program p;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment