[flang-commits] [PATCH] D113273: [fir] TargetRewrite: Rewrite COMPLEX values

Kiran Chandramohan via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Nov 5 16:18:05 PDT 2021


kiranchandramohan added a subscriber: mleair.
kiranchandramohan added inline comments.


================
Comment at: flang/lib/Optimizer/CodeGen/TargetRewrite.cpp:263
+          })
+          .template Case<mlir::ComplexType>([&](mlir::ComplexType cmplx) {
+            rewriteCallComplexInputType(cmplx, oper, newInTys, newOpers);
----------------
rovka wrote:
> I tried to add a test with mlir::ComplexType, but it told me that the dialect is not registered. It doesn't seem to be registered in fir-dev AFAICT (I hope I'm looking in [[ https://github.com/flang-compiler/f18-llvm-project/blob/080bcac68a39ffa7c9bad4f1df6144965c430687/flang/include/flang/Optimizer/Support/InitFIR.h#L35 | the right place ]]). Does flang ever actually use mlir::ComplexType, or should I remove this code path?
Flang seems to use mlir::Complex while generating runtime calls. See code in https://github.com/flang-compiler/f18-llvm-project/blob/3aa4ab214082e718804d431139f59eb45df1f71d/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h#L224


```
complex function sum_test3(a)
  complex :: a(:)
  sum_test3 = sum(a)
end function
```

The MLIR generated for the above test contains the MLIR complex<f32> type.
```
func @_QPsum_test3(%arg0: !fir.box<!fir.array<?x!fir.complex<4>>>) -> !fir.complex<4> {
  %0 = fir.alloca !fir.complex<4>
  %1 = fir.alloca !fir.complex<4> {bindc_name = "sum_test3", uniq_name = "_QFsum_test3Esum_test3"}
  %2 = fir.absent !fir.box<i1>
  %c0 = arith.constant 0 : index
  %3 = fir.address_of(@_QQcl.2E2F7463312E66393000) : !fir.ref<!fir.char<1,10>>
  %c3_i32 = arith.constant 3 : i32
  %4 = fir.convert %0 : (!fir.ref<!fir.complex<4>>) -> !fir.ref<complex<f32>>
  %5 = fir.convert %arg0 : (!fir.box<!fir.array<?x!fir.complex<4>>>) -> !fir.box<none>
  %6 = fir.convert %3 : (!fir.ref<!fir.char<1,10>>) -> !fir.ref<i8>
  %7 = fir.convert %c0 : (index) -> i32
  %8 = fir.convert %2 : (!fir.box<i1>) -> !fir.box<none>
  %9 = fir.call @_FortranACppSumComplex4(%4, %5, %6, %c3_i32, %7, %8) : (!fir.ref<complex<f32>>, !fir.box<none>, !fir.ref<i8>, i32, i32, !fir.box<none>) -> none
  %10 = fir.load %0 : !fir.ref<!fir.complex<4>>
  fir.store %10 to %1 : !fir.ref<!fir.complex<4>>
  %11 = fir.load %1 : !fir.ref<!fir.complex<4>>
  return %11 : !fir.complex<4>
}
func private @_FortranACppSumComplex4(!fir.ref<complex<f32>>, !fir.box<none>, !fir.ref<i8>, i32, i32, !fir.box<none>) -> none attributes {fir.runtime}
fir.global linkonce @_QQcl.2E2F7463312E66393000 constant : !fir.char<1,10> {
  %0 = fir.string_lit "./tc1.f90\00"(10) : !fir.char<1,10>
  fir.has_value %0 : !fir.char<1,10>
}
```

I guess @jeanPerier @schweitz or @mleair can explain the usage better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113273



More information about the flang-commits mailing list