This is an archive of the discontinued LLVM Phabricator instance.

[DirectX backend] Add analysis to collect DXILResources
ClosedPublic

Authored by python3kgae on Oct 4 2022, 1:03 PM.

Details

Summary

Now only DXILTranslateMetadata uses DXILResources, so DXILResourceWrapper is only used by DXILTranslateMetadata.
Once we add lower for createHandle, DXILResourceWrapper will be used in more passes.
Also we can add resource index allocation in DXILResourceWrapper.

Diff Detail

Event Timeline

python3kgae created this revision.Oct 4 2022, 1:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 1:03 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
python3kgae requested review of this revision.Oct 4 2022, 1:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 1:03 PM

Add printer pass for test

python3kgae retitled this revision from [DirectX backend] [NFC] Add analysis to collect DXILResources to [DirectX backend] Add analysis to collect DXILResources.Oct 4 2022, 5:40 PM
beanz added inline comments.Oct 5 2022, 10:55 AM
llvm/lib/Target/DirectX/DXILResource.cpp
230

How difficult would it be go make the printed output here look more like DXC's disassembly output? It would be very convenient if we could use the printer pass to generate the disassembly printing too.

llvm/lib/Target/DirectX/DXILResource.h
57

Maybe rather than print we make these dump functions that default to dbgs(), then we can print them in the debugger.

llvm/lib/Target/DirectX/DXILResourceAnalysis.h
42

This being a pointer is unfortunate. If you change dxil::Resources to not store a reference to the module (which it probably doesn't need), you could add a public collect method and change it to have a constructor that takes the module and a default constructor that doesn't collect the resources.

python3kgae marked 3 inline comments as done.Oct 5 2022, 4:54 PM

Change print format.
Add Resources::collect and dump.

Fix clang-format

beanz added inline comments.Oct 6 2022, 12:22 PM
llvm/lib/Target/DirectX/DXILResource.cpp
70

Instead of a static array if you use a switch statement we don't need the asserts above.

101

Using a switch here makes sense too.

231

"comment" is a lot longer to write than just adding a ; to the front of the lines, and just including it in the string avoids double-calling operator<<

346

here too

llvm/lib/Target/DirectX/DXILResource.h
84
85
115
beanz added inline comments.Oct 6 2022, 1:10 PM
llvm/lib/Target/DirectX/DXILResource.h
165

Include llvm/Support/Compiler.h so that LLVM_DUMP_METHOD is properly defined to make the dump method not stripped in debug builds.

python3kgae marked 8 inline comments as done.

Use switch instead of static array.

beanz accepted this revision.Oct 6 2022, 4:31 PM

A few last really nitpicky whitespace issues. Otherwise looks good.

llvm/lib/Target/DirectX/DXILResource.cpp
345

nit: please add a blank line between functions.

llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp
28

nit: blank line here too

47

nit: blank line here too

llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
31–36

nit: blank lines before and after this function too.

This revision is now accepted and ready to land.Oct 6 2022, 4:31 PM
python3kgae marked 4 inline comments as done.

Add space between functions.

clang-format

This revision was landed with ongoing or failed builds.Oct 6 2022, 7:34 PM
This revision was automatically updated to reflect the committed changes.