FLANG
Utils.h
1//===-- Lower/Support/Utils.h -- utilities ----------------------*- 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_SUPPORT_UTILS_H
14#define FORTRAN_LOWER_SUPPORT_UTILS_H
15
16#include "flang/Common/indirection.h"
17#include "flang/Parser/char-block.h"
18#include "flang/Semantics/tools.h"
19#include "mlir/Dialect/Func/IR/FuncOps.h"
20#include "mlir/IR/BuiltinAttributes.h"
21#include "llvm/ADT/SmallSet.h"
22#include "llvm/ADT/StringRef.h"
23
24namespace Fortran::evaluate {
25class Component;
26} // namespace Fortran::evaluate
27
28namespace Fortran::lower {
29using SomeExpr = Fortran::evaluate::Expr<Fortran::evaluate::SomeType>;
30// FIXME: needed for privatizeSymbol that does not belong to this header.
32class SymMap;
33} // end namespace Fortran::lower
34
35namespace fir {
36class FirOpBuilder;
37}
38
39//===----------------------------------------------------------------------===//
40// Small inline helper functions to deal with repetitive, clumsy conversions.
41//===----------------------------------------------------------------------===//
42
44inline llvm::StringRef toStringRef(const Fortran::parser::CharBlock &cb) {
45 return {cb.begin(), cb.size()};
46}
47
49template <typename A>
50const A &removeIndirection(const A &a) {
51 return a;
52}
53template <typename A>
54const A &removeIndirection(const Fortran::common::Indirection<A> &a) {
55 return a.value();
56}
57
59template <typename A>
60static Fortran::lower::SomeExpr toEvExpr(const A &x) {
61 return Fortran::evaluate::AsGenericExpr(Fortran::common::Clone(x));
62}
63
64template <Fortran::common::TypeCategory FROM>
65static Fortran::lower::SomeExpr ignoreEvConvert(
68 FROM> &x) {
69 return toEvExpr(x.left());
70}
71template <typename A>
72static Fortran::lower::SomeExpr ignoreEvConvert(const A &x) {
73 return toEvExpr(x);
74}
75
79inline Fortran::lower::SomeExpr
81 Fortran::common::TypeCategory::Integer, 8>> &x) {
82 return Fortran::common::visit(
83 [](const auto &v) { return ignoreEvConvert(v); }, x.u);
84}
85
86namespace Fortran::lower {
87unsigned getHashValue(const Fortran::lower::SomeExpr *x);
88unsigned getHashValue(const Fortran::evaluate::Component *x);
89
90bool isEqual(const Fortran::lower::SomeExpr *x,
91 const Fortran::lower::SomeExpr *y);
92bool isEqual(const Fortran::evaluate::Component *x,
93 const Fortran::evaluate::Component *y);
94
95template <typename OpType, typename OperandsStructType>
96void privatizeSymbol(
97 lower::AbstractConverter &converter, fir::FirOpBuilder &firOpBuilder,
98 lower::SymMap &symTable,
99 llvm::SetVector<const semantics::Symbol *> &allPrivatizedSymbols,
100 llvm::SmallPtrSet<const semantics::Symbol *, 16> &mightHaveReadHostSym,
101 const semantics::Symbol *symToPrivatize, OperandsStructType *clauseOps,
102 std::optional<llvm::omp::Directive> dir = std::nullopt,
103 bool forceHeapAllocationForPrivateDynamicArrays = false);
104
105} // end namespace Fortran::lower
106
107// DenseMapInfo for pointers to Fortran::lower::SomeExpr.
108namespace llvm {
109template <>
110struct DenseMapInfo<const Fortran::lower::SomeExpr *> {
111 static unsigned getHashValue(const Fortran::lower::SomeExpr *v) {
112 return Fortran::lower::getHashValue(v);
113 }
114 static bool isEqual(const Fortran::lower::SomeExpr *lhs,
115 const Fortran::lower::SomeExpr *rhs) {
116 return Fortran::lower::isEqual(lhs, rhs);
117 }
118};
119
120// DenseMapInfo for pointers to Fortran::evaluate::Component.
121template <>
122struct DenseMapInfo<const Fortran::evaluate::Component *> {
123 static unsigned getHashValue(const Fortran::evaluate::Component *v) {
124 return Fortran::lower::getHashValue(v);
125 }
126 static bool isEqual(const Fortran::evaluate::Component *lhs,
127 const Fortran::evaluate::Component *rhs) {
128 return Fortran::lower::isEqual(lhs, rhs);
129 }
130};
131} // namespace llvm
132
133#endif // FORTRAN_LOWER_SUPPORT_UTILS_H
Definition indirection.h:31
Definition variable.h:73
Definition common.h:215
Definition type.h:56
Definition AbstractConverter.h:87
Definition SymbolMap.h:181
Definition char-block.h:26
Definition FIRBuilder.h:59
Definition call.h:34
Definition ParserActions.h:24
Definition bit-population-count.h:20
Definition AbstractConverter.h:37
Definition expression.h:210