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<FortranRuntimeResource> {
60 mlir::StringRef getName() const final { return "FortranRuntimeResource"; }
61 bool isAddressable() const override { return false; }
62};
63
66 : public mlir::SideEffects::Resource::Base<VolatileMemoryResource> {
67 mlir::StringRef getName() const final { return "VolatileMemoryResource"; }
68 bool isAddressable() const override { return false; }
69};
70
72using IntOrValue = llvm::PointerUnion<mlir::IntegerAttr, mlir::Value>;
73
74} // namespace fir
75
76#define GET_OP_CLASSES
77#include "flang/Optimizer/Dialect/FIROps.h.inc"
78
79namespace fir {
80class CoordinateIndicesAdaptor {
81public:
82 using value_type = IntOrValue;
83
84 CoordinateIndicesAdaptor(mlir::DenseI32ArrayAttr fieldIndices,
85 mlir::ValueRange values)
86 : fieldIndices(fieldIndices), values(values) {}
87
88 value_type operator[](size_t index) const {
89 assert(index < size() && "index out of bounds");
90 return *std::next(begin(), index);
91 }
92
93 size_t size() const {
94 return fieldIndices ? fieldIndices.size() : values.size();
95 }
96
97 bool empty() const {
98 return values.empty() && (!fieldIndices || fieldIndices.empty());
99 }
100
101 class iterator
102 : public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
103 value_type, std::ptrdiff_t,
104 value_type *, value_type> {
105 public:
106 iterator(const CoordinateIndicesAdaptor *base,
107 std::optional<llvm::ArrayRef<int32_t>::iterator> fieldIter,
108 llvm::detail::IterOfRange<const mlir::ValueRange> valuesIter)
109 : base(base), fieldIter(fieldIter), valuesIter(valuesIter) {}
110
111 value_type operator*() const {
112 if (fieldIter && **fieldIter != fir::CoordinateOp::kDynamicIndex) {
113 return mlir::IntegerAttr::get(base->fieldIndices.getElementType(),
114 **fieldIter);
115 }
116 return *valuesIter;
117 }
118
119 iterator &operator++() {
120 if (fieldIter) {
121 if (**fieldIter == fir::CoordinateOp::kDynamicIndex)
122 valuesIter++;
123 (*fieldIter)++;
124 } else {
125 valuesIter++;
126 }
127 return *this;
128 }
129
130 bool operator==(const iterator &rhs) const {
131 return base == rhs.base && fieldIter == rhs.fieldIter &&
132 valuesIter == rhs.valuesIter;
133 }
134
135 private:
136 const CoordinateIndicesAdaptor *base;
137 std::optional<llvm::ArrayRef<int32_t>::const_iterator> fieldIter;
138 llvm::detail::IterOfRange<const mlir::ValueRange> valuesIter;
139 };
140
141 iterator begin() const {
142 std::optional<llvm::ArrayRef<int32_t>::const_iterator> fieldIter;
143 if (fieldIndices)
144 fieldIter = fieldIndices.asArrayRef().begin();
145 return iterator(this, fieldIter, values.begin());
146 }
147
148 iterator end() const {
149 std::optional<llvm::ArrayRef<int32_t>::const_iterator> fieldIter;
150 if (fieldIndices)
151 fieldIter = fieldIndices.asArrayRef().end();
152 return iterator(this, fieldIter, values.end());
153 }
154
155private:
156 mlir::DenseI32ArrayAttr fieldIndices;
157 mlir::ValueRange values;
158};
159
164
167bool mayBeAbsentBox(mlir::Value val);
168
169} // namespace fir
170
171#endif // FORTRAN_OPTIMIZER_DIALECT_FIROPS_H
Definition FIROps.h:80
Definition FIRAttr.h:151
Definition FIRType.h:106
Definition OpenACC.h:20
Definition AbstractConverter.h:37
bool mayBeAbsentBox(mlir::Value val)
Definition FIROps.cpp:272
Model operations which affect global debugging information.
Definition FIROps.h:52
Runtime checks can terminate execution, but do not access user memory.
Definition FIROps.h:59
Definition FIROps.h:160
Model operations which read from/write to volatile memory.
Definition FIROps.h:66