1 //===-- Lower/OpenACC.h -- lower OpenACC 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_OPENACC_H 14 #define FORTRAN_LOWER_OPENACC_H 15 16 #include "mlir/Dialect/OpenACC/OpenACC.h" 17 18 namespace llvm { 19 template <typename T, unsigned N> 20 class SmallVector; 21 class StringRef; 22 } // namespace llvm 23 24 namespace mlir { 25 class Location; 26 class Type; 27 class ModuleOp; 28 class OpBuilder; 29 class Value; 30 } // namespace mlir 31 32 namespace fir { 33 class FirOpBuilder; 34 } 35 36 namespace Fortran { 37 namespace parser { 38 struct AccClauseList; 39 struct OpenACCConstruct; 40 struct OpenACCDeclarativeConstruct; 41 struct OpenACCRoutineConstruct; 42 } // namespace parser 43 44 namespace semantics { 45 class SemanticsContext; 46 class Symbol; 47 } // namespace semantics 48 49 namespace lower { 50 51 class AbstractConverter; 52 class StatementContext; 53 54 namespace pft { 55 struct Evaluation; 56 } // namespace pft 57 58 using AccRoutineInfoMappingList = 59 llvm::SmallVector<std::pair<std::string, mlir::SymbolRefAttr>>; 60 61 static constexpr llvm::StringRef declarePostAllocSuffix = 62 "_acc_declare_update_desc_post_alloc"; 63 static constexpr llvm::StringRef declarePreDeallocSuffix = 64 "_acc_declare_update_desc_pre_dealloc"; 65 static constexpr llvm::StringRef declarePostDeallocSuffix = 66 "_acc_declare_update_desc_post_dealloc"; 67 68 static constexpr llvm::StringRef privatizationRecipePrefix = "privatization"; 69 70 mlir::Value genOpenACCConstruct(AbstractConverter &, 71 Fortran::semantics::SemanticsContext &, 72 pft::Evaluation &, 73 const parser::OpenACCConstruct &); 74 void genOpenACCDeclarativeConstruct(AbstractConverter &, 75 Fortran::semantics::SemanticsContext &, 76 StatementContext &, 77 const parser::OpenACCDeclarativeConstruct &, 78 AccRoutineInfoMappingList &); 79 void genOpenACCRoutineConstruct(AbstractConverter &, 80 Fortran::semantics::SemanticsContext &, 81 mlir::ModuleOp, 82 const parser::OpenACCRoutineConstruct &, 83 AccRoutineInfoMappingList &); 84 85 void finalizeOpenACCRoutineAttachment(mlir::ModuleOp, 86 AccRoutineInfoMappingList &); 87 88 /// Get a acc.private.recipe op for the given type or create it if it does not 89 /// exist yet. 90 mlir::acc::PrivateRecipeOp createOrGetPrivateRecipe(mlir::OpBuilder &, 91 llvm::StringRef, 92 mlir::Location, mlir::Type); 93 94 /// Get a acc.reduction.recipe op for the given type or create it if it does not 95 /// exist yet. 96 mlir::acc::ReductionRecipeOp 97 createOrGetReductionRecipe(fir::FirOpBuilder &, llvm::StringRef, mlir::Location, 98 mlir::Type, mlir::acc::ReductionOperator, 99 llvm::SmallVector<mlir::Value> &); 100 101 /// Get a acc.firstprivate.recipe op for the given type or create it if it does 102 /// not exist yet. 103 mlir::acc::FirstprivateRecipeOp 104 createOrGetFirstprivateRecipe(mlir::OpBuilder &, llvm::StringRef, 105 mlir::Location, mlir::Type, 106 llvm::SmallVector<mlir::Value> &); 107 108 void attachDeclarePostAllocAction(AbstractConverter &, fir::FirOpBuilder &, 109 const Fortran::semantics::Symbol &); 110 void attachDeclarePreDeallocAction(AbstractConverter &, fir::FirOpBuilder &, 111 mlir::Value beginOpValue, 112 const Fortran::semantics::Symbol &); 113 void attachDeclarePostDeallocAction(AbstractConverter &, fir::FirOpBuilder &, 114 const Fortran::semantics::Symbol &); 115 116 void genOpenACCTerminator(fir::FirOpBuilder &, mlir::Operation *, 117 mlir::Location); 118 119 int64_t getCollapseValue(const Fortran::parser::AccClauseList &); 120 121 bool isInOpenACCLoop(fir::FirOpBuilder &); 122 123 void setInsertionPointAfterOpenACCLoopIfInside(fir::FirOpBuilder &); 124 125 void genEarlyReturnInOpenACCLoop(fir::FirOpBuilder &, mlir::Location); 126 127 } // namespace lower 128 } // namespace Fortran 129 130 #endif // FORTRAN_LOWER_OPENACC_H 131