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
75ff4513
Commit
75ff4513
authored
Sep 23, 2018
by
Paul
Browse files
Formatting
parent
adf9a5ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
34 deletions
+36
-34
src/include/migraph/matcher.hpp
src/include/migraph/matcher.hpp
+1
-1
test/matcher.cpp
test/matcher.cpp
+35
-33
No files found.
src/include/migraph/matcher.hpp
View file @
75ff4513
...
...
@@ -179,7 +179,7 @@ matcher_result match_instruction(program& p, instruction_ref ins, M&& m)
assert
(
ins
!=
p
.
end
());
matcher_result
result
;
matcher_context
ctx
{
p
.
end
()};
result
.
result
=
m
.
match
(
ctx
,
ins
);
result
.
result
=
m
.
match
(
ctx
,
ins
);
result
.
instructions
=
ctx
.
instructions
;
return
result
;
}
...
...
test/matcher.cpp
View file @
75ff4513
...
...
@@ -174,9 +174,9 @@ void match_args2()
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
::
args
(
matchers
::
name
(
"@literal"
),
matchers
::
name
(
"sum"
)),
matchers
::
standard_shape
());
auto
m
=
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"@literal"
),
matchers
::
name
(
"sum"
)),
matchers
::
standard_shape
());
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
p
.
end
()});
}
...
...
@@ -188,9 +188,8 @@ void match_args3()
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
::
args
(
matchers
::
name
(
"@literal"
)),
matchers
::
standard_shape
());
auto
m
=
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"@literal"
)),
matchers
::
standard_shape
());
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
sum
});
}
...
...
@@ -198,14 +197,14 @@ void match_args3()
void
match_args4
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum1
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
sum2
=
p
.
add_instruction
(
sum_op
{},
sum1
,
two
);
p
.
add_instruction
(
pass_op
{},
sum2
);
auto
m
=
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
),
matchers
::
name
(
"@literal"
)),
matchers
::
standard_shape
());
auto
m
=
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
),
matchers
::
name
(
"@literal"
)),
matchers
::
standard_shape
());
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
sum2
});
}
...
...
@@ -217,9 +216,9 @@ void match_args5()
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
::
args
(
matchers
::
name
(
"sum"
),
matchers
::
name
(
"@literal"
)),
matchers
::
standard_shape
());
auto
m
=
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
),
matchers
::
name
(
"@literal"
)),
matchers
::
standard_shape
());
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
p
.
end
()});
}
...
...
@@ -227,13 +226,12 @@ void match_args5()
void
match_args6
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
pass
=
p
.
add_instruction
(
pass_op
{},
sum
);
auto
m
=
matchers
::
name
(
"pass"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
)),
matchers
::
standard_shape
());
auto
m
=
matchers
::
name
(
"pass"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
)),
matchers
::
standard_shape
());
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
pass
});
}
...
...
@@ -241,27 +239,31 @@ void match_args6()
void
match_args7
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
pass
=
p
.
add_instruction
(
pass_op
{},
sum
);
auto
m
=
matchers
::
name
(
"pass"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"@literal"
),
matchers
::
name
(
"@literal"
)))),
matchers
::
standard_shape
());
auto
r
=
find_match
(
p
,
m
);
auto
m
=
matchers
::
name
(
"pass"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"@literal"
),
matchers
::
name
(
"@literal"
)))),
matchers
::
standard_shape
());
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
result
==
pass
});
}
void
match_bind1
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
sum
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
pass
=
p
.
add_instruction
(
pass_op
{},
sum
);
auto
m
=
matchers
::
name
(
"pass"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"@literal"
).
bind
(
"one"
),
matchers
::
name
(
"@literal"
).
bind
(
"two"
))).
bind
(
"sum"
)),
matchers
::
standard_shape
()).
bind
(
"pass"
);
auto
m
=
matchers
::
name
(
"pass"
)(
matchers
::
args
(
matchers
::
name
(
"sum"
)(
matchers
::
args
(
matchers
::
name
(
"@literal"
).
bind
(
"one"
),
matchers
::
name
(
"@literal"
).
bind
(
"two"
)))
.
bind
(
"sum"
)),
matchers
::
standard_shape
())
.
bind
(
"pass"
);
auto
r
=
find_match
(
p
,
m
);
EXPECT
(
bool
{
r
.
instructions
.
at
(
"one"
)
==
one
});
EXPECT
(
bool
{
r
.
instructions
.
at
(
"two"
)
==
two
});
...
...
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