diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td index 130ed9083848b..77e26cca1607f 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:$base, Variadic:$indices, DefaultValuedOptionalAttr:$nontemporal, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment); + OptionalAttr>: $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:$indices, DefaultValuedOptionalAttr:$nontemporal, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment); + OptionalAttr>: $alignment); let builders = [ OpBuilder<(ins "Value":$valueToStore, @@ -1875,8 +1873,7 @@ def Vector_MaskedLoadOp : Variadic:$indices, VectorOfNonZeroRankOf<[I1]>:$mask, AnyVectorOfNonZeroRank:$pass_thru, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)>, + OptionalAttr>: $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:$indices, VectorOfNonZeroRankOf<[I1]>:$mask, AnyVectorOfNonZeroRank:$valueToStore, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)> { + OptionalAttr>: $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]>:$indices, VectorOfNonZeroRankOf<[I1]>:$mask, AnyVectorOfNonZeroRank:$pass_thru, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)>, + OptionalAttr>: $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]>:$indices, VectorOfNonZeroRankOf<[I1]>:$mask, AnyVectorOfNonZeroRank:$valueToStore, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)> { + OptionalAttr>: $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:$indices, FixedVectorOfNonZeroRankOf<[I1]>:$mask, AnyVectorOfNonZeroRank:$pass_thru, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)>, + OptionalAttr>: $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:$indices, FixedVectorOfNonZeroRankOf<[I1]>:$mask, AnyVectorOfNonZeroRank:$valueToStore, - ConfinedAttr, - [AllAttrOf<[IntPositive, IntPowerOf2]>]>:$alignment)> { + OptionalAttr>: $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: ConfinedAttr; + class ArrayMaxCount : AttrConstraint< CPred<"::llvm::cast<::mlir::ArrayAttr>($_self).size() <= " # n>, "with at most " # n # " elements">;