This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] clang codeGen for HLSLShaderAttr.
ClosedPublic

Authored by python3kgae on May 2 2022, 12:15 AM.

Details

Summary

Translate HLSLShaderAttr to IR level.

  1. Skip mangle for hlsl entry functions.
  2. Add function attribute for hlsl entry functions.

Diff Detail

Event Timeline

python3kgae created this revision.May 2 2022, 12:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2022, 12:15 AM
python3kgae requested review of this revision.May 2 2022, 12:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2022, 12:15 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Anastasia added inline comments.May 24 2022, 5:51 AM
clang/lib/AST/Mangle.cpp
138 ↗(On Diff #426341)

Does HLSL shader entry inherits the same behavior as C-linkage functions (extern C) e.g. they can't be overloaded, templated, etc? If that's the case it might be easier to add C-linkage to it during parsing and then you can inherit the rest of logic including excluding it from mangling... This is how we implement kernel function handling in clang for OpenCL.

python3kgae added inline comments.May 24 2022, 10:36 AM
clang/lib/AST/Mangle.cpp
138 ↗(On Diff #426341)

Yes. It is like kernel for OpenCL.
I'll change to extern C.

Treat entry functions as in extern C scope.

Anastasia added inline comments.May 26 2022, 11:09 AM
clang/lib/CodeGen/CGHLSLRuntime.cpp
54

I don't think you need clang::CodeGen::?

clang/lib/CodeGen/CGHLSLRuntime.h
39

typo: setHLSLFnuctionAttributes -> setHLSLFunctionAttributes

clang/lib/CodeGen/CodeGenModule.cpp
1654 ↗(On Diff #431812)

I think all attributes are expected to be added in ConstructAttributeList.

Anastasia added inline comments.May 26 2022, 11:12 AM
clang/test/CodeGenHLSL/entry.hlsl
2

Is this test here accidental?

clang/test/CodeGenHLSL/shader_type_attr.hlsl
4

I struggle understand the difference in this test? Can it be merged with the above?

python3kgae marked 3 inline comments as done.May 26 2022, 2:49 PM
python3kgae added inline comments.
clang/test/CodeGenHLSL/entry.hlsl
2

This test is to make sure generate "dx.shader" attribute on entry function which set by -E option.

clang/test/CodeGenHLSL/shader_type_attr.hlsl
4

The difference between these 2 tests is entry.hlsl test for entry which does not have shader attribute on foo while shader_type_attr.hlsl test for entry in a library which has shader attribute (the [shader("compute")]).

Move addHLSLFunctionAttributes to ConstructAttributeList.

Anastasia added inline comments.May 30 2022, 7:39 AM
clang/lib/CodeGen/CGCall.cpp
2606

I think TargetDecl can't be nullptr at this point due to the above check? So perhaps using dyn_cast is better here?

clang/lib/CodeGen/CGHLSLRuntime.cpp
55

This parameter seems to be unused?

clang/test/CodeGenHLSL/shader_type_attr.hlsl
4

Ok, I see although in this patch you only add support for generating the attribute in IR so the logic for handling -E or input attribute is I assume elsewhere and it is tested separately?

But the tests are small so no big concerns to keep both either.

python3kgae marked an inline comment as done.

Code cleanup to match comments.

Anastasia accepted this revision.Jun 1 2022, 8:25 AM

LGTM! Thanks

This revision is now accepted and ready to land.Jun 1 2022, 8:25 AM

Rebase to upstream.

Add -fcgl to make test work without DirectX backend.

This revision was automatically updated to reflect the committed changes.