Commit 56537575 authored by Paul's avatar Paul
Browse files

Formatting

parent 375e4c15
...@@ -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);
......
...@@ -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);
......
...@@ -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)
......
...@@ -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());
......
...@@ -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();
} }
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