FLANG
FIROpenACCOpsInterfaces.h
1//===- FIROpenACCOpsInterfaces.h --------------------------------*- 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// This file contains external operation interfaces for FIR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FLANG_OPTIMIZER_OPENACC_FIROPENACC_OPS_INTERFACES_H_
14#define FLANG_OPTIMIZER_OPENACC_FIROPENACC_OPS_INTERFACES_H_
15
16#include "flang/Optimizer/Dialect/FIROperationMoveOpInterface.h"
17#include "flang/Optimizer/Dialect/FIROps.h"
18#include "flang/Optimizer/Dialect/FortranVariableInterface.h"
19#include "mlir/Dialect/OpenACC/OpenACC.h"
20
21namespace fir {
22class AddrOfOp;
23class DeclareOp;
24class GlobalOp;
25} // namespace fir
26
27namespace hlfir {
28class DeclareOp;
29class DesignateOp;
30} // namespace hlfir
31
32namespace fir::acc {
33
34template <typename Op>
36 : public mlir::acc::PartialEntityAccessOpInterface::ExternalModel<
37 PartialEntityAccessModel<Op>, Op> {
38 mlir::Value getBaseEntity(mlir::Operation *op) const;
39
40 // Default implementation - returns false (partial view)
41 bool isCompleteView(mlir::Operation *op) const { return false; }
42};
43
44// Full specializations for declare operations
45template <>
46struct PartialEntityAccessModel<fir::DeclareOp>
47 : public mlir::acc::PartialEntityAccessOpInterface::ExternalModel<
48 PartialEntityAccessModel<fir::DeclareOp>, fir::DeclareOp> {
49 mlir::Value getBaseEntity(mlir::Operation *op) const;
50 bool isCompleteView(mlir::Operation *op) const;
51};
52
53template <>
54struct PartialEntityAccessModel<hlfir::DeclareOp>
55 : public mlir::acc::PartialEntityAccessOpInterface::ExternalModel<
56 PartialEntityAccessModel<hlfir::DeclareOp>, hlfir::DeclareOp> {
57 mlir::Value getBaseEntity(mlir::Operation *op) const;
58 bool isCompleteView(mlir::Operation *op) const;
59};
60
63 : public mlir::acc::StoreLikeOpInterface::ExternalModel<StoreLikeModel,
64 fir::StoreOp> {
65 void
66 getStoredValues(mlir::Operation *op,
68 auto store = mlir::cast<fir::StoreOp>(op);
69 stored.push_back(
70 {{mlir::acc::StoredSourceKind::Operand, &store.getValueMutable(), {}},
71 {mlir::acc::StoreLocation{&store.getMemrefMutable()}}});
72 }
73};
74
76 : public mlir::acc::AddressOfGlobalOpInterface::ExternalModel<
77 AddressOfGlobalModel, fir::AddrOfOp> {
78 mlir::SymbolRefAttr getSymbol(mlir::Operation *op) const;
79};
80
82 : public mlir::acc::GlobalVariableOpInterface::ExternalModel<
83 GlobalVariableModel, fir::GlobalOp> {
84 bool isConstant(mlir::Operation *op) const;
85 bool hasInitializer(mlir::Operation *op) const;
86 mlir::Region *getInitRegion(mlir::Operation *op) const;
87 bool isDeviceAccessible(mlir::Operation *op) const;
88 bool isInDeviceMemory(mlir::Operation *op) const;
89 bool isCompilerGenerated(mlir::Operation *op) const;
90 bool hasLocalLinkage(mlir::Operation *op) const;
91};
92
93template <typename Op>
95 : public mlir::acc::IndirectGlobalAccessOpInterface::ExternalModel<
96 IndirectGlobalAccessModel<Op>, Op> {
97 void getReferencedSymbols(mlir::Operation *op,
99 mlir::SymbolTable *symbolTable) const;
100};
101
106template <typename Op>
108 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
109 OutlineRematerializationModel<Op>, Op> {
110 bool isRematerializationCandidate(mlir::Operation *op) const { return true; }
111};
112
113template <>
115 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
116 OutlineRematerializationModel<fir::ConvertOp>, fir::ConvertOp> {
117 bool isRematerializationCandidate(mlir::Operation *op) const;
118};
119
127template <typename Op>
129 : public mlir::acc::OutlineIdentityOperandOpInterface::ExternalModel<
130 OutlineIdentityOperandDeclareModel<Op>, Op> {
131 void dropOutlinedIdentityOperands(mlir::Operation *op) const;
132};
133
137template <typename Op>
139 : public mlir::acc::OffloadRegionOpInterface::ExternalModel<
140 OffloadRegionModel<Op>, Op> {
141 mlir::Region &getOffloadRegion(mlir::Operation *op) const {
142 return mlir::cast<Op>(op).getRegion();
143 }
144};
145
150template <typename Op>
151struct OperationMoveModel : public fir::OperationMoveOpInterface::ExternalModel<
152 OperationMoveModel<Op>, Op> {
153 // Returns true if it is allowed to move the given 'candidate'
154 // operation from the 'descendant' operation into 'op' operation.
155 // If 'candidate' is nullptr, then the caller is querying whether
156 // any operation from any descendant can be moved into 'op' operation.
157 bool canMoveFromDescendant(mlir::Operation *op, mlir::Operation *descendant,
158 mlir::Operation *candidate) const;
159
160 // Returns true if it is allowed to move the given 'candidate'
161 // operation out of 'op' operation. If 'candidate' is nullptr,
162 // then the caller is querying whether any operation can be moved
163 // out of 'op' operation.
164 bool canMoveOutOf(mlir::Operation *op, mlir::Operation *candidate) const;
165};
166
167namespace detail {
168void verifyFortranObjectViewResult(mlir::Operation *op,
169 mlir::OpResult resultView);
170}
171
173template <typename Op>
175 : public fir::FortranObjectViewOpInterface::ExternalModel<
176 AccFortranObjectViewModel<Op>, Op> {
177 mlir::Value getViewSource(mlir::Operation *op,
178 mlir::OpResult resultView) const;
179 std::optional<std::int64_t> getViewOffset(mlir::Operation *op,
180 mlir::OpResult resultView) const {
181 detail::verifyFortranObjectViewResult(op, resultView);
182 return 0;
183 }
184};
185
186} // namespace fir::acc
187
188#endif // FLANG_OPTIMIZER_OPENACC_FIROPENACC_OPS_INTERFACES_H_
Definition OpenACC.h:22
Definition AbstractConverter.h:37
External model for acc ops whose result is a zero-offset view of an operand.
Definition FIROpenACCOpsInterfaces.h:176
Definition FIROpenACCOpsInterfaces.h:77
Definition FIROpenACCOpsInterfaces.h:83
Definition FIROpenACCOpsInterfaces.h:96
Definition FIROpenACCOpsInterfaces.h:140
Definition FIROpenACCOpsInterfaces.h:152
Definition FIROpenACCOpsInterfaces.h:130
Definition FIROpenACCOpsInterfaces.h:109
Definition FIROpenACCOpsInterfaces.h:37
fir.store writes its value operand through its memory operand.
Definition FIROpenACCOpsInterfaces.h:64