Skip to content

Commit

Permalink
temporarily add fix from AnyDSL#187
Browse files Browse the repository at this point in the history
  • Loading branch information
NeuralCoder3 committed Mar 15, 2023
1 parent 350c340 commit e163d31
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions dialects/core/be/ll/ll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ std::string Emitter::convert(const Def* type) {

std::string Emitter::convert_ret_pi(const Pi* pi) {
auto dom = mem::strip_mem_ty(pi->dom());
if (dom == world().sigma()) { return "void"; }
if (dom == world().sigma()) return "void";
return convert(dom);
}

Expand Down Expand Up @@ -261,9 +261,8 @@ void Emitter::finalize(const Scope& scope) {
print(func_impls_, "{}:\n", lam->unique_name());

++tab;
for (const auto& part : bb.parts) {
for (const auto& part : bb.parts)
for (const auto& line : part) tab.print(func_impls_, "{}\n", line.str());
}
--tab;
func_impls_ << std::endl;
}
Expand Down Expand Up @@ -305,7 +304,27 @@ void Emitter::emit_epilogue(Lam* lam) {
}
}
} else if (auto ex = app->callee()->isa<Extract>(); ex && app->callee_type()->is_basicblock()) {
emit_unsafe(app->arg());
// emit_unsafe(app->arg());
// 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);
}
}
}

auto c = emit(ex->index());
if (ex->tuple()->num_projs() == 2) {
Expand Down Expand Up @@ -344,9 +363,8 @@ void Emitter::emit_epilogue(Lam* lam) {

std::vector<std::string> args;
auto app_args = app->args();
for (auto arg : app_args.skip_back()) {
for (auto arg : app_args.skip_back())
if (auto v_arg = emit_unsafe(arg); !v_arg.empty()) args.emplace_back(convert(arg->type()) + " " + v_arg);
}

if (app->args().back()->isa<Bot>()) {
// TODO: Perhaps it'd be better to simply η-wrap this prior to the BE...
Expand Down

0 comments on commit e163d31

Please sign in to comment.