This is an archive of the discontinued LLVM Phabricator instance.

[DirectX] Embed DXIL in LLVM Module
ClosedPublic

Authored by beanz on May 10 2022, 12:59 PM.

Details

Summary

At the end of the codegen pipeline for DXIL we will emit the DXIL into
a global variable in the Module annotated for the "DXIL" section.

This will be used by the MCDXContainerStreamer to emit the DXIL into a
DXContainer DXIL part.

Other parts of the DXContainer will be constructed similarly by
serializing their values into GlobalVariables.

This will allow DXIL to flow into DXContainers through the normal
MCStreamer flow used in the MC layer.

Depends on D122270

Diff Detail

Event Timeline

beanz created this revision.May 10 2022, 12:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2022, 12:59 PM
beanz requested review of this revision.May 10 2022, 12:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2022, 12:59 PM
kuhar added inline comments.May 10 2022, 1:06 PM
llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp
69–70
  1. Are we sure that WriteDXILToFile flushes the stream before returning?
  2. We don't need the assignment, you can do ArrayRef<uint8_t> X(A, B) to run the constructor that takes two pointers/.
  3. Use reinterpret_cast instead of C-style casts.
74

nit: the type if obvious from the RHS, so we can use auto *GV

80

Can you add a brief comment on why we return false? It appears like the module might be modified by one of the function calls above.

kuhar added inline comments.May 10 2022, 1:10 PM
llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp
69–70

There's also arrayRefFromStringRef in StringExtras.h, but I'm not 100% sure if non-const ArrayRef is convertible to const-typed one.

python3kgae added inline comments.May 10 2022, 3:46 PM
llvm/test/CodeGen/DirectX/embed-dxil.ll
1

Could this be an opt test?
Once https://reviews.llvm.org/D124805 is in, we'll have opt work for passes which name started with dxil-.
Maybe we can change the pass name to dxil-embed?

beanz added inline comments.May 10 2022, 5:53 PM
llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp
69–70

raw_string_ostream is unbuffered, so flushing does nothing.

Will address the other feedback in an updated patch.

80

Yea… I should probably just make it return true. I was thinking that the change wasn’t semantically important, but returning true is probably the better approach.

llvm/test/CodeGen/DirectX/embed-dxil.ll
1

Yea, making it an opt test might be better. I also might change the patch to not run the pass as part of the codegen pipeline for asm output because it is less important there. Once I get the MCStreamer and ASMPrinters up this should all come together nicely.

beanz marked 5 inline comments as done.Jun 6 2022, 11:41 AM
beanz updated this revision to Diff 434553.Jun 6 2022, 11:42 AM

Updates based on review feedback.

kuhar accepted this revision.Jun 6 2022, 11:49 AM

LGTM

This revision is now accepted and ready to land.Jun 6 2022, 11:49 AM
This revision was landed with ongoing or failed builds.Jun 6 2022, 1:04 PM
This revision was automatically updated to reflect the committed changes.