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

Improved backend support #182

Draft
wants to merge 245 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
60070f4
add lit test
christopherhjung Sep 28, 2022
d9199a9
save
christopherhjung Sep 29, 2022
7d07813
start of eta problem solution
NeuralCoder3 Oct 5, 2022
0338d45
ideas for type transformation
NeuralCoder3 Oct 5, 2022
970c2c9
inner autodiff type fix
NeuralCoder3 Oct 6, 2022
4869d56
fixed eta problem
NeuralCoder3 Oct 6, 2022
58b9519
one step towards fixing the infinite loop
NeuralCoder3 Oct 6, 2022
d1568c4
investigation of endless loop
NeuralCoder3 Oct 6, 2022
a330129
start of real tests
NeuralCoder3 Oct 7, 2022
d4ebad4
64 bit width is working
NeuralCoder3 Oct 7, 2022
e903622
save
christopherhjung Oct 9, 2022
75b96b2
Merge remote-tracking branch 'origin/autodiff' into autodiff
christopherhjung Oct 9, 2022
91c15e7
save
christopherhjung Oct 10, 2022
4fd9d09
real ad test
NeuralCoder3 Oct 10, 2022
67192e3
reordered dialects
NeuralCoder3 Oct 10, 2022
f67665b
made filter explicit
NeuralCoder3 Oct 10, 2022
087340f
enzyme test overview
NeuralCoder3 Oct 11, 2022
ed023e7
extracted relevant code
NeuralCoder3 Oct 11, 2022
70850ad
simple brussel test
NeuralCoder3 Oct 12, 2022
ccaf515
initialization
NeuralCoder3 Oct 12, 2022
bf0a218
time meassurement
NeuralCoder3 Oct 12, 2022
372973f
added brusselator functions
NeuralCoder3 Oct 12, 2022
f6ae248
fixed dominance
NeuralCoder3 Oct 12, 2022
5c528c8
more debugging on problem
NeuralCoder3 Oct 12, 2022
abe63c5
more attempts
NeuralCoder3 Oct 12, 2022
4231c0b
tried filters
NeuralCoder3 Oct 13, 2022
affc4e8
Merge branch 'master' into autodiff
NeuralCoder3 Oct 13, 2022
2903c96
localized problem even more
NeuralCoder3 Oct 13, 2022
5e0071b
working state without lamspec
NeuralCoder3 Oct 13, 2022
4849db5
earliest failure point
NeuralCoder3 Oct 13, 2022
c4326c6
bug in thorin
NeuralCoder3 Oct 13, 2022
cdd9f65
stuck at error in line 170
NeuralCoder3 Oct 13, 2022
1deea17
Merge branch 'eta-problem' into autodiff
NeuralCoder3 Oct 13, 2022
55fd344
Merge branch 'ad_real' into autodiff
NeuralCoder3 Oct 13, 2022
661e329
fixed merge/vscode issue
NeuralCoder3 Oct 13, 2022
670270a
new tests with pow deriv
NeuralCoder3 Oct 13, 2022
9a73cc7
refactor
NeuralCoder3 Oct 13, 2022
571a012
adapted tests to filter printing
NeuralCoder3 Oct 14, 2022
bdd9876
disabled LamSpec
NeuralCoder3 Oct 14, 2022
503565b
Merge branch 'master' into autodiff
NeuralCoder3 Oct 14, 2022
cf1c313
moved issues to closure
NeuralCoder3 Oct 14, 2022
84af1a0
removed debug print
NeuralCoder3 Oct 14, 2022
2baff33
Comparison to other functional languages
NeuralCoder3 Oct 17, 2022
53fd9f2
implement higher order scalerize
christopherhjung Oct 17, 2022
c0fd971
grouped evaluation, added thorin timing
NeuralCoder3 Oct 18, 2022
819bf8e
added timing
NeuralCoder3 Oct 18, 2022
392607d
alloca timing
NeuralCoder3 Oct 18, 2022
c78306b
commented out alloca run
NeuralCoder3 Oct 18, 2022
7e2d588
complete alloca
NeuralCoder3 Oct 18, 2022
a99aa96
implement autodiff arr and ptr support
christopherhjung Oct 20, 2022
a35f56c
refactoring
christopherhjung Oct 20, 2022
8566c36
more refactoring
christopherhjung Oct 20, 2022
a0d328c
haskell fully cps
NeuralCoder3 Oct 21, 2022
56274a6
polymorphic
NeuralCoder3 Oct 21, 2022
eaf5c6e
large program tests
NeuralCoder3 Oct 21, 2022
b1772d4
map issue
NeuralCoder3 Oct 21, 2022
e760116
avoid OS dependent ignores
NeuralCoder3 Oct 21, 2022
2054750
removed editor dependent files
NeuralCoder3 Oct 21, 2022
536f8e7
removed temporary files
NeuralCoder3 Oct 21, 2022
ea68622
started to improve comment style
NeuralCoder3 Oct 21, 2022
639b8fd
Merge branch 'master' into autodiff
NeuralCoder3 Oct 21, 2022
e7c681e
fix missing builder
christopherhjung Oct 21, 2022
aff8b00
add DS_Store to gitignore
christopherhjung Oct 21, 2022
d4a4e34
remove DS_Store
christopherhjung Oct 21, 2022
c2b7874
repeat commit e760116
NeuralCoder3 Oct 22, 2022
1c0b82b
Merge branch 'autodiff' into autodiff_ptr (only technically, inspecti…
NeuralCoder3 Oct 24, 2022
ec371b7
Merge branch 'master' into autodiff
NeuralCoder3 Oct 25, 2022
be13f84
top_level flat arguments
NeuralCoder3 Oct 25, 2022
1f9c5f3
reorder memory
NeuralCoder3 Oct 25, 2022
e05a86e
fixed thorin printer errors
NeuralCoder3 Oct 25, 2022
010e724
fixed compilation preventing bugs
NeuralCoder3 Oct 25, 2022
be06774
update
NeuralCoder3 Oct 25, 2022
e1c1f28
Merge branch 'autodiff' into ad_ptr_merge
NeuralCoder3 Oct 25, 2022
e3d0f71
clang format
NeuralCoder3 Oct 25, 2022
15a153e
clang format
NeuralCoder3 Oct 25, 2022
eb6cc63
readded unicodes
NeuralCoder3 Oct 25, 2022
21b58f3
filter print
NeuralCoder3 Oct 25, 2022
4cff7dd
removed unused declaration
NeuralCoder3 Oct 25, 2022
88acd2b
removed superfluous code from tests
NeuralCoder3 Oct 25, 2022
ecdfe71
also for simple_mem
NeuralCoder3 Oct 25, 2022
0719560
corrections
NeuralCoder3 Oct 25, 2022
62c08ae
moved phases, passes
NeuralCoder3 Oct 25, 2022
e15e605
removed duplicate files
NeuralCoder3 Oct 25, 2022
2888aaa
synchronized optimization order
NeuralCoder3 Oct 25, 2022
aed00fc
removed builder
NeuralCoder3 Oct 25, 2022
e94ebf4
update
NeuralCoder3 Oct 25, 2022
d30e495
cleanup
NeuralCoder3 Oct 26, 2022
d50ebe6
removed unused imports
NeuralCoder3 Oct 26, 2022
32635c8
fixed parsing error
NeuralCoder3 Oct 26, 2022
b17aa52
Merge branch 'master' into autodiff
NeuralCoder3 Oct 26, 2022
72e9dd0
readable error message
NeuralCoder3 Oct 26, 2022
cba4f59
fixed real test
NeuralCoder3 Oct 26, 2022
e967893
fixed secondary closure problem with higher order functions (by elmin…
NeuralCoder3 Oct 26, 2022
35be7ad
added optional filter annotation to expected output
NeuralCoder3 Oct 26, 2022
2444b29
split pow test in thorin and llvm part
NeuralCoder3 Oct 26, 2022
725f7ad
split toplevel memory operations
NeuralCoder3 Oct 26, 2022
fc15f7d
rewrote argument preparation
NeuralCoder3 Oct 26, 2022
db758c9
more toplevel updates
NeuralCoder3 Oct 26, 2022
27654d3
thoughts about autodiff_zero
NeuralCoder3 Oct 26, 2022
92fe7a9
update
NeuralCoder3 Oct 26, 2022
b641029
refactor extract
NeuralCoder3 Oct 26, 2022
23e4f1a
alphabetical order
NeuralCoder3 Oct 26, 2022
1b8d949
refactor
NeuralCoder3 Oct 26, 2022
d97bb60
refactor
NeuralCoder3 Oct 26, 2022
4a5c15d
separated memory functions
NeuralCoder3 Oct 27, 2022
aeca3d0
refactor
NeuralCoder3 Oct 28, 2022
f77617c
matrix.transpose differentiation
NeuralCoder3 Oct 28, 2022
100b680
code metric measurements
NeuralCoder3 Oct 31, 2022
169c9ff
visualization
NeuralCoder3 Oct 31, 2022
fd313e5
added impala files
NeuralCoder3 Oct 31, 2022
4dc44ed
Merge branch 'master' into autodiff
NeuralCoder3 Nov 2, 2022
dc22856
Merge branch 'autodiff' of https://github.com/NeuralCoder3/thorin2 in…
NeuralCoder3 Nov 2, 2022
a3daddd
removed get pullback function
NeuralCoder3 Nov 3, 2022
f173c28
Merge branch 'autodiff' into ad_ptr_merge
NeuralCoder3 Nov 3, 2022
9d4c253
more variants to try get it to work
NeuralCoder3 Nov 3, 2022
d89f551
Merge branch 'master' into autodiff
NeuralCoder3 Nov 4, 2022
d9fa330
additional test file
NeuralCoder3 Nov 4, 2022
8551c4f
merged
NeuralCoder3 Nov 4, 2022
0858ecc
working simplified test
NeuralCoder3 Nov 4, 2022
4b9ae49
fixed version 1
NeuralCoder3 Nov 4, 2022
1d0a08f
correctly fixed program
NeuralCoder3 Nov 4, 2022
9f8dae1
fixed (most) tests
NeuralCoder3 Nov 4, 2022
b8cb071
fixed memory test (now working)
NeuralCoder3 Nov 4, 2022
20bbd1f
format
NeuralCoder3 Nov 4, 2022
a455c0b
more informative error message
NeuralCoder3 Nov 4, 2022
0b66fba
Merge branch 'autodiff' into ad_ptr_merge
NeuralCoder3 Nov 4, 2022
66ccd45
fixed some more tests
NeuralCoder3 Nov 4, 2022
7dadddf
partially reverted tuple, app for now
NeuralCoder3 Nov 7, 2022
23f7244
split memory test in two parts to debug code gen in the presence/abse…
NeuralCoder3 Nov 7, 2022
965a811
disabled reshape (fixed 5 additional test cases) for now
NeuralCoder3 Nov 7, 2022
dd569fc
fixed non-memory tests
NeuralCoder3 Nov 7, 2022
c215f17
fixed zero application for now
NeuralCoder3 Nov 8, 2022
5253c78
rebuild correct memory tuple
NeuralCoder3 Nov 8, 2022
1779f61
create pullback for rebuild tuples
NeuralCoder3 Nov 8, 2022
8d00f43
simpler imperative memory test
NeuralCoder3 Nov 8, 2022
4688fca
association of (mostly) correct pullbacks
NeuralCoder3 Nov 8, 2022
393f8f6
found cps2ds error
NeuralCoder3 Nov 8, 2022
9c24614
fixed parser errors
NeuralCoder3 Nov 8, 2022
f86922d
more tests on the cps2ds issue
NeuralCoder3 Nov 9, 2022
428908c
Merge branch 'master' into autodiff
NeuralCoder3 Nov 9, 2022
d7b63e9
Merge branch 'autodiff' of https://github.com/NeuralCoder3/thorin2 in…
NeuralCoder3 Nov 9, 2022
50532e0
Merge branch 'autodiff' into ad_ptr_merge
NeuralCoder3 Nov 10, 2022
939456b
adapted test case
NeuralCoder3 Nov 10, 2022
ea6d984
more debugging
NeuralCoder3 Nov 10, 2022
fdf001c
merge bug test case from ad_ptr_merge branch
NeuralCoder3 Nov 10, 2022
7ad6892
Merge branch 'master' into direct_old_var
NeuralCoder3 Nov 10, 2022
50b3aef
Merge remote-tracking branch 'origin/optimize_phase_extensions' into …
NeuralCoder3 Nov 10, 2022
11e54e3
skeleton for add_mem conversion
NeuralCoder3 Nov 10, 2022
d410eb0
plan
NeuralCoder3 Nov 10, 2022
702d848
add mem
NeuralCoder3 Nov 11, 2022
66e55fb
removed eval
NeuralCoder3 Nov 14, 2022
b41b437
Merge branch 'master' into ad_ptr_merge
NeuralCoder3 Nov 14, 2022
e75ee79
Merge branch 'ad_ptr_merge' into ho_codegen
NeuralCoder3 Nov 14, 2022
94d8918
removed ad
NeuralCoder3 Nov 14, 2022
be2005f
merge ad from master
NeuralCoder3 Nov 14, 2022
b8a0c95
fixed name preservation for tests, small improvements
NeuralCoder3 Nov 15, 2022
734823a
add mem related tests
NeuralCoder3 Nov 15, 2022
28a2095
fixed tests
NeuralCoder3 Nov 15, 2022
480f812
added commands to failing tests
NeuralCoder3 Nov 15, 2022
d8afb79
arg style test
NeuralCoder3 Nov 15, 2022
35c4924
made functions external
NeuralCoder3 Nov 15, 2022
3178a71
tests without extern
NeuralCoder3 Nov 16, 2022
3ca0edc
add reshape flat
NeuralCoder3 Nov 16, 2022
4c292b7
test with preprocessor
NeuralCoder3 Nov 16, 2022
6f08aca
fixed test case lea access
NeuralCoder3 Nov 17, 2022
be1d7e1
fixed oblivious lea reconstruction
NeuralCoder3 Nov 17, 2022
1c46504
fixed more test cases for reshape (divergence)
NeuralCoder3 Nov 17, 2022
226ec64
fixed llvm codegen for conditionals
NeuralCoder3 Nov 17, 2022
81da58b
investigated disabled tests for clos
NeuralCoder3 Nov 17, 2022
005dc1a
moved reshape call to clos
NeuralCoder3 Nov 17, 2022
420984e
more robust testing
NeuralCoder3 Nov 17, 2022
212a498
Merge remote-tracking branch 'upstream/feature/add-mem' into ho_codegen
NeuralCoder3 Nov 18, 2022
1517b90
moved add mem to closure
NeuralCoder3 Nov 18, 2022
d72d448
added complex no mem test case
NeuralCoder3 Nov 18, 2022
5a1603b
Merge remote-tracking branch 'upstream/feature/add-mem' into ho_codegen
NeuralCoder3 Nov 22, 2022
d4094d7
Merge remote-tracking branch 'upstream/feature/add-mem' into ho_codegen
NeuralCoder3 Nov 23, 2022
897388e
Merge remote-tracking branch 'upstream/feature/add-mem' into ho_codegen
NeuralCoder3 Nov 24, 2022
b0aead5
resolved circular dependency
NeuralCoder3 Nov 29, 2022
6fbb8f6
Merge remote-tracking branch 'origin/master' into ho_codegen
NeuralCoder3 Nov 29, 2022
8e540be
merge reshape from ad_ptr_merge
NeuralCoder3 Nov 29, 2022
fdc74c7
handle external functions
NeuralCoder3 Nov 29, 2022
a076278
fixed handling of main function
NeuralCoder3 Nov 29, 2022
2d11419
merge ad_ptr_merge compilation extension
NeuralCoder3 Nov 29, 2022
4e08350
Merge remote-tracking branch 'origin/master' into ho_codegen
NeuralCoder3 Nov 30, 2022
f6fa75a
Merge remote-tracking branch 'origin/master' into test/direct_old_var
NeuralCoder3 Dec 2, 2022
31c8751
fixed tests
NeuralCoder3 Dec 2, 2022
03f8a59
updated test
NeuralCoder3 Dec 2, 2022
794726d
more attempts to fix cps2ds
NeuralCoder3 Dec 5, 2022
87cd669
fixed lambda rewrite
NeuralCoder3 Dec 5, 2022
1792c0a
refactoring
NeuralCoder3 Dec 5, 2022
eeaa8ab
add expected result
NeuralCoder3 Dec 5, 2022
a5b9c7b
re-enable curr nom print
NeuralCoder3 Dec 5, 2022
f88f568
more complex case
NeuralCoder3 Dec 5, 2022
8b3fa6a
removed comment
NeuralCoder3 Dec 5, 2022
cca49e6
rewrite recursively
NeuralCoder3 Dec 5, 2022
eae0fab
rewrite callee first
NeuralCoder3 Dec 5, 2022
668cd96
Merge remote-tracking branch 'origin/default-compilation' into ho_cod…
NeuralCoder3 Dec 5, 2022
87b6356
Merge remote-tracking branch 'origin/direct_fix' into ho_codegen
NeuralCoder3 Dec 6, 2022
fb1ec79
Merge remote-tracking branch 'origin/default-compilation' into ho_cod…
NeuralCoder3 Dec 6, 2022
299da40
only reshape small arrays
NeuralCoder3 Dec 7, 2022
78a8a13
move mem to front (for closure)
NeuralCoder3 Dec 8, 2022
d6f4ae2
Merge branch 'ho_codegen' of https://github.com/NeuralCoder3/thorin2 …
NeuralCoder3 Dec 8, 2022
4733334
merge
NeuralCoder3 Dec 8, 2022
9de0b35
allow for additional backends
NeuralCoder3 Dec 8, 2022
43bbf4d
removed empty function
NeuralCoder3 Dec 8, 2022
6a187f9
start of haskell backend
NeuralCoder3 Dec 8, 2022
4af170b
function shape
NeuralCoder3 Dec 8, 2022
ff2980c
start of haskell emitting
NeuralCoder3 Dec 8, 2022
685d2f1
add mem tests
NeuralCoder3 Dec 9, 2022
fe95409
do not overwrite mem from non-apps
NeuralCoder3 Dec 9, 2022
0add729
some comments
NeuralCoder3 Dec 9, 2022
f528b4b
error reporting script
NeuralCoder3 Dec 9, 2022
5b7d6bb
tuple
NeuralCoder3 Dec 9, 2022
3977590
dumper based emitter
NeuralCoder3 Dec 9, 2022
92c2a2e
switched to OCaml
NeuralCoder3 Dec 12, 2022
f961510
removed comments
NeuralCoder3 Dec 12, 2022
0ce1c6f
example code
NeuralCoder3 Dec 12, 2022
9b1d2f6
todos, fixes
NeuralCoder3 Dec 12, 2022
1fe61ac
syntax highlight
NeuralCoder3 Dec 12, 2022
0e6f52c
correctly negated check
NeuralCoder3 Dec 13, 2022
a3c67d9
Merge branch 'ho_codegen' of https://github.com/NeuralCoder3/thorin2 …
NeuralCoder3 Dec 13, 2022
a5a7595
merge codegen fixes from matrix
NeuralCoder3 Dec 20, 2022
0a96f0f
Merge branch 'ho_codegen' of https://github.com/NeuralCoder3/thorin2 …
NeuralCoder3 Dec 20, 2022
255797e
generalized internal cleanup
NeuralCoder3 Dec 22, 2022
5e2b2ea
more cases, complicated test case
NeuralCoder3 Dec 22, 2022
2d38fe5
emitter phase
NeuralCoder3 Dec 22, 2022
6c0024c
register phase
NeuralCoder3 Dec 23, 2022
f360a89
Merge remote-tracking branch 'origin/ho_codegen' into haskell-backend
NeuralCoder3 Dec 23, 2022
9e05da4
fix merge
NeuralCoder3 Dec 23, 2022
7d6871c
register emitter phase
NeuralCoder3 Dec 23, 2022
42a2431
completed backend (working pow test)
NeuralCoder3 Feb 1, 2023
1d42191
more complex test
NeuralCoder3 Feb 3, 2023
3d48e2a
naming
NeuralCoder3 Feb 3, 2023
b925f8a
thorin opt timing test
NeuralCoder3 Feb 3, 2023
12e1ac2
haskell backend
NeuralCoder3 Feb 3, 2023
06ffc75
timing tests
NeuralCoder3 Feb 3, 2023
4de7655
thorin time
NeuralCoder3 Feb 3, 2023
6a701f7
updated tests
NeuralCoder3 Feb 6, 2023
d34d699
rust timing
NeuralCoder3 Feb 6, 2023
c834870
updated tests
NeuralCoder3 Feb 7, 2023
d5e582f
explanation
NeuralCoder3 Feb 7, 2023
0878018
rust backend
NeuralCoder3 Feb 9, 2023
d940d00
cleanup comments
NeuralCoder3 Feb 9, 2023
8408bd5
static vs dynamic dispatch in rust
NeuralCoder3 Feb 13, 2023
3585006
reversed skeleton of minimal emitter from llvm backend
NeuralCoder3 Feb 16, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*.s
.DS_Store
.cache
build*
build*/
vgcore.*
34 changes: 22 additions & 12 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using namespace thorin;
using namespace std::literals;

enum Backends { Dot, H, LL, Md, Thorin, Num_Backends };
enum Backends { Dot, H, LL, CustBE, Custom, Md, Thorin, Num_Backends };

int main(int argc, char** argv) {
try {
Expand Down Expand Up @@ -48,6 +48,8 @@ int main(int argc, char** argv) {
| lyra::opt(dialect_paths, "path" )["-D"]["--dialect-path" ]("Path to search dialects in.")
| lyra::opt(inc_verbose )["-V"]["--verbose" ]("Verbose mode. Multiple -V options increase the verbosity. The maximum is 4.").cardinality(0, 4)
| lyra::opt(opt, "level" )["-O"]["--optimize" ]("Optimization level (default: 2).")
| lyra::opt(output[CustBE ], "dialect") ["--backend" ]("Sets the backend to use.")
| lyra::opt(output[Custom ], "file" ) ["--output" ]("Output file for the custom backend.")
| lyra::opt(output[Dot ], "file" ) ["--output-dot" ]("Emits the Thorin program as a graph using Graphviz' DOT language.")
| lyra::opt(output[H ], "file" ) ["--output-h" ]("Emits a header file to be used to interface with a dialect in C++.")
| lyra::opt(output[LL ], "file" ) ["--output-ll" ]("Compiles the Thorin program to LLVM.")
Expand Down Expand Up @@ -88,6 +90,7 @@ int main(int argc, char** argv) {
std::array<std::ostream*, Num_Backends> os;
os.fill(nullptr);
for (size_t be = 0; be != Num_Backends; ++be) {
if (be == CustBE) continue;
if (output[be].empty()) continue;
if (output[be] == "-") {
os[be] = &std::cout;
Expand All @@ -98,7 +101,7 @@ int main(int argc, char** argv) {
}

// we always need core and mem, as long as we are not in bootstrap mode..
if (!os[H]) dialect_plugins.insert(dialect_plugins.end(), {"core", "mem", "compile"});
if (!os[H]) dialect_plugins.insert(dialect_plugins.end(), {"core", "mem", "compile", "opt"});

std::vector<Dialect> dialects;
thorin::Backends backends;
Expand Down Expand Up @@ -129,18 +132,16 @@ int main(int argc, char** argv) {
fe::Parser parser(world, input, ifs, dialect_paths, &normalizers, os[Md]);
parser.parse_module();

if (os[H]) parser.bootstrap(*os[H]);

PipelineBuilder builder;
for (const auto& dialect : dialects) dialect.add_passes(builder);

if (os[H]) opt = std::min(opt, 1);
if (os[H]) {
parser.bootstrap(*os[H]);
opt = std::min(opt, 1);
}

// clang-format off
switch (opt) {
case 0: break;
case 1: Phase::run<Cleanup>(world); break;
case 2: optimize(world, passes, builder); break;
case 2: optimize(world, passes, dialects); break;
default: errln("error: illegal optimization level '{}'", opt);
}
// clang-format on
Expand All @@ -149,10 +150,19 @@ int main(int argc, char** argv) {
if (os[Dot]) dot::emit(world, *os[Dot]);

if (os[LL]) {
if (auto it = backends.find("ll"); it != backends.end()) {
it->second(world, *os[LL]);
os[Custom] = os[LL];
output[CustBE] = "ll";
}

if (os[Custom]) {
auto backendId = output[CustBE];
if (auto it = backends.find(backendId); it != backends.end()) {
auto backend = it->second;
// auto backendExtensions = extensions["ll"];
backend(world, *os[Custom]);
//, extensions.contains(backendId) ? (extensions[backendId]) : Extensions{});
} else
errln("error: 'll' emitter not loaded. Try loading 'mem' dialect.");
errln("error: '{}' emitter not loaded.", backendId);
}
} catch (const std::exception& e) {
errln("{}", e.what());
Expand Down
39 changes: 39 additions & 0 deletions dialects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ add_thorin_dialect(clos
clos/pass/rw/clos2sjlj.h
clos/pass/rw/clos_conv_prep.cpp
clos/pass/rw/clos_conv_prep.h
clos/pass/rw/phase_wrapper.h
clos/phase/clos_conv.cpp
clos/phase/clos_conv.h
clos/phase/lower_typed_clos.cpp
clos/phase/lower_typed_clos.h
mem/passes/fp/copy_prop.cpp
mem/passes/rw/reshape.cpp
mem/phases/rw/add_mem.cpp
DEPENDS
mem
affine
Expand All @@ -74,6 +77,8 @@ add_thorin_dialect(compile
compile/normalizers.cpp
compile/passes/debug_print.cpp
compile/passes/debug_print.h
compile/passes/internal_cleanup.cpp
compile/passes/internal_cleanup.h
INSTALL
)

Expand Down Expand Up @@ -110,6 +115,25 @@ add_thorin_dialect(direct
INSTALL
)

add_thorin_dialect(backend
SOURCES
backend/backend.cpp
backend/backend.h
backend/be/ocaml_emit.h
backend/be/ocaml_emit.cpp
backend/be/ocaml_emitter.cpp
backend/be/haskell_emit.h
backend/be/haskell_emit.cpp
backend/be/rust_emit.h
backend/be/rust_emit.cpp
DEPENDS
compile
core
math
mem
INSTALL
)

add_thorin_dialect(math
SOURCES
math/math.cpp
Expand All @@ -131,6 +155,8 @@ add_thorin_dialect(mem
mem/passes/rw/alloc2malloc.h
mem/passes/rw/remem_elim.cpp
mem/passes/rw/remem_elim.h
mem/passes/rw/reshape.cpp
mem/passes/rw/reshape.h
mem/phases/rw/add_mem.cpp
mem/phases/rw/add_mem.h
DEPENDS
Expand All @@ -140,12 +166,25 @@ add_thorin_dialect(mem
INSTALL
)

add_thorin_dialect(opt
SOURCES
opt/opt.cpp
opt/opt.h
opt/normalizers.cpp
DEPENDS
compile
mem
core
INSTALL
)

add_thorin_dialect(refly
SOURCES
refly/refly.h
refly/refly.cpp
refly/passes/remove_perm.h
refly/passes/remove_perm.cpp
refly/passes/debug_dump.h
refly/normalizers.cpp
INSTALL
)
7 changes: 2 additions & 5 deletions dialects/affine/affine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
using namespace thorin;

extern "C" THORIN_EXPORT thorin::DialectInfo thorin_get_dialect_info() {
return {"affine",
[](thorin::PipelineBuilder& builder) {
builder.extend_opt_phase([](thorin::PassMan& man) { man.add<thorin::affine::LowerFor>(); });
},
[](Passes& passes) { register_pass<affine::lower_for_pass, affine::LowerFor>(passes); }, nullptr, nullptr};
return {"affine", [](Passes& passes) { register_pass<affine::lower_for_pass, affine::LowerFor>(passes); }, nullptr,
nullptr};
}
10 changes: 5 additions & 5 deletions dialects/affine/passes/lower_for.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ const Def* LowerFor::rewrite(const Def* def) {

// reduce the body to remove the cn parameter
auto nom_body = body->as_nom<Lam>();
auto new_body = nom_body->stub(w, w.cn(w.sigma()), body->dbg());
new_body->set(nom_body->reduce(w.tuple({iter, acc, yield_lam})));
auto new_body = nom_body->stub(w, w.cn(acc->type()), body->dbg());
new_body->set(nom_body->reduce(w.tuple({iter, new_body->var(), yield_lam})));

// break
auto if_else_cn = w.cn(w.sigma());
auto if_else_cn = w.cn(acc->type());
auto if_else = w.nom_lam(if_else_cn, nullptr);
if_else->app(false, brk, acc);
if_else->app(false, brk, if_else->var());

auto cmp = core::op(core::icmp::ul, iter, end);
for_lam->branch(false, cmp, new_body, if_else, w.tuple());
for_lam->branch(false, cmp, new_body, if_else, acc);
}

DefArray for_args{for_ax->num_args() - 2, [&](size_t i) { return for_ax->arg(i); }};
Expand Down
20 changes: 0 additions & 20 deletions dialects/autodiff/autodiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,8 @@

using namespace thorin;

/// optimization idea:
/// * optimize [100]
/// * perform ad [105]
/// * resolve unsolved zeros (not added) [111]
/// * optimize further, cleanup direct style [115-120] (in direct)
/// * cleanup (zeros, externals) [299]
extern "C" THORIN_EXPORT thorin::DialectInfo thorin_get_dialect_info() {
return {"autodiff",
[](thorin::PipelineBuilder& builder) {
builder.add_opt(110);
builder.extend_opt_phase(105, [](thorin::PassMan& man) { man.add<thorin::autodiff::AutoDiffEval>(); });
builder.extend_opt_phase(111, [](thorin::PassMan& man) {
// in theory only after partial eval (beta, ...)
// but before other simplification
// zero and add need to be close together
man.add<thorin::autodiff::AutoDiffZero>();
});
builder.extend_opt_phase(299, [](PassMan& man) {
man.add<thorin::autodiff::AutoDiffZeroCleanup>();
man.add<thorin::autodiff::AutoDiffExternalCleanup>();
});
},
[](Passes& passes) {
register_pass<autodiff::ad_eval_pass, autodiff::AutoDiffEval>(passes);
register_pass<autodiff::ad_zero_pass, autodiff::AutoDiffZero>(passes);
Expand Down
26 changes: 26 additions & 0 deletions dialects/backend/backend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "dialects/backend/backend.h"

#include <thorin/config.h>
#include <thorin/pass/pass.h>

#include "thorin/dialects.h"

#include "dialects/backend/be/haskell_emit.h"
#include "dialects/backend/be/ocaml_emit.h"
#include "dialects/backend/be/rust_emit.h"

using namespace thorin;

extern "C" THORIN_EXPORT DialectInfo thorin_get_dialect_info() {
return {"backend",
[](Passes& passes) {
register_phase<backend::ocaml_phase, backend::OCamlEmitter>(passes); //, std::cout);
},
[](Backends& backends) {
// backends["ml"] = &backend::ocaml::emit;
backends["ml"] = &backend::ocaml::emit2;
backends["hs"] = &backend::haskell::emit;
backends["rs"] = &backend::rust::emit;
},
nullptr};
}
5 changes: 5 additions & 0 deletions dialects/backend/backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <thorin/world.h>

#include "dialects/backend/autogen.h"
15 changes: 15 additions & 0 deletions dialects/backend/backend.thorin
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// # The backend Dialect {#backend}
///
/// TODO:
///
/// [TOC]
///
/// ## Dependencies
///
.import compile;
///
/// ## Compilation Passes and Phases
///
/// ### Phases
///
.ax %backend.ocaml_phase: %compile.Phase;
Loading