static void rewrite_jump(Continuation* old_cont, Continuation* new_cont, Rewriter& rewriter) { Array<const Def*> args(old_cont->num_args()); for (size_t i = 0; i< old_cont->num_args(); ++i) args[i] = rewriter.instantiate(old_cont->arg(i)); auto callee = rewriter.instantiate(old_cont->callee()); new_cont->jump(callee, args, old_cont->jump_debug()); }
static void rewrite_def(const Def* def, Rewriter& rewriter) { if (rewriter.old2new.count(def) || def->isa_continuation()) return; for (auto op : def->ops()) rewrite_def(op, rewriter); auto new_type = rewrite_type(def->world(), def->type()); if (new_type != def->type()) { auto primop = def->as<PrimOp>(); Array<const Def*> ops(def->num_ops()); for (size_t i = 0; i < def->num_ops(); ++i) ops[i] = rewriter.instantiate(def->op(i)); rewriter.old2new[primop] = primop->rebuild(ops, new_type); for (auto use : primop->uses()) rewrite_def(use.def(), rewriter); } else { rewriter.instantiate(def); } }