Skip to content

[flang][OpenMP] Handle omp.private in FirOpBuilder::getAllocaBlock() #93927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions flang/lib/Optimizer/Builder/FIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ mlir::Block *fir::FirOpBuilder::getAllocaBlock() {
.getParentOfType<mlir::omp::OutlineableOpenMPOpInterface>()) {
return ompOutlineableIface.getAllocaBlock();
}
if (getRegion().getParentOfType<mlir::omp::DeclareReductionOp>())
return &getRegion().front();
if (auto accRecipeIface =
getRegion().getParentOfType<mlir::acc::RecipeInterface>()) {
return accRecipeIface.getAllocaBlock(getRegion());

if (auto recipeIface =
getRegion().getParentOfType<mlir::accomp::RecipeInterface>()) {
return recipeIface.getAllocaBlock(getRegion());
}

return getEntryBlock();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
! Test delayed privatization for allocatables: `firstprivate`.

! RUN: split-file %s %t

! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization \
! RUN: -o - %s 2>&1 | FileCheck %s
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %s 2>&1 |\
! RUN: -o - %t/test_ir.f90 2>&1 | FileCheck %s
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %t/test_ir.f90 2>&1 |\
! RUN: FileCheck %s

!--- test_ir.f90
subroutine delayed_privatization_allocatable
implicit none
integer, allocatable :: var1
Expand Down Expand Up @@ -34,3 +37,26 @@ subroutine delayed_privatization_allocatable
! CHECK-NEXT: %[[ORIG_BASE_LD:.*]] = fir.load %[[ORIG_BASE_ADDR]]
! CHECK-NEXT: hlfir.assign %[[ORIG_BASE_LD]] to %[[PRIV_BASE_BOX]] temporary_lhs
! CHECK-NEXT: }

! RUN: %flang -c -emit-llvm -fopenmp -mmlir --openmp-enable-delayed-privatization \
! RUN: -o - %t/test_compilation_to_obj.f90 | \
! RUN: llvm-dis 2>&1 |\
! RUN: FileCheck %s -check-prefix=LLVM

!--- test_compilation_to_obj.f90

program compilation_to_obj
real, allocatable :: t(:)

!$omp parallel firstprivate(t)
t(1) = 3.14
!$omp end parallel

end program compilation_to_obj

! LLVM: @[[GLOB_VAR:[^[:space:]]+]]t = internal global

