This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Add missing address spaces in IR generation of Blocks
ClosedPublic

Authored by Anastasia on Jan 17 2017, 10:17 AM.

Details

Reviewers
yaxunl
Summary

ObjC IR generation for Blocks currently:
I. Generates local to block variable declaration block literal in case it contains captures.
II. Global variable block literal in case it doesn't have any captures.

The address spaces are missing however if we use this generation for OpenCL.

This patch:

  • keeps default private address space for blocks generated as local variables (case I from above);
  • adds global address space for global block literals (case II from the above);
  • makes the block invoke function and enqueue_kernel prototype with the generic AS block pointer parameter to accommodate both private and global AS cases.
  • adds block handling into default AS because it's implemented as a special pointer type (BlockPointer) in the frontend and therefore it is used as a pointer everywhere. This is also needed to accommodate both private and global address space blocks for the two cases described above.
  • removes ObjC RT specific symbols (NSConcreteStackBlock and NSConcreteGlobalBlock) in the OpenCL mode.

Diff Detail

Event Timeline

Anastasia created this revision.Jan 17 2017, 10:17 AM

Ping! @yaxunl, Sam do you think you will have time to look into this?

yaxunl added inline comments.Jan 23 2017, 10:27 AM
lib/CodeGen/CGBlocks.cpp
723

should use CGM.getNullPointer to create a null pointer.

1126

should use CGM.getNullPointer to create a null pointer.

Anastasia updated this revision to Diff 85753.Jan 25 2017, 7:34 AM

Switched to getNullPointer helper.

Anastasia marked 2 inline comments as done.Jan 25 2017, 7:34 AM
Anastasia added inline comments.Jan 25 2017, 7:42 AM
lib/CodeGen/CGBlocks.cpp
723

Btw, does it mean we can no longer use generic llvm::Constant::getNullValue helper for PointerTypes? This feels wrong! Is it possible to extend the helper?

Also I find it a bit counter intuitive to use getNullPointer with the second argument QualType for the case like this where we don't have an actual AST type. Why is it needed? Some documentation might be helpful here. :) Could we extend this helper to use default second argument or an overload with one argument only.

yaxunl added inline comments.Jan 25 2017, 7:50 AM
lib/CodeGen/CGBlocks.cpp
726

The QualType needs to be the real QualType corresponding to the LLVM type, otherwise it won't work on targets with non-zero null pointer.

1129

same issue as above.

test/CodeGenOpenCL/cl20-device-side-enqueue.cl
3

Can we add a run line for triple amdgcn-amd-amdhsa-opencl to make sure the null pointer is generated correctly?

yaxunl added inline comments.Jan 25 2017, 8:01 AM
lib/CodeGen/CGBlocks.cpp
723

The LLVM type may not have sufficient information, so in general situation QualType is needed. The comment before getNullPointer declaration explains the meaning of the parameters:

/// Get target specific null pointer.
/// \param T is the LLVM type of the null pointer.
/// \param QT is the clang QualType of the null pointer.
/// \return ConstantPointerNull with the given type \p T.
/// Each target can override it to return its own desired constant value.
virtual llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
    llvm::PointerType *T, QualType QT) const;
Anastasia updated this revision to Diff 85888.Jan 26 2017, 5:12 AM

Updated NULL ptr generation and added separate CodeGen test for checking amended Block generation behaviour in OpenCL!

Anastasia marked 2 inline comments as done.Jan 26 2017, 5:13 AM
Anastasia added inline comments.
test/CodeGenOpenCL/cl20-device-side-enqueue.cl
3

I added a new test (above). This one gets too complicated!

yaxunl accepted this revision.Jan 26 2017, 7:02 AM

LGTM. Thanks!

This revision is now accepted and ready to land.Jan 26 2017, 7:02 AM
Anastasia closed this revision.Feb 7 2017, 5:57 AM
Anastasia marked an inline comment as done.

Committed in r 293286