| 1 | //===-- lib/Semantics/openmp-utils.h --------------------------------------===// |
| 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 | // Common utilities used in OpenMP semantic checks. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef FORTRAN_SEMANTICS_OPENMP_UTILS_H |
| 14 | #define FORTRAN_SEMANTICS_OPENMP_UTILS_H |
| 15 | |
| 16 | #include "flang/Evaluate/type.h" |
| 17 | #include "flang/Parser/char-block.h" |
| 18 | #include "flang/Parser/parse-tree.h" |
| 19 | #include "flang/Semantics/tools.h" |
| 20 | |
| 21 | #include "llvm/ADT/ArrayRef.h" |
| 22 | |
| 23 | #include <optional> |
| 24 | #include <string> |
| 25 | |
| 26 | namespace Fortran::semantics { |
| 27 | class SemanticsContext; |
| 28 | class Symbol; |
| 29 | |
| 30 | // Add this namespace to avoid potential conflicts |
| 31 | namespace omp { |
| 32 | // There is no consistent way to get the source of an ActionStmt, but there |
| 33 | // is "source" in Statement<T>. This structure keeps the ActionStmt with the |
| 34 | // extracted source for further use. |
| 35 | struct SourcedActionStmt { |
| 36 | const parser::ActionStmt *stmt{nullptr}; |
| 37 | parser::CharBlock source; |
| 38 | |
| 39 | operator bool() const { return stmt != nullptr; } |
| 40 | }; |
| 41 | |
| 42 | SourcedActionStmt GetActionStmt(const parser::ExecutionPartConstruct *x); |
| 43 | SourcedActionStmt GetActionStmt(const parser::Block &block); |
| 44 | |
| 45 | std::string ThisVersion(unsigned version); |
| 46 | std::string TryVersion(unsigned version); |
| 47 | |
| 48 | const parser::Designator *GetDesignatorFromObj(const parser::OmpObject &object); |
| 49 | const parser::DataRef *GetDataRefFromObj(const parser::OmpObject &object); |
| 50 | const parser::ArrayElement *GetArrayElementFromObj( |
| 51 | const parser::OmpObject &object); |
| 52 | const Symbol *GetObjectSymbol(const parser::OmpObject &object); |
| 53 | const Symbol *GetArgumentSymbol(const parser::OmpArgument &argument); |
| 54 | std::optional<parser::CharBlock> GetObjectSource( |
| 55 | const parser::OmpObject &object); |
| 56 | |
| 57 | bool IsCommonBlock(const Symbol &sym); |
| 58 | bool IsExtendedListItem(const Symbol &sym); |
| 59 | bool IsVariableListItem(const Symbol &sym); |
| 60 | bool IsVarOrFunctionRef(const MaybeExpr &expr); |
| 61 | |
| 62 | std::optional<SomeExpr> GetEvaluateExpr(const parser::Expr &parserExpr); |
| 63 | std::optional<evaluate::DynamicType> GetDynamicType( |
| 64 | const parser::Expr &parserExpr); |
| 65 | |
| 66 | std::optional<bool> IsContiguous( |
| 67 | SemanticsContext &semaCtx, const parser::OmpObject &object); |
| 68 | |
| 69 | std::vector<SomeExpr> GetAllDesignators(const SomeExpr &expr); |
| 70 | const SomeExpr *HasStorageOverlap( |
| 71 | const SomeExpr &base, llvm::ArrayRef<SomeExpr> exprs); |
| 72 | bool IsSubexpressionOf(const SomeExpr &sub, const SomeExpr &super); |
| 73 | bool IsAssignment(const parser::ActionStmt *x); |
| 74 | bool IsPointerAssignment(const evaluate::Assignment &x); |
| 75 | const parser::Block &GetInnermostExecPart(const parser::Block &block); |
| 76 | } // namespace omp |
| 77 | } // namespace Fortran::semantics |
| 78 | |
| 79 | #endif // FORTRAN_SEMANTICS_OPENMP_UTILS_H |
| 80 | |