This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add hlfir.designate definition
ClosedPublic

Authored by jeanPerier on Nov 16 2022, 5:00 AM.

Details

Summary

Add hlfir.designate operation definition. This is the HLFIR building
blocks to represent Fortran designator. An hlfir.designator is a
Fortran "part-ref" and an optional susbstring or part ref.
See the operation added description for more detail, and
https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md
for the rational of this operation.

Diff Detail

Event Timeline

jeanPerier created this revision.Nov 16 2022, 5:00 AM
Herald added a project: Restricted Project. · View Herald Transcript
jeanPerier requested review of this revision.Nov 16 2022, 5:00 AM
PeteSteinfeld requested changes to this revision.Nov 16 2022, 7:52 AM

Things build OK and generally look good, but when I run tests, I get failures in the tests for .../HLFIR/designate.fir and .../HLFIR/invalid.fir. Here's the relevant excerpts from the log file:

******************** TEST 'Flang :: HLFIR/designate.fir' FAILED ********************
Script:
--
: 'RUN: at line 3';   fir-opt /local/home/psteinfeld/main/designate/flang/test/HLFIR/designate.fir | fir-opt | /local/home/psteinfeld/main/designate/build/bin/FileCheck /local/home/psteinfeld/main/designate/flang/test/HLFIR/designate.fir
--
Exit Code: 1

Command Output (stderr):
--
/local/home/psteinfeld/main/designate/flang/test/HLFIR/designate.fir:68:8: error: 'hlfir.designate' op result type rank is not consistent with operands, expected rank 21867
  %0 = hlfir.designate %arg0 substr %c3, %c4 typeparams %c2:  (!fir.boxchar<1>, index, index, index) -> !fir.boxchar<1>
       ^
/local/home/psteinfeld/main/designate/flang/test/HLFIR/designate.fir:68:8: note: see current operation: %3 = "hlfir.designate"(%arg0, %1, %2, %0) {is_triplet = array<i1>, operand_segment_sizes = array<i32: 1, 0, 0, 2, 0, 1>} : (!fir.boxchar<1>, index, index, index) -> !fir.boxchar<1>
/local/home/psteinfeld/main/designate/flang/test/HLFIR/designate.fir:11:17: error: CHECK-LABEL: expected string not found in input
// CHECK-LABEL: func.func @array_ref(
                ^
<stdin>:1:1: note: scanning from here
module {
^

Input file: <stdin>
Check file: /local/home/psteinfeld/main/designate/flang/test/HLFIR/designate.fir

-dump-input=help explains the following input dump.

Input was:
<<<<<<
          1: module { 
label:11     X~~~~~~~~ error: no match found
          2: } 
label:11     ~~
          3:  
label:11     ~
>>>>>>

--

********************

  ....

******************** TEST 'Flang :: HLFIR/invalid.fir' FAILED ********************
Script:
--
: 'RUN: at line 3';   fir-opt -split-input-file -verify-diagnostics /local/home/psteinfeld/main/designate/flang/test/HLFIR/invalid.fir
--
Exit Code: 1

Command Output (stdout):
--

// -----

// -----

// -----
module {
  func.func @bad_array_declare(%arg0: !fir.ref<!fir.array<?x?xf32>>) {
    %0:2 = hlfir.declare %arg0 {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>)
    return
  }
}


// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

// -----

--
Command Output (stderr):
--
within split at /local/home/psteinfeld/main/designate/flang/test/HLFIR/invalid.fir:204 offset :4:8: error: unexpected error: 'hlfir.designate' op result type rank is not consistent with operands, expected rank 21981
  %0 = hlfir.designate %arg0 imag:  (!fir.ref<!fir.complex<4>>) -> !fir.ref<!fir.complex<4>>
       ^
within split at /local/home/psteinfeld/main/designate/flang/test/HLFIR/invalid.fir:204 offset :3:6: error: expected error "'hlfir.designate' op result element type is not consistent with operands, expected '!fir.real<4>'" was not produced
  // expected-error@+1 {{'hlfir.designate' op result element type is not consistent with operands, expected '!fir.real<4>'}}
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
within split at /local/home/psteinfeld/main/designate/flang/test/HLFIR/invalid.fir:211 offset :4:8: error: unexpected error: 'hlfir.designate' op result type rank is not consistent with operands, expected rank 21981
  %0 = hlfir.designate %arg0 imag:  (!fir.ref<!fir.box<!fir.complex<4>>>) -> !fir.ref<!fir.box<!fir.real<4>>>
       ^
within split at /local/home/psteinfeld/main/designate/flang/test/HLFIR/invalid.fir:211 offset :3:6: error: expected error "'hlfir.designate' op result type must only be a box address type if it designates a component that is a fir.box or fir.class and if there are no indices, substrings, and complex part" was not produced
  // expected-error@+1 {{'hlfir.designate' op result type must only be a box address type if it designates a component that is a fir.box or fir.class and if there are no indices, substrings, and complex part}}
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
within split at /local/home/psteinfeld/main/designate/flang/test/HLFIR/invalid.fir:235 offset :5:8: error: unexpected error: 'hlfir.designate' op result type rank is not consistent with operands, expected rank 21981
  %0 = hlfir.designate %arg0 substr %c1, %c1:  (!fir.ref<!fir.char<1,10>>, index, index) -> !fir.boxchar<1>
       ^
within split at /local/home/psteinfeld/main/designate/flang/test/HLFIR/invalid.fir:235 offset :4:6: error: expected error "'hlfir.designate' op must be provided one length parameter when the result is a character" was not produced
  // expected-error@+1 {{'hlfir.designate' op must be provided one length parameter when the result is a character}}
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--

********************
flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h
45

Should read "If this is the type..."

flang/include/flang/Optimizer/HLFIR/HLFIROps.td
141

Should read "This operation represents ..."

142

Should read "a substring or ..."

This revision now requires changes to proceed.Nov 16 2022, 7:52 AM
jeanPerier marked 3 inline comments as done.

Fix uninitialized variable in DesignateOp verifier and fix
a couple typos in comments and descriptions.

Things build OK and generally look good, but when I run tests, I get failures in the tests for .../HLFIR/designate.fir and .../HLFIR/invalid.fir.

Thanks @PeteSteinfeld, that should be fixed now. I did not set the expected output rank to 0 when there is not component ref and the base is not an array. Serves me right for not initializing my variables.

vzakhari added inline comments.
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
202

Just curious if it is possible to use llvm::ArrayRef<Subscript> here.

jeanPerier added inline comments.Nov 17 2022, 12:49 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
202

That would have been nice, but the "extraClassDeclaration" definitions are emitted after the builder declarations (I guess this could be changed by modifying MLIR tablegen processor, but I think it is not worth it just for this).

PeteSteinfeld accepted this revision.Nov 17 2022, 7:45 AM

Thanks, Jean.

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Nov 17 2022, 7:45 AM
vzakhari added inline comments.Nov 17 2022, 8:37 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
202

I see. Thank you for checking!

This revision was automatically updated to reflect the committed changes.