This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Add hlfir.copy_in and hlfir.copy_out operations
ClosedPublic

Authored by jeanPerier on Jan 23 2023, 3:21 AM.

Details

Summary

These operations implement the optional copy of a non contiguous
variable into a temporary before a call, and the copy back from the
temporary after the call.

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 23 2023, 3:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 3:21 AM
jeanPerier requested review of this revision.Jan 23 2023, 3:21 AM
This revision is now accepted and ready to land.Jan 23 2023, 5:42 AM
PeteSteinfeld requested changes to this revision.Jan 23 2023, 8:09 AM

All builds and tests correctly, but it looks like some changes are needed to HLFIROps.td.

flang/include/flang/Optimizer/HLFIR/HLFIROps.td
533

Should this be "copies the data"?

534–537

I didn't understand this sentence.

541

Should read "In such cases ..."

579–587

"getHandleNullBox()" is not used anywhere. Do we need it?

Both of these functions would read more clearly if their names evoked the fact that they return bools. For example, "handlesNullAddr".

I couldn't find a definition of "getHandleOptional" anywhere.

This revision now requires changes to proceed.Jan 23 2023, 8:09 AM
vzakhari added inline comments.Jan 23 2023, 9:40 PM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
530

nit: maybe mention the return value (result(0)) in this case, so that "Otherwise" below does not look lonely.

560

Can you please document this parameter? Is the intended usage to produce !fir.box, when the temporary value is "don't care" after the call, and !fir.ref otherwise?

577

nit: it seems a two-bit enum could have been more clear, but I can accept bool for this purpose as well :)

598

typo? $var is provided **and** $was_copied is true?

jeanPerier marked 4 inline comments as done.

Simplify the operation and answers comments:

  • Instead of indicating with a flag how a variable can be optional (null box or null address in box), pass an extra boolean value when the input is optional to indicate if it is present.
  • Instead of allowing the operation to return a raw address of box, always returns a box: the box is always created, and it is needed anway when there is a copy-back.
jeanPerier added inline comments.Jan 24 2023, 7:16 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
534–537

Rephrased the sentence and removed the part in parenthesis that brings little here.

560

I changed the operation to always return a fir.box because it made things a lot simpler, so I removed this boolean.

577

Fair point, an MLIR enum would have save custom printing/parsing. I anyway removed this while simplifying the operation.

579–587

I removed those while reworking the operation. This patch is like adding am API for review, the actual usage of the API will come in a later patch.

I couldn't find a definition of "getHandleOptional" anywhere.

MLIR generates getters automatically for all the names after "let arguments = " it convert the snake case .td name syntax (handle_optional) to camel case (getHandleOptional). See https://mlir.llvm.org/docs/DefiningDialects/Operations/#operation-arguments for more details.

vzakhari accepted this revision.Jan 24 2023, 8:46 AM

Thank you for the update! LGTM

PeteSteinfeld accepted this revision.Jan 24 2023, 12:49 PM

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Jan 24 2023, 12:49 PM