flang-compiler / f18-llvm-project

Fork of llvm/llvm-project for f18. In sync with f18-mlir and f18.
http://llvm.org
28 stars 16 forks source link

tco "not yet implemented type has dynamic size" #790

Closed oroppas closed 2 years ago

oroppas commented 3 years ago

Allow me to raise awareness since this seems to be the last blocking issue to codegen Xfoil.

tco polplt.mlir -o polplt.bc

loc("polplt.mlir":1619:11): error: /home/ryuta/packages/llvm/flang/f18-llvm-project/flang/lib/Optimizer/CodeGen/CodeGen.cpp:1941: not yet implemented type has dynamic size

The relevant line

grep -n coordinate_of Xfoil/src/polplt.mlir | grep -C 1 1619
1597:  %1116 = fir.coordinate_of %arg18, %1115 : (!fir.ref<!fir.array<?xi32>>, index) -> !fir.ref<i32>
1619:  %1130 = fir.coordinate_of %417, %1129 : (!fir.ref<!fir.array<?x!fir.char<1,?>>>, index) -> !fir.ref<!fir.char<1,?>>
2142:  %1461 = fir.coordinate_of %arg10, %1460 : (!fir.ref<!fir.array<?xi32>>, index) -> !fir.ref<i32>
schweitzpgi commented 3 years ago

Is there a way to reproduce this? I'm not sure if has been fixed or not.

oroppas commented 3 years ago

Let me create a reproducer from the original fortran source.

oroppas commented 3 years ago

Here's the minimal reproducible code:

      SUBROUTINE FOO(NPOL, NAME, CH2)

      CHARACTER*(*) NAME(NPOL)
      LOGICAL NAMVAR
      INTEGER IP

      IP = 1
      IF(NAMVAR) CALL PLCHAR(XPT,YLINE,.8*CH2,NAME(IP) ,0.,14)

      END
bbc -o - ./tco-dynamic_size.f  | tco
loc("<stdin>":28:9): error: /home/ryuta/packages/flang/f18-llvm-project/flang/lib/Optimizer/CodeGen/CodeGen.cpp:2003: not yet implemented type has dynamic size`

and FIR

func @_QPfoo(%arg0: !fir.ref<i32>, %arg1: !fir.boxchar<1>, %arg2: !fir.ref<f32>) {
  %0 = fir.alloca i32
  %1 = fir.alloca f32
  %2 = fir.alloca f32
  %3 = fir.alloca i32 {bindc_name = "ip", uniq_name = "_QFfooEip"}
  %4 = fir.alloca !fir.logical<4> {bindc_name = "namvar", uniq_name = "_QFfooEnamvar"}
  %5 = fir.alloca f32 {bindc_name = "xpt", uniq_name = "_QFfooExpt"}
  %6 = fir.alloca f32 {bindc_name = "yline", uniq_name = "_QFfooEyline"}
  %7:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
  %8 = fir.convert %7#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<?x!fir.char<1,?>>>
  %c1_i32 = constant 1 : i32
  fir.store %c1_i32 to %3 : !fir.ref<i32>
  %9 = fir.load %4 : !fir.ref<!fir.logical<4>>
  %10 = fir.convert %9 : (!fir.logical<4>) -> i1
  fir.if %10 {
    %cst = constant 8.000000e-01 : f32
    %11 = fir.load %arg2 : !fir.ref<f32>
    %12 = mulf %cst, %11 : f32
    fir.store %12 to %2 : !fir.ref<f32>
    %c1 = constant 1 : index
    %c0 = constant 0 : index
    %13 = fir.load %3 : !fir.ref<i32>
    %14 = fir.convert %13 : (i32) -> i64
    %15 = fir.convert %14 : (i64) -> index
    %16 = subi %15, %c1 : index
    %17 = muli %7#1, %16 : index
    %18 = addi %17, %c0 : index
    %19 = fir.coordinate_of %8, %18 : (!fir.ref<!fir.array<?x!fir.char<1,?>>>, index) -> !fir.ref<!fir.char<1,?>>
    %20 = fir.emboxchar %19, %7#1 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
    %cst_0 = constant 0.000000e+00 : f32
    fir.store %cst_0 to %1 : !fir.ref<f32>
    %c14_i32 = constant 14 : i32
    fir.store %c14_i32 to %0 : !fir.ref<i32>
    fir.call @_QPplchar(%5, %6, %2, %20, %1, %0) : (!fir.ref<f32>, !fir.ref<f32>, !fir.ref<f32>, !fir.boxchar<1>, !fir.ref<f32>, !fir.ref<i32>) -> ()
  } else {
  }
  return
}
func private @_QPplchar(!fir.ref<f32>, !fir.ref<f32>, !fir.ref<f32>, !fir.boxchar<1>, !fir.ref<f32>, !fir.ref<i32>)
oroppas commented 2 years ago

Fixed in fir-dev branch.