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

Use statepoints to compute stack roots when invoking koreCollect #426

Merged
merged 52 commits into from
Sep 29, 2021

Conversation

dwightguth
Copy link
Collaborator

@dwightguth dwightguth commented Sep 20, 2021

This PR makes use of the LLVM garbage collection API in order to compute the gc roots on the stack when calling koreCollect.

It operates via the following pieces:

  • We extract out "opaque" functions for address space casts and inttoptr and ptrtoint casts, so that the optimizer is not aware of them. This is needed due to limitations in the implementation of garbage collection in LLVM
  • We modify the address space of all the garbage collected pointers in the code generation phase to use address space 1
  • We invoke the RewriteStatepointsForGC llvm pass on every compilation so that we can generate the statepoint calls themselves
  • We create an llvm pass that runs after RewriteStatepointsForGC that emits a global variable that tracks the sort category of every live pointer at every statepoint, so that we know how to relocate it
  • We modify koreAlloc functions so that we have typed versions that return specific types, in order to better track the sort category of gc roots
  • We add code to parse the stack map when the program starts
  • We use libunwind in order to walk the stack and generate a list of all the gc roots during collection
  • We remove the parameters to koreCollect since we do not need them to track roots anymore
  • We switch to using tailcc instead of fastcc so as to simplify tail call optimization

Generating roots from global variables remains the same as before.

This is rather big, so I'd like multiple sets of eyes on it. Note that I have not yet added new calls to koreCollect at the start of other functions in the llvm backend (like apply_rule and side_condition and eval). I decided to do that in a follow up PR since this is already so large.

Ready for review.

@dwightguth dwightguth force-pushed the statepoint2 branch 7 times, most recently from a02befb to c27a46d Compare September 20, 2021 21:27
@dwightguth dwightguth force-pushed the statepoint2 branch 4 times, most recently from 06c6407 to 8f468f6 Compare September 27, 2021 19:31
Dwight Guth added 3 commits September 27, 2021 14:49
This lowered setting is required because nix still uses MacOS SDK 10.12
which has a bug when the binary size is too big
Copy link
Contributor

@Baltoli Baltoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor stylistic issue but otherwise LGTM

lib/llvm/EmitGCLayoutInfo.cpp Outdated Show resolved Hide resolved
Dwight Guth and others added 2 commits September 29, 2021 11:30
Co-authored-by: Bruce Collie <brucecollie82@gmail.com>
@dwightguth dwightguth merged commit 4c6095d into master Sep 29, 2021
@dwightguth dwightguth deleted the statepoint2 branch September 29, 2021 20:53
dwightguth pushed a commit that referenced this pull request Oct 5, 2021
dwightguth pushed a commit that referenced this pull request Oct 5, 2021
dwightguth pushed a commit that referenced this pull request Oct 6, 2021
dwightguth pushed a commit that referenced this pull request Oct 6, 2021
dwightguth pushed a commit that referenced this pull request Oct 13, 2021
dwightguth pushed a commit that referenced this pull request Oct 13, 2021
* add llvm file with opaque function definitions

* add llvm pass

* implement getMangledTypeStr

* introduce references to address space 1

* refactor allocateTerm

* add statepoint gc strategy

* add noreturn to finish_rewriting

* add missing typed alloction functions

* add code to retrieve stack map

* parse stack map when application boots

* remove manual root tracking

* use libunwind to walk stack for roots

* wire up gc in scripts

* use tailcc instead of fastcc

* add gc-leaf-function attribute to tail calls

* fix bug involving match reason functions

* reverse order of relocations in llvm pass

* fixes for llvm 10

* fix llvm pass for llvm 10

* fix bug on mac os

* fix cmake

* use LLVM_VERSION_MAJOR

* fix mac os

* link against libunwind

* fix name mangling issue on mac os

* fix ciscript

* fix linking against libunwind on mac os

* add back missing dependencies on libunwind

* try to fix nix on mac os

* add comments

* add LLVM_LINK variable to cmake

* install opaque.ll in separate directory

* change llvm-kompile script to invoke llvm-link

* make sure opaque functions will actually get inlined

* break long line

* skip constants in stack map

* remove gc-leaf-function attribute from tail calls

* add llvm pass to mark tail calls as gc-leaf-function

* fix gc offsets

* format new files

* fix bug on llvm 10

* fix format

* don't reverse on older llvm

* use slightly lower threshold for iterated optimization on nix

This lowered setting is required because nix still uses MacOS SDK 10.12
which has a bug when the binary size is too big

* fix code review comments

* fix llvm 12

* Fix merge conflict

* Update lib/llvm/EmitGCLayoutInfo.cpp

Co-authored-by: Bruce Collie <brucecollie82@gmail.com>

* Update MarkTailCallsAsGCLeaf.cpp

Co-authored-by: Bruce Collie <brucecollie82@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants