mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-24 06:10:12 +00:00
[Flang][OpenMP] Use fir.if instead of scf.if in lastprivate lowering
For finding the last iteration of a loop, or the last section an if condition is generated. Using scf::if can cause some lowering issues since the code contained inside it can have branches. Using fir::if instead ensures that the fir::if is lowered into branches along with any code contained inside that can generate branches. Fixes #62458. Reviewed By: NimishMishra Differential Revision: https://reviews.llvm.org/D149547
This commit is contained in:
parent
52882de0e6
commit
39e8e59950
@ -23,7 +23,6 @@
|
||||
#include "flang/Parser/parse-tree.h"
|
||||
#include "flang/Semantics/tools.h"
|
||||
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
|
||||
#include "mlir/Dialect/SCF/IR/SCF.h"
|
||||
#include "llvm/Frontend/OpenMP/OMPConstants.h"
|
||||
|
||||
using namespace mlir;
|
||||
@ -222,20 +221,20 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
|
||||
// omp.section {
|
||||
// fir.allocate for `private`/`firstprivate`
|
||||
// <More operations here>
|
||||
// scf.if %true {
|
||||
// fir.if %true {
|
||||
// ^%lpv_update_blk
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// To keep code consistency while handling privatization
|
||||
// through this control flow, add a `scf.if` operation
|
||||
// through this control flow, add a `fir.if` operation
|
||||
// that always evaluates to true, in order to create
|
||||
// a dedicated sub-region in `omp.section` where
|
||||
// lastprivate FIR can reside. Later canonicalizations
|
||||
// will optimize away this operation.
|
||||
|
||||
mlir::scf::IfOp ifOp = firOpBuilder.create<mlir::scf::IfOp>(
|
||||
auto ifOp = firOpBuilder.create<fir::IfOp>(
|
||||
op->getLoc(),
|
||||
firOpBuilder.createIntegerConstant(
|
||||
op->getLoc(), firOpBuilder.getIntegerType(1), 0x1),
|
||||
@ -280,7 +279,7 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
|
||||
// omp.wsloop { ...
|
||||
// ... store
|
||||
// store ===> %cmp = llvm.icmp "eq" %iv %ub
|
||||
// omp.yield scf.if %cmp {
|
||||
// omp.yield fir.if %cmp {
|
||||
// } ^%lpv_update_blk:
|
||||
// }
|
||||
// omp.yield
|
||||
@ -295,8 +294,8 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
|
||||
op->getRegion(0).front().getArguments()[0],
|
||||
mlir::dyn_cast<mlir::omp::WsLoopOp>(op).getUpperBound()[0]);
|
||||
}
|
||||
mlir::scf::IfOp ifOp = firOpBuilder.create<mlir::scf::IfOp>(
|
||||
op->getLoc(), cmpOp, /*else*/ false);
|
||||
auto ifOp =
|
||||
firOpBuilder.create<fir::IfOp>(op->getLoc(), cmpOp, /*else*/ false);
|
||||
firOpBuilder.setInsertionPointToStart(&ifOp.getThenRegion().front());
|
||||
lastPrivIP = firOpBuilder.saveInsertionPoint();
|
||||
} else {
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
! Testing last iteration check
|
||||
!CHECK-NEXT: %[[IV_CMP:.*]] = arith.cmpi eq, %[[INDX_WS]]
|
||||
!CHECK: scf.if %[[IV_CMP]] {
|
||||
!CHECK: fir.if %[[IV_CMP]] {
|
||||
|
||||
! Testing lastprivate val update
|
||||
!CHECK-DAG: %[[CVT:.*]] = fir.convert %[[ARG1_REF]] : (!fir.ref<!fir.char<1,5>>) -> !fir.ref<i8>
|
||||
@ -53,7 +53,7 @@ end subroutine
|
||||
|
||||
! Testing last iteration check
|
||||
!CHECK-DAG: %[[IV_CMP:.*]] = arith.cmpi eq, %[[INDX_WS]]
|
||||
!CHECK-DAG: scf.if %[[IV_CMP]] {
|
||||
!CHECK-DAG: fir.if %[[IV_CMP]] {
|
||||
|
||||
! Testing lastprivate val update
|
||||
!CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE]] : !fir.ref<i32>
|
||||
@ -82,7 +82,7 @@ end subroutine
|
||||
|
||||
! Testing last iteration check
|
||||
!CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
|
||||
!CHECK-NEXT: scf.if %[[IV_CMP1]] {
|
||||
!CHECK-NEXT: fir.if %[[IV_CMP1]] {
|
||||
! Testing lastprivate val update
|
||||
!CHECK-DAG: %[[CLONE_LD1:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
|
||||
!CHECK-DAG: fir.store %[[CLONE_LD1]] to %[[ARG1]] : !fir.ref<i32>
|
||||
@ -113,7 +113,7 @@ end subroutine
|
||||
|
||||
!Testing last iteration check
|
||||
!CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
|
||||
!CHECK-NEXT: scf.if %[[IV_CMP1]] {
|
||||
!CHECK-NEXT: fir.if %[[IV_CMP1]] {
|
||||
!Testing lastprivate val update
|
||||
!CHECK-DAG: %[[CLONE_LD2:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
|
||||
!CHECK-DAG: fir.store %[[CLONE_LD2]] to %[[ARG2]] : !fir.ref<i32>
|
||||
@ -149,7 +149,7 @@ end subroutine
|
||||
|
||||
! Testing last iteration check
|
||||
!CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
|
||||
!CHECK-NEXT: scf.if %[[IV_CMP1]] {
|
||||
!CHECK-NEXT: fir.if %[[IV_CMP1]] {
|
||||
! Testing lastprivate val update
|
||||
!CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
|
||||
!CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG2]] : !fir.ref<i32>
|
||||
@ -180,7 +180,7 @@ end subroutine
|
||||
!CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
|
||||
! Testing last iteration check
|
||||
!CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
|
||||
!CHECK-NEXT: scf.if %[[IV_CMP1]] {
|
||||
!CHECK-NEXT: fir.if %[[IV_CMP1]] {
|
||||
! Testing lastprivate val update
|
||||
!CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
|
||||
!CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG1]] : !fir.ref<i32>
|
||||
|
@ -131,7 +131,7 @@ subroutine lastprivate()
|
||||
!CHECK: %[[const:.*]] = arith.constant 1 : i32
|
||||
!CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
|
||||
!CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
|
||||
!CHECK: scf.if %[[true]] {
|
||||
!CHECK: fir.if %[[true]] {
|
||||
!CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
|
||||
!CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
|
||||
!CHECK: }
|
||||
@ -168,7 +168,7 @@ subroutine lastprivate()
|
||||
!CHECK: %[[const:.*]] = arith.constant 1 : i32
|
||||
!CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
|
||||
!CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
|
||||
!CHECK: scf.if %true {
|
||||
!CHECK: fir.if %true {
|
||||
!CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
|
||||
!CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
|
||||
!CHECK: }
|
||||
@ -205,7 +205,7 @@ subroutine lastprivate()
|
||||
!CHECK: %[[const:.*]] = arith.constant 1 : i32
|
||||
!CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
|
||||
!CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
|
||||
!CHECK: scf.if %true {
|
||||
!CHECK: fir.if %true {
|
||||
!CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
|
||||
!CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
|
||||
!CHECK: omp.barrier
|
||||
|
Loading…
Reference in New Issue
Block a user