Commit 50361163 authored by Paul's avatar Paul
Browse files

Use static replace_argument

parent b1ba0937
......@@ -39,7 +39,7 @@ void eliminate_contiguous::apply(program& p) const
replace(new_args, arg, prev);
if(try_compute_shape(ins->op, new_args))
{
replace_argument(ins, arg, prev);
instruction::replace_argument(ins, arg, prev);
}
}
}
......
......@@ -125,18 +125,17 @@ struct instruction
migraph::erase(output, ins);
}
// internal
void replace(std::vector<instruction_ref> args)
static void backreference(instruction_ref ref)
{
clear_arguments();
arguments = std::move(args);
for(auto&& arg : ref->inputs())
arg->add_output(ref);
}
// internal
void replace_argument(instruction_ref old, instruction_ref new_ins)
static void replace_argument(instruction_ref ins, instruction_ref old, instruction_ref new_ins)
{
std::replace(arguments.begin(), arguments.end(), old, new_ins);
old->remove_output(*this);
ins->replace_argument(old, new_ins);
backreference(ins);
ins->recompute_shape();
}
// internal
......@@ -147,6 +146,20 @@ struct instruction
replace(std::move(args));
}
// internal
void replace(std::vector<instruction_ref> args)
{
clear_arguments();
arguments = std::move(args);
}
// internal
void replace_argument(instruction_ref old, instruction_ref new_ins)
{
std::replace(arguments.begin(), arguments.end(), old, new_ins);
old->remove_output(*this);
}
operation op;
shape result;
std::vector<instruction_ref> output;
......@@ -154,19 +167,6 @@ struct instruction
literal lit;
};
inline void backreference(instruction_ref ref)
{
for(auto&& arg : ref->inputs())
arg->add_output(ref);
}
inline void replace_argument(instruction_ref ins, instruction_ref old, instruction_ref new_ins)
{
ins->replace_argument(old, new_ins);
backreference(ins);
ins->recompute_shape();
}
// TODO: Move to a cpp file
inline shape compute_shape(const operation& op, const std::vector<instruction_ref>& args)
{
......
......@@ -92,7 +92,7 @@ instruction_ref program::insert_instruction(instruction_ref ins,
// TODO: Use move
shape r = compute_shape(op, args);
auto result = impl->instructions.insert(ins, {op, r, std::move(args)});
backreference(result);
instruction::backreference(result);
// assert(result->inputs() == args);
assert(result->valid(begin()));
return result;
......@@ -109,7 +109,7 @@ instruction_ref program::replace_instruction(instruction_ref ins,
shape r = compute_shape(op, args);
ins->replace(op, r, std::move(args));
backreference(ins);
instruction::backreference(ins);
assert(ins->valid(begin()));
return ins;
}
......@@ -129,7 +129,7 @@ instruction_ref program::replace_instruction(instruction_ref ins, instruction_re
// TODO: Check for possible cycles
if(out != rep)
{
replace_argument(out, ins, rep);
instruction::replace_argument(out, ins, rep);
}
assert(out->valid(begin()));
}
......
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