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 mlir::Region *getInitRegion(mlir::Operation *op) const;
72 bool isDeviceData(mlir::Operation *op) const;
73};
74
75template <typename Op>
77 : public mlir::acc::IndirectGlobalAccessOpInterface::ExternalModel<
78 IndirectGlobalAccessModel<Op>, Op> {
79 void getReferencedSymbols(mlir::Operation *op,
80 llvm::SmallVectorImpl<mlir::SymbolRefAttr> &symbols,
81 mlir::SymbolTable *symbolTable) const;
82};
83
88template <typename Op>
90 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
91 OutlineRematerializationModel<Op>, Op> {
92 bool isRematerializationCandidate(mlir::Operation *op) const { return true; }
93};
94
95template <>
97 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
98 OutlineRematerializationModel<fir::ConvertOp>, fir::ConvertOp> {
99 bool isRematerializationCandidate(mlir::Operation *op) const;
100};
101
105template <typename Op>
107 : public mlir::acc::OffloadRegionOpInterface::ExternalModel<
108 OffloadRegionModel<Op>, Op> {
109 mlir::Region &getOffloadRegion(mlir::Operation *op) const {
110 return mlir::cast<Op>(op).getRegion();
111 }
112};
113
118template <typename Op>
119struct OperationMoveModel : public fir::OperationMoveOpInterface::ExternalModel<
120 OperationMoveModel<Op>, Op> {
121 // Returns true if it is allowed to move the given 'candidate'
122 // operation from the 'descendant' operation into 'op' operation.
123 // If 'candidate' is nullptr, then the caller is querying whether
124 // any operation from any descendant can be moved into 'op' operation.
125 bool canMoveFromDescendant(mlir::Operation *op, mlir::Operation *descendant,
126 mlir::Operation *candidate) const;
127
128 // Returns true if it is allowed to move the given 'candidate'
129 // operation out of 'op' operation. If 'candidate' is nullptr,
130 // then the caller is querying whether any operation can be moved
131 // out of 'op' operation.
132 bool canMoveOutOf(mlir::Operation *op, mlir::Operation *candidate) const;
133};
134
136 : public fir::FortranObjectViewOpInterface::ExternalModel<
137 ReductionInitOpFortranObjectViewModel, mlir::acc::ReductionInitOp> {
138 mlir::Value getViewSource(mlir::Operation *op,
139 mlir::OpResult resultView) const;
140 std::optional<std::int64_t> getViewOffset(mlir::Operation *op,
141 mlir::OpResult resultView) const;
142};
143
144} // namespace fir::acc
145
146#endif // FLANG_OPTIMIZER_OPENACC_FIROPENACC_OPS_INTERFACES_H_
Definition AbstractConverter.h:37
Definition FIROpenACCOpsInterfaces.h:63
Definition FIROpenACCOpsInterfaces.h:69
Definition FIROpenACCOpsInterfaces.h:78
Definition FIROpenACCOpsInterfaces.h:108
Definition FIROpenACCOpsInterfaces.h:120
Definition FIROpenACCOpsInterfaces.h:91
Definition FIROpenACCOpsInterfaces.h:37
Definition FIROpenACCOpsInterfaces.h:137