1 //===-- Lower/OpenMP.h -- lower Open MP directives --------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef FORTRAN_LOWER_OPENMP_H 14 #define FORTRAN_LOWER_OPENMP_H 15 16 #include "llvm/ADT/SmallVector.h" 17 18 #include <cinttypes> 19 #include <utility> 20 21 namespace mlir { 22 class Operation; 23 class Location; 24 namespace omp { 25 enum class DeclareTargetDeviceType : uint32_t; 26 enum class DeclareTargetCaptureClause : uint32_t; 27 } // namespace omp 28 } // namespace mlir 29 30 namespace fir { 31 class FirOpBuilder; 32 } // namespace fir 33 34 namespace Fortran { 35 namespace parser { 36 struct OpenMPConstruct; 37 struct OpenMPDeclarativeConstruct; 38 struct OmpEndLoopDirective; 39 struct OmpClauseList; 40 } // namespace parser 41 42 namespace semantics { 43 class Symbol; 44 class SemanticsContext; 45 } // namespace semantics 46 47 namespace lower { 48 49 class AbstractConverter; 50 class SymMap; 51 52 namespace pft { 53 struct Evaluation; 54 struct Variable; 55 } // namespace pft 56 57 struct OMPDeferredDeclareTargetInfo { 58 mlir::omp::DeclareTargetCaptureClause declareTargetCaptureClause; 59 mlir::omp::DeclareTargetDeviceType declareTargetDeviceType; 60 const Fortran::semantics::Symbol &sym; 61 }; 62 63 // Generate the OpenMP terminator for Operation at Location. 64 mlir::Operation *genOpenMPTerminator(fir::FirOpBuilder &, mlir::Operation *, 65 mlir::Location); 66 67 void genOpenMPConstruct(AbstractConverter &, Fortran::lower::SymMap &, 68 semantics::SemanticsContext &, pft::Evaluation &, 69 const parser::OpenMPConstruct &); 70 void genOpenMPDeclarativeConstruct(AbstractConverter &, 71 Fortran::lower::SymMap &, 72 semantics::SemanticsContext &, 73 pft::Evaluation &, 74 const parser::OpenMPDeclarativeConstruct &); 75 /// Symbols in OpenMP code can have flags (e.g. threadprivate directive) 76 /// that require additional handling when lowering the corresponding 77 /// variable. Perform such handling according to the flags on the symbol. 78 /// The variable \p var is required to have a `Symbol`. 79 void genOpenMPSymbolProperties(AbstractConverter &converter, 80 const pft::Variable &var); 81 82 int64_t getCollapseValue(const Fortran::parser::OmpClauseList &clauseList); 83 void genThreadprivateOp(AbstractConverter &, const pft::Variable &); 84 void genDeclareTargetIntGlobal(AbstractConverter &, const pft::Variable &); 85 bool isOpenMPTargetConstruct(const parser::OpenMPConstruct &); 86 bool isOpenMPDeviceDeclareTarget(Fortran::lower::AbstractConverter &, 87 Fortran::semantics::SemanticsContext &, 88 Fortran::lower::pft::Evaluation &, 89 const parser::OpenMPDeclarativeConstruct &); 90 void gatherOpenMPDeferredDeclareTargets( 91 Fortran::lower::AbstractConverter &, Fortran::semantics::SemanticsContext &, 92 Fortran::lower::pft::Evaluation &, 93 const parser::OpenMPDeclarativeConstruct &, 94 llvm::SmallVectorImpl<OMPDeferredDeclareTargetInfo> &); 95 bool markOpenMPDeferredDeclareTargetFunctions( 96 mlir::Operation *, llvm::SmallVectorImpl<OMPDeferredDeclareTargetInfo> &, 97 AbstractConverter &); 98 void genOpenMPRequires(mlir::Operation *, const Fortran::semantics::Symbol *); 99 100 } // namespace lower 101 } // namespace Fortran 102 103 #endif // FORTRAN_LOWER_OPENMP_H 104