MLIR 23.0.0git
OpenACC.h
Go to the documentation of this file.
1//===- OpenACC.h - MLIR OpenACC Dialect -------------------------*- C++ -*-===//
2//
3// Part of the MLIR 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 declares the OpenACC dialect in MLIR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_OPENACC_OPENACC_H_
14#define MLIR_DIALECT_OPENACC_OPENACC_H_
15
18#include "mlir/IR/Dialect.h"
21#include "mlir/IR/SymbolTable.h"
22
26#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc"
27#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc"
28#include "mlir/Dialect/OpenACC/OpenACCOpsInterfaces.h.inc"
29#include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.h.inc"
31#include "mlir/IR/Value.h"
35#include <variant>
36
37#define GET_TYPEDEF_CLASSES
38#include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc"
39
40#define GET_ATTRDEF_CLASSES
41#include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"
42
44
45#define GET_OP_CLASSES
46#include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
47
48#define ACC_DATA_ENTRY_OPS \
49 mlir::acc::CopyinOp, mlir::acc::CreateOp, mlir::acc::PresentOp, \
50 mlir::acc::NoCreateOp, mlir::acc::AttachOp, mlir::acc::DevicePtrOp, \
51 mlir::acc::GetDevicePtrOp, mlir::acc::PrivateOp, \
52 mlir::acc::FirstprivateOp, mlir::acc::FirstprivateMapInitialOp, \
53 mlir::acc::UpdateDeviceOp, mlir::acc::UseDeviceOp, \
54 mlir::acc::ReductionOp, mlir::acc::DeclareDeviceResidentOp, \
55 mlir::acc::DeclareLinkOp, mlir::acc::CacheOp
56#define ACC_DATA_EXIT_OPS \
57 mlir::acc::CopyoutOp, mlir::acc::DeleteOp, mlir::acc::DetachOp, \
58 mlir::acc::UpdateHostOp
59#define ACC_DATA_CLAUSE_OPS ACC_DATA_ENTRY_OPS, ACC_DATA_EXIT_OPS
60#define ACC_COMPUTE_CONSTRUCT_OPS \
61 mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
62#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
63 ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
64#define ACC_DATA_CONSTRUCT_STRUCTURED_OPS \
65 mlir::acc::DataOp, mlir::acc::DeclareOp, mlir::acc::HostDataOp
66#define ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS \
67 mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, mlir::acc::UpdateOp, \
68 mlir::acc::DeclareEnterOp, mlir::acc::DeclareExitOp
69#define ACC_DATA_CONSTRUCT_OPS \
70 ACC_DATA_CONSTRUCT_STRUCTURED_OPS, ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS
71#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
72 ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
73#define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
74 ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
75
76namespace mlir {
77namespace acc {
78
79/// Enumeration used to encode the execution mapping on a loop construct.
80/// They refer directly to the OpenACC 3.3 standard:
81/// 2.9.2. gang
82/// 2.9.3. worker
83/// 2.9.4. vector
84///
85/// Value can be combined bitwise to reflect the mapping applied to the
86/// construct. e.g. `acc.loop gang vector`, the `gang` and `vector` could be
87/// combined and the final mapping value would be 5 (4 | 1).
88enum OpenACCExecMapping { NONE = 0, VECTOR = 1, WORKER = 2, GANG = 4 };
89
90/// Used to obtain the `var` from a data clause operation.
91/// Returns empty value if not a data clause operation or is a data exit
92/// operation with no `var`.
93mlir::Value getVar(mlir::Operation *accDataClauseOp);
94
95/// Used to obtain the `var` from a data clause operation if it implements
96/// `PointerLikeType`.
98getVarPtr(mlir::Operation *accDataClauseOp);
99
100/// Used to obtains the `varType` from a data clause operation which records
101/// the type of variable. When `var` is `PointerLikeType`, this returns
102/// the type of the pointer target.
103mlir::Type getVarType(mlir::Operation *accDataClauseOp);
104
105/// Used to obtain the `accVar` from a data clause operation.
106/// When a data entry operation, it obtains its result `accVar` value.
107/// If a data exit operation, it obtains its operand `accVar` value.
108/// Returns empty value if not a data clause operation.
109mlir::Value getAccVar(mlir::Operation *accDataClauseOp);
110
111/// Used to obtain the `accVar` from a data clause operation if it implements
112/// `PointerLikeType`.
114getAccPtr(mlir::Operation *accDataClauseOp);
115
116/// Used to obtain the `varPtrPtr` from a data clause operation.
117/// Returns empty value if not a data clause operation.
119
120/// Used to obtain `bounds` from an acc data clause operation.
121/// Returns an empty vector if there are no bounds.
123
124/// Used to obtain `async` operands from an acc data clause operation.
125/// Returns an empty vector if there are no such operands.
127getAsyncOperands(mlir::Operation *accDataClauseOp);
128
129/// Returns an array of acc:DeviceTypeAttr attributes attached to
130/// an acc data clause operation, that correspond to the device types
131/// associated with the async clauses with an async-value.
132mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp);
133
134/// Returns an array of acc:DeviceTypeAttr attributes attached to
135/// an acc data clause operation, that correspond to the device types
136/// associated with the async clauses without an async-value.
137mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp);
138
139/// Used to obtain the `name` from an acc operation.
140std::optional<llvm::StringRef> getVarName(mlir::Operation *accOp);
141
142/// Used to obtain the `dataClause` from a data entry operation.
143/// Returns empty optional if not a data entry operation.
144std::optional<mlir::acc::DataClause>
145getDataClause(mlir::Operation *accDataEntryOp);
146
147/// Used to find out whether data operation is implicit.
148/// Returns false if not a data operation or if it is a data operation without
149/// implicit flag.
150bool getImplicitFlag(mlir::Operation *accDataEntryOp);
151
152/// Used to get an immutable range iterating over the data operands.
154
155/// Used to get a mutable range iterating over the data operands.
157
158/// Used to get the recipe attribute from a data clause operation.
159mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp);
160
161/// Used to check whether the provided `type` implements the `PointerLikeType`
162/// interface.
163inline bool isPointerLikeType(mlir::Type type) {
164 return mlir::isa<mlir::acc::PointerLikeType>(type);
165}
166
167/// Used to check whether the provided `type` implements the `MappableType`
168/// interface.
169inline bool isMappableType(mlir::Type type) {
170 return mlir::isa<mlir::acc::MappableType>(type);
171}
172
173/// Used to obtain the attribute name for declare.
174static constexpr StringLiteral getDeclareAttrName() {
175 return StringLiteral("acc.declare");
176}
177
178static constexpr StringLiteral getDeclareActionAttrName() {
179 return StringLiteral("acc.declare_action");
180}
181
182static constexpr StringLiteral getRoutineInfoAttrName() {
183 return RoutineInfoAttr::name;
184}
185
186static constexpr StringLiteral getSpecializedRoutineAttrName() {
187 return SpecializedRoutineAttr::name;
188}
189
190/// Used to check whether the current operation is marked with
191/// `acc routine`. The operation passed in should be a function.
193 return op && op->hasAttr(mlir::acc::getRoutineInfoAttrName());
194}
195
196/// Used to check whether this is a specialized accelerator version of
197/// `acc routine` function.
201
202static constexpr StringLiteral getFromDefaultClauseAttrName() {
203 return StringLiteral("acc.from_default");
204}
205
206static constexpr StringLiteral getVarNameAttrName() {
207 return VarNameAttr::name;
208}
209
210static constexpr StringLiteral getCombinedConstructsAttrName() {
211 return CombinedConstructsTypeAttr::name;
212}
213
215 : public mlir::SideEffects::Resource::Base<RuntimeCounters> {
216 mlir::StringRef getName() const final { return "AccRuntimeCounters"; }
217 bool isAddressable() const override { return false; }
218};
219
221 : public mlir::SideEffects::Resource::Base<ConstructResource> {
222 mlir::StringRef getName() const final { return "AccConstructResource"; }
223 bool isAddressable() const override { return false; }
224};
225
227 : public mlir::SideEffects::Resource::Base<CurrentDeviceIdResource> {
228 mlir::StringRef getName() const final { return "AccCurrentDeviceIdResource"; }
229 bool isAddressable() const override { return false; }
230};
231
232} // namespace acc
233} // namespace mlir
234
235#endif // MLIR_DIALECT_OPENACC_OPENACC_H_
This class provides a mutable adaptor for a range of operands.
Definition ValueRange.h:119
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
bool hasAttr(StringAttr name)
Return true if the operation has an attribute with the provided name, false otherwise.
Definition Operation.h:586
This base class is used for derived effects that are non-parametric.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:389
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
static constexpr StringLiteral getFromDefaultClauseAttrName()
Definition OpenACC.h:202
mlir::Value getAccVar(mlir::Operation *accDataClauseOp)
Used to obtain the accVar from a data clause operation.
Definition OpenACC.cpp:5098
mlir::Value getVar(mlir::Operation *accDataClauseOp)
Used to obtain the var from a data clause operation.
Definition OpenACC.cpp:5067
bool isAccRoutine(mlir::Operation *op)
Used to check whether the current operation is marked with acc routine.
Definition OpenACC.h:192
mlir::TypedValue< mlir::acc::PointerLikeType > getAccPtr(mlir::Operation *accDataClauseOp)
Used to obtain the accVar from a data clause operation if it implements PointerLikeType.
Definition OpenACC.cpp:5086
static constexpr StringLiteral getSpecializedRoutineAttrName()
Definition OpenACC.h:186
std::optional< mlir::acc::DataClause > getDataClause(mlir::Operation *accDataEntryOp)
Used to obtain the dataClause from a data entry operation.
Definition OpenACC.cpp:5171
bool isPointerLikeType(mlir::Type type)
Used to check whether the provided type implements the PointerLikeType interface.
Definition OpenACC.h:163
mlir::MutableOperandRange getMutableDataOperands(mlir::Operation *accOp)
Used to get a mutable range iterating over the data operands.
Definition OpenACC.cpp:5199
mlir::SmallVector< mlir::Value > getBounds(mlir::Operation *accDataClauseOp)
Used to obtain bounds from an acc data clause operation.
Definition OpenACC.cpp:5116
OpenACCExecMapping
Enumeration used to encode the execution mapping on a loop construct.
Definition OpenACC.h:88
bool isSpecializedAccRoutine(mlir::Operation *op)
Used to check whether this is a specialized accelerator version of acc routine function.
Definition OpenACC.h:198
mlir::ValueRange getDataOperands(mlir::Operation *accOp)
Used to get an immutable range iterating over the data operands.
Definition OpenACC.cpp:5189
std::optional< llvm::StringRef > getVarName(mlir::Operation *accOp)
Used to obtain the name from an acc operation.
Definition OpenACC.cpp:5160
static constexpr StringLiteral getRoutineInfoAttrName()
Definition OpenACC.h:182
bool getImplicitFlag(mlir::Operation *accDataEntryOp)
Used to find out whether data operation is implicit.
Definition OpenACC.cpp:5181
mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp)
Used to get the recipe attribute from a data clause operation.
Definition OpenACC.cpp:5208
mlir::SmallVector< mlir::Value > getAsyncOperands(mlir::Operation *accDataClauseOp)
Used to obtain async operands from an acc data clause operation.
Definition OpenACC.cpp:5131
bool isMappableType(mlir::Type type)
Used to check whether the provided type implements the MappableType interface.
Definition OpenACC.h:169
static constexpr StringLiteral getCombinedConstructsAttrName()
Definition OpenACC.h:210
mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp)
Used to obtain the varPtrPtr from a data clause operation.
Definition OpenACC.cpp:5106
static constexpr StringLiteral getVarNameAttrName()
Definition OpenACC.h:206
mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:5153
static constexpr StringLiteral getDeclareAttrName()
Used to obtain the attribute name for declare.
Definition OpenACC.h:174
static constexpr StringLiteral getDeclareActionAttrName()
Definition OpenACC.h:178
mlir::Type getVarType(mlir::Operation *accDataClauseOp)
Used to obtains the varType from a data clause operation which records the type of variable.
Definition OpenACC.cpp:5075
mlir::TypedValue< mlir::acc::PointerLikeType > getVarPtr(mlir::Operation *accDataClauseOp)
Used to obtain the var from a data clause operation if it implements PointerLikeType.
Definition OpenACC.cpp:5053
mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:5145
Include the generated interface declarations.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
Definition Value.h:494
mlir::StringRef getName() const final
Return a string name of the resource.
Definition OpenACC.h:222
bool isAddressable() const override
Returns true if this resource is addressable (effects on it can alias pointer-based memory).
Definition OpenACC.h:223
bool isAddressable() const override
Returns true if this resource is addressable (effects on it can alias pointer-based memory).
Definition OpenACC.h:229
mlir::StringRef getName() const final
Return a string name of the resource.
Definition OpenACC.h:228
mlir::StringRef getName() const final
Return a string name of the resource.
Definition OpenACC.h:216
bool isAddressable() const override
Returns true if this resource is addressable (effects on it can alias pointer-based memory).
Definition OpenACC.h:217