"...targets/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "76f7ae49f71eb0892c0d531a275c371e3ef61e56"
Commit f0a16e67 authored by Paul's avatar Paul
Browse files

Check if eval can run before computing

parent 17bc98d0
......@@ -72,6 +72,8 @@ struct instruction
static void
replace(instruction_ref ins, operation o, const shape& r, std::vector<instruction_ref> args);
bool can_eval() const;
argument eval() const;
void finalize(context& ctx);
......
......@@ -162,22 +162,36 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
old->remove_output(*this);
}
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() const
{
if(op.name() == "@literal")
{
return this->get_literal().get_argument();
}
if(is_context_free(op))
if(is_context_free(op) and this->can_eval())
{
std::vector<argument> args;
for(auto&& arg : this->inputs())
{
argument a = arg->eval();
if(a.empty())
return {};
args.push_back(a);
}
std::transform(this->inputs().begin(), this->inputs().end(), std::back_inserter(args), [](auto arg) {
return arg->eval();
});
return op.compute(result, args);
}
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