This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP][Lower] Program level implicit SAVE variable handling for declare target
ClosedPublic

Authored by agozillon on Jun 2 2023, 2:48 PM.

Details

Summary

This is an attempt at mimicing the method in which
threadprivate handles the following type of variables:

program main
  integer :: i
  !$omp declare target to(i)
end

Which essentially generates a GlobalOp for the variable (which
would normally only be an alloca) when it's instantiated. The
main difference is there is no operation generated within the
function, instead the declare target attribute is appended
later within handleDeclareTarget.

Diff Detail

Event Timeline

agozillon created this revision.Jun 2 2023, 2:48 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
agozillon requested review of this revision.Jun 2 2023, 2:48 PM
agozillon updated this revision to Diff 527999.Jun 2 2023, 2:51 PM
  • missing newline as always, sorry for the spam.

Will need to rebase this when https://reviews.llvm.org/D150329 is landed to get it to pass CI, I tried to do some arcanist trickery to base it on that patch, but alas it didn't work.

This is one method of handling the implicit SAVE attributes that is similar to what threadprivate currently does (it also does some other fun edge cases too, but I don't believe they're needed for declare target, at least at the moment), I believe it should be viable to generate working LLVM-IR from this, but it is possible it may need further tweaking after the fact as this isn't a case I've currently had the chance to look into (and I've just begun to look into the mapping now that we have our initial test off the ground).

agozillon updated this revision to Diff 528386.Jun 5 2023, 5:49 AM

Rebase on upstream now that dependent patch has been commited, this will hopefully satisfiy CI

The rebase seems to have fixed the buildbot failure. If someone could please give this a look over to see if following threadprivate's approach is a reasonable direction for fixing this issue with declare target, thank you very much

A small ping on this for some reviewer attention if at all possible please.

flang/lib/Lower/OpenMP.cpp
2741–2768

Can this code be shared with the threadprivate usage?

agozillon updated this revision to Diff 539538.Jul 12 2023, 6:33 AM
  • Share declare target behaviour with current Firstprivate function
agozillon marked an inline comment as done.Jul 12 2023, 6:43 AM
agozillon added inline comments.
flang/lib/Lower/OpenMP.cpp
2741–2768

Done, we only use a little segment of the behavior of the function (perhaps more later if there's other issues that the function fixes that declare target needs) but it's shareable!

I was hoping you will factor the common portion into a separate function and call that function from both threadprivate and declare target. Could you give that and try and if it is not possible you can revert to the previous version that duplicated code and submit it since it is more readable.

LG.

This revision is now accepted and ready to land.Jul 12 2023, 8:33 AM
agozillon marked an inline comment as done.Jul 12 2023, 8:41 AM

I was hoping you will factor the common portion into a separate function and call that function from both threadprivate and declare target. Could you give that and try and if it is not possible you can revert to the previous version that duplicated code and submit it since it is more readable.

LG.

Sure, that shouldn't be a problem I imagine, the separated function would still have to be called from Bridge.cpp for declare target and then internally inside of genThreadprivateOp for threadprivate.

  • Revert "Share declare target behaviour with current Firstprivate function"
  • Tidy code try two

Made an attempt at tidying it up again as requested.

I'll upstream this tomorrow as it's a little late in the day here for me to risk angering the buildbots and I'd like to give the patch CI a chance to pass! So if you do get some time please do skim over the changes to see if they're what you were hoping for.