This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Convert AMDGPUResourceUsageAnalysis to a Module pass
ClosedPublic

Authored by arsenm on Jan 17 2022, 10:20 AM.

Details

Reviewers
rampitec
sebastian-ne
Group Reviewers
Restricted Project
Summary

This is more precise in the face of indirect calls and aliases, still
assuming the call target is defined somewhere in the current module.

This sometimes changes the order the functions are printed, and also
changes the point where context errors are printed relative to
stdout. This also likely has negative consequences for compile time
and memory usage.

Diff Detail

Event Timeline

arsenm created this revision.Jan 17 2022, 10:20 AM
arsenm requested review of this revision.Jan 17 2022, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2022, 10:20 AM
Herald added a subscriber: wdng. · View Herald Transcript

Thanks for doing this.
The code looks good to me, though for some reason the llpc graphics frontend is now missing metadata or crashes when trying to read metadata from the generated elf. I’m still debugging.

I think I found the problem and I’m a little surprised it currently works.
In the llpc pipeline, a module pass (PipelineStateClearer) writes pal metadata into the amdgpu.pal.metadata.msgpack metadata.
This metadata is read by the AMDGPUAsmPrinter, extended as functions are emitted and finally written out in AMDGPUTarget[…]Streamer::finish.

The reading of the metadata happens in AMDGPUAsmPrinter::emitStartOfAsmFile, which is called from AsmPrinter::doInitialization, which in turn is called when the pass manager is initialized.
So, the metadata is read at pass manager initialization, but it’s only written afterwards when running a pass, resulting in missing metadata in the output.

I think I found the problem and I’m a little surprised it currently works.
In the llpc pipeline, a module pass (PipelineStateClearer) writes pal metadata into the amdgpu.pal.metadata.msgpack metadata.
This metadata is read by the AMDGPUAsmPrinter, extended as functions are emitted and finally written out in AMDGPUTarget[…]Streamer::finish.

The reading of the metadata happens in AMDGPUAsmPrinter::emitStartOfAsmFile, which is called from AsmPrinter::doInitialization, which in turn is called when the pass manager is initialized.
So, the metadata is read at pass manager initialization, but it’s only written afterwards when running a pass, resulting in missing metadata in the output.

So what is the takeaway from this? My initial thought is this that metadata is not intended to be used to share information between passes this way. I think we need to get indirect/alias calls working correctly, so should I just push the first patch and wait for you to resolve this issue?

sebastian-ne accepted this revision.Feb 2 2022, 1:13 AM
This revision is now accepted and ready to land.Feb 2 2022, 1:13 AM