This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] Enforce half type support is present for builtins
ClosedPublic

Authored by jchlanda on Mar 23 2023, 5:33 AM.

Details

Summary

Follow up to https://reviews.llvm.org/D145238 that enforces native half type support is present when using builtins and gives more descriptive error in not.
Tidy up CodeGenFunction::EmitNVPTXBuiltinExpr by moving helper lambdas to dedicated functions (most of helpers already reside in dedicated functions).

Diff Detail

Event Timeline

jchlanda created this revision.Mar 23 2023, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2023, 5:33 AM
jchlanda requested review of this revision.Mar 23 2023, 5:33 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 23 2023, 5:33 AM
tra added inline comments.Mar 23 2023, 10:10 AM
clang/lib/CodeGen/CGBuiltin.cpp
18754

We seem to be checking builtin IDs twice. Once here and then in MakeHalfType where we need to map them to intrinsics.
I think the approach used for atomics above would work better here, too -- just pass appropriate Intrinsic as a parameter to MakeHalfType and remove the switch there.

Another option you may consider is that if the availability is only dependent on PTX or SM version, then we may get by with declaring the builtins as TARGET_BUILTIN with appropriate constraints and let the standard enforcement machinery to handle diags.

jchlanda updated this revision to Diff 508046.Mar 24 2023, 4:33 AM

Remove duplicated switch over builtins.

jchlanda added inline comments.Mar 24 2023, 4:34 AM
clang/lib/CodeGen/CGBuiltin.cpp
18754

I've refactored those switches and passed intrinsic ID to MakeHalfType helper.

tra accepted this revision.Mar 24 2023, 10:28 AM
tra added inline comments.
clang/lib/CodeGen/CGBuiltin.cpp
18313

This is where lambda would have some advantage as we could capture what it needs without having to pass 'this' or 'E' explicitly.
In this case it's not too bad, so I'm fine either way, with a very slight bias towards lambdas. The static functions just don't seem to buy us anything here, IMO.

This revision is now accepted and ready to land.Mar 24 2023, 10:28 AM
jchlanda marked an inline comment as done.Mar 27 2023, 2:37 AM
jchlanda added inline comments.
clang/lib/CodeGen/CGBuiltin.cpp
18313

My reasoning was that it keeps CodeGenFunction::EmitNVPTXBuiltinExpr clean, all that it does now is to dispatch to a correct handler based on the builtin id (with exception of mmas); you are right though, it does it at the price of making the signatures more verbose.

This revision was landed with ongoing or failed builds.Mar 27 2023, 11:48 PM
This revision was automatically updated to reflect the committed changes.