Skip to content

Commit d393a96

Browse files
committed
[flang] Allow embox's source_box to be a !fir.box.
In order to create temporary copies of assumed-type arrays (e.g. for `-frepack-arrays`), we have to allow the source_box to be a !fir.box. This patch replaces llvm#147618.
1 parent f090554 commit d393a96

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

flang/include/flang/Optimizer/Dialect/FIRCG/CGOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def fircg_XEmboxOp : fircg_Op<"ext_embox", [AttrSizedOperandSegments]> {
6060
Variadic<AnyIntegerType>:$slice,
6161
Variadic<AnyCoordinateType>:$subcomponent,
6262
Variadic<AnyIntegerType>:$substr, Variadic<AnyIntegerType>:$lenParams,
63-
Optional<fir_ClassType>:$sourceBox, OptionalAttr<I32Attr>:$allocator_idx);
63+
Optional<BoxOrClassType>:$sourceBox,
64+
OptionalAttr<I32Attr>:$allocator_idx);
6465
let results = (outs BoxOrClassType);
6566

6667
let assemblyFormat = [{

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -834,15 +834,11 @@ def fir_EmboxOp : fir_Op<"embox", [NoMemoryEffect, AttrSizedOperandSegments]> {
834834
- allocator_idx: specify special allocator to use.
835835
}];
836836

837-
let arguments = (ins
838-
AnyReferenceLike:$memref,
839-
Optional<AnyShapeType>:$shape,
840-
Optional<fir_SliceType>:$slice,
841-
Variadic<AnyIntegerType>:$typeparams,
842-
Optional<fir_ClassType>:$sourceBox,
843-
OptionalAttr<AffineMapAttr>:$accessMap,
844-
OptionalAttr<I32Attr>:$allocator_idx
845-
);
837+
let arguments = (ins AnyReferenceLike:$memref, Optional<AnyShapeType>:$shape,
838+
Optional<fir_SliceType>:$slice, Variadic<AnyIntegerType>:$typeparams,
839+
Optional<BoxOrClassType>:$sourceBox,
840+
OptionalAttr<AffineMapAttr>:$accessMap,
841+
OptionalAttr<I32Attr>:$allocator_idx);
846842

847843
let results = (outs BoxOrClassType);
848844

flang/include/flang/Optimizer/Dialect/FIRTypes.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,10 @@ def AnyBoxLike : TypeConstraint<Or<[fir_BoxType.predicate,
626626
fir_BoxCharType.predicate, fir_BoxProcType.predicate,
627627
fir_ClassType.predicate]>, "any box">;
628628

629-
def BoxOrClassType : TypeConstraint<Or<[fir_BoxType.predicate,
630-
fir_ClassType.predicate]>, "box or class">;
629+
def BoxOrClassLike
630+
: TypeConstraint<Or<[fir_BoxType.predicate, fir_ClassType.predicate]>,
631+
"box or class">;
632+
def BoxOrClassType : Type<BoxOrClassLike.predicate, "box or class">;
631633

632634
def AnyRefOrBoxLike : TypeConstraint<Or<[AnyReferenceLike.predicate,
633635
AnyBoxLike.predicate, FunctionType.predicate]>,

flang/test/Fir/fir-ops.fir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,16 @@ func.func @embox_tdesc(%arg0: !fir.class<!fir.array<10x!fir.type<derived_poly{a:
843843
return
844844
}
845845

846+
// CHECK-LABEL: func.func @embox_with_source_box(
847+
// CHECK-SAME: %[[ARG0:.*]]: !fir.heap<!fir.array<?xnone>>,
848+
// CHECK-SAME: %[[ARG1:.*]]: !fir.shape<1>,
849+
// CHECK-SAME: %[[ARG2:.*]]: !fir.box<!fir.array<?xnone>>) -> !fir.class<!fir.heap<!fir.array<?xnone>>> {
850+
func.func @embox_with_source_box(%arg0: !fir.heap<!fir.array<?xnone>>, %arg1: !fir.shape<1>, %arg2: !fir.box<!fir.array<?xnone>>) -> !fir.class<!fir.heap<!fir.array<?xnone>>> {
851+
// CHECK: %[[VAL_0:.*]] = fir.embox %[[ARG0]](%[[ARG1]]) source_box %[[ARG2]] : (!fir.heap<!fir.array<?xnone>>, !fir.shape<1>, !fir.box<!fir.array<?xnone>>) -> !fir.class<!fir.heap<!fir.array<?xnone>>>
852+
%0 = fir.embox %arg0(%arg1) source_box %arg2 : (!fir.heap<!fir.array<?xnone>>, !fir.shape<1>, !fir.box<!fir.array<?xnone>>) -> !fir.class<!fir.heap<!fir.array<?xnone>>>
853+
return %0 : !fir.class<!fir.heap<!fir.array<?xnone>>>
854+
}
855+
846856
func.func @test_fortran_var_attrs() {
847857
%0 = fir.alloca !fir.heap<f32> {fortran_attrs = #fir.var_attrs<allocatable>}
848858
%1 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<asynchronous>}

0 commit comments

Comments
 (0)