FLANG
FIROps.h
1//===-- Optimizer/Dialect/FIROps.h - FIR operations -------------*- 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#ifndef FORTRAN_OPTIMIZER_DIALECT_FIROPS_H
10#define FORTRAN_OPTIMIZER_DIALECT_FIROPS_H
11
12#include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h"
13#include "flang/Optimizer/Dialect/FIRAttr.h"
14#include "flang/Optimizer/Dialect/FIRType.h"
15#include "flang/Optimizer/Dialect/FirAliasTagOpInterface.h"
16#include "flang/Optimizer/Dialect/FortranVariableInterface.h"
17#include "flang/Optimizer/Dialect/SafeTempArrayCopyAttrInterface.h"
18#include "mlir/Dialect/Arith/IR/Arith.h"
19#include "mlir/Dialect/Func/IR/FuncOps.h"
20#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
21#include "mlir/Interfaces/LoopLikeInterface.h"
22#include "mlir/Interfaces/SideEffectInterfaces.h"
23#include "mlir/Interfaces/ViewLikeInterface.h"
24
25namespace fir {
26
27class FirEndOp;
28class DoLoopOp;
29class RealAttr;
30
31void buildCmpCOp(mlir::OpBuilder &builder, mlir::OperationState &result,
32 mlir::arith::CmpFPredicate predicate, mlir::Value lhs,
33 mlir::Value rhs);
34unsigned getCaseArgumentOffset(llvm::ArrayRef<mlir::Attribute> cases,
35 unsigned dest);
36DoLoopOp getForInductionVarOwner(mlir::Value val);
37mlir::ParseResult isValidCaseAttr(mlir::Attribute attr);
38mlir::ParseResult parseCmpcOp(mlir::OpAsmParser &parser,
39 mlir::OperationState &result);
40mlir::ParseResult parseSelector(mlir::OpAsmParser &parser,
41 mlir::OperationState &result,
42 mlir::OpAsmParser::UnresolvedOperand &selector,
43 mlir::Type &type);
44bool useStrictVolatileVerification();
45
46static constexpr llvm::StringRef getNormalizedLowerBoundAttrName() {
47 return "normalized.lb";
48}
49
52 : public mlir::SideEffects::Resource::Base<DebuggingResource> {
53 mlir::StringRef getName() const final { return "DebuggingResource"; }
54 bool isAddressable() const override { return false; }
55};
56
59 : public mlir::SideEffects::Resource::Base<VolatileMemoryResource> {
60 mlir::StringRef getName() const final { return "VolatileMemoryResource"; }
61 bool isAddressable() const override { return false; }
62};
63
65using IntOrValue = llvm::PointerUnion<mlir::IntegerAttr, mlir::Value>;
66
67} // namespace fir
68
69#define GET_OP_CLASSES
70#include "flang/Optimizer/Dialect/FIROps.h.inc"
71
72namespace fir {
73class CoordinateIndicesAdaptor {
74public:
75 using value_type = IntOrValue;
76
77 CoordinateIndicesAdaptor(mlir::DenseI32ArrayAttr fieldIndices,
78 mlir::ValueRange values)
79 : fieldIndices(fieldIndices), values(values) {}
80
81 value_type operator[](size_t index) const {
82 assert(index < size() && "index out of bounds");
83 return *std::next(begin(), index);
84 }
85
86 size_t size() const {
87 return fieldIndices ? fieldIndices.size() : values.size();
88 }
89
90 bool empty() const {
91 return values.empty() && (!fieldIndices || fieldIndices.empty());
92 }
93
94 class iterator
95 : public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
96 value_type, std::ptrdiff_t,
97 value_type *, value_type> {
98 public:
99 iterator(const CoordinateIndicesAdaptor *base,
100 std::optional<llvm::ArrayRef<int32_t>::iterator> fieldIter,
101 llvm::detail::IterOfRange<const mlir::ValueRange> valuesIter)
102 : base(base), fieldIter(fieldIter), valuesIter(valuesIter) {}
103
104 value_type operator*() const {
105 if (fieldIter && **fieldIter != fir::CoordinateOp::kDynamicIndex) {
106 return mlir::IntegerAttr::get(base->fieldIndices.getElementType(),
107 **fieldIter);
108 }
109 return *valuesIter;
110 }
111
112 iterator &operator++() {
113 if (fieldIter) {
114 if (**fieldIter == fir::CoordinateOp::kDynamicIndex)
115 valuesIter++;
116 (*fieldIter)++;
117 } else {
118 valuesIter++;
119 }
120 return *this;
121 }
122
123 bool operator==(const iterator &rhs) const {
124 return base == rhs.base && fieldIter == rhs.fieldIter &&
125 valuesIter == rhs.valuesIter;
126 }
127
128 private:
129 const CoordinateIndicesAdaptor *base;
130 std::optional<llvm::ArrayRef<int32_t>::const_iterator> fieldIter;
131 llvm::detail::IterOfRange<const mlir::ValueRange> valuesIter;
132 };
133
134 iterator begin() const {
135 std::optional<llvm::ArrayRef<int32_t>::const_iterator> fieldIter;
136 if (fieldIndices)
137 fieldIter = fieldIndices.asArrayRef().begin();
138 return iterator(this, fieldIter, values.begin());
139 }
140
141 iterator end() const {
142 std::optional<llvm::ArrayRef<int32_t>::const_iterator> fieldIter;
143 if (fieldIndices)
144 fieldIter = fieldIndices.asArrayRef().end();
145 return iterator(this, fieldIter, values.end());
146 }
147
148private:
149 mlir::DenseI32ArrayAttr fieldIndices;
150 mlir::ValueRange values;
151};
152
157
160bool mayBeAbsentBox(mlir::Value val);
161
162} // namespace fir
163
164#endif // FORTRAN_OPTIMIZER_DIALECT_FIROPS_H
Definition FIROps.h:73
Definition FIRAttr.h:140
Definition FIRType.h:92
Definition OpenACC.h:20
Definition AbstractConverter.h:37
bool mayBeAbsentBox(mlir::Value val)
Definition FIROps.cpp:177
Model operations which affect global debugging information.
Definition FIROps.h:52
Definition FIROps.h:153
Model operations which read from/write to volatile memory.
Definition FIROps.h:59