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
e2de3cc2
"git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "b76e669cb5faec30a4b5735fd0e0670f0a95d3c9"
Commit
e2de3cc2
authored
Jul 09, 2018
by
Paul
Browse files
Fix issue with DCE, and add more tests
parent
c7ad413e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
3 deletions
+30
-3
src/dead_code_elimination.cpp
src/dead_code_elimination.cpp
+7
-2
src/include/migraph/instruction.hpp
src/include/migraph/instruction.hpp
+1
-0
src/program.cpp
src/program.cpp
+2
-1
test/dead_code_elimination_test.cpp
test/dead_code_elimination_test.cpp
+20
-0
No files found.
src/dead_code_elimination.cpp
View file @
e2de3cc2
...
...
@@ -11,19 +11,24 @@ void dead_code_elimination::apply(program& p) const
auto
last
=
std
::
prev
(
p
.
end
());
for
(
auto
ins
:
iterator_for
(
p
))
{
// Skip the first instruction, since we always process the previous
// instruction
if
(
ins
==
p
.
begin
())
continue
;
// Skip the last instruction
if
(
ins
==
last
)
if
(
std
::
prev
(
ins
)
==
last
)
break
;
fix
([
&
](
auto
self
,
auto
leaf
)
{
assert
(
p
.
has_instruction
(
leaf
));
if
(
leaf
->
output
.
empty
())
{
auto
args
=
leaf
->
arguments
;
leaf
->
clear_arguments
();
p
.
move_instruction
(
leaf
,
p
.
end
());
for
(
auto
arg
:
args
)
self
(
arg
);
}
})(
ins
);
})(
std
::
prev
(
ins
)
)
;
}
p
.
remove_instructions
(
std
::
next
(
last
),
p
.
end
());
}
...
...
src/include/migraph/instruction.hpp
View file @
e2de3cc2
...
...
@@ -54,6 +54,7 @@ struct instruction
{
migraph
::
erase
(
arg
->
output
,
*
this
);
}
arguments
.
clear
();
}
friend
bool
operator
==
(
const
instruction
&
i
,
instruction_ref
ref
)
...
...
src/program.cpp
View file @
e2de3cc2
...
...
@@ -62,8 +62,9 @@ instruction_ref program::remove_instruction(instruction_ref ins)
instruction_ref
program
::
remove_instructions
(
instruction_ref
first
,
instruction_ref
last
)
{
if
(
first
==
last
)
return
first
;
// TODO: Check every element
assert
(
has_instruction
(
first
));
assert
(
has_instruction
(
last
));
std
::
for_each
(
first
,
last
,
[
&
](
instruction
&
ins
)
{
ins
.
clear_arguments
();
});
assert
(
std
::
all_of
(
first
,
last
,
[
&
](
instruction
&
ins
)
{
return
ins
.
output
.
empty
();
}));
return
impl
->
instructions
.
erase
(
first
,
last
);
...
...
test/dead_code_elimination_test.cpp
View file @
e2de3cc2
...
...
@@ -60,9 +60,29 @@ void duplicate_test2()
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
depth_test
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
x1
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
x2
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
add_instruction
(
minus_op
{},
x1
,
x2
);
p
.
add_instruction
(
minus_op
{},
x1
,
x2
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
count
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
p
.
compile
(
dce_target
{});
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
(
count
-
4
));
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
int
main
()
{
simple_test
();
duplicate_test1
();
duplicate_test2
();
depth_test
();
}
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