MLIR 24.0.0git
AtomicOps.cpp
Go to the documentation of this file.
1//===- AtomicOps.cpp - MLIR SPIR-V Atomic Ops ----------------------------===//
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// Defines the atomic operations in the SPIR-V dialect.
10//
11//===----------------------------------------------------------------------===//
12
14
15#include "SPIRVOpUtils.h"
16#include "SPIRVParsingUtils.h"
17
18using namespace mlir::spirv::AttrNames;
19
20namespace mlir::spirv {
21
22template <typename T>
23static StringRef stringifyTypeName();
24
25template <>
27 return "integer";
28}
29
30template <>
32 return "float";
33}
34
35// Verifies an atomic update op.
36template <typename AtomicOpTy, typename ExpectedElementType>
37static LogicalResult verifyAtomicUpdateOp(Operation *op) {
38 auto ptrType = cast<spirv::PointerType>(op->getOperand(0).getType());
39 auto elementType = ptrType.getPointeeType();
40 if (!isa<ExpectedElementType>(elementType))
41 return op->emitOpError() << "pointer operand must point to an "
43 << " value, found " << elementType;
44
45 spirv::MemorySemantics memorySemantics = cast<AtomicOpTy>(op).getSemantics();
46 if (failed(verifyMemorySemantics(op, memorySemantics))) {
47 return failure();
48 }
49 return success();
50}
51
52//===----------------------------------------------------------------------===//
53// spirv.AtomicAndOp
54//===----------------------------------------------------------------------===//
55
56LogicalResult AtomicAndOp::verify() {
58}
59
60//===----------------------------------------------------------------------===//
61// spirv.AtomicCompareExchangeOp
62//===----------------------------------------------------------------------===//
63
64LogicalResult AtomicCompareExchangeOp::verify() {
65 if (failed(verifyMemorySemantics(getOperation(), getEqualSemantics())))
66 return failure();
67 return verifyMemorySemantics(getOperation(), getUnequalSemantics());
68}
69
70//===----------------------------------------------------------------------===//
71// spirv.AtomicCompareExchangeWeakOp
72//===----------------------------------------------------------------------===//
73
74LogicalResult AtomicCompareExchangeWeakOp::verify() {
75 if (failed(verifyMemorySemantics(getOperation(), getEqualSemantics())))
76 return failure();
77 return verifyMemorySemantics(getOperation(), getUnequalSemantics());
78}
79
80//===----------------------------------------------------------------------===//
81// spirv.AtomicExchangeOp
82//===----------------------------------------------------------------------===//
83
84LogicalResult AtomicExchangeOp::verify() {
85 return verifyMemorySemantics(getOperation(), getSemantics());
86}
87
88//===----------------------------------------------------------------------===//
89// spirv.AtomicLoadOp
90//===----------------------------------------------------------------------===//
91
92LogicalResult AtomicLoadOp::verify() {
93 return verifyMemorySemantics(getOperation(), getSemantics());
94}
95
96//===----------------------------------------------------------------------===//
97// spirv.AtomicStoreOp
98//===----------------------------------------------------------------------===//
99
100LogicalResult AtomicStoreOp::verify() {
101 return verifyMemorySemantics(getOperation(), getSemantics());
102}
103
104//===----------------------------------------------------------------------===//
105// spirv.AtomicIAddOp
106//===----------------------------------------------------------------------===//
107
108LogicalResult AtomicIAddOp::verify() {
110}
111
112//===----------------------------------------------------------------------===//
113// spirv.EXT.AtomicFAddOp
114//===----------------------------------------------------------------------===//
115
116LogicalResult EXTAtomicFAddOp::verify() {
118}
119
120//===----------------------------------------------------------------------===//
121// spirv.AtomicIDecrementOp
122//===----------------------------------------------------------------------===//
123
124LogicalResult AtomicIDecrementOp::verify() {
126}
127
128//===----------------------------------------------------------------------===//
129// spirv.AtomicIIncrementOp
130//===----------------------------------------------------------------------===//
131
132LogicalResult AtomicIIncrementOp::verify() {
134}
135
136//===----------------------------------------------------------------------===//
137// spirv.AtomicISubOp
138//===----------------------------------------------------------------------===//
139
140LogicalResult AtomicISubOp::verify() {
142}
143
144//===----------------------------------------------------------------------===//
145// spirv.AtomicOrOp
146//===----------------------------------------------------------------------===//
147
148LogicalResult AtomicOrOp::verify() {
150}
151
152//===----------------------------------------------------------------------===//
153// spirv.AtomicSMaxOp
154//===----------------------------------------------------------------------===//
155
156LogicalResult AtomicSMaxOp::verify() {
158}
159
160//===----------------------------------------------------------------------===//
161// spirv.AtomicSMinOp
162//===----------------------------------------------------------------------===//
163
164LogicalResult AtomicSMinOp::verify() {
166}
167
168//===----------------------------------------------------------------------===//
169// spirv.AtomicUMaxOp
170//===----------------------------------------------------------------------===//
171
172LogicalResult AtomicUMaxOp::verify() {
174}
175
176//===----------------------------------------------------------------------===//
177// spirv.AtomicUMinOp
178//===----------------------------------------------------------------------===//
179
180LogicalResult AtomicUMinOp::verify() {
182}
183
184//===----------------------------------------------------------------------===//
185// spirv.AtomicXorOp
186//===----------------------------------------------------------------------===//
187
188LogicalResult AtomicXorOp::verify() {
190}
191
192} // namespace mlir::spirv
return success()
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
Value getOperand(unsigned idx)
Definition Operation.h:375
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
Type getType() const
Return the type of this value.
Definition Value.h:105
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:734
static StringRef stringifyTypeName()
LogicalResult verifyMemorySemantics(Operation *op, spirv::MemorySemantics memorySemantics)
Definition SPIRVOps.cpp:69
StringRef stringifyTypeName< FloatType >()
Definition AtomicOps.cpp:31
StringRef stringifyTypeName< IntegerType >()
Definition AtomicOps.cpp:26
static LogicalResult verifyAtomicUpdateOp(Operation *op)
Definition AtomicOps.cpp:37