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
62 : public mlir::acc::AddressOfGlobalOpInterface::ExternalModel<
63 AddressOfGlobalModel, fir::AddrOfOp> {
64 mlir::SymbolRefAttr getSymbol(mlir::Operation *op) const;
65};
66
68 : public mlir::acc::GlobalVariableOpInterface::ExternalModel<
69 GlobalVariableModel, fir::GlobalOp> {
70 bool isConstant(mlir::Operation *op) const;
71 bool hasInitializer(mlir::Operation *op) const;
72 mlir::Region *getInitRegion(mlir::Operation *op) const;
73 bool isDeviceData(mlir::Operation *op) const;
74};
75
76template <typename Op>
78 : public mlir::acc::IndirectGlobalAccessOpInterface::ExternalModel<
79 IndirectGlobalAccessModel<Op>, Op> {
80 void getReferencedSymbols(mlir::Operation *op,
81 llvm::SmallVectorImpl<mlir::SymbolRefAttr> &symbols,
82 mlir::SymbolTable *symbolTable) const;
83};
84
89template <typename Op>
91 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
92 OutlineRematerializationModel<Op>, Op> {
93 bool isRematerializationCandidate(mlir::Operation *op) const { return true; }
94};
95
96template <>
98 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
99 OutlineRematerializationModel<fir::ConvertOp>, fir::ConvertOp> {
100 bool isRematerializationCandidate(mlir::Operation *op) const;
101};
102
110template <typename Op>
112 : public mlir::acc::OutlineIdentityOperandOpInterface::ExternalModel<
113 OutlineIdentityOperandDeclareModel<Op>, Op> {
114 void dropOutlinedIdentityOperands(mlir::Operation *op) const;
115};
116
120template <typename Op>
122 : public mlir::acc::OffloadRegionOpInterface::ExternalModel<
123 OffloadRegionModel<Op>, Op> {
124 mlir::Region &getOffloadRegion(mlir::Operation *op) const {
125 return mlir::cast<Op>(op).getRegion();
126 }
127};
128
133template <typename Op>
134struct OperationMoveModel : public fir::OperationMoveOpInterface::ExternalModel<
135 OperationMoveModel<Op>, Op> {
136 // Returns true if it is allowed to move the given 'candidate'
137 // operation from the 'descendant' operation into 'op' operation.
138 // If 'candidate' is nullptr, then the caller is querying whether
139 // any operation from any descendant can be moved into 'op' operation.
140 bool canMoveFromDescendant(mlir::Operation *op, mlir::Operation *descendant,
141 mlir::Operation *candidate) const;
142
143 // Returns true if it is allowed to move the given 'candidate'
144 // operation out of 'op' operation. If 'candidate' is nullptr,
145 // then the caller is querying whether any operation can be moved
146 // out of 'op' operation.
147 bool canMoveOutOf(mlir::Operation *op, mlir::Operation *candidate) const;
148};
149
150namespace detail {
151void verifyFortranObjectViewResult(mlir::Operation *op,
152 mlir::OpResult resultView);
153}
154
156template <typename Op>
158 : public fir::FortranObjectViewOpInterface::ExternalModel<
159 AccFortranObjectViewModel<Op>, Op> {
160 mlir::Value getViewSource(mlir::Operation *op,
161 mlir::OpResult resultView) const;
162 std::optional<std::int64_t> getViewOffset(mlir::Operation *op,
163 mlir::OpResult resultView) const {
164 detail::verifyFortranObjectViewResult(op, resultView);
165 return 0;
166 }
167};
168
169} // namespace fir::acc
170
171#endif // FLANG_OPTIMIZER_OPENACC_FIROPENACC_OPS_INTERFACES_H_
Definition AbstractConverter.h:37
External model for acc ops whose result is a zero-offset view of an operand.
Definition FIROpenACCOpsInterfaces.h:159
Definition FIROpenACCOpsInterfaces.h:63
Definition FIROpenACCOpsInterfaces.h:69
Definition FIROpenACCOpsInterfaces.h:79
Definition FIROpenACCOpsInterfaces.h:123
Definition FIROpenACCOpsInterfaces.h:135
Definition FIROpenACCOpsInterfaces.h:113
Definition FIROpenACCOpsInterfaces.h:92
Definition FIROpenACCOpsInterfaces.h:37