This is an archive of the discontinued LLVM Phabricator instance.

[flang][codegen] Add `fir.end` conversion placeholder
ClosedPublic

Authored by awarzynski on Nov 5 2021, 9:54 AM.

Details

Summary

This patch extends the FIRToLLVMLowering pass in Flang by adding a
hook to transform fir.end. This is just a placeholder for now as fir.end is not required yet.

This is part of the upstreaming effort from the fir-dev branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

Diff Detail

Event Timeline

awarzynski created this revision.Nov 5 2021, 9:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2021, 9:54 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
awarzynski requested review of this revision.Nov 5 2021, 9:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2021, 9:54 AM

Without the change in "FIROps.td" I was getting the following error:

error: custom op 'fir.end' has no custom assembly form

I'm not that familiar with the design, so perhaps this is not the right approach?

Without the change in "FIROps.td" I was getting the following error:

error: custom op 'fir.end' has no custom assembly form

I'm not that familiar with the design, so perhaps this is not the right approach?

flang/include/flang/Optimizer/Dialect/FIROps.td
812 ↗(On Diff #385108)

You need this to be able to parse the "pretty" form. But do you need one?

flang/test/Fir/convert-to-llvm.fir
331 ↗(On Diff #385108)

You could test it with just "fir.end"() : () -> () and not define a custom parser.

mehdi_amini added inline comments.Nov 5 2021, 11:37 AM
flang/include/flang/Optimizer/Dialect/FIROps.td
812 ↗(On Diff #385108)

If you ever need a trivial custom form in the future, the preferred way would be to write it as let assemblyFormat = "attr-dict-with-keyword";

The assemblyFormat makes sure that you don't forget elements, like the optional dictionary of attributes here :)

awarzynski marked 3 inline comments as done.Nov 8 2021, 2:19 AM
awarzynski added inline comments.
flang/include/flang/Optimizer/Dialect/FIROps.td
812 ↗(On Diff #385108)

You need this to be able to parse the "pretty" form. But do you need one?

I don't think I do - thanks for pointing this out! :)

flang/test/Fir/convert-to-llvm.fir
331 ↗(On Diff #385108)

Ah, thanks! Yes, I will use that instead.

awarzynski updated this revision to Diff 385429.Nov 8 2021, 2:20 AM
awarzynski marked an inline comment as done.

Remove the pretty printer and adjust the test accordingly

mehdi_amini added inline comments.Nov 8 2021, 10:07 AM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
849

Nit: I think you can spell this rewriter.eraseOp for the same effect, but it expressed the intent a bit more clearly.

852

I was wondering if we need a pattern of its own for this op or if this should be handled by the parent operation?

The test shows it in isolation, but that does not exist, does it?

mehdi_amini added inline comments.Nov 8 2021, 10:08 AM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
852

I even wonder if the verifier for fir.end shouldn't check on the actual parent op and limit it to be nested in some specific ones.

@mehdi_amini , these are much appreciated pointers, thank you!

flang/lib/Optimizer/CodeGen/CodeGen.cpp
852

I think that would make more sense. But, IIUC, in the current design there's only one such parent and it's only going to be needed for F2003. We are still working towards F95, so this is not required yet.

Perhaps we should just postpone this one until it's really needed?

clementval added inline comments.Nov 8 2021, 10:21 AM
flang/test/Fir/convert-to-llvm.fir
332 ↗(On Diff #385429)

It would probably make more sense to have a real use case where the op is actually used as a terminator.

clementval added inline comments.Nov 11 2021, 4:46 AM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
849

+1

fir.end is only used in fir.dispatch_table, and fir.dispatch_table is currently a notifyMatchFailure, i.e. it's not implemented. I think that that's what we should do with fir.end as well. Let me update this accordingly. @schweitz , any thoughts?

Leave fir.end as unimplemented

fir.end is only used in fir.dispatch_table, and fir.dispatch_table is currently a notifyMatchFailure, i.e. it's not implemented. I think that that's what we should do with fir.end as well. Let me update this accordingly. @schweitz , any thoughts?

Seems reasonable. fir.end used to be widely applicable, but it's steadily been eroded.

In fact, given https://llvm.discourse.group/t/rfc-making-terminator-optional-for-single-block-graph-regions/2997 it seems like fir.end will be end of life soon.

clementval accepted this revision.Nov 17 2021, 1:53 AM

Can you update the commit message since it has change from the first version of your patch.

This revision is now accepted and ready to land.Nov 17 2021, 1:53 AM
awarzynski retitled this revision from [flang] Transform `fir.end` to an empty statement to [flang][codegen] Add `fir.end` conversion placeholder.Nov 18 2021, 1:46 AM
awarzynski edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.