Commit 7d645dd0 authored by charlie's avatar charlie
Browse files

Pass module, skip order check if other module

parent bd24f471
...@@ -42,7 +42,7 @@ struct instruction ...@@ -42,7 +42,7 @@ struct instruction
friend bool operator==(const instruction& i, instruction_ref ref); friend bool operator==(const instruction& i, instruction_ref ref);
bool valid(instruction_ref start, bool check_order = false) const; bool valid(const module& m, bool check_order = false) const;
bool valid() const; bool valid() const;
......
...@@ -76,27 +76,16 @@ bool operator==(const instruction& i, instruction_ref ref) ...@@ -76,27 +76,16 @@ bool operator==(const instruction& i, instruction_ref ref)
static void debug_name(std::ostream& os, const instruction& ins); static void debug_name(std::ostream& os, const instruction& ins);
bool instruction::valid(instruction_ref start, bool check_order) const bool instruction::valid(const module& m, bool check_order) const
{ {
// Need this lambda because std::distance has undefined behavior when comparing iterators of
// from different ranges
auto ins_dist = [](instruction_ref s, instruction_ref e) {
int dist = 0;
while((*s) != (*e))
{
++s;
++dist;
}
return dist;
};
return valid() && std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) { return valid() && std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) {
auto self = std::find(i->outputs().begin(), i->outputs().end(), *this); auto self = std::find(i->outputs().begin(), i->outputs().end(), *this);
bool ret = self != i->outputs().end(); bool ret = self != i->outputs().end();
if(check_order) // assume argument is in previous module if m.has_instruction(i) is false
if(check_order and m.has_instruction(i))
{ {
// arguments for this instruction before this instruction // check arguments for this instruction before this instruction
ret = ret and (ins_dist(start, i) < ins_dist(start, *self)); ret = ret and (std::distance(m.begin(), i) < std::distance(m.begin(), *self));
} }
return ret; return ret;
}); });
......
...@@ -511,7 +511,7 @@ instruction_ref module::validate() const ...@@ -511,7 +511,7 @@ instruction_ref module::validate() const
bool check_order = std::all_of(inputs.begin(), inputs.end(), [&](auto in) { bool check_order = std::all_of(inputs.begin(), inputs.end(), [&](auto in) {
return contains(impl->instructions, *in); return contains(impl->instructions, *in);
}); });
return !i.valid(impl->instructions.begin(), check_order); return !i.valid(*this, check_order);
}); });
} }
......
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