This is an archive of the discontinued LLVM Phabricator instance.

[flang][CodeGen] Transform `fir.emboxchar` to a sequence of LLVM MLIR
ClosedPublic

Authored by awarzynski on Nov 11 2021, 5:37 AM.

Details

Summary

This patch extends the FIRToLLVMLowering pass in Flang by adding a
hook to transform fir.emboxchar to a sequence of LLVM MLIR
instructions.

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 11 2021, 5:37 AM
awarzynski requested review of this revision.Nov 11 2021, 5:37 AM

Move the test to flang/test/Fir/convert-to-llvm-target.fir, make it target specific

Based on the description of emboxchar, I'd expect it to work with fir.array. However, with fir.array the operation wouldn't match. Any pointers @schweitz ?

Remove auto, give variables more meaningful names, rebase

Don't forget to sync back to fir-dev. Especially when you make lots of changes (auto, variable names) otherwise it's gonna become a nightmare to track.

flang/lib/Optimizer/CodeGen/CodeGen.cpp
1403

This is often auto in MLIR code base.

1408

getLoc() is almost 100% of the time auto in the LLVM/MLIR code base.

clementval accepted this revision.Nov 12 2021, 2:30 AM

LG. Just couple of nits

flang/lib/Optimizer/CodeGen/CodeGen.cpp
1414

clang-format.

This revision is now accepted and ready to land.Nov 12 2021, 2:30 AM

Don't forget to sync back to fir-dev.

Yup, I was planning to send a bigger patch back to fir-dev once I finish fir.boxchar. Is that OK?

flang/lib/Optimizer/CodeGen/CodeGen.cpp
1403

Having seen LLVMContext, ASTContext, MCContext ... I just really like to know exactly which context I'm dealing with. But I guess that it's unlikely to be anything other than MLIRContext in this file.

1408

Almost:

grep  -iEr "Location getLoc" mlir/ | wc -l
       9

But auto is indeed more popular. Let me revert this.

Don't forget to sync back to fir-dev.

Yup, I was planning to send a bigger patch back to fir-dev once I finish fir.boxchar. Is that OK?

Yes. We should at least sync once a week if we had couple of patches. fir-dev is still moving and keeping it in sync will help to "freeze" some part of the tree in fir-dev later.

clang-format and use auto instead of mlir::Location (for consistency)

mehdi_amini added inline comments.Nov 12 2021, 10:05 PM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
1408

getLoc() is almost 100% of the time auto in the LLVM/MLIR code base.

I don't think so.
I would use almost always Location: auto does not improve readability is enough for me to not use it (also it could be an SMLoc in some context) . When I use auto when writing code it is mostly out of laziness / convenience, but we should optimize for other to read code instead of the ease to write it.

I don't know how you grepped, but mine is:

$ git grep getLoc\( mlir | grep "loc =" | grep "auto" | wc -l
130
$ git grep getLoc\( mlir | grep "loc =" | grep -v "auto" | wc -l
237

So much more

awarzynski added inline comments.Nov 15 2021, 2:54 AM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
1408

Thanks for checking! Clearly I wasn't awake when grepping.

we should optimize for other to read code instead of the ease to write it.

Agreed. Will update before merging.