@@ -2033,11 +2033,8 @@ BufferOp DMABDOp::getBufferOp() {
20332033
20342034// Parse/print hooks for the custom<DynamicScalar>($operand, $static_attr)
20352035// directive: a single scalar that is either an SSA value (runtime, %v) or a
2036- // compile-time integer constant (folded into the attribute). Mirrors
2037- // custom<DynamicIndexList> but for one scalar rather than a list, so a constant
2038- // never materializes an operand. The generated code binds the Optional<I32>
2039- // operand as std::optional<UnresolvedOperand> and the OptionalAttr<AIEI32Attr>
2040- // as IntegerAttr, exactly like upstream transform.tune AlternativesOp.
2036+ // compile-time integer constant (folded into the attribute), so a constant
2037+ // never materializes an operand. The scalar analog of custom<DynamicIndexList>.
20412038static ParseResult
20422039parseDynamicScalar (OpAsmParser &parser,
20432040 std::optional<OpAsmParser::UnresolvedOperand> &operand,
@@ -2068,9 +2065,7 @@ static void printDynamicScalar(OpAsmPrinter &printer, Operation *,
20682065}
20692066
20702067// Split a scalar OpFoldResult into an operand (runtime value) or an i32
2071- // attribute (compile-time constant), mirroring how sizes/strides split a
2072- // constant into static_* and a runtime value into an operand. An absent (null)
2073- // OpFoldResult leaves both unset.
2068+ // attribute (compile-time constant). A null OpFoldResult leaves both unset.
20742069static void splitScalarOfr (mlir::OpBuilder &builder, mlir::OpFoldResult ofr,
20752070 mlir::Value &operand, mlir::IntegerAttr &attr) {
20762071 operand = nullptr ;
@@ -2092,15 +2087,15 @@ void DMABDOp::buildMixed(mlir::OpBuilder &builder, mlir::OperationState &state,
20922087 llvm::ArrayRef<mlir::OpFoldResult> sizes,
20932088 llvm::ArrayRef<mlir::OpFoldResult> strides,
20942089 BDPadLayoutArrayAttr padDims, PacketInfoAttr packet) {
2095- // Split each mixed list into its dynamic operands + static array with the
2096- // ShapedType::kDynamic sentinel, exactly as tensor.extract_slice does .
2090+ // Split each mixed list into its dynamic operands + static array ( with the
2091+ // ShapedType::kDynamic sentinel for the runtime entries) .
20972092 llvm::SmallVector<int64_t > staticSizes, staticStrides;
20982093 llvm::SmallVector<mlir::Value> dynSizes, dynStrides;
20992094 mlir::dispatchIndexOpFoldResults (sizes, dynSizes, staticSizes);
21002095 mlir::dispatchIndexOpFoldResults (strides, dynStrides, staticStrides);
21012096
21022097 // Leave the static arrays unset when there is no ND layout so they elide
2103- // from the printed form (a plain linear transfer has no sizes/strides) .
2098+ // from the printed form.
21042099 DenseI64ArrayAttr staticSizesAttr =
21052100 staticSizes.empty () ? DenseI64ArrayAttr{}
21062101 : builder.getDenseI64ArrayAttr (staticSizes);
@@ -2137,13 +2132,13 @@ void DMABDOp::buildWithConstants(mlir::OpBuilder &builder,
21372132 BDPadLayoutArrayAttr padDims,
21382133 PacketInfoAttr packet) {
21392134 // Constant offset/len flow to the static_offset/static_len attributes (no
2140- // arith.constant materialized). Use i32 to match the AIEI32Attr type so
2141- // splitScalarOfr's cast stays sign-exact for negative offsets.
2135+ // arith.constant materialized). i32 matches AIEI32Attr, keeping the cast
2136+ // sign-exact for negative offsets.
21422137 mlir::OpFoldResult offsetOfr = builder.getI32IntegerAttr (offset);
21432138 mlir::OpFoldResult lenOfr = builder.getI32IntegerAttr (len);
21442139
21452140 // Turn the outermost-first BDDimLayoutArrayAttr into all-constant
2146- // OpFoldResults and let buildMixed handle the decomposition .
2141+ // OpFoldResults for buildMixed.
21472142 llvm::SmallVector<mlir::OpFoldResult> sizes, strides;
21482143 if (dims) {
21492144 for (BDDimLayoutAttr d : dims) {
@@ -2261,11 +2256,9 @@ LogicalResult DMABDOp::verify() {
22612256 if (std::optional<int32_t > nextBdId = getNextBdId ();
22622257 nextBdId.has_value () && static_cast <uint32_t >(*nextBdId) >= maxBds)
22632258 return emitOpError (" nextBdId attribute exceeds max: " ) << maxBds - 1 ;
2264- // Guard the mixed static/dynamic invariant before any consumer counts
2265- // sentinels against operands: the number of ShapedType::kDynamic entries in
2266- // each static array must equal the number of dynamic operands, and sizes and
2267- // strides must agree in rank. Skips the crash in getMixedValues when the two
2268- // are inconsistent (llvm #179401).
2259+ // The dynamic-operand count must match the kDynamic-sentinel count in each
2260+ // static array, and sizes/strides must agree in rank. Checked before any
2261+ // consumer calls getMixedValues, which crashes on a mismatch (llvm #179401).
22692262 llvm::ArrayRef<int64_t > staticSizes =
22702263 getStaticSizes ().value_or (llvm::ArrayRef<int64_t >{});
22712264 llvm::ArrayRef<int64_t > staticStrides =
@@ -2282,9 +2275,7 @@ LogicalResult DMABDOp::verify() {
22822275 << " )" ;
22832276
22842277 // Fold the mixed sizes/strides to a constant BDDimLayoutAttr list for
2285- // verification. A runtime size/stride yields nullopt + a diagnostic; on the
2286- // static verification path that is an error. `dims` mirrors the historical
2287- // std::optional<ArrayRef> shape so the checks below are unchanged.
2278+ // verification; a runtime size/stride yields nullopt plus a diagnostic.
22882279 std::optional<llvm::SmallVector<BDDimLayoutAttr>> dims;
22892280 if (!getMixedSizes ().empty ()) {
22902281 dims = getConstantDimensions ();
@@ -2403,10 +2394,10 @@ LogicalResult DMABDOp::verify() {
24032394 return emitOpError (" Packet ID field can only hold 5 bits." );
24042395 }
24052396
2397+ // A runtime len operand or the static_len attribute both count as having a
2398+ // length here.
24062399 if (!hasLen () && !getBuffer ().getType ().hasStaticShape ())
24072400 return emitOpError () << " buffer with dynamic shape requires static length." ;
2408- // Either a runtime operand or the static_len attribute satisfies the "has a
2409- // length" requirement.
24102401
24112402 if (getBurstLength () != 0 && !parentTile.isShimNOCTile ())
24122403 return emitOpError (" Burst length is only supported in Shim NOC tiles that "
@@ -2511,12 +2502,11 @@ struct LinearizeContiguousBDTransfer : public mlir::OpRewritePattern<DMABDOp> {
25112502 if (!bufferIsExternal && !parentIsShim && !inShimDMA)
25122503 return mlir::failure ();
25132504
2514- // Only when ND dimensions are present and all-constant. Runtime-valued
2515- // sizes can't be folded/linearized; decline silently (no diagnostic) so
2516- // valid IR with runtime sizes doesn't produce a spurious error .
2505+ // Only ND dimensions that are present and all-constant can be linearized;
2506+ // decline silently on runtime-valued sizes/strides so valid dynamic IR
2507+ // doesn't get a spurious diagnostic .
25172508 if (op.getMixedSizes ().empty ())
25182509 return mlir::failure ();
2519- // Check all sizes/strides are constants before attempting to fold.
25202510 for (mlir::OpFoldResult s : op.getMixedSizes ())
25212511 if (!mlir::getConstantIntValue (s))
25222512 return mlir::failure ();
@@ -2548,17 +2538,13 @@ struct LinearizeContiguousBDTransfer : public mlir::OpRewritePattern<DMABDOp> {
25482538 return mlir::failure ();
25492539 int32_t len = static_cast <int32_t >(product);
25502540
2551- // Rewrite to a linear BD: set len as the static_len attribute (a constant,
2552- // so no arith.constant operand) and clear the sizes/strides (both operands
2553- // and static arrays). All other attributes (offset, packet, burst_length,
2554- // bd_id, etc.) are preserved automatically.
2541+ // Rewrite to a linear BD: len as the static_len attribute, sizes/strides
2542+ // cleared. Other attributes are preserved.
25552543 rewriter.modifyOpInPlace (op, [&]() {
25562544 op.getLenMutable ().clear ();
25572545 op.setStaticLen (len);
25582546 op.getSizesMutable ().clear ();
25592547 op.getStridesMutable ().clear ();
2560- // Drop the static arrays entirely so the linear BD prints without any
2561- // sizes/strides clause (the attributes are optional).
25622548 op.setStaticSizes (std::nullopt );
25632549 op.setStaticStrides (std::nullopt );
25642550 });
@@ -2568,10 +2554,7 @@ struct LinearizeContiguousBDTransfer : public mlir::OpRewritePattern<DMABDOp> {
25682554} // namespace
25692555
25702556// Canonicalization pattern for DMABDOp: fold a constant offset/len/size/stride
2571- // operand back into the corresponding static attribute (removing the operand),
2572- // via the upstream foldDynamicIndexList helper for the lists and
2573- // getConstantIntValue for the scalars. Mirrors the constant-argument folding
2574- // tensor.extract_slice performs for its offsets/sizes/strides.
2557+ // operand back into the corresponding static_* attribute, removing the operand.
25752558namespace {
25762559struct FoldConstantBDDimList : public mlir ::OpRewritePattern<DMABDOp> {
25772560 using OpRewritePattern::OpRewritePattern;
@@ -2606,8 +2589,7 @@ struct FoldConstantBDDimList : public mlir::OpRewritePattern<DMABDOp> {
26062589 rewriter.modifyOpInPlace (op, [&]() {
26072590 op.getSizesMutable ().assign (dynSizes);
26082591 op.getStridesMutable ().assign (dynStrides);
2609- // Leave the static arrays unset (not empty) when there is no ND layout so
2610- // they elide from the printed form (a plain linear transfer).
2592+ // Leave the static arrays unset when there is no ND layout so they elide.
26112593 if (staticSizes.empty ())
26122594 op.removeStaticSizesAttr ();
26132595 else
0 commit comments