Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Control construct and re-engineer closure conversion #138

Draft
wants to merge 201 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
d8b95b0
remove arg_fn_type helper
Hugobros3 Jan 18, 2023
525c972
FnType::ret_param is now the ground truth for returns
Hugobros3 Jan 18, 2023
568fa98
closure conversion: remove some dead code
Hugobros3 Jan 18, 2023
b48a002
remove now-useless inner_order()
Hugobros3 Jan 18, 2023
b03cddc
remove dead dominance frontier analysis
Hugobros3 Jan 18, 2023
34003ad
document what codegen_prepare.cpp does
Hugobros3 Jan 31, 2023
8c4b2f3
get rid of duplicated logic in CondEval, reuse the Rewriter instead
Hugobros3 Jan 31, 2023
d6477a3
importer: do not leak private fields
Hugobros3 Jan 31, 2023
3a7369d
Revert most changes on norecursion branch.
m-kurtenacker Feb 1, 2023
86d187e
Made Rewrite more general
Hugobros3 Feb 1, 2023
a5d9ad7
merge Mangler and Rewriter, yielding big simplifications
Hugobros3 Feb 1, 2023
90dae0d
Importer is now based on Rewriter
Hugobros3 Feb 1, 2023
4074e38
instance filters inside of App
Hugobros3 Feb 2, 2023
c96db06
move the rewriter to its own files
Hugobros3 Feb 2, 2023
662b2bb
implement dead load opt in the importer
Hugobros3 Feb 2, 2023
a4a7220
nuke dead clone_bodies pass
Hugobros3 Feb 2, 2023
a241b3d
moved inlining of single-use conts to importer
Hugobros3 Feb 2, 2023
fed974d
hoist_enters: remove simplifications that the importer handles
Hugobros3 Feb 2, 2023
51590e4
remove execinfo header from world
Hugobros3 Feb 3, 2023
fa53dde
consume Run inside App
Hugobros3 Feb 11, 2023
975dc84
PE: made is_top_level slightly less dodgy
Hugobros3 Feb 11, 2023
35d32c8
mangler: rewrite the arguments when checking for tail-recursion opt
Hugobros3 Feb 11, 2023
87fc04f
PE: use a unique queue instead of the bounded weirdness
Hugobros3 Feb 11, 2023
2cf7a86
PE: temporarily bypass the app-instantiated filter to fix rodent-avx2
Hugobros3 Feb 11, 2023
d452b28
stub/rebuild now use the Rewriter
Hugobros3 Feb 12, 2023
ef2cc3e
working on getting App-PE to work reliably
Hugobros3 Feb 12, 2023
e0383c7
app ctor: try to instanciate filter anytime it is empty
Hugobros3 Feb 13, 2023
4ecb060
turned codegen_prepare into a rewriting pass
Hugobros3 Feb 14, 2023
3f078da
pull eta_conversion into the importer
Hugobros3 Feb 14, 2023
42609cd
use Run for applying eta conversion
Hugobros3 Feb 27, 2023
b2ff214
fix instantiate() being commented out by mistake
Hugobros3 Feb 28, 2023
4817c02
cleanup the cleanup code
Hugobros3 Feb 28, 2023
cb0a16d
initial lift2cff pass
Hugobros3 Mar 2, 2023
0663cb5
Merge branch 'closure_cleanup' into lift2cff
Hugobros3 Mar 2, 2023
c942f32
re-implemented closure conversion as a rewriting pass
Hugobros3 Mar 2, 2023
55d8d04
rewrote Scopes analysis
Hugobros3 Mar 4, 2023
2127ac3
scopes: less broken handling of transitive fvs
Hugobros3 Mar 4, 2023
86b5aed
fix yet more Scope issues
Hugobros3 Mar 5, 2023
774e218
remove vestigial references to exit() from Scope
Hugobros3 Mar 5, 2023
16bc139
ported old graphviz dump code
Hugobros3 Mar 6, 2023
f897543
upgraded verifier
Hugobros3 Mar 6, 2023
c0aaa26
closure conversion: make it even dumber
Hugobros3 Mar 6, 2023
42046db
various hacks to get artic tests to pass
Hugobros3 Mar 6, 2023
03cef07
improved scoping heuristic
Hugobros3 Mar 7, 2023
754b8b7
mess with hoist enters so it doesn't suffer from out-of-date scoping …
Hugobros3 Mar 7, 2023
692b1a0
dot printer: prettyified again
Hugobros3 Mar 7, 2023
f6d5574
scope.cpp: add a fast-path if we only care about top-level-ness
Hugobros3 Mar 8, 2023
4984bb6
move as much as possible out of Continuation::stub
Hugobros3 Mar 8, 2023
356e5aa
move Scope::for_each to ScopeForest, ownership refactor refactor
Hugobros3 Mar 8, 2023
a3abbf2
scopes: diagnose ill-nested scopes
Hugobros3 Mar 8, 2023
a77b638
scope nesting is now analysable
Hugobros3 Mar 8, 2023
16ae4ab
graphviz: now dumps scopes _properly_
Hugobros3 Mar 9, 2023
9d03634
cleaned up scoping code and improved dumping
Hugobros3 Mar 10, 2023
64ce00e
closure conversion sorta works
Hugobros3 Mar 13, 2023
2faef60
fix world memory leaks
Hugobros3 May 7, 2023
06fa962
added an explicit return type
Hugobros3 May 7, 2023
a2b6977
added 'Return' node
Hugobros3 May 10, 2023
214a15e
use return types as ground truth in lift2cff and closure_conversion
Hugobros3 May 11, 2023
0141806
intrinsics don't count as free variables
Hugobros3 May 11, 2023
eb75046
rephrase better the closure conversion approach
Hugobros3 May 11, 2023
535d757
fix some Return issues
Hugobros3 May 11, 2023
9f855cd
fold app(return(foo), ...) into app(foo, ...)
Hugobros3 May 11, 2023
2e94055
fix LLVM codegen to work with Return
Hugobros3 May 11, 2023
e202aac
mangler: handle lifting loops properly
Hugobros3 May 13, 2023
b5d1665
closure conversion: convert absolutely everything
Hugobros3 May 13, 2023
2cc6b80
closure conversion: only apply to things used in non-callee positions
Hugobros3 May 16, 2023
bd75bbe
rewrote lift2cff
Hugobros3 May 16, 2023
61e9717
don't lift top-level continuations
Hugobros3 May 16, 2023
e02166b
lift2cff: eliminate higher-order params
Hugobros3 May 16, 2023
f3c4f13
closure conversion: support creating closures recursively
Hugobros3 May 16, 2023
d08b9ea
c: cleanup some fpga-related code
Hugobros3 May 21, 2023
f7c9374
Return: added continuation() helper
Hugobros3 May 21, 2023
ee33949
rename Return to ReturnPoint
Hugobros3 May 21, 2023
da6a787
fixed C backend for ReturnPoint
Hugobros3 May 21, 2023
30b8a95
added control/join nodes
Hugobros3 May 22, 2023
2e59f93
closure conversion: deal with intrinsics more precisely
Hugobros3 May 22, 2023
6668b3c
rename ret_type helpers
Hugobros3 May 22, 2023
c6e7aac
c backend: use the return_type helpers
Hugobros3 May 22, 2023
46caaad
closure conversion: wrap closure-converted/lifted things passed to in…
Hugobros3 May 22, 2023
f88c889
fix incorrect join point type rebuild fn
Hugobros3 May 22, 2023
f1e855c
c: cleanup, bugfixes
Hugobros3 May 22, 2023
269f8b6
closure conversion seems to work OK now, needs to implement Control...
Hugobros3 May 22, 2023
989a518
added lower_control pass
Hugobros3 May 23, 2023
a5d6a6d
llvm: allow tail-calls
Hugobros3 May 23, 2023
f9afab5
do closure conversion again after lowering control
Hugobros3 May 23, 2023
fbcd98b
c: allow indirect calls
Hugobros3 May 24, 2023
d01f64b
print some scoping info as part of dumping
Hugobros3 May 25, 2023
6849352
c: added support for closures
Hugobros3 May 25, 2023
ef90c81
added a type param to Def::stub
Hugobros3 May 25, 2023
0eb31b2
added some type helpers
Hugobros3 May 25, 2023
4982d2b
fix closure conversion missing transitive free defs
Hugobros3 May 26, 2023
825ca4c
c: emit return buffers
Hugobros3 May 26, 2023
59f2f3b
added pass to turn most return buffers into closures
Hugobros3 May 26, 2023
af6e8d2
nuke old free_defs path
Hugobros3 Jun 12, 2023
a1b11d5
closure conversion: avoid bursting the stack
Hugobros3 Jun 15, 2023
1849f9c
run closure conversion before lowering control
Hugobros3 Jun 15, 2023
c7578e5
mangler: improve documentation
Hugobros3 Jun 16, 2023
dfdbe31
c.cpp: refactor 'calling' code into a function
Hugobros3 Jul 3, 2023
fb49d5d
revised lift2cff
Hugobros3 Jul 3, 2023
db9d767
closure_conv: add the extra param even if no fvs
Hugobros3 Jul 3, 2023
9ad3c61
rewrote closure conversion _again_
Hugobros3 Jul 3, 2023
eaead8d
closure conversion: rebuild bodies correctly
Hugobros3 Jul 3, 2023
6cbd52b
change closure conversion handling to allow for recursion
Hugobros3 Jul 3, 2023
218652b
lower control&recursion before closure conv
Hugobros3 Jul 3, 2023
f1148d5
closure conversion: handle recursion closer to correctly
Hugobros3 Jul 4, 2023
a7b3d3d
closure_conv: don't check the lifted scope
Hugobros3 Jul 6, 2023
773a364
closure_conversion: made yet more robust
Hugobros3 Jul 6, 2023
c78d6b4
scope: added some safeties
Hugobros3 Jul 6, 2023
5bc24f3
emit_c: changed ABI for closures
Hugobros3 Jul 6, 2023
e8e17e2
simplified codegen_prepare
Hugobros3 Jul 7, 2023
3ecced6
Standardised what is considered a 'thin' environment
Hugobros3 Jul 7, 2023
411a2b6
flattened match
Hugobros3 Jul 7, 2023
c3712bd
fix c backend emitting int literal suffixes as part of member names
Hugobros3 Jul 7, 2023
c946df9
c: fix NaN and Inf codegen for c99
Hugobros3 Jul 7, 2023
2467162
closure-conv: check we're not leaking basic blocks...
Hugobros3 Jul 7, 2023
ed25cba
split closure allocated environments in another node
Hugobros3 Jul 7, 2023
ba270f5
closure_conv: allow stealing basic blocks from parent scopes
Hugobros3 Jul 9, 2023
3f30251
added more validation for closures
Hugobros3 Jul 9, 2023
b7cec70
closure-conv: include return points targets in closures
Hugobros3 Jul 10, 2023
b75ca82
aobench builds
Hugobros3 Jul 10, 2023
a3e9d0d
fix some C codegen issues
Hugobros3 Jul 10, 2023
ca0c642
disable hoist_enters (I broke it at some point)
Hugobros3 Jul 10, 2023
321c92b
closure-conv: simplify lifting
Hugobros3 Jul 12, 2023
2b2958f
closure-conv: added more validation
Hugobros3 Jul 12, 2023
db3c4da
closure-conv: also handle returning functions in general
Hugobros3 Jul 12, 2023
68745fa
lower_control: eliminate indirections by PE
Hugobros3 Jul 12, 2023
fb284ce
disable codegen_prepare and add a cleanup pass after lower_control
Hugobros3 Jul 12, 2023
e88612e
LLVM BE: deal with return types better
Hugobros3 Jul 13, 2023
1236be1
deleted broken lift2cff pass
Hugobros3 Jul 13, 2023
13a9baf
added 'static' variant of Control
Hugobros3 Jul 13, 2023
ee82b99
added a pass that classifies control bloks as static or not
Hugobros3 Jul 13, 2023
860f8b5
added multiple modes to closure conversion
Hugobros3 Jul 14, 2023
db6961c
disable classify_control (broken)
Hugobros3 Jul 17, 2023
5ed3591
graphviz-dump: handle control
Hugobros3 Jul 17, 2023
b2f2af2
lift2cff: disallow continuations as additional free variables
Hugobros3 Jul 17, 2023
698a65b
simplify: eliminate unecessary closures
Hugobros3 Jul 17, 2023
6235e45
treat ReturnType values as "thin"
Hugobros3 Jul 17, 2023
9fdfdd6
lift2cff: avoid creating returning functions that aren't top-level
Hugobros3 Jul 17, 2023
11c4043
allow elimination of heap allocations
Hugobros3 Jul 17, 2023
f6c08f3
added more scope diagnosis/debug code
Hugobros3 Jul 19, 2023
c2a904c
prevent a closure from being part of it's own environment
Hugobros3 Jul 19, 2023
7dc9d2b
taught the scheduler to tolerate recursive values
Hugobros3 Jul 19, 2023
dfe2edc
c: allow creating cycles using Heap
Hugobros3 Jul 19, 2023
e5e2e67
c: do not emit recusive closures twice
Hugobros3 Jul 19, 2023
7a4809a
c: avoid capturing a return jmp_buf if not required
Hugobros3 Jul 21, 2023
a1b9b78
c: _correctly_ deal with mutually recursive closures
Hugobros3 Jul 21, 2023
70ba09e
rec_stream: fix double parentheses when dumping primops
Hugobros3 Jul 21, 2023
f295677
CC: fix defs not being cached correctly
Hugobros3 Jul 21, 2023
cc3862f
temporarily disable a problematic assert
Hugobros3 Jul 21, 2023
c9be161
made control join targets captured environments live on the stack
Hugobros3 Jul 21, 2023
5bf6f64
extract helper for return types
Hugobros3 Jul 22, 2023
2b6c603
llvm: be more lenient about ptr/int casts
Hugobros3 Jul 22, 2023
aa3fd96
llvm: implemented physical ReturnType values through setjmp/longjmp
Hugobros3 Jul 22, 2023
4b8b24b
llvm: fixed closure calls
Hugobros3 Jul 22, 2023
19ed12b
llvm: implemented stack cells
Hugobros3 Jul 22, 2023
ea1e8fb
fix buggy setjmp path
Hugobros3 Jul 22, 2023
668a8ae
llvm: avoid using unqualified types for now
Hugobros3 Jul 22, 2023
8e1b55c
llvm: emit tail-calls properly
Hugobros3 Jul 24, 2023
31e6e7b
llvm: fix recursive cell handling
Hugobros3 Jul 24, 2023
873abe1
cleanup: generalise eta-reduction
Hugobros3 Jul 24, 2023
3621673
cleanup: eta-reduction for return sites
Hugobros3 Jul 24, 2023
7ac2790
started work on a nicer, scoped dump
Hugobros3 Jul 24, 2023
9f74dcd
scoped_dump: added rudimentary colour
Hugobros3 Jul 24, 2023
0f1b3fe
scoped_dump: pretty-print app nodes
Hugobros3 Jul 24, 2023
64536c1
dump: don't include cont name in param
Hugobros3 Jul 24, 2023
9dfb829
llvm: implement returning tailcalls
Hugobros3 Jul 24, 2023
1ea41a0
more clever and more correct TCE
Hugobros3 Jul 24, 2023
de3eefc
fix: ReturnPoint consuming Run
Hugobros3 Jul 25, 2023
dbb3130
added scoped_dump header
Hugobros3 Jul 25, 2023
4a1d7a2
added convenience 'dump_scoped' method to World
Hugobros3 Jul 25, 2023
f6d9c2a
made eta-reduction on return pointers more reliable
Hugobros3 Jul 25, 2023
17c5eca
c: deal with tail-calls correctly
Hugobros3 Jul 25, 2023
27ba7fd
lift2cff: avoid duplicating lifted fns
Hugobros3 Jul 25, 2023
cc96b2d
c: nicer whitespace
Hugobros3 Jul 25, 2023
44b6f79
importer: generalised closure simplification
Hugobros3 Jul 25, 2023
1f5b761
cleanup compilation pipeline
Hugobros3 Jul 25, 2023
187a4fd
fix lift_builtins
Hugobros3 Jul 27, 2023
a26ebb8
terser logging
Hugobros3 Jul 27, 2023
4960c90
refactored the LLVM backend to be less continuation-oriented
Hugobros3 Jul 28, 2023
4523b1c
cleanup: keep going after inlining something
Hugobros3 Jul 28, 2023
0dcded8
fixed lift_builtins to work with closures properly
Hugobros3 Jul 28, 2023
4b4964e
lift2cff: handle lifting accelerator bodies too!
Hugobros3 Jul 31, 2023
2298f6c
fix and re-enable flatten_tuples
Hugobros3 Jul 31, 2023
c1cd61d
scoped_dump: added ability to dump to disk
Hugobros3 Jul 31, 2023
00f35a9
cleanup: be more careful to avoid getting stuck
Hugobros3 Jul 31, 2023
cf19851
remove old lift_builtins path and dependencies
Hugobros3 Jul 31, 2023
b983042
lower_control: more general implementation
Hugobros3 Jul 31, 2023
60447e9
LLVM BE: use scopes to determine basic-block-ness
Hugobros3 Jul 31, 2023
568495a
fix some issues when emitting accelerator code
Hugobros3 Jul 31, 2023
f0737ce
CC: handle accelerator environments correctly
Hugobros3 Aug 1, 2023
882cc36
fix regression introduced by last commit
Hugobros3 Aug 1, 2023
802e2ea
LLVM: fix more emission issues
Hugobros3 Aug 3, 2023
080ad8c
scheduler: use the scopes analysis for early()
Hugobros3 Aug 3, 2023
9a7e8e8
CC: wrap non-CC'able continuations in a trampoline closure where needed
Hugobros3 Aug 3, 2023
4c18c2d
LLVM: emit a _little_ bit more debug info
Hugobros3 Aug 3, 2023
fd380a6
fix segfault
Hugobros3 Aug 10, 2023
c143879
overhauled debug output
Hugobros3 Aug 28, 2023
c0b62ed
LLVM: made emit_call return a CallInst or nothing
Hugobros3 Aug 28, 2023
e146dc2
fix CC @llvm handling
Hugobros3 Aug 31, 2023
b004f86
remove old debug_history code
Hugobros3 Aug 31, 2023
fd13061
Made Debug a dumb struct, made Loc optional
Hugobros3 Aug 31, 2023
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
25 changes: 14 additions & 11 deletions src/thorin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ set(THORIN_SOURCES
world.h
analyses/cfg.cpp
analyses/cfg.h
analyses/domfrontier.cpp
analyses/domfrontier.h
analyses/domtree.cpp
analyses/domtree.h
analyses/free_defs.cpp
analyses/free_defs.h
analyses/looptree.cpp
analyses/looptree.h
analyses/schedule.cpp
Expand All @@ -43,15 +39,10 @@ set(THORIN_SOURCES
tables/primtypetable.h
tables/mathoptable.h
transform/cleanup_world.cpp
transform/cleanup_world.h
transform/clone_bodies.cpp
transform/clone_bodies.h
transform/closure_conversion.cpp
transform/closure_conversion.h
transform/codegen_prepare.h
transform/codegen_prepare.cpp
transform/dead_load_opt.cpp
transform/dead_load_opt.h
transform/hoist_enters.cpp
transform/hoist_enters.h
transform/flatten_tuples.cpp
Expand All @@ -60,20 +51,28 @@ set(THORIN_SOURCES
transform/importer.h
transform/inliner.cpp
transform/inliner.h
transform/lift_builtins.cpp
transform/lift_builtins.h
transform/insert_pipeline_continue.cpp
transform/insert_pipeline_continue.h
transform/mangle.cpp
transform/mangle.h
transform/resolve_loads.cpp
transform/resolve_loads.h
transform/partial_evaluation.cpp
transform/partial_evaluation.h
transform/rewrite.cpp
transform/rewrite.h
transform/split_slots.cpp
transform/split_slots.h
transform/hls_channels.cpp
transform/hls_channels.h
transform/hls_kernel_launch.h
transform/hls_kernel_launch.cpp
transform/lower_control.h
transform/lower_control.cpp
transform/lower_return.h
transform/lower_return.cpp
transform/classify_control.h
transform/classify_control.cpp
util/array.h
util/cast.h
util/hash.h
Expand All @@ -87,6 +86,9 @@ set(THORIN_SOURCES
util/symbol.h
util/types.h
util/utility.h
util/graphviz_dump.cpp
util/scoped_dump.h
util/scoped_dump.cpp
)

if(LLVM_FOUND)
Expand All @@ -104,6 +106,7 @@ if(LLVM_FOUND)
be/llvm/runtime.cpp
be/llvm/runtime.h
be/llvm/vectorize.cpp
be/llvm/debug.cpp
)
endif()

Expand Down
4 changes: 1 addition & 3 deletions src/thorin/analyses/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <stack>

#include "thorin/world.h"
#include "thorin/analyses/domfrontier.h"
#include "thorin/analyses/domtree.h"
#include "thorin/analyses/looptree.h"
#include "thorin/analyses/scope.h"
Expand All @@ -30,7 +29,7 @@ Stream& CFNode::stream(Stream& s) const { return s << continuation(); }
CFA::CFA(const Scope& scope)
: scope_(scope)
, entry_(node(scope.entry()))
, exit_ (node(scope.exit() ))
, exit_ (node(scope.entry()->world().end_scope()))
{
std::queue<Continuation*> cfg_queue;
ContinuationSet cfg_done;
Expand Down Expand Up @@ -194,7 +193,6 @@ template<bool forward> const CFNodes& CFG<forward>::preds(const CFNode* n) const
template<bool forward> const CFNodes& CFG<forward>::succs(const CFNode* n) const { assert(n != nullptr); return forward ? n->succs() : n->preds(); }
template<bool forward> const DomTreeBase<forward>& CFG<forward>::domtree() const { return lazy_init(this, domtree_); }
template<bool forward> const LoopTree<forward>& CFG<forward>::looptree() const { return lazy_init(this, looptree_); }
template<bool forward> const DomFrontierBase<forward>& CFG<forward>::domfrontier() const { return lazy_init(this, domfrontier_); }

template class CFG<true>;
template class CFG<false>;
Expand Down
2 changes: 0 additions & 2 deletions src/thorin/analyses/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class CFG {
const CFNode* operator [] (Continuation* continuation) const { return cfa()[continuation]; } ///< Maps from @p l to @p CFNode.
const DomTreeBase<forward>& domtree() const;
const LoopTree<forward>& looptree() const;
const DomFrontierBase<forward>& domfrontier() const;

static size_t index(const CFNode* n) { return forward ? n->f_index_ : n->b_index_; }

Expand All @@ -143,7 +142,6 @@ class CFG {
Map<const CFNode*> rpo_;
mutable std::unique_ptr<const DomTreeBase<forward>> domtree_;
mutable std::unique_ptr<const LoopTree<forward>> looptree_;
mutable std::unique_ptr<const DomFrontierBase<forward>> domfrontier_;
};

//------------------------------------------------------------------------------
Expand Down
25 changes: 0 additions & 25 deletions src/thorin/analyses/domfrontier.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions src/thorin/analyses/domfrontier.h

This file was deleted.

67 changes: 0 additions & 67 deletions src/thorin/analyses/free_defs.cpp

This file was deleted.

15 changes: 0 additions & 15 deletions src/thorin/analyses/free_defs.h

This file was deleted.

Loading