From a09fed7886275c5dc1dbd5ec6e09fd1facd5b285 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Fri, 26 Apr 2024 15:05:02 -0700 Subject: [PATCH] [CIR][CIRGen] Atomics: improve docs and constraints --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 42 +++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 7114be39d939..e65416068964 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -3678,12 +3678,12 @@ def AtomicFetchKind : I32EnumAttr< } def AtomicFetch : CIR_Op<"atomic.fetch", - [Pure, SameSecondOperandAndResultType]> { + [AllTypesMatch<["result", "val"]>]> { let summary = "Atomic fetch with unary and binary operations"; let description = [{ - Represents `__atomic_binop_fetch` and `__atomic_fetch_binop` builtins, + Represents `__atomic__fetch` and `__atomic_fetch_` builtins, where `binop` is on of the binary opcodes : `add`, `sub`, `and`, `xor`, - `or` and `nand`. + `or`, `nand`, `max` and `min`. `ptr` is an integer or fp pointer, followed by `val`, which must be an integer or fp (only supported for `add` and `sub`). The operation @@ -3693,9 +3693,14 @@ def AtomicFetch : CIR_Op<"atomic.fetch", `__atomic_fetch_binop` and returns the value that had previously been in *ptr, otherwise it returns the final result of the computation (`__atomic_binop_fetch`). + + Example: + %res = cir.atomic.fetch(add, %ptr : !cir.ptr, + %val : !s32i, seq_cst) : !s32i }]; let results = (outs CIR_AnyIntOrFloat:$result); - let arguments = (ins PrimitiveIntOrFPPtr:$ptr, CIR_AnyIntOrFloat:$val, + let arguments = (ins Arg:$ptr, + CIR_AnyIntOrFloat:$val, AtomicFetchKind:$binop, Arg:$mem_order, UnitAttr:$is_volatile, @@ -3715,14 +3720,19 @@ def AtomicFetch : CIR_Op<"atomic.fetch", let hasVerifier = 1; } -def AtomicXchg : CIR_Op<"atomic.xchg", [Pure, SameSecondOperandAndResultType]> { +def AtomicXchg : CIR_Op<"atomic.xchg", [AllTypesMatch<["result", "val"]>]> { let summary = "Atomic exchange"; let description = [{ - Atomic exchange functionality mapped from different use of builtins in - C/C++. + Atomic exchange operations. Implements C/C++ builtins such as + `__atomic_exchange`and `__atomic_exchange_n`. + + Example: + %res = cir.atomic.xchg(%ptr : !cir.ptr, + %val : !u64i, seq_cst) : !u64i }]; let results = (outs CIR_AnyType:$result); - let arguments = (ins CIR_PointerType:$ptr, CIR_AnyType:$val, + let arguments = (ins Arg:$ptr, + CIR_AnyType:$val, Arg:$mem_order, UnitAttr:$is_volatile); @@ -3738,14 +3748,24 @@ def AtomicXchg : CIR_Op<"atomic.xchg", [Pure, SameSecondOperandAndResultType]> { let hasVerifier = 0; } -def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg", [Pure]> { +def AtomicCmpXchg : CIR_Op<"atomic.cmp_xchg", + [AllTypesMatch<["old", "expected", "desired"]>]> { let summary = "Atomic compare exchange"; let description = [{ - C/C++ Atomic compare and exchange. Example: + C/C++ Atomic compare and exchange operation. Implements builtins like + `__atomic_compare_exchange_n` and `__atomic_compare_exchange`. + + Example: + %old, %cmp = cir.atomic.cmp_xchg(%ptr : !cir.ptr, + %expected : !u64i, + %desired : !u64i, + success = seq_cst, + failure = seq_cst) weak + : (!u64i, !cir.bool) }]; let results = (outs CIR_AnyType:$old, CIR_BoolType:$cmp); - let arguments = (ins CIR_AnyType:$ptr, + let arguments = (ins Arg:$ptr, CIR_AnyType:$expected, CIR_AnyType:$desired, Arg:$succ_order,