This is an archive of the discontinued LLVM Phabricator instance.

[DirectX backend] Add pass to emit dxil metadata.
ClosedPublic

Authored by python3kgae on May 7 2022, 12:32 AM.

Details

Summary

A new pass DxilEmitMetadata is added to translate information saved in llvm ir into metadata to match DXIL spec.

Only generate DXIL validator version in this PR.

In llvm ir, validator version is saved in ModuleFlag with "dx.valver" as Key.

!llvm.module.flags = !{!0, !1}
!1 = !{i32 6, !"dx.valver", !2}
!2 = !{i32 1, i32 1}

DXIL validator version has major and minor versions that are specified as named metadata:

!dx.valver = !{!2}
!2 = !{i32 1, i32 7}

Diff Detail

Event Timeline

python3kgae created this revision.May 7 2022, 12:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2022, 12:32 AM
python3kgae requested review of this revision.May 7 2022, 12:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2022, 12:32 AM
python3kgae added inline comments.
llvm/test/CodeGen/DirectX/dxil_ver.ll
2

Will change to opt test once the parent PR is in.

kuhar added inline comments.May 8 2022, 7:47 PM
llvm/lib/Target/DirectX/DxilEmitMetadata.cpp
24 ↗(On Diff #427823)

Could you space things out more? I'd expect one empty line after each function.

28 ↗(On Diff #427823)

use StringLiteral

29 ↗(On Diff #427823)

nit: we can use contexpr

llvm/test/CodeGen/DirectX/dxil_ver.ll
15

nit: can you add an empty line at the of the file?

nikic resigned from this revision.May 9 2022, 4:30 AM
beanz added a comment.May 9 2022, 7:51 AM

Two super nitpick points off the top:
(1) Please be consistent that DXIL is all capitalized. I'd like LLVM to not have the annoyance issues that DXC's codebase has where DXIL is inconsistently capitalized.
(2) Can we instead name the pass "DXILTranslateMetadata"? The pass doesn't actually emit the metadata, it is translating it from one form in the module to another.

llvm/lib/Target/DirectX/DxilEmitMetadata.cpp
23 ↗(On Diff #427823)

File-scoped functions should be static:

https://www.llvm.org/docs/CodingStandards.html#anonymous-namespaces

Also, your function says it is converting to a 32-bit unsigned integer, but the return type is unsigned (which is usually but not guaranteed to be 32-bits), use uint32_t instead.

nit: Uint32->UInt32 (unsigned int is two words not one)

31 ↗(On Diff #427823)

Stylistically, I don't love declaring these constants. They're not used in a bunch of places and I feel like version tuples are well enough understood that we should be able to intuit the format.

That said, you don't need to change it.

92 ↗(On Diff #427823)

This is unused and does nothing. Should it be here?

python3kgae marked 7 inline comments as done.

Update based on comments.

kuhar accepted this revision.May 9 2022, 10:25 AM

LGTM but please get another one before submitting.

llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
64

You can open this namespace higher up so that you don't need to annotate each function with static

This revision is now accepted and ready to land.May 9 2022, 10:25 AM
beanz accepted this revision.May 10 2022, 9:45 AM

LGTM.

llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
64

not to nitpick, but that comment contradicts the coding standards, and is the opposite of the feedback I provided :)

see: https://www.llvm.org/docs/CodingStandards.html#anonymous-namespaces

kuhar added inline comments.May 10 2022, 9:51 AM
llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
64

TIL, I thought that the guideline was the inverse. Thanks, @beanz.

beanz added inline comments.May 10 2022, 10:24 AM
llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
64

I literally made the same mistake like two weeks ago (hence having the link handy) 😄

Rebase to fix merge conflict.

Fix merge error.

Resolve merge conflict.

This revision was landed with ongoing or failed builds.May 11 2022, 8:40 AM
This revision was automatically updated to reflect the committed changes.