Fix ktdp_lowering.construct_indirect_access_tile to align with ktdp variant semantics - #140
Conversation
|
I think this warrants a verifier that checks the block is empty (excluding the terminator), at the very least. Honestly, I find the whole "hidden block just to define SSA values" super weird to begin with. We could just add the intermediate variables to the domain of the affine map and let the user specify the map directly. With a bit of finesse, we could even try and keep the syntax - as long as you don't |
…ion and behave more consistently with its ktdp variant Signed-off-by: Bardia Mahjour <bmahjour@ca.ibm.com>
Signed-off-by: Bardia Mahjour <bmahjour@ca.ibm.com>
4e421d3 to
3ee25b6
Compare
Again I see your point, but since the upstream variant is already in this form, I strongly suggest we keep consistent until such time that we revisit the KTIR syntax. |
…_buf_memref Signed-off-by: Bardia Mahjour <bmahjour@ca.ibm.com>
Signed-off-by: Bardia Mahjour <bmahjour@ca.ibm.com>
Signed-off-by: Bardia Mahjour <bmahjour@ca.ibm.com>
Fix
ktdp_lowering.construct_indirect_access_tileto align withktdpvariant semanticsWhat was wrong
The op was structurally inconsistent with its
ktdp.construct_indirect_access_tilecounterpart in several ways:Semantic / structural issues:
intermediate_variableswere modelled as plainVariadic<Index>operands read from the enclosing scope. In thektdpvariant they are block arguments of a hidden single-block region — values defined by the op, not passed into it. This distinction matters: they enumerate the iteration space of the tile and must not be SSA-reachable as ordinary operands.$basewereVariadic<Index>(flat SSA values). This cannot represent affine expressions like(%c0 + %arg7)which appear throughout the transformation pipeline without pre-materializing intermediatearithops. Thektdpvariant stores these asArrayAttrofAffineMapAttrover a unified(captured..., intermediate...)domain for exactly this reason.Variadic<Index>operands. While the representation is correct in principle (IAB subscripts are always bare variable references becausespyreop.idx32toaddrpre-computes the flat address), listing them as operands was wrong because intermediate-variable IAB subscripts are region block args, not outer SSA values — resolving them as operands would fail at parse time.Implementation issues (discovered during parser/printer audit against the
ktdpvariant):ktdpbuilds it after.ensureTerminatorwas called after adding block arguments;ktdpcalls it before.expr.replaceDimsper result;ktdpusesraw.compose(remap).asserts that guardvariables_space_set/variables_space_orderdimension consistency.llvm::interleaveCommafor block args;ktdpusesp << getRegion().getArguments().What was changed
Op structure (
KTDPLowering.td):Variadic<Index>:$intermediate_variablesfromargumentsand replaced withlet regions = (region SizedRegion<1>:$region)+SingleBlockImplicitTerminator<"ktdp::RegionTerminatorOp">, exactly mirroring thektdpvariant.Variadic<Index>:$direct_subscriptswithArrayAttr:$per_dim_subscript_maps— oneAffineMapAttrper$basedimension over the unified(captured..., intermediate...)domain.Variadic<Index>:$ind_addr_buf_subscriptswithDenseI32ArrayAttr:$ind_addr_buf_dim_positions— one integer per IAB dimension giving its position in the unified variable list. No affine map is needed here because IAB entries already hold flat absolute addresses; the subscript is structurally always a bare variable reference.AttrSizedOperandSegments(now only one variadic operand segment:$captured_variables).getIntermediateVariables()helper viaextraClassDeclaration, mirroring thektdpvariant.Implementation (
KTDPLoweringOps.cpp):result.regions.reserve(1);ensureTerminatorcalled before block arguments; map canonicalization switched toraw.compose(remap);posMapreplaces redundant dual-scan lookup; infinite-loop guard added.ensureTerminatorcalled before block arguments; threeasserts added forvariables_space_set/variables_space_order/numIntermediateVariablesconsistency.p << getRegion().getArguments()for block-arg output.Tests (
indirect_access_tile.mlir):(affine-expr)syntax; a fourth test case added covering the post-per-entry-legalization form where the IAB subscript is a captured loop IV.