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/Lower/IterationSpace.h"
18#include "flang/Parser/char-block.h"
19#include "flang/Semantics/tools.h"
20#include "mlir/Dialect/Arith/IR/Arith.h"
21#include "mlir/Dialect/Func/IR/FuncOps.h"
22#include "mlir/IR/BuiltinAttributes.h"
23#include "llvm/ADT/SmallSet.h"
24#include "llvm/ADT/StringRef.h"
25
26namespace Fortran::lower {
28} // end namespace Fortran::lower
29
30//===----------------------------------------------------------------------===//
31// Small inline helper functions to deal with repetitive, clumsy conversions.
32//===----------------------------------------------------------------------===//
33
35inline llvm::StringRef toStringRef(const Fortran::parser::CharBlock &cb) {
36 return {cb.begin(), cb.size()};
37}
38
40template <typename A>
41const A &removeIndirection(const A &a) {
42 return a;
43}
44template <typename A>
45const A &removeIndirection(const Fortran::common::Indirection<A> &a) {
46 return a.value();
47}
48
50template <typename A>
51static Fortran::lower::SomeExpr toEvExpr(const A &x) {
52 return Fortran::evaluate::AsGenericExpr(Fortran::common::Clone(x));
53}
54
55template <Fortran::common::TypeCategory FROM>
56static Fortran::lower::SomeExpr ignoreEvConvert(
59 FROM> &x) {
60 return toEvExpr(x.left());
61}
62template <typename A>
63static Fortran::lower::SomeExpr ignoreEvConvert(const A &x) {
64 return toEvExpr(x);
65}
66
72 Fortran::common::TypeCategory::Integer, 8>> &x) {
73 return Fortran::common::visit(
74 [](const auto &v) { return ignoreEvConvert(v); }, x.u);
75}
76
79template <typename A>
80A flatZip(const A &container1, const A &container2) {
81 assert(container1.size() == container2.size());
82 A result;
83 for (auto [e1, e2] : llvm::zip(container1, container2)) {
84 result.emplace_back(e1);
85 result.emplace_back(e2);
86 }
87 return result;
88}
89
90namespace Fortran::lower {
91unsigned getHashValue(const Fortran::lower::SomeExpr *x);
92unsigned getHashValue(const Fortran::lower::ExplicitIterSpace::ArrayBases &x);
93
94bool isEqual(const Fortran::lower::SomeExpr *x,
96bool isEqual(const Fortran::lower::ExplicitIterSpace::ArrayBases &x,
97 const Fortran::lower::ExplicitIterSpace::ArrayBases &y);
98
99template <typename OpType, typename OperandsStructType>
100void privatizeSymbol(
101 lower::AbstractConverter &converter, fir::FirOpBuilder &firOpBuilder,
102 lower::SymMap &symTable,
103 llvm::SetVector<const semantics::Symbol *> &allPrivatizedSymbols,
104 llvm::SmallPtrSet<const semantics::Symbol *, 16> &mightHaveReadHostSym,
105 const semantics::Symbol *symToPrivatize, OperandsStructType *clauseOps,
106 std::optional<llvm::omp::Directive> dir = std::nullopt);
107
108} // end namespace Fortran::lower
109
110// DenseMapInfo for pointers to Fortran::lower::SomeExpr.
111namespace llvm {
112template <>
113struct DenseMapInfo<const Fortran::lower::SomeExpr *> {
114 static inline const Fortran::lower::SomeExpr *getEmptyKey() {
115 return reinterpret_cast<Fortran::lower::SomeExpr *>(~0);
116 }
117 static inline const Fortran::lower::SomeExpr *getTombstoneKey() {
118 return reinterpret_cast<Fortran::lower::SomeExpr *>(~0 - 1);
119 }
120 static unsigned getHashValue(const Fortran::lower::SomeExpr *v) {
121 return Fortran::lower::getHashValue(v);
122 }
123 static bool isEqual(const Fortran::lower::SomeExpr *lhs,
124 const Fortran::lower::SomeExpr *rhs) {
125 return Fortran::lower::isEqual(lhs, rhs);
126 }
127};
128} // namespace llvm
129
130#endif // FORTRAN_LOWER_SUPPORT_UTILS_H
Definition: indirection.h:31
Definition: common.h:214
Definition: type.h:57
Definition: char-block.h:28
Definition: FIRBuilder.h:55
Definition: ParserActions.h:24
Definition: bit-population-count.h:20
Definition: expression.h:211