Skip to content

Commit 1da8a95

Browse files
Use Data instead of Box for allocatable array
1 parent 7c98c64 commit 1da8a95

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,16 +3282,21 @@ class FirConverter : public Fortran::lower::AbstractConverter {
32823282
Fortran::lower::SomeExpr expr{*ea.Analyze(
32833283
std::get<Fortran::parser::DataRef>(p.value().u))};
32843284
Fortran::lower::StatementContext stmtCtx;
3285+
mlir::Location loc = genLocation(dir.source);
32853286
mlir::Value memRef{Fortran::lower::convertExprToHLFIR(
3286-
genLocation(dir.source), *this, expr,
3287-
localSymbols, stmtCtx)
3287+
loc, *this, expr, localSymbols, stmtCtx)
32883288
.getBase()};
3289+
if (mlir::isa<fir::BaseBoxType>(
3290+
fir::unwrapRefType(memRef.getType()))) {
3291+
memRef = fir::LoadOp::create(*builder, loc, memRef);
3292+
memRef = fir::BoxAddrOp::create(*builder, loc, memRef);
3293+
}
32893294

32903295
// TODO: Don't use default value, instead get the following
32913296
// info from the directive
32923297
uint32_t isWrite{0}, localityHint{3}, isData{1};
3293-
fir::PrefetchOp::create(*builder, genLocation(dir.source),
3294-
memRef, isWrite, localityHint, isData);
3298+
fir::PrefetchOp::create(*builder, loc, memRef, isWrite,
3299+
localityHint, isData);
32953300
}
32963301
},
32973302
[&](const auto &) {}},

flang/test/Lower/HLFIR/prefetch.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ subroutine test_prefetch_02(t1)
5050
a = t1%a ** 2
5151

5252
do i = 1, 256
53-
! HLFIR: fir.prefetch %[[H_A]]#0 {cacheType, localityHint = 3 : i32} : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>
53+
! HLFIR: %[[A_LOAD:.*]] = fir.load %[[H_A]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>
54+
! HLFIR: %[[A_BOX:.*]] = fir.box_addr %[[A_LOAD]] : (!fir.box<!fir.heap<!fir.array<?x?xi32>>>) -> !fir.heap<!fir.array<?x?xi32>>
55+
! HLFIR: fir.prefetch %[[A_BOX]] {cacheType, localityHint = 3 : i32} : !fir.heap<!fir.array<?x?xi32>>
5456
!dir$ prefetch a
5557
a(i, :) = a(i, :) + i
5658
do j = 1, 256

0 commit comments

Comments
 (0)