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
56537575
Commit
56537575
authored
Jul 09, 2018
by
Paul
Browse files
Formatting
parent
375e4c15
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
14 deletions
+23
-14
src/dead_code_elimination.cpp
src/dead_code_elimination.cpp
+2
-2
src/include/migraph/functional.hpp
src/include/migraph/functional.hpp
+4
-4
src/include/migraph/iterator_for.hpp
src/include/migraph/iterator_for.hpp
+10
-2
src/program.cpp
src/program.cpp
+1
-2
test/dead_code_elimination_test.cpp
test/dead_code_elimination_test.cpp
+6
-4
No files found.
src/dead_code_elimination.cpp
View file @
56537575
...
@@ -8,7 +8,7 @@ namespace migraph {
...
@@ -8,7 +8,7 @@ namespace migraph {
void
dead_code_elimination
::
apply
(
program
&
p
)
const
void
dead_code_elimination
::
apply
(
program
&
p
)
const
{
{
for
(
auto
i
:
iterator_for
(
p
))
for
(
auto
i
:
iterator_for
(
p
))
{
{
// Skip over instructions that may have been removed
// Skip over instructions that may have been removed
if
(
!
p
.
has_instruction
(
i
))
if
(
!
p
.
has_instruction
(
i
))
...
@@ -23,7 +23,7 @@ void dead_code_elimination::apply(program& p) const
...
@@ -23,7 +23,7 @@ void dead_code_elimination::apply(program& p) const
std
::
cout
<<
p
<<
std
::
endl
;
std
::
cout
<<
p
<<
std
::
endl
;
auto
args
=
ins
->
arguments
;
auto
args
=
ins
->
arguments
;
p
.
remove_instruction
(
ins
);
p
.
remove_instruction
(
ins
);
for
(
auto
arg
:
args
)
for
(
auto
arg
:
args
)
self
(
arg
);
self
(
arg
);
}
}
})(
i
);
})(
i
);
...
...
src/include/migraph/functional.hpp
View file @
56537575
...
@@ -7,12 +7,12 @@ namespace migraph {
...
@@ -7,12 +7,12 @@ namespace migraph {
namespace
detail
{
namespace
detail
{
template
<
class
R
,
class
F
>
template
<
class
R
,
class
F
>
struct
fix_f
struct
fix_f
{
{
F
f
;
F
f
;
template
<
class
...
Ts
>
template
<
class
...
Ts
>
R
operator
()(
Ts
&&
...
xs
)
const
R
operator
()(
Ts
&&
...
xs
)
const
{
{
return
f
(
*
this
,
std
::
forward
<
Ts
>
(
xs
)...);
return
f
(
*
this
,
std
::
forward
<
Ts
>
(
xs
)...);
...
@@ -22,13 +22,13 @@ struct fix_f
...
@@ -22,13 +22,13 @@ struct fix_f
}
// namespace detail
}
// namespace detail
/// Implements a fix-point combinator
/// Implements a fix-point combinator
template
<
class
R
,
class
F
>
template
<
class
R
,
class
F
>
detail
::
fix_f
<
R
,
F
>
fix
(
F
f
)
detail
::
fix_f
<
R
,
F
>
fix
(
F
f
)
{
{
return
{
f
};
return
{
f
};
}
}
template
<
class
F
>
template
<
class
F
>
auto
fix
(
F
f
)
auto
fix
(
F
f
)
{
{
return
fix
<
void
>
(
f
);
return
fix
<
void
>
(
f
);
...
...
src/include/migraph/iterator_for.hpp
View file @
56537575
...
@@ -20,8 +20,16 @@ struct iterator_for_range
...
@@ -20,8 +20,16 @@ struct iterator_for_range
bool
operator
!=
(
const
iterator
&
rhs
)
{
return
i
!=
rhs
.
i
;
}
bool
operator
!=
(
const
iterator
&
rhs
)
{
return
i
!=
rhs
.
i
;
}
};
};
iterator
begin
()
{
assert
(
base
!=
nullptr
);
return
{
base
->
begin
()};
}
iterator
begin
()
iterator
end
()
{
assert
(
base
!=
nullptr
);
return
{
base
->
end
()};
}
{
assert
(
base
!=
nullptr
);
return
{
base
->
begin
()};
}
iterator
end
()
{
assert
(
base
!=
nullptr
);
return
{
base
->
end
()};
}
};
};
template
<
class
T
>
template
<
class
T
>
iterator_for_range
<
T
>
iterator_for
(
T
&
x
)
iterator_for_range
<
T
>
iterator_for
(
T
&
x
)
...
...
src/program.cpp
View file @
56537575
...
@@ -52,8 +52,7 @@ program::replace_instruction(instruction_ref ins, operation op, std::vector<inst
...
@@ -52,8 +52,7 @@ program::replace_instruction(instruction_ref ins, operation op, std::vector<inst
return
ins
;
return
ins
;
}
}
instruction_ref
instruction_ref
program
::
remove_instruction
(
instruction_ref
ins
)
program
::
remove_instruction
(
instruction_ref
ins
)
{
{
assert
(
has_instruction
(
ins
));
assert
(
has_instruction
(
ins
));
assert
(
ins
->
output
.
empty
());
assert
(
ins
->
output
.
empty
());
...
...
test/dead_code_elimination_test.cpp
View file @
56537575
...
@@ -5,7 +5,10 @@
...
@@ -5,7 +5,10 @@
struct
dce_target
struct
dce_target
{
{
std
::
string
name
()
const
{
return
"dce"
;
}
std
::
string
name
()
const
{
return
"dce"
;
}
std
::
vector
<
migraph
::
pass
>
get_passes
(
migraph
::
context
&
)
const
{
return
{
migraph
::
dead_code_elimination
{}
};
}
std
::
vector
<
migraph
::
pass
>
get_passes
(
migraph
::
context
&
)
const
{
return
{
migraph
::
dead_code_elimination
{}};
}
migraph
::
context
get_context
()
const
{
return
{};
}
migraph
::
context
get_context
()
const
{
return
{};
}
};
};
...
@@ -34,7 +37,7 @@ void duplicate_test()
...
@@ -34,7 +37,7 @@ void duplicate_test()
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
count
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
auto
count
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
p
.
compile
(
dce_target
{});
p
.
compile
(
dce_target
{});
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
(
count
-
1
));
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
(
count
-
1
));
auto
result
=
p
.
eval
({});
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
...
@@ -45,4 +48,3 @@ int main()
...
@@ -45,4 +48,3 @@ int main()
simple_test
();
simple_test
();
duplicate_test
();
duplicate_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