AnyDSL / thorin

The Higher-Order Intermediate Representation
https://anydsl.github.io
GNU Lesser General Public License v3.0
151 stars 15 forks source link

LLVM: Make the codegen more value-oriented, generalise jumping code #150

Closed Hugobros3 closed 9 months ago

Hugobros3 commented 9 months ago

This PR refactors the LLVM backend to be a bit simpler when it comes to dealing with calling continuations.

It introduces emit_call which is used to emit any sort of calls: it handles calling basic blocks, functions, closures, bottom/unreachable as well as calling the return parameter of a function.

It's interesting to lift it out as it's own function, different from emit_epilogue, because often we generate an unconditional jump as part of emitting an intrinsic, or a direct-style (returning) call. This simplifies the backend a bit because now there is only one place where LLVM branches are actually emitted.

Furthermore, emitting calls to intrinsics was simplified and now emit_intrinsic* functions all return values, leaving emit_epiloguel the responsibility of calling the next continuation through emit_call.

Testing results

Rodent builds and works, Artic tests all pass, Stincilla builds and passes tests.