[Mlir-commits] [mlir] [mlir][xegpu] add support for structure control flow ops in workgroup to subgroup distribution (PR #142618)
Charitha Saumya
llvmlistbot at llvm.org
Tue Jun 10 10:19:16 PDT 2025
================
@@ -334,10 +398,60 @@ struct XeGPUWgToSgDistributePass
} // namespace
void XeGPUWgToSgDistributePass::runOnOperation() {
+ // Track existing UnrealizedConversionCastOps
+ SmallVector<Operation *> existingCastOps;
+ getOperation()->walk([&](UnrealizedConversionCastOp castOp) {
+ existingCastOps.push_back(castOp.getOperation());
+ });
+
+ TypeConverter converter;
+ converter.addConversion([&](Type type) -> Type { return type; });
+ converter.addConversion(
+ [&](RankedTensorType type,
+ SmallVectorImpl<Type> &result) -> std::optional<LogicalResult> {
+ Type elemTy = type.getElementType();
+ ArrayRef<int64_t> shape = type.getShape();
+
+ int count;
+ SmallVector<int64_t> subShape;
+ std::tie(subShape, count) = getSgShapeAndCount(
+ shape, dyn_cast<xegpu::LayoutAttr>(type.getEncoding()));
+
+ auto newTy = VectorType::get(subShape, elemTy);
+ result.append(count, newTy);
+ return success();
+ });
+
+ // Step 1: Apply SCFStructuralTypeConversions to SCF operations with
+ // VectorType operands. This first converts such operands to RankedTensorType,
+ // propagates the layout attribute into the encoding attribute, and finally
+ // converts the RankedTensorType to VectorType based on the encoding.
+ xegpu::doSCFStructuralTypeConversionWithTensorType(getOperation(), converter);
+
MLIRContext *ctx = &getContext();
RewritePatternSet patterns(ctx);
ConversionTarget target(*ctx);
+ converter.addConversion(
----------------
charithaintc wrote:
why reuse the type converter here?
https://github.com/llvm/llvm-project/pull/142618
More information about the Mlir-commits
mailing list