Add a pass for inserting safepoints into (nearly) arbitrary IR


Add a pass for inserting safepoints into (nearly) arbitrary IR

This pass is responsible for figuring out where to place call safepoints and safepoint polls. It doesn't actually make the relocations explicit; that's the job of the RewriteStatepointsForGC pass (

Note that this code is not yet finalized. Its moving in tree for incremental development, but further cleanup is needed and will happen over the next few days. It is not yet part of the standard pass order.

Planned changes in the near future:

  • I plan on restructuring the statepoint rewrite to use the functions add to the IRBuilder a while back.
  • In the current pass, the function "gc.safepoint_poll" is treated specially but is not an intrinsic. I plan to make identifying the poll function a property of the GCStrategy at some point in the near future.
  • As follow on patches, I will be separating a collection of test cases we have out of tree and submitting them upstream.
  • It's not explicit in the code, but these two patches are introducing a new state for a statepoint which looks a lot like a patchpoint. There's no a transient form which doesn't yet have the relocations explicitly represented, but does prevent reordering of memory operations. Once this is in, I need to update actually make this explicit by reserving the 'unused' argument of the statepoint as a flag, updating the docs, and making the code explicitly check for such a thing. This wasn't really planned, but once I split the two passes - which was done for other reasons - the intermediate state fell out. Just reminds us once again that we need to merge statepoints and patchpoints at some point in the not that distant future.

Future directions planned:

  • Identifying more cases where a backedge safepoint isn't required to ensure timely execution of a safepoint poll.
  • Tweaking the insertion process to generate easier to optimize IR. (For example, investigating making SplitBackedge) the default.
  • Adding opt-in flags for a GCStrategy to use this pass. Once done, add this pass to the actual pass ordering.

Differential Revision: