Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
7773d52
cherry-picked changes from abandonned PR https://github.com/AnyDSL/th…
Hugobros3 Aug 6, 2025
c106a1f
eat app(return_point(callee), ...)
Hugobros3 Aug 8, 2025
d314273
fold away eta-expanded return points
Hugobros3 Aug 8, 2025
e799afb
fix bad codegen-prepare interaction with ret types
Hugobros3 Aug 8, 2025
cd99b1a
restore eliminate_params functionality
Hugobros3 Aug 8, 2025
b6689c5
refactor how the spir-v backend deals with jumps
Hugobros3 Aug 12, 2025
edfd566
simplify codegen_prepare
Hugobros3 Aug 12, 2025
daf783b
revive 2023 closure conversion rewrite
Hugobros3 Aug 10, 2025
a34b5f8
scoped_dump: deal with nom types properly
Hugobros3 Aug 10, 2025
7830371
dramatically simplify lifting
Hugobros3 Aug 10, 2025
c9c0415
improved closure demoting (lift2cff)
Hugobros3 Aug 10, 2025
605b530
lift: fix interactions with intrinsics, in particular Match
Hugobros3 Aug 10, 2025
d9b2021
emitter: queue all reachable bodied continuations
Hugobros3 Aug 10, 2025
7e7369c
deal more robustly with closure self params
Hugobros3 Aug 12, 2025
db3fb5c
added pass to lower closure environments
Hugobros3 Aug 13, 2025
396b792
demote closures: fix guard
Hugobros3 Aug 13, 2025
9732517
lift: fix bug when environemnt is a single tuple
Hugobros3 Aug 13, 2025
37a6c60
c: fixes wrt closure emission
Hugobros3 Aug 13, 2025
bf7713c
lift: turn return objects into closures so they can be captured properly
Hugobros3 Aug 14, 2025
e1a727c
simplify calls to closures without self params
Hugobros3 Aug 14, 2025
2fa48eb
c: start emitting captured returns
Hugobros3 Aug 14, 2025
17706a6
refactor the C backend to match the spir-v one wrt emit_jump
Hugobros3 Aug 14, 2025
4188559
allow capture_ret to also capture inlined return points
Hugobros3 Aug 14, 2025
a0643d7
warn where setjmp is required
Hugobros3 Aug 14, 2025
95aba44
eta reduction fixes
Hugobros3 Aug 14, 2025
912a7df
generalise demote_closures
Hugobros3 Aug 14, 2025
aabd46c
implemented a scanning analysis before lifting
Hugobros3 Aug 14, 2025
aea689b
tuned cascading CC analysis
Hugobros3 Aug 14, 2025
2a59129
c: fix incorrect BB param names
Hugobros3 Aug 14, 2025
7201cb7
c: fix numerical limits for c99
Hugobros3 Aug 14, 2025
c8df43a
c: emit closure longjmp wrappers
Hugobros3 Aug 14, 2025
c5dd191
hacks for scheduling unreachable blocks
Hugobros3 Aug 14, 2025
c1cef5a
c: fix bad code scheduling when emitting captured returns
Hugobros3 Aug 15, 2025
4a9a6ed
fix match cases being closure converted for no reason
Hugobros3 Aug 15, 2025
4c5865d
lift: allow tail-recursive functions to remain so upon CC
Hugobros3 Aug 15, 2025
0350881
carefully tweaking demote_closures to work correctly
Hugobros3 Aug 15, 2025
34dbd07
make tail-call conversion work at all levels
Hugobros3 Aug 15, 2025
8ee290f
demote_closures: robustly handle inside/outside of closures
Hugobros3 Aug 17, 2025
7c089c4
fix eliminate_params
Hugobros3 Aug 17, 2025
e2b84e3
allow eliminate_tail_rec to create higher-order params before cff
Hugobros3 Aug 17, 2025
1d83791
lift: fix param names being forgotten
Hugobros3 Aug 17, 2025
d65ccef
lift: use a vector of free vars in the analysis results
Hugobros3 Aug 17, 2025
1e31990
lift: eliminate todo queue, recursion is handled
Hugobros3 Aug 17, 2025
cfe9abb
lift: handle accelerator intrinsics again
Hugobros3 Aug 17, 2025
aa2d608
fix runtime calls
Hugobros3 Aug 19, 2025
7e17e89
made smart scheduler cope with unreachable BB cases
Hugobros3 Aug 20, 2025
f9e36ae
limit eta-reduction to only apply to continuations
Hugobros3 Aug 29, 2025
66d37d6
lift: wrap non-convertible continuations in dummy closures
Hugobros3 Aug 29, 2025
bc901c9
scoped_dump: print filters
Hugobros3 Aug 29, 2025
12eb474
Small bugfix in C backend for CUDA target.
m-kurtenacker Sep 3, 2025
d35df4e
fix accelerator signatures when environment is empty
Hugobros3 Sep 25, 2025
a2cf580
fix lifting edge case when accelerator body isn't a closure
Hugobros3 Sep 25, 2025
41c0815
use the Mangler to demote closures
Hugobros3 Sep 25, 2025
b317f42
demote_closures: cleanup
Hugobros3 Sep 25, 2025
2d3cac8
fix spirv regressions
Hugobros3 Sep 25, 2025
76b7def
implement spirv printf
Hugobros3 Sep 26, 2025
d84a460
Fixed small issues in previous commit.
m-kurtenacker Sep 26, 2025
be85ad9
fixes for printf
Hugobros3 Sep 26, 2025
7f2122c
fix bb emission order
Hugobros3 Sep 29, 2025
561adad
runtime: allow passing plain pointers to kernels
Hugobros3 Sep 30, 2025
ceca8da
spirv: fix scheduling issue when emitting workarround cast
Hugobros3 Oct 1, 2025
1b356f0
lift: now flattens accelerator parameters
Hugobros3 Oct 3, 2025
42f8107
llvm: added support for Cell
Hugobros3 Oct 3, 2025
0883309
spirv: fix handling of switches and variant indexes
Hugobros3 Oct 4, 2025
2167af2
get rid of a few problematic asserts
Hugobros3 Oct 4, 2025
013cc05
fix codegen on OpenCL
Hugobros3 Oct 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/thorin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ set(THORIN_SOURCES
transform/codegen_prepare.cpp
transform/dead_load_opt.cpp
transform/dead_load_opt.h
transform/demote_closures.cpp
transform/demote_closures.h
transform/hoist_enters.cpp
transform/hoist_enters.h
transform/flatten_tuples.cpp
Expand All @@ -56,8 +58,12 @@ set(THORIN_SOURCES
transform/importer.h
transform/inliner.cpp
transform/inliner.h
transform/lift.cpp
transform/lift.h
transform/lift_builtins.cpp
transform/lift_builtins.h
transform/lower_closure_env.cpp
transform/lower_closure_env.h
transform/mangle.cpp
transform/mangle.h
transform/resolve_loads.cpp
Expand Down
26 changes: 18 additions & 8 deletions src/thorin/analyses/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ Scheduler::Scheduler(const Scope& s, ScopesForest& forest)
}
};

for (auto n : cfg().reverse_post_order()) {
queue.push(n->continuation());
auto p = done.emplace(n->continuation());
assert_unused(p.second);
}
assert(s.entry()->has_body());
done.emplace(s.entry());
enqueue(s.entry(), 0, s.entry()->body());

while (!queue.empty()) {
auto def = pop(queue);
for (size_t i = 0, e = def->num_ops(); i != e; ++i) {
// all reachable continuations have already been registered above
// NOTE we might still see references to unreachable continuations in the schedule
if (!def->op(i)->isa<Continuation>())
enqueue(def, i, def->op(i));
enqueue(def, i, def->op(i));
}
}

Expand Down Expand Up @@ -77,7 +74,8 @@ Continuation* Scheduler::late(const Def* def) {
} else {
for (auto use : uses(def)) {
auto cont = late(use);
result = result ? domtree().least_common_ancestor(cfg(result), cfg(cont))->continuation() : cont;
result = result ? forest_->least_common_ancestor(result, cont) : cont;
assert(result);
}
}

Expand All @@ -91,6 +89,10 @@ Continuation* Scheduler::smart(const Def* def) {
auto l = cfg(late (def));
auto s = l;

// if the 'early' or 'late' BB in the schedule is statically unreachable, instead emit early
if (!e || !l)
return early(def);

int depth = cfg().looptree()[l]->depth();
for (auto i = l; i != e;) {
auto idom = domtree().idom(i);
Expand All @@ -112,11 +114,19 @@ Continuation* Scheduler::smart(const Def* def) {
return smart_[def] = s->continuation();
}

static void add_scope_to_schedule(Schedule& sched, const Scope& s) {
sched.push_back(s.entry());
for (auto child : s.children_scopes()) {
add_scope_to_schedule(sched, s.forest().get_scope(child));
}
}

Schedule schedule(const Scope& scope) {
// until we have sth better simply use the RPO of the CFG
Schedule result;
for (auto n : scope.f_cfg().reverse_post_order())
result.emplace_back(n->continuation());
//add_scope_to_schedule(result, scope);

return result;
}
Expand Down
23 changes: 23 additions & 0 deletions src/thorin/analyses/scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ ContinuationSet ScopesForest::top_level_scopes() {
return set;
}


std::vector<Continuation*> ScopesForest::parent_scopes_path(Continuation* s) {
std::vector<Continuation*> path;
while (s) {
path.insert(path.begin(), s);
s = get_scope(s).parent_scope();
}
return path;
}

Continuation* ScopesForest::least_common_ancestor(Continuation* a, Continuation* b) {
Scope& sa = get_scope(a);
Scope& sb = get_scope(b);
auto path_a = parent_scopes_path(a);
auto path_b = parent_scopes_path(b);
Continuation* best_ancestor = nullptr;
for (size_t i = 0; i < path_a.size() && i < path_b.size(); i++) {
if (path_b[i] == path_a[i])
best_ancestor = path_a[i];
}
return best_ancestor;
}

template<bool elide_empty>
void ScopesForest::for_each(std::function<void(Scope&)> f) {
for (auto cont : top_level_scopes()) {
Expand Down
3 changes: 3 additions & 0 deletions src/thorin/analyses/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class ScopesForest {

ContinuationSet top_level_scopes();

std::vector<Continuation*> parent_scopes_path(Continuation*);
Continuation* least_common_ancestor(Continuation* a, Continuation* b);

/**
* Transitively visits all @em reachable Scope%s in @p world that do not have free variables.
* We call these Scope%s @em top-level Scope%s.
Expand Down
10 changes: 9 additions & 1 deletion src/thorin/analyses/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ namespace thorin {

// TODO this needs serious rewriting

static bool verify_calls(World& world, ScopesForest&) {
static bool verify_calls(World& world, ScopesForest& forest) {
bool ok = true;
for (auto def : world.defs()) {
if (auto cont = def->isa<Continuation>())
ok &= cont->verify();
if (auto closure = def->isa<Closure>()) {
world.VLOG("verifying closure '{}'", closure);
auto& scope = forest.get_scope(closure->fn());
if (scope.parent_scope()) {
world.ELOG("Closure {} has a non-top level fn: {}", closure, closure->fn());
ok = false;
}
}
}
return ok;
}
Expand Down
Loading