This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Handle functions in llvm's global ctors and dtors list
ClosedPublic

Authored by rksharma on Jul 9 2021, 1:40 AM.

Details

Summary

This patch introduces a new code object metadata field, ".kind" which is used to add support for init and fini kernels.

HSAStreamer will use function attributes, "device-init" and "device-fini" to distinguish between init and fini kernels from the regular kernels and will emit metadata with ".kind" set to "init" and "fini" respectively.

To reduce the number of init and fini kernels, the ctors and dtors present in the llvm's global.ctors and global.dtors lists are called from a single init and fini kernel respectively.

Diff Detail

Event Timeline

rksharma created this revision.Jul 9 2021, 1:40 AM
rksharma requested review of this revision.Jul 9 2021, 1:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2021, 1:40 AM
rksharma updated this revision to Diff 357436.Jul 9 2021, 1:46 AM

Fix nit: wrong heading in AMDGPUCtorDtorLowering.cpp

rksharma updated this revision to Diff 357494.Jul 9 2021, 6:18 AM

Append the unified init and fini kernels into the used list.

need a test for the metadata correctly generated in the code object

Why is metadata needed here? I thought constructors/destructors went into a special section

llvm/docs/AMDGPUUsage.rst
3145

kind seems a bit too generic for this

llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
33

Typo Kerel

34

Probably should use llvm.amdgcn prefix and . separators

rksharma updated this revision to Diff 359687.Jul 19 2021, 1:07 AM

Added a metadata test

rksharma marked an inline comment as done.Jul 19 2021, 1:12 AM

Why is metadata needed here? I thought constructors/destructors went into a special section

I think we need ISA level linking for the init and fini section approach to work.

llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
34

With llvm. as a prefix, it starts to treat it as an intrinsic and complaints about it being defined.

yaxunl accepted this revision.Jul 28 2021, 6:05 AM

LGTM. Thanks.

This revision is now accepted and ready to land.Jul 28 2021, 6:05 AM
This revision was landed with ongoing or failed builds.Aug 4 2021, 7:24 AM
This revision was automatically updated to reflect the committed changes.
This revision is now accepted and ready to land.Aug 4 2021, 11:10 AM
rksharma updated this revision to Diff 364691.Aug 5 2021, 9:21 PM

return modified as true when creating new init and fini kernels

rksharma updated this revision to Diff 364697.Aug 5 2021, 10:06 PM

clang-format changes