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"
36#include <variant>
37
38#define GET_TYPEDEF_CLASSES
39#include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc"
40
41#define GET_ATTRDEF_CLASSES
42#include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"
43
45
46#define GET_OP_CLASSES
47#include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
48
49#define ACC_DATA_ENTRY_OPS \
50 mlir::acc::CopyinOp, mlir::acc::CreateOp, mlir::acc::PresentOp, \
51 mlir::acc::NoCreateOp, mlir::acc::AttachOp, mlir::acc::DevicePtrOp, \
52 mlir::acc::GetDevicePtrOp, mlir::acc::PrivateOp, \
53 mlir::acc::FirstprivateOp, mlir::acc::FirstprivateMapInitialOp, \
54 mlir::acc::UpdateDeviceOp, mlir::acc::UseDeviceOp, \
55 mlir::acc::ReductionOp, mlir::acc::DeclareDeviceResidentOp, \
56 mlir::acc::DeclareLinkOp, mlir::acc::CacheOp
57#define ACC_DATA_ENTRY_AND_INIT_OPS \
58 ACC_DATA_ENTRY_OPS, mlir::acc::ReductionInitOp
59#define ACC_DATA_EXIT_OPS \
60 mlir::acc::CopyoutOp, mlir::acc::DeleteOp, mlir::acc::DetachOp, \
61 mlir::acc::UpdateHostOp
62#define ACC_DATA_CLAUSE_OPS ACC_DATA_ENTRY_OPS, ACC_DATA_EXIT_OPS
63#define ACC_COMPUTE_CONSTRUCT_OPS \
64 mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
65#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
66 ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
67#define ACC_DATA_CONSTRUCT_STRUCTURED_OPS \
68 mlir::acc::DataOp, mlir::acc::DeclareOp, mlir::acc::HostDataOp
69#define ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS \
70 mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, mlir::acc::UpdateOp, \
71 mlir::acc::DeclareEnterOp, mlir::acc::DeclareExitOp
72#define ACC_DATA_CONSTRUCT_OPS \
73 ACC_DATA_CONSTRUCT_STRUCTURED_OPS, ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS
74#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
75 ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
76#define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
77 ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
78
79namespace mlir {
80namespace acc {
81
82/// Enumeration used to encode the execution mapping on a loop construct.
83/// They refer directly to the OpenACC 3.3 standard:
84/// 2.9.2. gang
85/// 2.9.3. worker
86/// 2.9.4. vector
87///
88/// Value can be combined bitwise to reflect the mapping applied to the
89/// construct. e.g. `acc.loop gang vector`, the `gang` and `vector` could be
90/// combined and the final mapping value would be 5 (4 | 1).
91enum OpenACCExecMapping { NONE = 0, VECTOR = 1, WORKER = 2, GANG = 4 };
92
93/// Used to obtain the `var` from a data clause operation.
94/// Returns empty value if not a data clause operation or is a data exit
95/// operation with no `var`.
96mlir::Value getVar(mlir::Operation *accDataClauseOp);
97
98/// Used to obtain the `var` from a data clause operation if it implements
99/// `PointerLikeType`.
101getVarPtr(mlir::Operation *accDataClauseOp);
102
103/// Used to obtains the `varType` from a data clause operation which records
104/// the type of variable. When `var` is `PointerLikeType`, this returns
105/// the type of the pointer target.
106mlir::Type getVarType(mlir::Operation *accDataClauseOp);
107
108/// Used to obtain the `accVar` from a data clause operation.
109/// When a data entry operation, it obtains its result `accVar` value.
110/// If a data exit operation, it obtains its operand `accVar` value.
111/// Returns empty value if not a data clause operation.
112mlir::Value getAccVar(mlir::Operation *accDataClauseOp);
113
114/// Used to obtain the `accVar` from a data clause operation if it implements
115/// `PointerLikeType`.
117getAccPtr(mlir::Operation *accDataClauseOp);
118
119/// Used to obtain the `varPtrPtr` from a data clause operation.
120/// Returns empty value if not a data clause operation.
122
123/// Used to obtain `bounds` from an acc data clause operation.
124/// Returns an empty vector if there are no bounds.
126
127/// Used to obtain `async` operands from an acc data clause operation.
128/// Returns an empty vector if there are no such operands.
130getAsyncOperands(mlir::Operation *accDataClauseOp);
131
132/// Returns an array of acc:DeviceTypeAttr attributes attached to
133/// an acc data clause operation, that correspond to the device types
134/// associated with the async clauses with an async-value.
135mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp);
136
137/// Returns an array of acc:DeviceTypeAttr attributes attached to
138/// an acc data clause operation, that correspond to the device types
139/// associated with the async clauses without an async-value.
140mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp);
141
142/// Used to obtain the `name` from an acc operation.
143std::optional<llvm::StringRef> getVarName(mlir::Operation *accOp);
144
145/// Used to obtain the `dataClause` from a data entry operation.
146/// Returns empty optional if not a data entry operation.
147std::optional<mlir::acc::DataClause>
148getDataClause(mlir::Operation *accDataEntryOp);
149
150/// Used to find out whether data operation is implicit.
151/// Returns false if not a data operation or if it is a data operation without
152/// implicit flag.
153bool getImplicitFlag(mlir::Operation *accDataEntryOp);
154
155/// Used to get an immutable range iterating over the data operands.
157
158/// Used to get a mutable range iterating over the data operands.
160
161/// Used to get the recipe attribute from a data clause operation.
162mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp);
163
164/// Used to check whether the provided `type` implements the `PointerLikeType`
165/// interface.
166inline bool isPointerLikeType(mlir::Type type) {
167 return mlir::isa<mlir::acc::PointerLikeType>(type);
168}
169
170/// Used to check whether the provided `type` implements the `MappableType`
171/// interface.
172inline bool isMappableType(mlir::Type type) {
173 return mlir::isa<mlir::acc::MappableType>(type);
174}
175
176/// Used to obtain the attribute name for declare.
177static constexpr StringLiteral getDeclareAttrName() {
178 return StringLiteral("acc.declare");
179}
180
181static constexpr StringLiteral getDeclareActionAttrName() {
182 return StringLiteral("acc.declare_action");
183}
184
185static constexpr StringLiteral getRoutineInfoAttrName() {
186 return RoutineInfoAttr::name;
187}
188
189static constexpr StringLiteral getSpecializedRoutineAttrName() {
190 return SpecializedRoutineAttr::name;
191}
192
193/// Used to check whether the current operation is marked with
194/// `acc routine`. The operation passed in should be a function.
196 return op && op->hasAttr(mlir::acc::getRoutineInfoAttrName());
197}
198
199/// Used to check whether this is a specialized accelerator version of
200/// `acc routine` function.
204
205static constexpr StringLiteral getFromDefaultClauseAttrName() {
206 return StringLiteral("acc.from_default");
207}
208
209/// Name for an attribute attached to a loop indicating the number of loops
210/// collapsed to create that loop
211static constexpr StringLiteral getCollapseCountAttrName() {
212 return StringLiteral("acc.collapse_count");
213}
214
215static constexpr StringLiteral getVarNameAttrName() {
216 return VarNameAttr::name;
217}
218
219static constexpr StringLiteral getCombinedConstructsAttrName() {
220 return CombinedConstructsTypeAttr::name;
221}
222
224 : public mlir::SideEffects::Resource::Base<RuntimeCounters> {
225 mlir::StringRef getName() const final { return "AccRuntimeCounters"; }
226 bool isAddressable() const override { return false; }
227};
228
230 : public mlir::SideEffects::Resource::Base<ConstructResource> {
231 mlir::StringRef getName() const final { return "AccConstructResource"; }
232 bool isAddressable() const override { return false; }
233};
234
236 : public mlir::SideEffects::Resource::Base<CurrentDeviceIdResource> {
237 mlir::StringRef getName() const final { return "AccCurrentDeviceIdResource"; }
238 bool isAddressable() const override { return false; }
239};
240
241} // namespace acc
242} // namespace mlir
243
244#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:87
bool hasAttr(StringAttr name)
Return true if the operation has an attribute with the provided name, false otherwise.
Definition Operation.h:585
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:205
mlir::Value getAccVar(mlir::Operation *accDataClauseOp)
Used to obtain the accVar from a data clause operation.
Definition OpenACC.cpp:5248
mlir::Value getVar(mlir::Operation *accDataClauseOp)
Used to obtain the var from a data clause operation.
Definition OpenACC.cpp:5217
bool isAccRoutine(mlir::Operation *op)
Used to check whether the current operation is marked with acc routine.
Definition OpenACC.h:195
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:5236
static constexpr StringLiteral getSpecializedRoutineAttrName()
Definition OpenACC.h:189
std::optional< mlir::acc::DataClause > getDataClause(mlir::Operation *accDataEntryOp)
Used to obtain the dataClause from a data entry operation.
Definition OpenACC.cpp:5321
bool isPointerLikeType(mlir::Type type)
Used to check whether the provided type implements the PointerLikeType interface.
Definition OpenACC.h:166
mlir::MutableOperandRange getMutableDataOperands(mlir::Operation *accOp)
Used to get a mutable range iterating over the data operands.
Definition OpenACC.cpp:5349
mlir::SmallVector< mlir::Value > getBounds(mlir::Operation *accDataClauseOp)
Used to obtain bounds from an acc data clause operation.
Definition OpenACC.cpp:5266
OpenACCExecMapping
Enumeration used to encode the execution mapping on a loop construct.
Definition OpenACC.h:91
bool isSpecializedAccRoutine(mlir::Operation *op)
Used to check whether this is a specialized accelerator version of acc routine function.
Definition OpenACC.h:201
mlir::ValueRange getDataOperands(mlir::Operation *accOp)
Used to get an immutable range iterating over the data operands.
Definition OpenACC.cpp:5339
std::optional< llvm::StringRef > getVarName(mlir::Operation *accOp)
Used to obtain the name from an acc operation.
Definition OpenACC.cpp:5310
static constexpr StringLiteral getRoutineInfoAttrName()
Definition OpenACC.h:185
bool getImplicitFlag(mlir::Operation *accDataEntryOp)
Used to find out whether data operation is implicit.
Definition OpenACC.cpp:5331
mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp)
Used to get the recipe attribute from a data clause operation.
Definition OpenACC.cpp:5358
mlir::SmallVector< mlir::Value > getAsyncOperands(mlir::Operation *accDataClauseOp)
Used to obtain async operands from an acc data clause operation.
Definition OpenACC.cpp:5281
bool isMappableType(mlir::Type type)
Used to check whether the provided type implements the MappableType interface.
Definition OpenACC.h:172
static constexpr StringLiteral getCombinedConstructsAttrName()
Definition OpenACC.h:219
mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp)
Used to obtain the varPtrPtr from a data clause operation.
Definition OpenACC.cpp:5256
static constexpr StringLiteral getVarNameAttrName()
Definition OpenACC.h:215
mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:5303
static constexpr StringLiteral getDeclareAttrName()
Used to obtain the attribute name for declare.
Definition OpenACC.h:177
static constexpr StringLiteral getDeclareActionAttrName()
Definition OpenACC.h:181
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:5225
static constexpr StringLiteral getCollapseCountAttrName()
Name for an attribute attached to a loop indicating the number of loops collapsed to create that loop...
Definition OpenACC.h:211
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:5203
mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:5295
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:231
bool isAddressable() const override
Returns true if this resource is addressable (effects on it can alias pointer-based memory).
Definition OpenACC.h:232
bool isAddressable() const override
Returns true if this resource is addressable (effects on it can alias pointer-based memory).
Definition OpenACC.h:238
mlir::StringRef getName() const final
Return a string name of the resource.
Definition OpenACC.h:237
mlir::StringRef getName() const final
Return a string name of the resource.
Definition OpenACC.h:225
bool isAddressable() const override
Returns true if this resource is addressable (effects on it can alias pointer-based memory).
Definition OpenACC.h:226