MLIR 22.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
17#include "mlir/IR/Dialect.h"
20#include "mlir/IR/SymbolTable.h"
21
23#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc"
24#include "mlir/Dialect/OpenACC/OpenACCOpsEnums.h.inc"
25#include "mlir/Dialect/OpenACC/OpenACCOpsInterfaces.h.inc"
26#include "mlir/Dialect/OpenACC/OpenACCTypeInterfaces.h.inc"
28#include "mlir/IR/Value.h"
32#include <variant>
33
34#define GET_TYPEDEF_CLASSES
35#include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc"
36
37#define GET_ATTRDEF_CLASSES
38#include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"
39
41
42#define GET_OP_CLASSES
43#include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
44
45#define ACC_DATA_ENTRY_OPS \
46 mlir::acc::CopyinOp, mlir::acc::CreateOp, mlir::acc::PresentOp, \
47 mlir::acc::NoCreateOp, mlir::acc::AttachOp, mlir::acc::DevicePtrOp, \
48 mlir::acc::GetDevicePtrOp, mlir::acc::PrivateOp, \
49 mlir::acc::FirstprivateOp, mlir::acc::FirstprivateMapInitialOp, \
50 mlir::acc::UpdateDeviceOp, mlir::acc::UseDeviceOp, \
51 mlir::acc::ReductionOp, mlir::acc::DeclareDeviceResidentOp, \
52 mlir::acc::DeclareLinkOp, mlir::acc::CacheOp
53#define ACC_DATA_EXIT_OPS \
54 mlir::acc::CopyoutOp, mlir::acc::DeleteOp, mlir::acc::DetachOp, \
55 mlir::acc::UpdateHostOp
56#define ACC_DATA_CLAUSE_OPS ACC_DATA_ENTRY_OPS, ACC_DATA_EXIT_OPS
57#define ACC_COMPUTE_CONSTRUCT_OPS \
58 mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
59#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
60 ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
61#define ACC_DATA_CONSTRUCT_STRUCTURED_OPS \
62 mlir::acc::DataOp, mlir::acc::DeclareOp, mlir::acc::HostDataOp
63#define ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS \
64 mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, mlir::acc::UpdateOp, \
65 mlir::acc::DeclareEnterOp, mlir::acc::DeclareExitOp
66#define ACC_DATA_CONSTRUCT_OPS \
67 ACC_DATA_CONSTRUCT_STRUCTURED_OPS, ACC_DATA_CONSTRUCT_UNSTRUCTURED_OPS
68#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
69 ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
70#define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
71 ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
72
73namespace mlir {
74namespace acc {
75
76/// Enumeration used to encode the execution mapping on a loop construct.
77/// They refer directly to the OpenACC 3.3 standard:
78/// 2.9.2. gang
79/// 2.9.3. worker
80/// 2.9.4. vector
81///
82/// Value can be combined bitwise to reflect the mapping applied to the
83/// construct. e.g. `acc.loop gang vector`, the `gang` and `vector` could be
84/// combined and the final mapping value would be 5 (4 | 1).
85enum OpenACCExecMapping { NONE = 0, VECTOR = 1, WORKER = 2, GANG = 4 };
86
87/// Used to obtain the `var` from a data clause operation.
88/// Returns empty value if not a data clause operation or is a data exit
89/// operation with no `var`.
90mlir::Value getVar(mlir::Operation *accDataClauseOp);
91
92/// Used to obtain the `var` from a data clause operation if it implements
93/// `PointerLikeType`.
95getVarPtr(mlir::Operation *accDataClauseOp);
96
97/// Used to obtains the `varType` from a data clause operation which records
98/// the type of variable. When `var` is `PointerLikeType`, this returns
99/// the type of the pointer target.
100mlir::Type getVarType(mlir::Operation *accDataClauseOp);
101
102/// Used to obtain the `accVar` from a data clause operation.
103/// When a data entry operation, it obtains its result `accVar` value.
104/// If a data exit operation, it obtains its operand `accVar` value.
105/// Returns empty value if not a data clause operation.
106mlir::Value getAccVar(mlir::Operation *accDataClauseOp);
107
108/// Used to obtain the `accVar` from a data clause operation if it implements
109/// `PointerLikeType`.
111getAccPtr(mlir::Operation *accDataClauseOp);
112
113/// Used to obtain the `varPtrPtr` from a data clause operation.
114/// Returns empty value if not a data clause operation.
116
117/// Used to obtain `bounds` from an acc data clause operation.
118/// Returns an empty vector if there are no bounds.
120
121/// Used to obtain `async` operands from an acc data clause operation.
122/// Returns an empty vector if there are no such operands.
124getAsyncOperands(mlir::Operation *accDataClauseOp);
125
126/// Returns an array of acc:DeviceTypeAttr attributes attached to
127/// an acc data clause operation, that correspond to the device types
128/// associated with the async clauses with an async-value.
129mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp);
130
131/// Returns an array of acc:DeviceTypeAttr attributes attached to
132/// an acc data clause operation, that correspond to the device types
133/// associated with the async clauses without an async-value.
134mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp);
135
136/// Used to obtain the `name` from an acc operation.
137std::optional<llvm::StringRef> getVarName(mlir::Operation *accOp);
138
139/// Used to obtain the `dataClause` from a data entry operation.
140/// Returns empty optional if not a data entry operation.
141std::optional<mlir::acc::DataClause>
142getDataClause(mlir::Operation *accDataEntryOp);
143
144/// Used to find out whether data operation is implicit.
145/// Returns false if not a data operation or if it is a data operation without
146/// implicit flag.
147bool getImplicitFlag(mlir::Operation *accDataEntryOp);
148
149/// Used to get an immutable range iterating over the data operands.
151
152/// Used to get a mutable range iterating over the data operands.
154
155/// Used to get the recipe attribute from a data clause operation.
156mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp);
157
158/// Used to check whether the provided `type` implements the `PointerLikeType`
159/// interface.
160inline bool isPointerLikeType(mlir::Type type) {
161 return mlir::isa<mlir::acc::PointerLikeType>(type);
162}
163
164/// Used to check whether the provided `type` implements the `MappableType`
165/// interface.
166inline bool isMappableType(mlir::Type type) {
167 return mlir::isa<mlir::acc::MappableType>(type);
168}
169
170/// Used to obtain the attribute name for declare.
171static constexpr StringLiteral getDeclareAttrName() {
172 return StringLiteral("acc.declare");
173}
174
175static constexpr StringLiteral getDeclareActionAttrName() {
176 return StringLiteral("acc.declare_action");
177}
178
179static constexpr StringLiteral getRoutineInfoAttrName() {
180 return RoutineInfoAttr::name;
181}
182
183static constexpr StringLiteral getSpecializedRoutineAttrName() {
184 return SpecializedRoutineAttr::name;
185}
186
187/// Used to check whether the current operation is marked with
188/// `acc routine`. The operation passed in should be a function.
192
193/// Used to check whether this is a specialized accelerator version of
194/// `acc routine` function.
198
199static constexpr StringLiteral getFromDefaultClauseAttrName() {
200 return StringLiteral("acc.from_default");
201}
202
203static constexpr StringLiteral getVarNameAttrName() {
204 return VarNameAttr::name;
205}
206
207static constexpr StringLiteral getCombinedConstructsAttrName() {
208 return CombinedConstructsTypeAttr::name;
209}
210
212 : public mlir::SideEffects::Resource::Base<RuntimeCounters> {
213 mlir::StringRef getName() final { return "AccRuntimeCounters"; }
214};
215
217 : public mlir::SideEffects::Resource::Base<ConstructResource> {
218 mlir::StringRef getName() final { return "AccConstructResource"; }
219};
220
222 : public mlir::SideEffects::Resource::Base<CurrentDeviceIdResource> {
223 mlir::StringRef getName() final { return "AccCurrentDeviceIdResource"; }
224};
225
226} // namespace acc
227} // namespace mlir
228
229#endif // MLIR_DIALECT_OPENACC_OPENACC_H_
This class provides a mutable adaptor for a range of operands.
Definition ValueRange.h:118
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:560
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:387
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:199
mlir::Value getAccVar(mlir::Operation *accDataClauseOp)
Used to obtain the accVar from a data clause operation.
Definition OpenACC.cpp:4835
mlir::Value getVar(mlir::Operation *accDataClauseOp)
Used to obtain the var from a data clause operation.
Definition OpenACC.cpp:4804
bool isAccRoutine(mlir::Operation *op)
Used to check whether the current operation is marked with acc routine.
Definition OpenACC.h:189
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:4823
static constexpr StringLiteral getSpecializedRoutineAttrName()
Definition OpenACC.h:183
std::optional< mlir::acc::DataClause > getDataClause(mlir::Operation *accDataEntryOp)
Used to obtain the dataClause from a data entry operation.
Definition OpenACC.cpp:4908
bool isPointerLikeType(mlir::Type type)
Used to check whether the provided type implements the PointerLikeType interface.
Definition OpenACC.h:160
mlir::MutableOperandRange getMutableDataOperands(mlir::Operation *accOp)
Used to get a mutable range iterating over the data operands.
Definition OpenACC.cpp:4936
mlir::SmallVector< mlir::Value > getBounds(mlir::Operation *accDataClauseOp)
Used to obtain bounds from an acc data clause operation.
Definition OpenACC.cpp:4853
OpenACCExecMapping
Enumeration used to encode the execution mapping on a loop construct.
Definition OpenACC.h:85
bool isSpecializedAccRoutine(mlir::Operation *op)
Used to check whether this is a specialized accelerator version of acc routine function.
Definition OpenACC.h:195
mlir::ValueRange getDataOperands(mlir::Operation *accOp)
Used to get an immutable range iterating over the data operands.
Definition OpenACC.cpp:4926
std::optional< llvm::StringRef > getVarName(mlir::Operation *accOp)
Used to obtain the name from an acc operation.
Definition OpenACC.cpp:4897
static constexpr StringLiteral getRoutineInfoAttrName()
Definition OpenACC.h:179
bool getImplicitFlag(mlir::Operation *accDataEntryOp)
Used to find out whether data operation is implicit.
Definition OpenACC.cpp:4918
mlir::SymbolRefAttr getRecipe(mlir::Operation *accOp)
Used to get the recipe attribute from a data clause operation.
Definition OpenACC.cpp:4945
mlir::SmallVector< mlir::Value > getAsyncOperands(mlir::Operation *accDataClauseOp)
Used to obtain async operands from an acc data clause operation.
Definition OpenACC.cpp:4868
bool isMappableType(mlir::Type type)
Used to check whether the provided type implements the MappableType interface.
Definition OpenACC.h:166
static constexpr StringLiteral getCombinedConstructsAttrName()
Definition OpenACC.h:207
mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp)
Used to obtain the varPtrPtr from a data clause operation.
Definition OpenACC.cpp:4843
static constexpr StringLiteral getVarNameAttrName()
Definition OpenACC.h:203
mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:4890
static constexpr StringLiteral getDeclareAttrName()
Used to obtain the attribute name for declare.
Definition OpenACC.h:171
static constexpr StringLiteral getDeclareActionAttrName()
Definition OpenACC.h:175
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:4812
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:4790
mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp)
Returns an array of acc:DeviceTypeAttr attributes attached to an acc data clause operation,...
Definition OpenACC.cpp:4882
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:497
mlir::StringRef getName() final
Return a string name of the resource.
Definition OpenACC.h:218
mlir::StringRef getName() final
Return a string name of the resource.
Definition OpenACC.h:223
mlir::StringRef getName() final
Return a string name of the resource.
Definition OpenACC.h:213