This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Add the FIR LLVMPointer Type
ClosedPublic

Authored by kiranchandramohan on Nov 12 2021, 4:07 AM.

Details

Summary

Add a fir.llvm_ptr type to allow any level of indirections

Currently, fir pointer types (fir.ref, fir.ptr, and fir.heap) carry
a special Fortran semantics, and cannot be freely combined/nested.

When implementing some features, lowering sometimes needs more liberty
regarding the number of indirection levels. Add a fir.llvm_ptr that has
no constraints.

Allow its usage in fir.coordinate_op, fir.load, and fir.store.

Convert the FIR LLVMPointer to an LLVMPointer in the LLVM dialect.

Co-authored-by: Jean Perier <jperier@nvidia.com>

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2021, 4:07 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
kiranchandramohan requested review of this revision.Nov 12 2021, 4:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 12 2021, 4:07 AM
clementval accepted this revision.Nov 12 2021, 5:08 AM

LG. Thanks Kiran! This was one of the remaining thing to be upstream from the dialect.

flang/lib/Optimizer/Dialect/FIRType.cpp
475

nit: Can we do this with assembly format directly?

This revision is now accepted and ready to land.Nov 12 2021, 5:08 AM
kiranchandramohan added inline comments.
flang/lib/Optimizer/Dialect/FIRType.cpp
475

I gave this a try but was not successful. It could be because I used it incorrectly or because the support for all types is not yet available. @Mogball ?

Specifically, I made the following change to the definition of the type.

  let parameters = (ins "mlir::Type":$eleTy);

+ let assemblyFormat = "`<` $eleTy `>`";

I got the following errors.

tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc: In static member function ‘static mlir::Type fir::LLVMPointerType::parse(mlir::AsmParser&)’:
tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc:569:52: error: incomplete type ‘mlir::FieldParser<mlir::Type>’ used in nested name specifier
  569 |   _result_eleTy = ::mlir::FieldParser<mlir::Type>::parse(parser);
      |                                                    ^~~~~
tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc:578:29: error: no matching function for call to ‘fir::LLVMPointerType::get(mlir::MLIRContext*, mlir::Type&)’
  578 |     _result_eleTy.getValue());
      |                             ^
tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc:554:17: note: candidate: ‘static fir::LLVMPointerType fir::LLVMPointerType::get(mlir::Type)’
  554 | LLVMPointerType LLVMPointerType::get(mlir::Type elementType) {
Mogball added inline comments.Nov 14 2021, 3:02 PM
flang/lib/Optimizer/Dialect/FIRType.cpp
475

I forgot to add a template specialization for Types. Let me get that right now.

475
flang/lib/Optimizer/Dialect/FIRType.cpp
475

Thanks, @Mogball that fixes the fieldparser issue. But I still get one more error about the get Function. Would you know what causes this?

tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc: In static member function ‘static mlir::Type fir::LLVMPointerType::parse(mlir::AsmParser&)’:
tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc:578:29: error: no matching function for call to ‘fir::LLVMPointerType::get(mlir::MLIRContext*, mlir::Type&)’
  578 |     _result_eleTy.getValue());
      |                             ^
tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc:554:17: note: candidate: ‘static fir::LLVMPointerType fir::LLVMPointerType::get(mlir::Type)’
  554 | LLVMPointerType LLVMPointerType::get(mlir::Type elementType) {
      |                 ^~~~~~~~~~~~~~~
tools/flang/include/flang/Optimizer/Dialect/FIROpsTypes.cpp.inc:554:17: note:   candidate expects 1 argument, 2 provided

If I comment out the additional argument (the context) then the error goes away.

flang/lib/Optimizer/Dialect/FIRType.cpp
475

Please ignore, I think this is due to the builder being the following,

let builders = [
   TypeBuilderWithInferredContext<(ins "mlir::Type":$elementType), [{
     return Base::get(elementType.getContext(), elementType);
   }]>,
 ];

Use the assembly format for creating the printer and parser
for the type.

kiranchandramohan marked 3 inline comments as done.Nov 15 2021, 1:50 AM
kiranchandramohan added inline comments.
flang/lib/Optimizer/Dialect/FIRType.cpp
475

@clementval Done in flang/include/flang/Optimizer/Dialect/FIRTypes.td.

clementval accepted this revision.Nov 15 2021, 5:09 AM
clementval added inline comments.
flang/lib/Optimizer/Dialect/FIRType.cpp
475

Thanks! can you just remove the two functions below before landing this?

flang/lib/Optimizer/Dialect/FIRType.cpp
475

The functions below are for the FIR pointer type. I have not added the functions for the FIR LLVM Pointer type.

clementval added inline comments.Nov 15 2021, 5:46 AM
flang/lib/Optimizer/Dialect/FIRType.cpp
475

Sorry I didn't look correctly.

This revision was automatically updated to reflect the committed changes.