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 isDeviceAccessible(mlir::Operation *op) const;
74 bool isInDeviceMemory(mlir::Operation *op) const;
75 bool isCompilerGenerated(mlir::Operation *op) const;
76};
77
78template <typename Op>
80 : public mlir::acc::IndirectGlobalAccessOpInterface::ExternalModel<
81 IndirectGlobalAccessModel<Op>, Op> {
82 void getReferencedSymbols(mlir::Operation *op,
84 mlir::SymbolTable *symbolTable) const;
85};
86
91template <typename Op>
93 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
94 OutlineRematerializationModel<Op>, Op> {
95 bool isRematerializationCandidate(mlir::Operation *op) const { return true; }
96};
97
98template <>
100 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
101 OutlineRematerializationModel<fir::ConvertOp>, fir::ConvertOp> {
102 bool isRematerializationCandidate(mlir::Operation *op) const;
103};
104
112template <typename Op>
114 : public mlir::acc::OutlineIdentityOperandOpInterface::ExternalModel<
115 OutlineIdentityOperandDeclareModel<Op>, Op> {
116 void dropOutlinedIdentityOperands(mlir::Operation *op) const;
117};
118
122template <typename Op>
124 : public mlir::acc::OffloadRegionOpInterface::ExternalModel<
125 OffloadRegionModel<Op>, Op> {
126 mlir::Region &getOffloadRegion(mlir::Operation *op) const {
127 return mlir::cast<Op>(op).getRegion();
128 }
129};
130
135template <typename Op>
136struct OperationMoveModel : public fir::OperationMoveOpInterface::ExternalModel<
137 OperationMoveModel<Op>, Op> {
138 // Returns true if it is allowed to move the given 'candidate'
139 // operation from the 'descendant' operation into 'op' operation.
140 // If 'candidate' is nullptr, then the caller is querying whether
141 // any operation from any descendant can be moved into 'op' operation.
142 bool canMoveFromDescendant(mlir::Operation *op, mlir::Operation *descendant,
143 mlir::Operation *candidate) const;
144
145 // Returns true if it is allowed to move the given 'candidate'
146 // operation out of 'op' operation. If 'candidate' is nullptr,
147 // then the caller is querying whether any operation can be moved
148 // out of 'op' operation.
149 bool canMoveOutOf(mlir::Operation *op, mlir::Operation *candidate) const;
150};
151
152namespace detail {
153void verifyFortranObjectViewResult(mlir::Operation *op,
154 mlir::OpResult resultView);
155}
156
158template <typename Op>
160 : public fir::FortranObjectViewOpInterface::ExternalModel<
161 AccFortranObjectViewModel<Op>, Op> {
162 mlir::Value getViewSource(mlir::Operation *op,
163 mlir::OpResult resultView) const;
164 std::optional<std::int64_t> getViewOffset(mlir::Operation *op,
165 mlir::OpResult resultView) const {
166 detail::verifyFortranObjectViewResult(op, resultView);
167 return 0;
168 }
169};
170
171} // namespace fir::acc
172
173#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:161
Definition FIROpenACCOpsInterfaces.h:63
Definition FIROpenACCOpsInterfaces.h:69
Definition FIROpenACCOpsInterfaces.h:81
Definition FIROpenACCOpsInterfaces.h:125
Definition FIROpenACCOpsInterfaces.h:137
Definition FIROpenACCOpsInterfaces.h:115
Definition FIROpenACCOpsInterfaces.h:94
Definition FIROpenACCOpsInterfaces.h:37