MLIR  18.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 
16 #include "mlir/IR/BuiltinTypes.h"
17 #include "mlir/IR/Dialect.h"
18 #include "mlir/IR/OpDefinition.h"
19 #include "mlir/IR/PatternMatch.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/OpenACCTypeInterfaces.h.inc"
29 
30 #define GET_TYPEDEF_CLASSES
31 #include "mlir/Dialect/OpenACC/OpenACCOpsTypes.h.inc"
32 
33 #define GET_ATTRDEF_CLASSES
34 #include "mlir/Dialect/OpenACC/OpenACCOpsAttributes.h.inc"
35 
37 
38 #define GET_OP_CLASSES
39 #include "mlir/Dialect/OpenACC/OpenACCOps.h.inc"
40 
41 #define ACC_DATA_ENTRY_OPS \
42  mlir::acc::CopyinOp, mlir::acc::CreateOp, mlir::acc::PresentOp, \
43  mlir::acc::NoCreateOp, mlir::acc::AttachOp, mlir::acc::DevicePtrOp, \
44  mlir::acc::GetDevicePtrOp, mlir::acc::PrivateOp, \
45  mlir::acc::FirstprivateOp, mlir::acc::UpdateDeviceOp, \
46  mlir::acc::UseDeviceOp, mlir::acc::ReductionOp, \
47  mlir::acc::DeclareDeviceResidentOp, mlir::acc::DeclareLinkOp, \
48  mlir::acc::CacheOp
49 #define ACC_COMPUTE_CONSTRUCT_OPS \
50  mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
51 #define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
52  ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
53 #define ACC_DATA_CONSTRUCT_OPS \
54  mlir::acc::DataOp, mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, \
55  mlir::acc::UpdateOp, mlir::acc::HostDataOp, mlir::acc::DeclareEnterOp, \
56  mlir::acc::DeclareExitOp, mlir::acc::DeclareOp
57 #define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
58  ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
59 #define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
60  ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
61 
62 namespace mlir {
63 namespace acc {
64 
65 /// Enumeration used to encode the execution mapping on a loop construct.
66 /// They refer directly to the OpenACC 3.3 standard:
67 /// 2.9.2. gang
68 /// 2.9.3. worker
69 /// 2.9.4. vector
70 ///
71 /// Value can be combined bitwise to reflect the mapping applied to the
72 /// construct. e.g. `acc.loop gang vector`, the `gang` and `vector` could be
73 /// combined and the final mapping value would be 5 (4 | 1).
74 enum OpenACCExecMapping { NONE = 0, VECTOR = 1, WORKER = 2, GANG = 4 };
75 
76 /// Used to obtain the `varPtr` from a data entry operation.
77 /// Returns empty value if not a data entry operation.
78 mlir::Value getVarPtr(mlir::Operation *accDataEntryOp);
79 
80 /// Used to obtain the `dataClause` from a data entry operation.
81 /// Returns empty optional if not a data entry operation.
82 std::optional<mlir::acc::DataClause>
83 getDataClause(mlir::Operation *accDataEntryOp);
84 
85 /// Used to find out whether data operation is implicit.
86 /// Returns false if not a data operation or if it is a data operation without
87 /// implicit flag.
88 bool getImplicitFlag(mlir::Operation *accDataEntryOp);
89 
90 /// Used to obtain the attribute name for declare.
91 static constexpr StringLiteral getDeclareAttrName() {
92  return StringLiteral("acc.declare");
93 }
94 
95 static constexpr StringLiteral getDeclareActionAttrName() {
96  return StringLiteral("acc.declare_action");
97 }
98 
99 static constexpr StringLiteral getRoutineInfoAttrName() {
100  return StringLiteral("acc.routine_info");
101 }
102 
103 } // namespace acc
104 } // namespace mlir
105 
106 #endif // MLIR_DIALECT_OPENACC_OPENACC_H_
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
std::optional< mlir::acc::DataClause > getDataClause(mlir::Operation *accDataEntryOp)
Used to obtain the dataClause from a data entry operation.
Definition: OpenACC.cpp:1348
OpenACCExecMapping
Enumeration used to encode the execution mapping on a loop construct.
Definition: OpenACC.h:74
@ WORKER
Definition: OpenACC.h:74
@ NONE
Definition: OpenACC.h:74
@ GANG
Definition: OpenACC.h:74
@ VECTOR
Definition: OpenACC.h:74
static constexpr StringLiteral getRoutineInfoAttrName()
Definition: OpenACC.h:99
mlir::Value getVarPtr(mlir::Operation *accDataEntryOp)
Used to obtain the varPtr from a data entry operation.
Definition: OpenACC.cpp:1339
bool getImplicitFlag(mlir::Operation *accDataEntryOp)
Used to find out whether data operation is implicit.
Definition: OpenACC.cpp:1358
static constexpr StringLiteral getDeclareAttrName()
Used to obtain the attribute name for declare.
Definition: OpenACC.h:91
static constexpr StringLiteral getDeclareActionAttrName()
Definition: OpenACC.h:95
Include the generated interface declarations.