thorin2 icon indicating copy to clipboard operation
thorin2 copied to clipboard

Backend Preparation: Nested Extract Splitting

Open NeuralCoder3 opened this issue 2 years ago • 0 comments

We need a phase that splits nested extracts into basic blocks to move this burden away from the backends. Issue raised in regard to #181

Related code snippet:

// A call to an extract like constructed for conditionals (else,then)#cond (args)
// TODO: we can not rely on the structure of the extract (it might be a nested extract)
for (auto callee_def : ex->tuple()->projs()) {
    // dissect the tuple of lambdas
    auto callee = callee_def->isa_nom<Lam>();
    assert(callee);
    // each callees type should agree with the argument type (should be checked by type checking).
    // Especially, the number of vars should be the number of arguments.
    // TODO: does not hold for complex arguments that are not tuples.
    assert(callee->num_vars() == app->num_args());
    for (size_t i = 0, e = callee->num_vars(); i != e; ++i) {
        // emits the arguments one by one (TODO: handle together like before)
        if (auto arg = emit_unsafe(app->arg(i)); !arg.empty()) {
            auto phi = callee->var(i);
            assert(!match<mem::M>(phi->type()));
            lam2bb_[callee].phis[phi].emplace_back(arg, id(lam, true));
            locals_[phi] = id(phi);
        }
    }
}

instead of emit_unsafe(app->arg()); in the case

auto ex = app->callee()->isa<Extract>(); ex && app->callee_type()->is_basicblock()

The corresponding tests in affine are marked as *.disabled_extract.

NeuralCoder3 avatar Mar 13 '23 12:03 NeuralCoder3