This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Support custom format of stack maps
ClosedPublic

Authored by cherry on Oct 30 2018, 1:36 PM.

Details

Summary

Add a hook to the GCMetadataPrinter for emitting stack maps in
custom format. The hook will be called at stack map generation
time. The default stack map format is used if there is no hook.

For this to be useful a few data structures and accessors are
exposed from the StackMaps class, so the custom printer can
access the stack map data.

Diff Detail

Repository
rL LLVM

Event Timeline

cherry created this revision.Oct 30 2018, 1:36 PM
apilipenko added inline comments.
include/llvm/CodeGen/StackMaps.h
267–281 ↗(On Diff #171779)

The code move part of this change can be landed separately without further review so as to reduce the size of this diff.

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3005–3007 ↗(On Diff #171779)

I'm not sure that early termination is the right thing to do. There might be more than one GC strategy in use in the current module, and all of them might want to emit stack maps.

cherry marked an inline comment as done.Nov 7 2018, 1:59 PM

Thanks for the review!

include/llvm/CodeGen/StackMaps.h
267–281 ↗(On Diff #171779)
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3005–3007 ↗(On Diff #171779)

In theory there could be more than one GC strategies, although I couldn't see how it can be used.

What about changing it to running all the GCMetadataPrinters, then return if any of the emitStackMaps returns true?

cherry updated this revision to Diff 173025.Nov 7 2018, 2:01 PM
cherry marked an inline comment as done.
cherry added a reviewer: apilipenko.
cherry marked an inline comment as not done.
reames added a subscriber: reames.Nov 9 2018, 4:35 PM

A few drive by comments for the moment.

include/llvm/CodeGen/GCMetadataPrinter.h
68 ↗(On Diff #173025)

This new call is arguably duplicating the existing finishModule callback. It'd be nice to find a way to merge the two honestly.

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3005–3007 ↗(On Diff #171779)

The structure of the existing code is that a single model can contain functions compiled with two different gc strategies. I agree it's a bit odd, but it should continue to work.

I'd also like to move towards being able to emit *multiple* formats for a single GC. (Primarily for testing purposes.) That can be out of scope for your change if you desire.

apilipenko added inline comments.Nov 12 2018, 3:32 PM
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3005–3007 ↗(On Diff #171779)

You can make the value returned from emitStackMaps indicate whether the default stackmap is needed. You would print the default format (SM.serializeToStackMapSection ) if at least one of the MPs requested default format serialization.

If a strategy doesn't have a MP than by default it requests default serialization printing.

cherry updated this revision to Diff 174861.Nov 20 2018, 6:31 PM
cherry set the repository for this revision to rL LLVM.
cherry added inline comments.
include/llvm/CodeGen/GCMetadataPrinter.h
68 ↗(On Diff #173025)

I agree that this would be nice. However, given the signature of finishAssembly, assuming we don't want to change that, there are some problems:

  • we need to pass a StackMaps object. One possibility is to link it to the GCModuleInfo object.
  • finishAssembly doesn't return anything, but we need a return value to decide whether to use the default format.

Any idea of how to solve these?

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3005–3007 ↗(On Diff #171779)

Done as @apilipenko suggested.

For emitting multiple formats, the hook GCMetadataPrinter::emitStackMaps itself can do it. It can also call SM.serializeToStackMapSection to emit the default format (along with a custom format).

reames accepted this revision.Nov 25 2018, 7:06 PM

LGTM

We can continue the discussion around finalizeModule and emitStackMaps separately. It's definitely not a blocker for this patch.

include/llvm/CodeGen/GCMetadataPrinter.h
68 ↗(On Diff #173025)

In case my tone was unclear, this was not a must fix. It was a please think about it, and share any ideas you might have. If we can't find the right abstraction, I'm fine with this landing with the new API.

This revision is now accepted and ready to land.Nov 25 2018, 7:06 PM
This revision was automatically updated to reflect the committed changes.

Thank you for the review!