This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Target directive host codegen - rebased
ClosedPublic

Authored by sfantao on Sep 14 2015, 6:53 PM.

Details

Summary

This patch rebases and creates a new revision for http://reviews.llvm.org/D11361 as requested by John.

Here's the adapted original summary (the global captures issue has been fixed in the meantime):

This patch implements the outlining for offloading functions for code annotated with the OpenMP target directive. It uses a temporary naming of the outlined functions that will have to be updated later on once target side codegen and registration of offloading libraries is implemented - the naming needs to be made unique in the produced library.

Unlike other captured regions, target offloading cannot use directly the Capture declaration, as each captured field has to be passed explicitly to the runtime library and associated with potentially different mapping types (to/from/alloc...). A proxy function is used to wrap the default capturing implemented in clang and adapt it to what OpenMP offloading requires.

Thanks!
Samuel

Diff Detail

Event Timeline

sfantao updated this revision to Diff 34774.Sep 14 2015, 6:53 PM
sfantao retitled this revision from to [OpenMP] Target directive host codegen - rebased.
sfantao updated this object.
sfantao added reviewers: ABataev, hfinkel, rjmccall.
sfantao added subscribers: cfe-commits, Hahnfeld.
sfantao updated this revision to Diff 34869.Sep 15 2015, 8:01 PM

Update code to use implicit parameters for the captured variables using GenerateOpenMPCapturedStmtFunction, similarly to what is done to other directives.

UseOnlyReferences boolean was added to GenerateOpenMPCapturedStmtFunction, given that for target regions, all the captures need to be references, VAT sizes included. UseOnlyReferences is set to false by default and only set to true when emitting a target directive.

ABataev added inline comments.Sep 16 2015, 2:21 AM
lib/CodeGen/CGOpenMPRuntime.cpp
3076–3086

Use getTypeSize(CGF, ElementType) instead

3114–3160

Could you use emitOMPIfClause() function instead of this long block?

lib/CodeGen/CGStmtOpenMP.cpp
38

Use MakeAddrLValue(CreateMemTemp(CurField->getType(), "__vla_size_ref"), CurField->getType()) instead.

80–81

Use getContext().getLValueReferenceType(ArgType, /*SpelledAsLValue=*/false);

121–123
if (UseOnlyReferences)
  ArgLVal = CGF.EmitLoadOfReferenceLValue(ArgLVal.getAddress(), FD->getType()->casAs<ReferenceType>());
auto *ExprArg = EmitLoadOfLValue(ArgLVal, SourceLocation()).getScalarVal();
sfantao updated this revision to Diff 34933.Sep 16 2015, 3:31 PM

Minor changes to address Alexey's remarks.

lib/CodeGen/CGOpenMPRuntime.cpp
3076–3086

In some previous review of this patch there was a suggestion to change from getTypeSize(CGF, ElementType)/8 to getTypeSizeInChars(ElementType).getQuantity(). Just double checking if you really want me to revert that.

3114–3160

I don't think I can reuse the current implementation. The reason is that the "else" basic block is always emitted and the "if" basic block needs to have a branch to the "else" basic block, and all these basic blocks are only visible inside emitOMPIfClause(). Basically, the if clause codegen would have to be combined with the testing of the return code of the offloading call.

lib/CodeGen/CGStmtOpenMP.cpp
38

Done!

80–81

Done!

121–123

Done!

sfantao updated this revision to Diff 34936.Sep 16 2015, 3:53 PM

Fix imprecision in previous diff.

sfantao added inline comments.Sep 16 2015, 3:55 PM
lib/CodeGen/CGStmtOpenMP.cpp
121–123

I am actually doing ArgLVal.getType() instead FD->getType(). FD doesn't have a reference type here.

ABataev added inline comments.Sep 17 2015, 12:46 AM
lib/CodeGen/CGOpenMPRuntime.cpp
3076–3086

You were using uint64_t ASTContext::getTypeSize(ElementType), but I'm talking about static llvm::Value *getTypeSize(CGF, ElementType), which is defined in CGOpenMPRuntime.cpp. It does exactly the same thing you're doing in this part of code.

3114–3160

You can emit an empty else block, it will be optimized by backend

lib/CodeGen/CGStmtOpenMP.cpp
121–123

Agree, thanks.

sfantao updated this revision to Diff 35121.Sep 18 2015, 12:08 PM

Update if clause emission for target directive following Alexey's remark.

lib/CodeGen/CGOpenMPRuntime.cpp
3076–3086

Got it! Done!

Just a related question: isn't the loop in getTypeSize() doing the same thing as CGF.getVLASize()? Just wondering if that should be reused in there.

Thanks!

3114–3160

In the new diff I now use a temp variable to keep the error code and try to reuse the if clause current logic. Let me know if this along the lines you want it to be.

ABataev added inline comments.Sep 23 2015, 9:41 PM
lib/CodeGen/CGOpenMPRuntime.cpp
3076–3086

Not quite. getVLASize() works only for VLA types, while getTypeSize() works for types with constant size too.

3082

Turn this to LValue like CGF.MakeAddrLValue(CGF.CreateMemTemp(OffloadErrorQType, ".run_host_version"), OffloadErrorQType); and use this Lvalue rather than Address.

3087–3089

Pointers, Sizes, MapTypes must be captured by reference.

3230–3236

Move this to 'then' branch of the next if-stmt.

sfantao updated this revision to Diff 36317.Oct 1 2015, 3:46 PM

Address Alexey's remarks from last review.

lib/CodeGen/CGOpenMPRuntime.cpp
3076–3086

Oh, sure. Done!

3082

Done!

3087–3089

Oh, sure. Done!

3230–3236

Ok, done.

ABataev accepted this revision.Oct 1 2015, 10:17 PM
ABataev edited edge metadata.
This revision is now accepted and ready to land.Oct 1 2015, 10:17 PM
sfantao closed this revision.Oct 2 2015, 9:16 AM

Committed in r249148!

Thanks,
Samuel