"example/vscode:/vscode.git/clone" did not exist on "4cccaba1f10fdb052cfdb77e659e5eb74acbe842"
Commit b2051bbc authored by Paul's avatar Paul
Browse files

Merge branch 'develop' into hcc23

parents 52c90f8a 1af75182
...@@ -72,7 +72,9 @@ struct instruction ...@@ -72,7 +72,9 @@ struct instruction
static void static void
replace(instruction_ref ins, operation o, const shape& r, std::vector<instruction_ref> args); replace(instruction_ref ins, operation o, const shape& r, std::vector<instruction_ref> args);
argument eval() const; bool can_eval() const;
argument eval(bool check_eval = true) const;
void finalize(context& ctx); void finalize(context& ctx);
......
...@@ -162,7 +162,24 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins) ...@@ -162,7 +162,24 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
old->remove_output(*this); old->remove_output(*this);
} }
argument instruction::eval() const bool instruction::can_eval() const
{
if(op.name() == "@literal")
{
return true;
}
else if(is_context_free(op))
{
return std::all_of(
this->inputs().begin(), this->inputs().end(), [](auto arg) { return arg->can_eval(); });
}
else
{
return false;
}
}
argument instruction::eval(bool check_eval) const
{ {
if(op.name() == "@literal") if(op.name() == "@literal")
{ {
...@@ -170,14 +187,13 @@ argument instruction::eval() const ...@@ -170,14 +187,13 @@ argument instruction::eval() const
} }
if(is_context_free(op)) if(is_context_free(op))
{ {
if(check_eval and not this->can_eval())
return {};
std::vector<argument> args; std::vector<argument> args;
for(auto&& arg : this->inputs()) std::transform(this->inputs().begin(),
{ this->inputs().end(),
argument a = arg->eval(); std::back_inserter(args),
if(a.empty()) [](auto arg) { return arg->eval(false); });
return {};
args.push_back(a);
}
return op.compute(result, args); return op.compute(result, args);
} }
return {}; return {};
......
...@@ -22,22 +22,32 @@ bool skip_propogate(instruction_ref ins) ...@@ -22,22 +22,32 @@ bool skip_propogate(instruction_ref ins)
void propagate_constant::apply(program& p) const void propagate_constant::apply(program& p) const
{ {
fix([&](auto self, auto ins) { for(auto i : iterator_for(p))
if(not skip_propogate(ins)) {
{ if(i->name() != "@literal")
auto r = ins->eval(); continue;
if(not r.empty()) if(i->outputs().empty())
continue;
fix([&](auto self, auto ins) {
std::unordered_set<instruction_ref> children(ins->outputs().begin(),
ins->outputs().end());
for(auto child : children)
{ {
assert(r.get_shape() == ins->get_shape()); if(skip_propogate(child))
auto l = p.add_literal(r.get_shape(), r.data()); {
p.replace_instruction(ins, l); self(child);
return; continue;
}
auto r = child->eval();
if(not r.empty())
{
assert(r.get_shape() == child->get_shape());
auto l = p.add_literal(r.get_shape(), r.data());
self(p.replace_instruction(child, l));
}
} }
} })(i);
std::unordered_set<instruction_ref> children(ins->inputs().begin(), ins->inputs().end()); }
for(auto child : children)
self(child);
})(std::prev(p.end()));
} }
} // namespace MIGRAPHX_INLINE_NS } // namespace MIGRAPHX_INLINE_NS
......
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