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/FortranVariableInterface.h"
18#include "mlir/Dialect/OpenACC/OpenACC.h"
19
20namespace fir {
21class AddrOfOp;
22class DeclareOp;
23class GlobalOp;
24} // namespace fir
25
26namespace hlfir {
27class DeclareOp;
28class DesignateOp;
29} // namespace hlfir
30
31namespace fir::acc {
32
33template <typename Op>
35 : public mlir::acc::PartialEntityAccessOpInterface::ExternalModel<
36 PartialEntityAccessModel<Op>, Op> {
37 mlir::Value getBaseEntity(mlir::Operation *op) const;
38
39 // Default implementation - returns false (partial view)
40 bool isCompleteView(mlir::Operation *op) const { return false; }
41};
42
43// Full specializations for declare operations
44template <>
45struct PartialEntityAccessModel<fir::DeclareOp>
46 : public mlir::acc::PartialEntityAccessOpInterface::ExternalModel<
47 PartialEntityAccessModel<fir::DeclareOp>, fir::DeclareOp> {
48 mlir::Value getBaseEntity(mlir::Operation *op) const;
49 bool isCompleteView(mlir::Operation *op) const;
50};
51
52template <>
53struct PartialEntityAccessModel<hlfir::DeclareOp>
54 : public mlir::acc::PartialEntityAccessOpInterface::ExternalModel<
55 PartialEntityAccessModel<hlfir::DeclareOp>, hlfir::DeclareOp> {
56 mlir::Value getBaseEntity(mlir::Operation *op) const;
57 bool isCompleteView(mlir::Operation *op) const;
58};
59
61 : public mlir::acc::AddressOfGlobalOpInterface::ExternalModel<
62 AddressOfGlobalModel, fir::AddrOfOp> {
63 mlir::SymbolRefAttr getSymbol(mlir::Operation *op) const;
64};
65
67 : public mlir::acc::GlobalVariableOpInterface::ExternalModel<
68 GlobalVariableModel, fir::GlobalOp> {
69 bool isConstant(mlir::Operation *op) const;
70 mlir::Region *getInitRegion(mlir::Operation *op) const;
71 bool isDeviceData(mlir::Operation *op) const;
72};
73
74template <typename Op>
76 : public mlir::acc::IndirectGlobalAccessOpInterface::ExternalModel<
77 IndirectGlobalAccessModel<Op>, Op> {
78 void getReferencedSymbols(mlir::Operation *op,
79 llvm::SmallVectorImpl<mlir::SymbolRefAttr> &symbols,
80 mlir::SymbolTable *symbolTable) const;
81};
82
87template <typename Op>
89 : public mlir::acc::OutlineRematerializationOpInterface::ExternalModel<
90 OutlineRematerializationModel<Op>, Op> {};
91
95template <typename Op>
97 : public mlir::acc::OffloadRegionOpInterface::ExternalModel<
98 OffloadRegionModel<Op>, Op> {
99 mlir::Region &getOffloadRegion(mlir::Operation *op) const {
100 return mlir::cast<Op>(op).getRegion();
101 }
102};
103
108template <typename Op>
109struct OperationMoveModel : public fir::OperationMoveOpInterface::ExternalModel<
110 OperationMoveModel<Op>, Op> {
111 // Returns true if it is allowed to move the given 'candidate'
112 // operation from the 'descendant' operation into 'op' operation.
113 // If 'candidate' is nullptr, then the caller is querying whether
114 // any operation from any descendant can be moved into 'op' operation.
115 bool canMoveFromDescendant(mlir::Operation *op, mlir::Operation *descendant,
116 mlir::Operation *candidate) const;
117
118 // Returns true if it is allowed to move the given 'candidate'
119 // operation out of 'op' operation. If 'candidate' is nullptr,
120 // then the caller is querying whether any operation can be moved
121 // out of 'op' operation.
122 bool canMoveOutOf(mlir::Operation *op, mlir::Operation *candidate) const;
123};
124
126 : public fir::FortranObjectViewOpInterface::ExternalModel<
127 ReductionInitOpFortranObjectViewModel, mlir::acc::ReductionInitOp> {
128 mlir::Value getViewSource(mlir::Operation *op,
129 mlir::OpResult resultView) const;
130 std::optional<std::int64_t> getViewOffset(mlir::Operation *op,
131 mlir::OpResult resultView) const;
132};
133
134} // namespace fir::acc
135
136#endif // FLANG_OPTIMIZER_OPENACC_FIROPENACC_OPS_INTERFACES_H_
Definition AbstractConverter.h:37
Definition FIROpenACCOpsInterfaces.h:62
Definition FIROpenACCOpsInterfaces.h:68
Definition FIROpenACCOpsInterfaces.h:77
Definition FIROpenACCOpsInterfaces.h:98
Definition FIROpenACCOpsInterfaces.h:110
Definition FIROpenACCOpsInterfaces.h:90
Definition FIROpenACCOpsInterfaces.h:36
Definition FIROpenACCOpsInterfaces.h:127