This is an archive of the discontinued LLVM Phabricator instance.

Update fir.insert_on_range syntax to make the range more explicit (NFC)
ClosedPublic

Authored by mehdi_amini on Oct 31 2021, 5:09 PM.

Diff Detail

Event Timeline

mehdi_amini created this revision.Oct 31 2021, 5:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2021, 5:09 PM
mehdi_amini requested review of this revision.Oct 31 2021, 5:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2021, 5:09 PM
kiranchandramohan added inline comments.
flang/lib/Optimizer/Dialect/FIROps.cpp
1397–1403

Remove commented code?

clementval added inline comments.Nov 1 2021, 2:52 AM
flang/lib/Optimizer/Dialect/FIROps.cpp
1403

Why is this removed?

mehdi_amini added inline comments.Nov 1 2021, 10:35 AM
flang/lib/Optimizer/Dialect/FIROps.cpp
1403

Oh right I forgot to update this: this builder seems conceptually broken to me.
It takes an ArrayRef<mlir::Value> where it expects only constants.
Builders can't fail: so this does not seems like a good API: every caller will have to check that the values are constant before calling this, which will again recheck (but die).
Also the fact that it can be deleted show it isn't used right now.

I'll pull this in another revision and rebase the current one though.

Rebase/update on builder removal

mehdi_amini marked 2 inline comments as done.Nov 1 2021, 1:36 PM
flang/lib/Optimizer/Dialect/FIROps.cpp
1407

Did you miss the comma here?
There might be a missing multi-coordinate test.

1413

upper bounds?

Fix the multi-dimensional case and add a test for it!

mehdi_amini marked 2 inline comments as done.Nov 1 2021, 10:01 PM
mehdi_amini added inline comments.
flang/lib/Optimizer/Dialect/FIROps.cpp
1407

Thanks, good catch :)

kiranchandramohan accepted this revision.Nov 2 2021, 4:21 AM

LGTM. Looks like a good syntax improvement. Also seems to match the example given in https://github.com/llvm/llvm-project/blob/bcad20bc6591c8b503923402038c735a77373f99/flang/include/flang/Optimizer/Dialect/FIROps.td#L2003.

I have a Nit suggestion.

Please wait for @clementval/@schweitz.

flang/lib/Optimizer/Dialect/FIROps.cpp
1388

Nit: The fortran array syntax uses Paren. Might be good to use that. Not a strong opinion. You can wait for other's comments.
i.e Fortran syntax is a(1,3) and not a[1,3].

This revision is now accepted and ready to land.Nov 2 2021, 4:21 AM
mehdi_amini marked an inline comment as done.Nov 2 2021, 4:11 PM
mehdi_amini added inline comments.
flang/lib/Optimizer/Dialect/FIROps.cpp
1388

Happy to adjust as needed!

Something that would be nice to clarify in a doc for the FIR dialect in general are some principles around row/col major and whether indexing starts at 0 or 1, I'm frequently confused.

mehdi_amini added inline comments.Nov 2 2021, 4:13 PM
flang/lib/Optimizer/Dialect/FIROps.cpp
1388

Happy to adjust as needed!

Thinking about it, I would likely try be to consistently using ( ) for Fortran indexing (col-major, starts at 1) and square brackets for the C-like indexing.
That way the syntax is a bit more than sugar but provides a visual aid on the semantics of the indexing, WDYT?

flang/lib/Optimizer/Dialect/FIROps.cpp
1388

That sounds good to me.
WDYT @schweitz @clementval?

I can help with submitting this to fir-dev.

BTW @mehdi_amini, is there a way to put up the FIR dialect operations on a webpage just like the MLIR dialects (https://mlir.llvm.org/docs/Dialects/SCFDialect/)?

clementval accepted this revision.Nov 3 2021, 5:54 AM
clementval added inline comments.
flang/lib/Optimizer/Dialect/FIROps.cpp
1388

+1 to use Fortran syntax.

Thanks Mehdi for this patch. We welcome changes that improve the readability of the code. Could you consider delaying these kind patches till we have finished upstreaming most of the changes, so as to avoid additional effort to merge this back into fir-dev.
Kiran as volunteered to merge this back to fir-dev now.

mehdi_amini added inline comments.Nov 3 2021, 10:50 AM
flang/include/flang/Optimizer/Dialect/FIROps.td
1981

Actually this change should likely be separated in another revision from the ASM syntax one.

Thanks Mehdi for this patch. We welcome changes that improve the readability of the code. Could you consider delaying these kind patches till we have finished upstreaming most of the changes, so as to avoid additional effort to merge this back into fir-dev.
Kiran as volunteered to merge this back to fir-dev now.

@mehdi_amini This comment was mainly for any further syntax change in the dialect. This one can go in anytime.

@mehdi_amini This comment was mainly for any further syntax change in the dialect. This one can go in anytime.

Ah ok, pushing now then.

flang/include/flang/Optimizer/Dialect/FIROps.td
1981

It's too annoying to split up because IndexElementsAttr can't be parsed alone by default, I'll minimize the churn and land this together this time.