@@ -3678,12 +3678,12 @@ def AtomicFetchKind : I32EnumAttr<
36783678}
36793679
36803680def AtomicFetch : CIR_Op<"atomic.fetch",
3681- [Pure, SameSecondOperandAndResultType ]> {
3681+ [AllTypesMatch<["result", "val"]> ]> {
36823682 let summary = "Atomic fetch with unary and binary operations";
36833683 let description = [{
3684- Represents `__atomic_binop_fetch ` and `__atomic_fetch_binop ` builtins,
3684+ Represents `__atomic_<binop>_fetch ` and `__atomic_fetch_<binop> ` builtins,
36853685 where `binop` is on of the binary opcodes : `add`, `sub`, `and`, `xor`,
3686- `or` and `nand `.
3686+ `or`, `nand`, `max` and `min `.
36873687
36883688 `ptr` is an integer or fp pointer, followed by `val`, which must be
36893689 an integer or fp (only supported for `add` and `sub`). The operation
@@ -3693,9 +3693,14 @@ def AtomicFetch : CIR_Op<"atomic.fetch",
36933693 `__atomic_fetch_binop` and returns the value that had
36943694 previously been in *ptr, otherwise it returns the final result
36953695 of the computation (`__atomic_binop_fetch`).
3696+
3697+ Example:
3698+ %res = cir.atomic.fetch(add, %ptr : !cir.ptr<!s32i>,
3699+ %val : !s32i, seq_cst) : !s32i
36963700 }];
36973701 let results = (outs CIR_AnyIntOrFloat:$result);
3698- let arguments = (ins PrimitiveIntOrFPPtr:$ptr, CIR_AnyIntOrFloat:$val,
3702+ let arguments = (ins Arg<PrimitiveIntOrFPPtr, "", [MemRead, MemWrite]>:$ptr,
3703+ CIR_AnyIntOrFloat:$val,
36993704 AtomicFetchKind:$binop,
37003705 Arg<MemOrder, "memory order">:$mem_order,
37013706 UnitAttr:$is_volatile,
@@ -3715,14 +3720,19 @@ def AtomicFetch : CIR_Op<"atomic.fetch",
37153720 let hasVerifier = 1;
37163721}
37173722
3718- def AtomicXchg : CIR_Op<"atomic.xchg", [Pure, SameSecondOperandAndResultType ]> {
3723+ def AtomicXchg : CIR_Op<"atomic.xchg", [AllTypesMatch<["result", "val"]> ]> {
37193724 let summary = "Atomic exchange";
37203725 let description = [{
3721- Atomic exchange functionality mapped from different use of builtins in
3722- C/C++.
3726+ Atomic exchange operations. Implements C/C++ builtins such as
3727+ `__atomic_exchange`and `__atomic_exchange_n`.
3728+
3729+ Example:
3730+ %res = cir.atomic.xchg(%ptr : !cir.ptr<!some_struct>,
3731+ %val : !u64i, seq_cst) : !u64i
37233732 }];
37243733 let results = (outs CIR_AnyType:$result);
3725- let arguments = (ins CIR_PointerType:$ptr, CIR_AnyType:$val,
3734+ let arguments = (ins Arg<CIR_PointerType, "", [MemRead, MemWrite]>:$ptr,
3735+ CIR_AnyType:$val,
37263736 Arg<MemOrder, "memory order">:$mem_order,
37273737 UnitAttr:$is_volatile);
37283738
@@ -3738,14 +3748,24 @@ def AtomicXchg : CIR_Op<"atomic.xchg", [Pure, SameSecondOperandAndResultType]> {
37383748 let hasVerifier = 0;
37393749}
37403750
3741- def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg", [Pure]> {
3751+ def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg",
3752+ [AllTypesMatch<["old", "expected", "desired"]>]> {
37423753 let summary = "Atomic compare exchange";
37433754 let description = [{
3744- C/C++ Atomic compare and exchange. Example:
3755+ C/C++ Atomic compare and exchange operation. Implements builtins like
3756+ `__atomic_compare_exchange_n` and `__atomic_compare_exchange`.
3757+
3758+ Example:
3759+ %old, %cmp = cir.atomic.cmp_xchg(%ptr : !cir.ptr<!some_struct>,
3760+ %expected : !u64i,
3761+ %desired : !u64i,
3762+ success = seq_cst,
3763+ failure = seq_cst) weak
3764+ : (!u64i, !cir.bool)
37453765
37463766 }];
37473767 let results = (outs CIR_AnyType:$old, CIR_BoolType:$cmp);
3748- let arguments = (ins CIR_AnyType :$ptr,
3768+ let arguments = (ins Arg<CIR_PointerType, "", [MemRead, MemWrite]> :$ptr,
37493769 CIR_AnyType:$expected,
37503770 CIR_AnyType:$desired,
37513771 Arg<MemOrder, "success memory order">:$succ_order,
0 commit comments