Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
ad2ac47c
Commit
ad2ac47c
authored
Sep 24, 2018
by
Paul
Browse files
Add more tests and fix any_of bug
parent
7dc4ac24
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
7 deletions
+51
-7
src/include/migraph/matcher.hpp
src/include/migraph/matcher.hpp
+1
-1
test/matcher.cpp
test/matcher.cpp
+50
-6
No files found.
src/include/migraph/matcher.hpp
View file @
ad2ac47c
...
@@ -255,7 +255,7 @@ auto any_of(Ts... ms)
...
@@ -255,7 +255,7 @@ auto any_of(Ts... ms)
{
{
return
make_bf_matcher
([
=
](
matcher_context
&
ctx
,
instruction_ref
ins
)
{
return
make_bf_matcher
([
=
](
matcher_context
&
ctx
,
instruction_ref
ins
)
{
bool
matches
=
fold
(
bool
matches
=
fold
(
[
&
](
auto
x
,
auto
y
)
{
return
x
or
y
.
match
(
ctx
,
ins
)
!=
ctx
.
not_found
();
})(
tru
e
,
ms
...);
[
&
](
auto
x
,
auto
y
)
{
return
x
or
y
.
match
(
ctx
,
ins
)
!=
ctx
.
not_found
();
})(
fals
e
,
ms
...);
if
(
matches
)
if
(
matches
)
return
ins
;
return
ins
;
return
ctx
.
not_found
();
return
ctx
.
not_found
();
...
...
test/matcher.cpp
View file @
ad2ac47c
...
@@ -250,7 +250,7 @@ void match_args7()
...
@@ -250,7 +250,7 @@ void match_args7()
EXPECT
(
bool
{
r
.
result
==
pass
});
EXPECT
(
bool
{
r
.
result
==
pass
});
}
}
void
match_all_of
()
void
match_all_of
1
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
one
=
p
.
add_literal
(
1
);
...
@@ -263,7 +263,20 @@ void match_all_of()
...
@@ -263,7 +263,20 @@ void match_all_of()
EXPECT
(
bool
{
r
.
result
==
sum
});
EXPECT
(
bool
{
r
.
result
==
sum
});
}
}
void
match_any_of
()
void
match_all_of2
()
{
migraph
::
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
=
matchers
::
name
(
"sum"
)(
matchers
::
all_of
(
matchers
::
arg
(
0
)(
matchers
::
name
(
"sum"
)),
matchers
::
arg
(
1
)(
matchers
::
name
(
"@literal"
))));
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
p
.
end
()});
}
void
match_any_of1
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
one
=
p
.
add_literal
(
1
);
...
@@ -276,7 +289,20 @@ void match_any_of()
...
@@ -276,7 +289,20 @@ void match_any_of()
EXPECT
(
bool
{
r
.
result
==
sum
});
EXPECT
(
bool
{
r
.
result
==
sum
});
}
}
void
match_none_of
()
void
match_any_of2
()
{
migraph
::
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
=
matchers
::
name
(
"sum"
)(
matchers
::
any_of
(
matchers
::
arg
(
0
)(
matchers
::
name
(
"sum"
)),
matchers
::
arg
(
1
)(
matchers
::
name
(
"sum"
))));
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
p
.
end
()});
}
void
match_none_of1
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
one
=
p
.
add_literal
(
1
);
...
@@ -289,6 +315,19 @@ void match_none_of()
...
@@ -289,6 +315,19 @@ void match_none_of()
EXPECT
(
bool
{
r
.
result
==
sum
});
EXPECT
(
bool
{
r
.
result
==
sum
});
}
}
void
match_none_of2
()
{
migraph
::
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
=
matchers
::
name
(
"sum"
)(
matchers
::
none_of
(
matchers
::
arg
(
0
)(
matchers
::
name
(
"@literal"
)),
matchers
::
arg
(
1
)(
matchers
::
name
(
"@literal"
))));
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
p
.
end
()});
}
void
match_bind1
()
void
match_bind1
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
...
@@ -364,10 +403,15 @@ int main()
...
@@ -364,10 +403,15 @@ int main()
match_args6
();
match_args6
();
match_args7
();
match_args7
();
match_all_of
();
match_all_of1
();
match_any_of
();
match_all_of2
();
match_none_of
();
match_any_of1
();
match_any_of2
();
match_none_of1
();
match_none_of2
();
match_bind1
();
match_bind1
();
match_finder
();
match_finder
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment