[PATCH] D114159: [flang][codegen] Add a conversion for `fir.coordinate_of` - part 1

Andrzej Warzynski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 2 05:40:55 PST 2021


awarzynski added a comment.

NOTE: The following discussion refers to the code from `doRewriteBox`.

I'm looking at the "GENERAL CASE" in `doRewriteBox` again, which is the trickiest one here. Let me summarise a bit. There are quite a few potential cases and I don't want to miss anything.

The following cases are IMO quite clear and already fully  tested:

  // 1. (`fir.array`)
  %box = ... : !fix.box<!fir.array<?xU>>
  %idx = ... : index
  %resultAddr = coordinate_of %box, %idx : !fir.ref<U>
  
  // 2 (`fir.derived`)
  %box = ... : !fix.box<!fir.type<derived_type{field_1:i32}>>
  %idx = ... : i32
  %resultAddr = coordinate_of %box, %idx : !fir.ref<i32>
  
  // 3 (`fir.derived` inside `fir.array`)
  %box = ... : !fir.box<!fir.array<10 x !fir.type<derived_1{field_1:f32, field_2:f32}>>>
  %idx1 = ... : index
  %idx2 = ... : i32
  %resultAddr = coordinate_of %box, %idx1, %idx2 : !fir.ref<f32>

I've also added a test for the following case, but I am realising that the generated code is **not valid**:

  4. (`fir.array` inside `fir.derived`)
  %box = ... : !fix.box<!fir.type<derived_type{field_1:!fir.array<10xf32>}>>
  %idx1 = ... : i32
  %idx2 = ... : index
  %resultAddr = coordinate_of %box, %idx1, %idx2 : !fir.ref<f32>

It's not valid, because the stride is calculated as (@rovka, thanks for pointing this out!):

  mlir::Value stride = loadStrideFromBox(loc, operands[0], index - i, rewriter);

i.e., it's always extracted from the outer `box` (`%box` in the snippet above). Making this code work correctly for `4.` would require a design discussion. I think that's out-of-scope here. Instead, I'll add a new `TODO` for nested arrays and move the corresponding test to flang/test/Fir/Todo/. WDYT? Also, have I missed any cases?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114159/new/

https://reviews.llvm.org/D114159



More information about the llvm-commits mailing list