-
Notifications
You must be signed in to change notification settings - Fork 15k
[mlir][vector] Improve vector dialect documentation and constraint predicates #155259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][vector] Improve vector dialect documentation and constraint predicates #155259
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Erick Ochoa Lopez (amd-eochoalo) ChangesThis PR changes the documentation of the vector dialect to better reflect reality. When vector operations with alignment requirements are violated, undefined behavior will occur. This PR also adds the predicate Full diff: https://github.com/llvm/llvm-project/pull/155259.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index bcc423a634148..f650a51840cf5 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -1712,16 +1712,15 @@ def Vector_LoadOp : Vector_Op<"load", [
An optional `alignment` attribute allows to specify the byte alignment of the
load operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
}];
let arguments = (ins Arg<AnyMemRef, "the reference to load from",
[MemRead]>:$base,
Variadic<Index>:$indices,
DefaultValuedOptionalAttr<BoolAttr, "false">:$nontemporal,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment);
let builders = [
OpBuilder<(ins "VectorType":$resultType,
@@ -1827,8 +1826,8 @@ def Vector_StoreOp : Vector_Op<"store", [
An optional `alignment` attribute allows to specify the byte alignment of the
store operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
}];
let arguments = (ins
@@ -1837,8 +1836,7 @@ def Vector_StoreOp : Vector_Op<"store", [
[MemWrite]>:$base,
Variadic<Index>:$indices,
DefaultValuedOptionalAttr<BoolAttr, "false">:$nontemporal,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment);
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment);
let builders = [
OpBuilder<(ins "Value":$valueToStore,
@@ -1875,8 +1873,7 @@ def Vector_MaskedLoadOp :
Variadic<Index>:$indices,
VectorOfNonZeroRankOf<[I1]>:$mask,
AnyVectorOfNonZeroRank:$pass_thru,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)>,
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment)>,
Results<(outs AnyVectorOfNonZeroRank:$result)> {
let summary = "loads elements from memory into a vector as defined by a mask vector";
@@ -1915,8 +1912,8 @@ def Vector_MaskedLoadOp :
An optional `alignment` attribute allows to specify the byte alignment of the
load operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
}];
let extraClassDeclaration = [{
MemRefType getMemRefType() {
@@ -1968,8 +1965,7 @@ def Vector_MaskedStoreOp :
Variadic<Index>:$indices,
VectorOfNonZeroRankOf<[I1]>:$mask,
AnyVectorOfNonZeroRank:$valueToStore,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)> {
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment)> {
let summary = "stores elements from a vector into memory as defined by a mask vector";
@@ -2007,8 +2003,8 @@ def Vector_MaskedStoreOp :
An optional `alignment` attribute allows to specify the byte alignment of the
store operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
}];
let extraClassDeclaration = [{
MemRefType getMemRefType() {
@@ -2051,8 +2047,7 @@ def Vector_GatherOp :
VectorOfNonZeroRankOf<[AnyInteger, Index]>:$index_vec,
VectorOfNonZeroRankOf<[I1]>:$mask,
AnyVectorOfNonZeroRank:$pass_thru,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)>,
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment)>,
Results<(outs AnyVectorOfNonZeroRank:$result)> {
let summary = [{
@@ -2100,8 +2095,8 @@ def Vector_GatherOp :
An optional `alignment` attribute allows to specify the byte alignment of the
gather operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
Examples:
@@ -2154,8 +2149,7 @@ def Vector_ScatterOp :
VectorOfNonZeroRankOf<[AnyInteger, Index]>:$index_vec,
VectorOfNonZeroRankOf<[I1]>:$mask,
AnyVectorOfNonZeroRank:$valueToStore,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)> {
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment)> {
let summary = [{
scatters elements from a vector into memory as defined by an index vector
@@ -2191,8 +2185,8 @@ def Vector_ScatterOp :
An optional `alignment` attribute allows to specify the byte alignment of the
scatter operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
Examples:
@@ -2239,8 +2233,7 @@ def Vector_ExpandLoadOp :
Variadic<Index>:$indices,
FixedVectorOfNonZeroRankOf<[I1]>:$mask,
AnyVectorOfNonZeroRank:$pass_thru,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)>,
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment)>,
Results<(outs AnyVectorOfNonZeroRank:$result)> {
let summary = "reads elements from memory and spreads them into a vector as defined by a mask";
@@ -2274,8 +2267,8 @@ def Vector_ExpandLoadOp :
An optional `alignment` attribute allows to specify the byte alignment of the
load operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
Note, at the moment this Op is only available for fixed-width vectors.
@@ -2328,8 +2321,7 @@ def Vector_CompressStoreOp :
Variadic<Index>:$indices,
FixedVectorOfNonZeroRankOf<[I1]>:$mask,
AnyVectorOfNonZeroRank:$valueToStore,
- ConfinedAttr<OptionalAttr<I64Attr>,
- [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)> {
+ OptionalAttr<IntValidAlignment<I64Attr>>: $alignment)> {
let summary = "writes elements selectively from a vector as defined by a mask";
@@ -2362,8 +2354,8 @@ def Vector_CompressStoreOp :
An optional `alignment` attribute allows to specify the byte alignment of the
store operation. It must be a positive power of 2. The operation must access
- memory at an address aligned to this boundary. Violations may lead to
- architecture-specific faults or performance penalties.
+ memory at an address aligned to this boundary. Violating this requirement
+ triggers immediate undefined behavior.
Note, at the moment this Op is only available for fixed-width vectors.
diff --git a/mlir/include/mlir/IR/CommonAttrConstraints.td b/mlir/include/mlir/IR/CommonAttrConstraints.td
index 18da85a580710..e1869c1821b11 100644
--- a/mlir/include/mlir/IR/CommonAttrConstraints.td
+++ b/mlir/include/mlir/IR/CommonAttrConstraints.td
@@ -800,6 +800,10 @@ def IntPowerOf2 : AttrConstraint<
CPred<"::llvm::cast<::mlir::IntegerAttr>($_self).getValue().isPowerOf2()">,
"whose value is a power of two > 0">;
+def IntPositivePowerOf2 : AllAttrOf<[IntPositive, IntPowerOf2]>;
+
+class IntValidAlignment<Attr attr>: ConfinedAttr<attr, [IntPositivePowerOf2]>;
+
class ArrayMaxCount<int n> : AttrConstraint<
CPred<"::llvm::cast<::mlir::ArrayAttr>($_self).size() <= " # n>,
"with at most " # n # " elements">;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the updates!
This PR changes the documentation of the vector dialect to better reflect reality. When vector operations with alignment requirements are violated, undefined behavior will occur.
This PR also adds the predicate
IntValidAlignment
and adds it as constraint predicates for alignment attribtues.