Skip to content

Commit 70ef5eb

Browse files
authored
[Flang][OpenMP] Lowering nontemporal clause to MLIR for SIMD directive (#108339)
Currently, Flang throws a "**not yet implemented: Unhandled clause NONTEMPORAL in SIMD construct**" error when encountering nontemporal clause. This patch adds support for this clause in SIMD construct.
1 parent 9d9d2b4 commit 70ef5eb

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,18 @@ bool ClauseProcessor::processMap(
10091009
return clauseFound;
10101010
}
10111011

1012+
bool ClauseProcessor::processNontemporal(
1013+
mlir::omp::NontemporalClauseOps &result) const {
1014+
return findRepeatableClause<omp::clause::Nontemporal>(
1015+
[&](const omp::clause::Nontemporal &clause, const parser::CharBlock &) {
1016+
for (const Object &object : clause.v) {
1017+
semantics::Symbol *sym = object.sym();
1018+
mlir::Value symVal = converter.getSymbolAddress(*sym);
1019+
result.nontemporalVars.push_back(symVal);
1020+
}
1021+
});
1022+
}
1023+
10121024
bool ClauseProcessor::processReduction(
10131025
mlir::Location currentLocation, mlir::omp::ReductionClauseOps &result,
10141026
llvm::SmallVectorImpl<mlir::Type> *outReductionTypes,

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class ClauseProcessor {
121121
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms = nullptr,
122122
llvm::SmallVectorImpl<mlir::Location> *mapSymLocs = nullptr,
123123
llvm::SmallVectorImpl<mlir::Type> *mapSymTypes = nullptr) const;
124+
bool processNontemporal(mlir::omp::NontemporalClauseOps &result) const;
124125
bool processReduction(
125126
mlir::Location currentLocation, mlir::omp::ReductionClauseOps &result,
126127
llvm::SmallVectorImpl<mlir::Type> *reductionTypes = nullptr,

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,13 +1123,13 @@ static void genSimdClauses(lower::AbstractConverter &converter,
11231123
ClauseProcessor cp(converter, semaCtx, clauses);
11241124
cp.processAligned(clauseOps);
11251125
cp.processIf(llvm::omp::Directive::OMPD_simd, clauseOps);
1126+
cp.processNontemporal(clauseOps);
11261127
cp.processOrder(clauseOps);
11271128
cp.processReduction(loc, clauseOps);
11281129
cp.processSafelen(clauseOps);
11291130
cp.processSimdlen(clauseOps);
11301131

1131-
cp.processTODO<clause::Linear, clause::Nontemporal>(
1132-
loc, llvm::omp::Directive::OMPD_simd);
1132+
cp.processTODO<clause::Linear>(loc, llvm::omp::Directive::OMPD_simd);
11331133
}
11341134

11351135
static void genSingleClauses(lower::AbstractConverter &converter,

flang/test/Lower/OpenMP/simd.f90

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,21 @@ subroutine simdloop_aligned_allocatable()
223223
A(i) = i
224224
end do
225225
end subroutine
226+
227+
!CHECK-LABEL: func @_QPsimd_with_nontemporal_clause
228+
subroutine simd_with_nontemporal_clause(n)
229+
!CHECK: %[[A_DECL:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFsimd_with_nontemporal_clauseEa"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
230+
!CHECK: %[[C_DECL:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFsimd_with_nontemporal_clauseEc"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
231+
integer :: i, n
232+
integer :: A, B, C
233+
!CHECK: %[[LB:.*]] = arith.constant 1 : i32
234+
!CHECK: %[[UB:.*]] = fir.load %{{.*}}#0 : !fir.ref<i32>
235+
!CHECK: %[[STEP:.*]] = arith.constant 1 : i32
236+
!CHECK: omp.simd nontemporal(%[[A_DECL]]#1, %[[C_DECL]]#1 : !fir.ref<i32>, !fir.ref<i32>) {
237+
!CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
238+
!$OMP SIMD NONTEMPORAL(A, C)
239+
do i = 1, n
240+
C = A + B
241+
end do
242+
!$OMP END SIMD
243+
end subroutine

0 commit comments

Comments
 (0)