[Mlir-commits] [mlir] [mlir][ptr] Add load and store ops. (PR #156093)

Fabian Mora llvmlistbot at llvm.org
Sun Aug 31 10:07:39 PDT 2025


================
@@ -84,6 +84,122 @@ LogicalResult FromPtrOp::verify() {
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// LoadOp
+//===----------------------------------------------------------------------===//
+
+/// Verifies the attributes and the type of atomic memory access operations.
+template <typename OpTy>
+static LogicalResult
+verifyAtomicMemOp(OpTy memOp, ArrayRef<AtomicOrdering> unsupportedOrderings) {
+  if (memOp.getOrdering() != AtomicOrdering::not_atomic) {
+    if (llvm::is_contained(unsupportedOrderings, memOp.getOrdering()))
+      return memOp.emitOpError("unsupported ordering '")
+             << stringifyAtomicOrdering(memOp.getOrdering()) << "'";
+    if (!memOp.getAlignment())
+      return memOp.emitOpError("expected alignment for atomic access");
+    return success();
+  }
+  if (memOp.getSyncscope()) {
+    return memOp.emitOpError(
+        "expected syncscope to be null for non-atomic access");
+  }
+  return success();
+}
+
+/// Verifies that the alignment attribute is a power of 2 if present.
+static LogicalResult
+verifyAlignment(std::optional<int64_t> alignment,
+                function_ref<InFlightDiagnostic()> emitError) {
+  if (!alignment)
+    return success();
+  if (alignment.value() <= 0)
+    return emitError() << "alignment must be positive";
----------------
fabianmcg wrote:

No, because this is the impl of the method checking whether it's a power of 2:
```
constexpr bool isPowerOf2_64(uint64_t Value) {
  return llvm::has_single_bit(Value);
}
```
The method expects the value to be greater than 0. I'd also argue is good two have it separate because it allows users to more easily identify the error, rather than a generic is not a power of two.

https://github.com/llvm/llvm-project/pull/156093


More information about the Mlir-commits mailing list