[Mlir-commits] [mlir] [mlir][vector] Add AlignmentBytes struct (PR #152207)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Aug 5 14:15:12 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-vector
Author: Erick Ochoa Lopez (amd-eochoalo)
<details>
<summary>Changes</summary>
This patchset adds a small struct which represents the alignment in terms of bytes. Adding an explicit struct instead of using integers allows for easier reading and avoids confusion since the alignment can be given in different units. See for example the following [RFC.](https://discourse.llvm.org/t/rfc-changing-byte-alignment-to-bit-alignment-for-memref-and-vector-dialects/87727)
---
Full diff: https://github.com/llvm/llvm-project/pull/152207.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/Vector/IR/VectorOps.h (+9)
- (modified) mlir/include/mlir/Dialect/Vector/IR/VectorOps.td (+6-6)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.h b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.h
index 364c1728715e8..b5ae0123d8c53 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.h
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.h
@@ -77,6 +77,15 @@ struct VectorDim {
int64_t dim;
bool isScalable;
};
+
+struct AlignmentBytes {
+ uint64_t alignment = 0;
+ AlignmentBytes() = default;
+ explicit AlignmentBytes(uint64_t alignment) : alignment(alignment) {};
+ explicit operator bool() const { return alignment; }
+ uint64_t getAlignment() const { return alignment; }
+};
+
BroadcastableToResult
isBroadcastableTo(Type srcType, VectorType dstVectorType,
std::pair<VectorDim, VectorDim> *mismatchingDims = nullptr);
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index 3885439e11f89..3ebb5721d7181 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -1729,18 +1729,18 @@ def Vector_LoadOp : Vector_Op<"load", [
"Value":$base,
"ValueRange":$indices,
CArg<"bool", "false">:$nontemporal,
- CArg<"uint64_t", "0">:$alignment), [{
+ CArg<"AlignmentBytes", "AlignmentBytes()">: $alignment), [{
return build($_builder, $_state, resultType, base, indices, nontemporal,
- alignment != 0 ? $_builder.getI64IntegerAttr(alignment) :
+ alignment ? $_builder.getI64IntegerAttr(alignment.getAlignment()) :
nullptr);
}]>,
OpBuilder<(ins "TypeRange":$resultTypes,
"Value":$base,
"ValueRange":$indices,
CArg<"bool", "false">:$nontemporal,
- CArg<"uint64_t", "0">:$alignment), [{
+ CArg<"AlignmentBytes", "AlignmentBytes()">: $alignment), [{
return build($_builder, $_state, resultTypes, base, indices, nontemporal,
- alignment != 0 ? $_builder.getI64IntegerAttr(alignment) :
+ alignment ? $_builder.getI64IntegerAttr(alignment.getAlignment()) :
nullptr);
}]>
];
@@ -1847,9 +1847,9 @@ def Vector_StoreOp : Vector_Op<"store", [
"Value":$base,
"ValueRange":$indices,
CArg<"bool", "false">:$nontemporal,
- CArg<"uint64_t", "0">:$alignment), [{
+ CArg<"AlignmentBytes", "AlignmentBytes()">:$alignment), [{
return build($_builder, $_state, valueToStore, base, indices, nontemporal,
- alignment != 0 ? $_builder.getI64IntegerAttr(alignment) :
+ alignment ? $_builder.getI64IntegerAttr(alignment.getAlignment()) :
nullptr);
}]>
];
``````````
</details>
https://github.com/llvm/llvm-project/pull/152207
More information about the Mlir-commits
mailing list