This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Handle structs directly in AMDGPUABIInfo
ClosedPublic

Authored by rivanvx on May 11 2016, 6:47 AM.

Details

Summary

Structs are currently handled as pointer + byval, which makes AMDGPU LLVM backend generate incorrect code when structs are used. This patch changes struct argument to be handled directly and without flattening, which Clover (Mesa 3D Gallium OpenCL state tracker) will be able to handle. Flattening would expand the struct to individual elements and pass each as a separate argument, which Clover can not handle. Furthermore, such expansion does not fit the OpenCL programming model which requires to explicitely specify each argument index, size and memory location.

This patch is a modification of a patch provided by Matt Arsenault.

Diff Detail

Event Timeline

rivanvx updated this revision to Diff 56901.May 11 2016, 6:47 AM
rivanvx retitled this revision from to [CodeGen] Handle structs directly in AMDGPUABIInfo.
rivanvx updated this object.
rivanvx added reviewers: arsenm, tstellarAMD.
rivanvx added a subscriber: cfe-commits.
arsenm edited edge metadata.May 11 2016, 9:21 AM

Needs tests

rivanvx updated this revision to Diff 57023.May 12 2016, 5:42 AM
rivanvx edited edge metadata.

Now with 100% more tests.

Can you add some tests that include arrays, struct within structs and arrays of structs?

Some larger and smaller structs too. I think it would be good if single element structs are replaced with the element type

Also some tests for non-kernel functions. We might want to keep this as byval for calling those

rivanvx updated this revision to Diff 58920.May 29 2016, 3:04 PM

Updated patch. Single element structs are coerced to its element, and there are tests for structs of different sizes, structs of arrays, structs containing structs. Arrays of structs are disallowed by clang in kernels.
Non-kernel functions are not specifically handled, should they be? How to decide?

rivanvx updated this revision to Diff 64417.Jul 18 2016, 4:33 PM

Specifically handle only kernels.

arsenm added inline comments.Jul 19 2016, 11:22 AM
lib/CodeGen/TargetInfo.cpp
6856

No else after return

test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
63

Positive checks are greatly preferred

rivanvx updated this revision to Diff 64920.Jul 21 2016, 10:14 AM
rivanvx marked 2 inline comments as done.

Addressed both concerns.

arsenm accepted this revision.Jul 27 2016, 7:58 PM
arsenm edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jul 27 2016, 7:58 PM
arsenm closed this revision.Aug 22 2016, 12:34 PM

r279463