Commit 810df4de authored by Paul's avatar Paul
Browse files

Enable verify on the tests

parent da4ce054
...@@ -10,6 +10,7 @@ struct program; ...@@ -10,6 +10,7 @@ struct program;
struct memory_coloring struct memory_coloring
{ {
std::string allocation_op{}; std::string allocation_op{};
bool verify = false;
std::string name() const { return "memory coloring"; } std::string name() const { return "memory coloring"; }
void apply(program& p) const; void apply(program& p) const;
}; };
......
...@@ -7,7 +7,7 @@ void memory_coloring::apply(program& p) const ...@@ -7,7 +7,7 @@ void memory_coloring::apply(program& p) const
{ {
if(!enabled(MIGRAPH_DISABLE_MEMORY_COLORING{})) if(!enabled(MIGRAPH_DISABLE_MEMORY_COLORING{}))
{ {
memory_coloring_impl opt(&p, allocation_op); memory_coloring_impl opt(&p, allocation_op, verify);
opt.run(); opt.run();
} }
} }
......
...@@ -19,7 +19,7 @@ void memory_coloring_impl::run() ...@@ -19,7 +19,7 @@ void memory_coloring_impl::run()
alloc_queue.pop(); alloc_queue.pop();
} }
rewrite(); rewrite();
MIGRAPH_DEBUG(verify()); if(enable_verify) verify();
} }
} }
...@@ -247,37 +247,6 @@ void memory_coloring_impl::rewrite() ...@@ -247,37 +247,6 @@ void memory_coloring_impl::rewrite()
MIGRAPH_DEBUG(dump_program()); MIGRAPH_DEBUG(dump_program());
} }
#ifdef MIGRAPH_DEBUG_OPT
void memory_coloring_impl::dump(const std::string& str) { std::cout << str << std::endl; }
void memory_coloring_impl::dump_program() { std::cout << *p_program << std::endl; }
void memory_coloring_impl::dump_intervals()
{
if(num_of_lives > 0)
{
std::cout << "---live intervals ---" << std::endl;
for(int i = 0; i < num_of_lives; ++i)
{
live_interval& interval = live_intervals[i];
interval.dump();
}
std::cout << "---conflict table---" << std::endl;
for(int i = 0; i <= max_value_number; ++i)
{
std::cout << " segment:" << i;
std::cout << " =>";
std::set<int>& table = conflict_table[i];
for(auto& iter : table)
{
std::cout << (iter) << ",";
}
}
std::cout << std::endl;
}
}
void memory_coloring_impl::verify() void memory_coloring_impl::verify()
{ {
if(num_of_lives > 0) if(num_of_lives > 0)
...@@ -289,7 +258,9 @@ void memory_coloring_impl::verify() ...@@ -289,7 +258,9 @@ void memory_coloring_impl::verify()
if(segment.begin == invalid_offset) if(segment.begin == invalid_offset)
{ {
assert(interval.is_live_on_entry); // FIXME: We need to compute cascading operand aliases
// if(!interval.is_live_on_entry)
// MIGRAPH_THROW("interval is not live on entry");
continue; continue;
} }
...@@ -307,13 +278,45 @@ void memory_coloring_impl::verify() ...@@ -307,13 +278,45 @@ void memory_coloring_impl::verify()
if(range->offset == invalid_offset) if(range->offset == invalid_offset)
continue; continue;
if(!is_disjoin(*range, segment)) if(!is_disjoin(*range, segment))
assert(false); MIGRAPH_THROW("range and segment is not disjoined");
} }
} }
} }
} }
} }
#ifdef MIGRAPH_DEBUG_OPT
void memory_coloring_impl::dump(const std::string& str) { std::cout << str << std::endl; }
void memory_coloring_impl::dump_program() { std::cout << *p_program << std::endl; }
void memory_coloring_impl::dump_intervals()
{
if(num_of_lives > 0)
{
std::cout << "---live intervals ---" << std::endl;
for(int i = 0; i < num_of_lives; ++i)
{
live_interval& interval = live_intervals[i];
interval.dump();
}
std::cout << "---conflict table---" << std::endl;
for(int i = 0; i <= max_value_number; ++i)
{
std::cout << " segment:" << i;
std::cout << " =>";
std::set<int>& table = conflict_table[i];
for(auto& iter : table)
{
std::cout << (iter) << ",";
}
}
std::cout << std::endl;
}
}
// map liveness tracking point to instruction enum. // map liveness tracking point to instruction enum.
static int get_ins_enum(int x) static int get_ins_enum(int x)
{ {
......
...@@ -50,8 +50,8 @@ using interval_ptr = live_interval*; ...@@ -50,8 +50,8 @@ using interval_ptr = live_interval*;
struct memory_coloring_impl struct memory_coloring_impl
{ {
memory_coloring_impl(program* p, std::string alloc_op) memory_coloring_impl(program* p, std::string alloc_op, bool p_verify)
: p_program(p), allocation_op(std::move(alloc_op)) : p_program(p), allocation_op(std::move(alloc_op)), enable_verify(p_verify)
{ {
instr2_live.clear(); instr2_live.clear();
live_ranges.clear(); live_ranges.clear();
...@@ -116,7 +116,6 @@ struct memory_coloring_impl ...@@ -116,7 +116,6 @@ struct memory_coloring_impl
operand_alias[name] = last_allocate; operand_alias[name] = last_allocate;
return last_allocate; return last_allocate;
} }
#ifdef MIGRAPH_DEBUG_OPT
static bool is_disjoin(live_range& range1, live_range& range2) static bool is_disjoin(live_range& range1, live_range& range2)
{ {
if((range1.size == 0) || (range2.size == 0)) if((range1.size == 0) || (range2.size == 0))
...@@ -125,10 +124,11 @@ struct memory_coloring_impl ...@@ -125,10 +124,11 @@ struct memory_coloring_impl
long long end2 = range2.offset + range2.size - 1; long long end2 = range2.offset + range2.size - 1;
return ((end1 < range2.offset) || (end2 < range1.offset)); return ((end1 < range2.offset) || (end2 < range1.offset));
} }
void verify();
#ifdef MIGRAPH_DEBUG_OPT
void dump(const std::string&); void dump(const std::string&);
void dump_program(); void dump_program();
void dump_intervals(); void dump_intervals();
void verify();
#endif #endif
struct ordering struct ordering
{ {
...@@ -176,6 +176,7 @@ struct memory_coloring_impl ...@@ -176,6 +176,7 @@ struct memory_coloring_impl
// Whether to unify literals into coloring. // Whether to unify literals into coloring.
bool unify_literals; bool unify_literals;
std::string allocation_op{}; std::string allocation_op{};
bool enable_verify;
}; };
} // namespace migraph } // namespace migraph
#endif #endif
...@@ -10,7 +10,7 @@ struct memory_coloring_target ...@@ -10,7 +10,7 @@ struct memory_coloring_target
std::string name() const { return "memory_coloring"; } std::string name() const { return "memory_coloring"; }
std::vector<migraph::pass> get_passes(migraph::context&) const std::vector<migraph::pass> get_passes(migraph::context&) const
{ {
return {migraph::memory_coloring{"allocate"}}; return {migraph::memory_coloring{"allocate", true}};
} }
migraph::context get_context() const { return {}; } migraph::context get_context() const { return {}; }
}; };
......
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