Skip to content

Commit 4604c21

Browse files
Lancernakadutta
authored andcommitted
[CIR][NFC] Update existing atomic ops to match assembly conventions (llvm#161543)
This patch updates the definitions of `cir.atomic.xchg` and `cir.atomic.cmpxchg` to make them follow the established CIR assembly conventions. Some other minor changes are also made along the way: - The verifier for `cir.atomic.cmpxchg` is now fully declared in TableGen. - The `Op` suffix is appended to `CIR_AtomicXchg` and `CIR_AtomicCmpXchg` to follow the naming conventions for TableGen operation records.
1 parent f1915c6 commit 4604c21

File tree

6 files changed

+71
-80
lines changed

6 files changed

+71
-80
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,7 +4329,7 @@ def CIR_AllocExceptionOp : CIR_Op<"alloc.exception"> {
43294329
// Atomic operations
43304330
//===----------------------------------------------------------------------===//
43314331

4332-
def CIR_AtomicXchg : CIR_Op<"atomic.xchg", [
4332+
def CIR_AtomicXchgOp : CIR_Op<"atomic.xchg", [
43334333
AllTypesMatch<["result", "val"]>,
43344334
TypesMatchWith<"type of 'val' must match the pointee type of 'ptr'",
43354335
"ptr", "val", "mlir::cast<cir::PointerType>($_self).getPointee()">
@@ -4347,9 +4347,7 @@ def CIR_AtomicXchg : CIR_Op<"atomic.xchg", [
43474347
Example:
43484348

43494349
```mlir
4350-
%res = cir.atomic.xchg(%ptr : !cir.ptr<!u64i>,
4351-
%val : !u64i,
4352-
seq_cst) : !u64i
4350+
%res = cir.atomic.xchg seq_cst %ptr, %val : !cir.ptr<!u64i> -> !u64i
43534351
```
43544352
}];
43554353

@@ -4364,12 +4362,16 @@ def CIR_AtomicXchg : CIR_Op<"atomic.xchg", [
43644362
let assemblyFormat = [{
43654363
$mem_order (`volatile` $is_volatile^)?
43664364
$ptr `,` $val
4367-
`:` qualified(type($ptr)) `->` type($result) attr-dict
4365+
`:` functional-type(operands, results) attr-dict
43684366
}];
43694367
}
43704368

4371-
def CIR_AtomicCmpXchg : CIR_Op<"atomic.cmpxchg", [
4372-
AllTypesMatch<["old", "expected", "desired"]>
4369+
def CIR_AtomicCmpXchgOp : CIR_Op<"atomic.cmpxchg", [
4370+
AllTypesMatch<["old", "expected", "desired"]>,
4371+
TypesMatchWith<"type of 'expected' must match the pointee type of 'ptr'",
4372+
"ptr", "expected", "mlir::cast<cir::PointerType>($_self).getPointee()">,
4373+
TypesMatchWith<"type of 'desired' must match the pointee type of 'ptr'",
4374+
"ptr", "desired", "mlir::cast<cir::PointerType>($_self).getPointee()">
43734375
]> {
43744376
let summary = "Atomic compare and exchange";
43754377
let description = [{
@@ -4402,12 +4404,9 @@ def CIR_AtomicCmpXchg : CIR_Op<"atomic.cmpxchg", [
44024404
Example:
44034405

44044406
```mlir
4405-
%old, %success = cir.atomic.cmpxchg(%ptr : !cir.ptr<!u64i>,
4406-
%expected : !u64i,
4407-
%desired : !u64i,
4408-
success = seq_cst,
4409-
failure = seq_cst) weak
4410-
: (!u64i, !cir.bool)
4407+
%old, %success = cir.atomic.cmpxchg weak success(seq_cst) failure(acquire)
4408+
%ptr, %expected, %desired
4409+
: (!cir.ptr<!u64i>, !u64i, !u64i) -> (!u64i, !cir.bool)
44114410
```
44124411
}];
44134412
let results = (outs CIR_AnyType:$old, CIR_BoolType:$success);
@@ -4421,20 +4420,13 @@ def CIR_AtomicCmpXchg : CIR_Op<"atomic.cmpxchg", [
44214420
UnitAttr:$is_volatile);
44224421

44234422
let assemblyFormat = [{
4424-
`(`
4425-
$ptr `:` qualified(type($ptr)) `,`
4426-
$expected `:` type($expected) `,`
4427-
$desired `:` type($desired) `,`
4428-
`success` `=` $succ_order `,`
4429-
`failure` `=` $fail_order
4430-
`)`
4431-
(`align` `(` $alignment^ `)`)?
44324423
(`weak` $weak^)?
4424+
`success` `(` $succ_order `)` `failure` `(` $fail_order `)`
4425+
$ptr `,` $expected `,` $desired
4426+
(`align` `(` $alignment^ `)`)?
44334427
(`volatile` $is_volatile^)?
4434-
`:` `(` type($old) `,` type($success) `)` attr-dict
4428+
`:` functional-type(operands, results) attr-dict
44354429
}];
4436-
4437-
let hasVerifier = 1;
44384430
}
44394431

44404432
#endif // CLANG_CIR_DIALECT_IR_CIROPS_TD

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static void emitAtomicCmpXchg(CIRGenFunction &cgf, AtomicExpr *e, bool isWeak,
255255
mlir::Value expected = builder.createLoad(loc, val1);
256256
mlir::Value desired = builder.createLoad(loc, val2);
257257

258-
auto cmpxchg = cir::AtomicCmpXchg::create(
258+
auto cmpxchg = cir::AtomicCmpXchgOp::create(
259259
builder, loc, expected.getType(), builder.getBoolTy(), ptr.getPointer(),
260260
expected, desired,
261261
cir::MemOrderAttr::get(&cgf.getMLIRContext(), successOrder),
@@ -404,7 +404,7 @@ static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest,
404404
case AtomicExpr::AO__c11_atomic_exchange:
405405
case AtomicExpr::AO__atomic_exchange_n:
406406
case AtomicExpr::AO__atomic_exchange:
407-
opName = cir::AtomicXchg::getOperationName();
407+
opName = cir::AtomicXchgOp::getOperationName();
408408
break;
409409

410410
case AtomicExpr::AO__opencl_atomic_init:

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,20 +2900,6 @@ mlir::LogicalResult cir::ThrowOp::verify() {
29002900
return failure();
29012901
}
29022902

2903-
//===----------------------------------------------------------------------===//
2904-
// AtomicCmpXchg
2905-
//===----------------------------------------------------------------------===//
2906-
2907-
LogicalResult cir::AtomicCmpXchg::verify() {
2908-
mlir::Type pointeeType = getPtr().getType().getPointee();
2909-
2910-
if (pointeeType != getExpected().getType() ||
2911-
pointeeType != getDesired().getType())
2912-
return emitOpError("ptr, expected and desired types must match");
2913-
2914-
return success();
2915-
}
2916-
29172903
//===----------------------------------------------------------------------===//
29182904
// TypeInfoAttr
29192905
//===----------------------------------------------------------------------===//

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,8 @@ getLLVMMemOrder(std::optional<cir::MemOrder> memorder) {
694694
llvm_unreachable("unknown memory order");
695695
}
696696

697-
mlir::LogicalResult CIRToLLVMAtomicCmpXchgLowering::matchAndRewrite(
698-
cir::AtomicCmpXchg op, OpAdaptor adaptor,
697+
mlir::LogicalResult CIRToLLVMAtomicCmpXchgOpLowering::matchAndRewrite(
698+
cir::AtomicCmpXchgOp op, OpAdaptor adaptor,
699699
mlir::ConversionPatternRewriter &rewriter) const {
700700
mlir::Value expected = adaptor.getExpected();
701701
mlir::Value desired = adaptor.getDesired();
@@ -719,8 +719,8 @@ mlir::LogicalResult CIRToLLVMAtomicCmpXchgLowering::matchAndRewrite(
719719
return mlir::success();
720720
}
721721

722-
mlir::LogicalResult CIRToLLVMAtomicXchgLowering::matchAndRewrite(
723-
cir::AtomicXchg op, OpAdaptor adaptor,
722+
mlir::LogicalResult CIRToLLVMAtomicXchgOpLowering::matchAndRewrite(
723+
cir::AtomicXchgOp op, OpAdaptor adaptor,
724724
mlir::ConversionPatternRewriter &rewriter) const {
725725
assert(!cir::MissingFeatures::atomicSyncScopeID());
726726
mlir::LLVM::AtomicOrdering llvmOrder = getLLVMMemOrder(adaptor.getMemOrder());

clang/test/CIR/CodeGen/atomic.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void c11_atomic_cmpxchg_strong(_Atomic(int) *ptr, int *expected, int desired) {
211211

212212
__c11_atomic_compare_exchange_strong(ptr, expected, desired,
213213
__ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
214-
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg(%{{.+}} : !cir.ptr<!s32i>, %{{.+}} : !s32i, %{{.+}} : !s32i, success = seq_cst, failure = acquire) align(4) : (!s32i, !cir.bool)
214+
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} align(4) : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
215215
// CIR-NEXT: %[[FAILED:.+]] = cir.unary(not, %[[SUCCESS]]) : !cir.bool, !cir.bool
216216
// CIR-NEXT: cir.if %[[FAILED]] {
217217
// CIR-NEXT: cir.store align(4) %[[OLD]], %{{.+}} : !s32i, !cir.ptr<!s32i>
@@ -249,7 +249,7 @@ void c11_atomic_cmpxchg_weak(_Atomic(int) *ptr, int *expected, int desired) {
249249

250250
__c11_atomic_compare_exchange_weak(ptr, expected, desired,
251251
__ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
252-
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg(%{{.+}} : !cir.ptr<!s32i>, %{{.+}} : !s32i, %{{.+}} : !s32i, success = seq_cst, failure = acquire) align(4) weak : (!s32i, !cir.bool)
252+
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg weak success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} align(4) : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
253253
// CIR-NEXT: %[[FAILED:.+]] = cir.unary(not, %[[SUCCESS]]) : !cir.bool, !cir.bool
254254
// CIR-NEXT: cir.if %[[FAILED]] {
255255
// CIR-NEXT: cir.store align(4) %[[OLD]], %{{.+}} : !s32i, !cir.ptr<!s32i>
@@ -286,7 +286,7 @@ void atomic_cmpxchg(int *ptr, int *expected, int *desired) {
286286
// OGCG-LABEL: @atomic_cmpxchg
287287

288288
__atomic_compare_exchange(ptr, expected, desired, /*weak=*/0, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
289-
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg(%{{.+}} : !cir.ptr<!s32i>, %{{.+}} : !s32i, %{{.+}} : !s32i, success = seq_cst, failure = acquire) align(4) : (!s32i, !cir.bool)
289+
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} align(4) : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
290290
// CIR-NEXT: %[[FAILED:.+]] = cir.unary(not, %[[SUCCESS]]) : !cir.bool, !cir.bool
291291
// CIR-NEXT: cir.if %[[FAILED]] {
292292
// CIR-NEXT: cir.store align(4) %[[OLD]], %{{.+}} : !s32i, !cir.ptr<!s32i>
@@ -317,7 +317,7 @@ void atomic_cmpxchg(int *ptr, int *expected, int *desired) {
317317
// OGCG-NEXT: store i8 %[[SUCCESS_2]], ptr %{{.+}}, align 1
318318

319319
__atomic_compare_exchange(ptr, expected, desired, /*weak=*/1, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
320-
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg(%{{.+}} : !cir.ptr<!s32i>, %{{.+}} : !s32i, %{{.+}} : !s32i, success = seq_cst, failure = acquire) align(4) weak : (!s32i, !cir.bool)
320+
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg weak success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} align(4) : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
321321
// CIR-NEXT: %[[FAILED:.+]] = cir.unary(not, %[[SUCCESS]]) : !cir.bool, !cir.bool
322322
// CIR-NEXT: cir.if %[[FAILED]] {
323323
// CIR-NEXT: cir.store align(4) %[[OLD]], %{{.+}} : !s32i, !cir.ptr<!s32i>
@@ -354,7 +354,7 @@ void atomic_cmpxchg_n(int *ptr, int *expected, int desired) {
354354
// OGCG-LABEL: @atomic_cmpxchg_n
355355

356356
__atomic_compare_exchange_n(ptr, expected, desired, /*weak=*/0, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
357-
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg(%{{.+}} : !cir.ptr<!s32i>, %{{.+}} : !s32i, %{{.+}} : !s32i, success = seq_cst, failure = acquire) align(4) : (!s32i, !cir.bool)
357+
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} align(4) : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
358358
// CIR-NEXT: %[[FAILED:.+]] = cir.unary(not, %[[SUCCESS]]) : !cir.bool, !cir.bool
359359
// CIR-NEXT: cir.if %[[FAILED]] {
360360
// CIR-NEXT: cir.store align(4) %[[OLD]], %{{.+}} : !s32i, !cir.ptr<!s32i>
@@ -385,7 +385,7 @@ void atomic_cmpxchg_n(int *ptr, int *expected, int desired) {
385385
// OGCG-NEXT: store i8 %[[SUCCESS_2]], ptr %{{.+}}, align 1
386386

387387
__atomic_compare_exchange_n(ptr, expected, desired, /*weak=*/1, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
388-
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg(%{{.+}} : !cir.ptr<!s32i>, %{{.+}} : !s32i, %{{.+}} : !s32i, success = seq_cst, failure = acquire) align(4) weak : (!s32i, !cir.bool)
388+
// CIR: %[[OLD:.+]], %[[SUCCESS:.+]] = cir.atomic.cmpxchg weak success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} align(4) : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
389389
// CIR-NEXT: %[[FAILED:.+]] = cir.unary(not, %[[SUCCESS]]) : !cir.bool, !cir.bool
390390
// CIR-NEXT: cir.if %[[FAILED]] {
391391
// CIR-NEXT: cir.store align(4) %[[OLD]], %{{.+}} : !s32i, !cir.ptr<!s32i>
@@ -427,12 +427,12 @@ void c11_atomic_exchange(_Atomic(int) *ptr, int value) {
427427
__c11_atomic_exchange(ptr, value, __ATOMIC_RELEASE);
428428
__c11_atomic_exchange(ptr, value, __ATOMIC_ACQ_REL);
429429
__c11_atomic_exchange(ptr, value, __ATOMIC_SEQ_CST);
430-
// CIR: %{{.+}} = cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
431-
// CIR: %{{.+}} = cir.atomic.xchg consume %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
432-
// CIR: %{{.+}} = cir.atomic.xchg acquire %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
433-
// CIR: %{{.+}} = cir.atomic.xchg release %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
434-
// CIR: %{{.+}} = cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
435-
// CIR: %{{.+}} = cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
430+
// CIR: %{{.+}} = cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
431+
// CIR: %{{.+}} = cir.atomic.xchg consume %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
432+
// CIR: %{{.+}} = cir.atomic.xchg acquire %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
433+
// CIR: %{{.+}} = cir.atomic.xchg release %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
434+
// CIR: %{{.+}} = cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
435+
// CIR: %{{.+}} = cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
436436

437437
// LLVM: %{{.+}} = atomicrmw xchg ptr %{{.+}}, i32 %{{.+}} monotonic, align 4
438438
// LLVM: %{{.+}} = atomicrmw xchg ptr %{{.+}}, i32 %{{.+}} acquire, align 4
@@ -460,12 +460,12 @@ void atomic_exchange(int *ptr, int *value, int *old) {
460460
__atomic_exchange(ptr, value, old, __ATOMIC_RELEASE);
461461
__atomic_exchange(ptr, value, old, __ATOMIC_ACQ_REL);
462462
__atomic_exchange(ptr, value, old, __ATOMIC_SEQ_CST);
463-
// CIR: %{{.+}} = cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
464-
// CIR: %{{.+}} = cir.atomic.xchg consume %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
465-
// CIR: %{{.+}} = cir.atomic.xchg acquire %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
466-
// CIR: %{{.+}} = cir.atomic.xchg release %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
467-
// CIR: %{{.+}} = cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
468-
// CIR: %{{.+}} = cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
463+
// CIR: %{{.+}} = cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
464+
// CIR: %{{.+}} = cir.atomic.xchg consume %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
465+
// CIR: %{{.+}} = cir.atomic.xchg acquire %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
466+
// CIR: %{{.+}} = cir.atomic.xchg release %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
467+
// CIR: %{{.+}} = cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
468+
// CIR: %{{.+}} = cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
469469

470470
// LLVM: %{{.+}} = atomicrmw xchg ptr %{{.+}}, i32 %{{.+}} monotonic, align 4
471471
// LLVM: %{{.+}} = atomicrmw xchg ptr %{{.+}}, i32 %{{.+}} acquire, align 4
@@ -493,12 +493,12 @@ void atomic_exchange_n(int *ptr, int value) {
493493
__atomic_exchange_n(ptr, value, __ATOMIC_RELEASE);
494494
__atomic_exchange_n(ptr, value, __ATOMIC_ACQ_REL);
495495
__atomic_exchange_n(ptr, value, __ATOMIC_SEQ_CST);
496-
// CIR: %{{.+}} = cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
497-
// CIR: %{{.+}} = cir.atomic.xchg consume %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
498-
// CIR: %{{.+}} = cir.atomic.xchg acquire %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
499-
// CIR: %{{.+}} = cir.atomic.xchg release %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
500-
// CIR: %{{.+}} = cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
501-
// CIR: %{{.+}} = cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
496+
// CIR: %{{.+}} = cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
497+
// CIR: %{{.+}} = cir.atomic.xchg consume %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
498+
// CIR: %{{.+}} = cir.atomic.xchg acquire %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
499+
// CIR: %{{.+}} = cir.atomic.xchg release %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
500+
// CIR: %{{.+}} = cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
501+
// CIR: %{{.+}} = cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
502502

503503
// LLVM: %{{.+}} = atomicrmw xchg ptr %{{.+}}, i32 %{{.+}} monotonic, align 4
504504
// LLVM: %{{.+}} = atomicrmw xchg ptr %{{.+}}, i32 %{{.+}} acquire, align 4

clang/test/CIR/IR/atomic.cir

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,30 @@
55

66
cir.func @atomic_xchg(%ptr: !cir.ptr<!s32i>, %val: !s32i) {
77
// CHECK-LABEL: @atomic_xchg
8-
%0 = cir.atomic.xchg relaxed %ptr, %val : !cir.ptr<!s32i> -> !s32i
9-
// CHECK: cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
10-
%1 = cir.atomic.xchg consume %ptr, %val : !cir.ptr<!s32i> -> !s32i
11-
// CHECK: cir.atomic.xchg consume %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
12-
%2 = cir.atomic.xchg acquire %ptr, %val : !cir.ptr<!s32i> -> !s32i
13-
// CHECK: cir.atomic.xchg acquire %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
14-
%3 = cir.atomic.xchg release %ptr, %val : !cir.ptr<!s32i> -> !s32i
15-
// CHECK: cir.atomic.xchg release %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
16-
%4 = cir.atomic.xchg acq_rel %ptr, %val : !cir.ptr<!s32i> -> !s32i
17-
// CHECK: cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
18-
%5 = cir.atomic.xchg seq_cst %ptr, %val : !cir.ptr<!s32i> -> !s32i
19-
// CHECK: cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : !cir.ptr<!s32i> -> !s32i
8+
%0 = cir.atomic.xchg relaxed %ptr, %val : (!cir.ptr<!s32i>, !s32i) -> !s32i
9+
// CHECK: cir.atomic.xchg relaxed %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
10+
%1 = cir.atomic.xchg consume %ptr, %val : (!cir.ptr<!s32i>, !s32i) -> !s32i
11+
// CHECK: cir.atomic.xchg consume %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
12+
%2 = cir.atomic.xchg acquire %ptr, %val : (!cir.ptr<!s32i>, !s32i) -> !s32i
13+
// CHECK: cir.atomic.xchg acquire %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
14+
%3 = cir.atomic.xchg release %ptr, %val : (!cir.ptr<!s32i>, !s32i) -> !s32i
15+
// CHECK: cir.atomic.xchg release %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
16+
%4 = cir.atomic.xchg acq_rel %ptr, %val : (!cir.ptr<!s32i>, !s32i) -> !s32i
17+
// CHECK: cir.atomic.xchg acq_rel %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
18+
%5 = cir.atomic.xchg seq_cst %ptr, %val : (!cir.ptr<!s32i>, !s32i) -> !s32i
19+
// CHECK: cir.atomic.xchg seq_cst %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i) -> !s32i
20+
cir.return
21+
}
22+
23+
cir.func @atomic_cmpxchg(%ptr: !cir.ptr<!s32i>, %expected: !s32i, %desired: !s32i) {
24+
// CHECK-LABEL: @atomic_cmpxchg
25+
%0, %1 = cir.atomic.cmpxchg success(relaxed) failure(relaxed) %ptr, %expected, %desired : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
26+
// CHECK: cir.atomic.cmpxchg success(relaxed) failure(relaxed) %{{.+}}, %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
27+
%2, %3 = cir.atomic.cmpxchg weak success(relaxed) failure(relaxed) %ptr, %expected, %desired : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
28+
// CHECK: cir.atomic.cmpxchg weak success(relaxed) failure(relaxed) %{{.+}}, %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
29+
%4, %5 = cir.atomic.cmpxchg success(seq_cst) failure(acquire) %ptr, %expected, %desired : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
30+
// CHECK: cir.atomic.cmpxchg success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
31+
%6, %7 = cir.atomic.cmpxchg weak success(seq_cst) failure(acquire) %ptr, %expected, %desired : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
32+
// CHECK: cir.atomic.cmpxchg weak success(seq_cst) failure(acquire) %{{.+}}, %{{.+}}, %{{.+}} : (!cir.ptr<!s32i>, !s32i, !s32i) -> (!s32i, !cir.bool)
2033
cir.return
2134
}

0 commit comments

Comments
 (0)