! LLVM: define internal void @_QQmain..omp_par
! LLVM: %[[LOCAL_VAR:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
! LLVM-NEXT: %[[GLOB_VAL:.*]] = load { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @[[GLOB_VAR]]t, align 8
! LLVM-NEXT: store { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] } %[[GLOB_VAL]], ptr %[[LOCAL_VAR]], align 8
1 change: 0 additions & 1 deletion mlir/include/mlir/Dialect/OpenACC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ mlir_tablegen(OpenACCTypeInterfaces.cpp.inc -gen-type-interface-defs)
add_public_tablegen_target(MLIROpenACCTypeInterfacesIncGen)
add_dependencies(mlir-headers MLIROpenACCTypeInterfacesIncGen)

add_mlir_interface(OpenACCOpsInterfaces)
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/OpenACC/OpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"

#include "mlir/Dialect/OpenACC/OpenACCInterfaces.h"
#include "mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.h"

#define GET_OP_CLASSES
#include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
Expand Down
20 changes: 0 additions & 20 deletions mlir/include/mlir/Dialect/OpenACC/OpenACCInterfaces.h

This file was deleted.

2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ include "mlir/IR/OpBase.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Dialect/OpenACC/OpenACCBase.td"
include "mlir/Dialect/OpenACC/OpenACCOpsTypes.td"
include "mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td"
include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td"
include "mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td"
include "mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.td"

// AccCommon requires definition of OpenACC_Dialect.
include "mlir/Dialect/OpenACC/AccCommon.td"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
add_mlir_interface(AtomicInterfaces)

add_mlir_interface(OpenACCMPOpsInterfaces)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===- OpenACCMPOpsInterfaces.h - MLIR Interfaces for OpenACC/MP *- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file declares OpenACC/OpenMP Interface implementations for the
// OpenACC/OpenMP dialects.
//
//===----------------------------------------------------------------------===//

#ifndef OPENACC_MP_COMMON_INTERFACES_OPSINTERFACES_H_
#define OPENACC_MP_COMMON_INTERFACES_OPSINTERFACES_H_

#include "mlir/IR/OpDefinition.h"

#include "mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.h.inc"

#endif // OPENACC_MP_COMMON_INTERFACES_OPSINTERFACES_H_
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
//===-- OpenACCOpsInterfaces.td - OpenACC op interfaces ----*- tablegen -*-===//
//===-- OpenACCMPOpsInterfaces.td - OpenACC/MP op interfaces - tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This is the OpenACC Dialect interfaces definition file.
// This is the OpenACC/OpenMP Dialect interfaces definition file.
//
//===----------------------------------------------------------------------===//

#ifndef OPENACC_OPS_INTERFACES
#define OPENACC_OPS_INTERFACES
#ifndef OPENACC_MP_COMMON_OPS_INTERFACES
#define OPENACC_MP_COMMON_OPS_INTERFACES

include "mlir/IR/OpBase.td"

def RecipeInterface : OpInterface<"RecipeInterface"> {
let description = [{
OpenACC operations with one or more regions holding executable code.
OpenACC/OpenMP operations with one or more regions holding executable code.
}];
let cppNamespace = "::mlir::acc";
let cppNamespace = "::mlir::accomp";
let methods = [
InterfaceMethod<
/*description=*/[{
Expand All @@ -38,4 +38,4 @@ def RecipeInterface : OpInterface<"RecipeInterface"> {
];
}

#endif // OPENACC_OPS_INTERFACES
#endif // OPENACC_MP_COMMON_OPS_INTERFACES
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.h"
#include "mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
Expand Down
6 changes: 4 additions & 2 deletions mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
include "mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td"
include "mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.td"
include "mlir/Dialect/OpenMP/OpenMPAttrDefs.td"
include "mlir/Dialect/OpenMP/OpenMPOpBase.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
Expand All @@ -28,7 +29,7 @@ include "mlir/IR/SymbolInterfaces.td"
// 2.19.4 Data-Sharing Attribute Clauses
//===----------------------------------------------------------------------===//

def PrivateClauseOp : OpenMP_Op<"private", [IsolatedFromAbove]> {
def PrivateClauseOp : OpenMP_Op<"private", [IsolatedFromAbove, RecipeInterface]> {
let summary = "Provides declaration of [first]private logic.";
let description = [{
This operation provides a declaration of how to implement the
Expand Down Expand Up @@ -2091,7 +2092,8 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point"> {
//===----------------------------------------------------------------------===//

def DeclareReductionOp : OpenMP_Op<"declare_reduction", [Symbol,
IsolatedFromAbove]> {
IsolatedFromAbove,
RecipeInterface]> {
let summary = "declares a reduction kind";

let description = [{
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/OpenACC/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_mlir_dialect_library(MLIROpenACCDialect
MLIROpenACCOpsIncGen
MLIROpenACCEnumsIncGen
MLIROpenACCAttributesIncGen
MLIROpenACCOpsInterfacesIncGen
MLIROpenACCMPOpsInterfacesIncGen
MLIROpenACCTypeInterfacesIncGen

LINK_LIBS PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ using namespace acc;

#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.cpp.inc"
#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.cpp.inc"
#include "mlir/Dialect/OpenACC/OpenACCOpsInterfaces.cpp.inc"
#include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.cpp.inc"
#include "mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.cpp.inc"

namespace {
struct MemRefPointerLikeModel
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/OpenACC/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_mlir_dialect_library(MLIROpenACCTransforms
MLIROpenACCOpsIncGen
MLIROpenACCEnumsIncGen
MLIROpenACCAttributesIncGen
MLIROpenACCOpsInterfacesIncGen
MLIROpenACCMPOpsInterfacesIncGen
MLIROpenACCTypeInterfacesIncGen

LINK_LIBS PUBLIC
Expand Down
12 changes: 6 additions & 6 deletions utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9937,10 +9937,10 @@ td_library(
"include/mlir/Dialect/OpenACC/AccCommon.td",
"include/mlir/Dialect/OpenACC/OpenACCBase.td",
"include/mlir/Dialect/OpenACC/OpenACCOps.td",
"include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td",
"include/mlir/Dialect/OpenACC/OpenACCOpsTypes.td",
"include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td",
"include/mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td",
"include/mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.td",
],
includes = ["include"],
deps = [
Expand All @@ -9951,19 +9951,19 @@ td_library(
)

gentbl_cc_library(
name = "OpenACCOpsInterfacesIncGen",
name = "OpenACCMPOpsInterfacesIncGen",
tbl_outs = [
(
["-gen-op-interface-decls"],
"include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.h.inc",
"include/mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.h.inc",
),
(
["-gen-op-interface-defs"],
"include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.cpp.inc",
"include/mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.cpp.inc",
),
],
tblgen = ":mlir-tblgen",
td_file = "include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td",
td_file = "include/mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.td",
deps = [":OpenAccOpsTdFiles"],
)

Expand Down Expand Up @@ -10099,7 +10099,7 @@ cc_library(
":LoopLikeInterface",
":MemRefDialect",
":OpenACCOpsIncGen",
":OpenACCOpsInterfacesIncGen",
":OpenACCMPOpsInterfacesIncGen",
":OpenACCTypeInterfacesIncGen",
":OpenACCTypesIncGen",
":SideEffectInterfaces",
Expand Down
Loading