[Mlir-commits] [mlir] [MLIR][XeVM] Update XeVM type converter (PR #189306)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Apr 8 09:06:44 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
Author: Sang Ik Lee (silee2)
<details>
<summary>Changes</summary>
Ideally, DLTI should be used for getting Index type which as it is tied to bitwidth of pointer type that can be expressed with DLTI.
But currently, a separate pass option for bitwidth of Index type is used in many passes.
GPU to XeVM lowering pipeline also use passes with such options.
But XeVM type converter does not provide a way to reflect choice of Index type bitwidth and uses a hardcoded value.
This PR updates XeVM type converter to use Index type bitwidth from pass option.
---
Full diff: https://github.com/llvm/llvm-project/pull/189306.diff
3 Files Affected:
- (modified) mlir/include/mlir/Conversion/Passes.td (+4)
- (modified) mlir/lib/Conversion/XeGPUToXeVM/XeGPUToXeVM.cpp (+23-14)
- (modified) mlir/lib/Dialect/GPU/Pipelines/GPUToXeVMPipeline.cpp (+4-1)
``````````diff
diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index 644d27938177b..26ab46d99dec1 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -1653,6 +1653,10 @@ def ConvertXeGPUToXeVMPass : Pass<"convert-xegpu-to-xevm"> {
"memref::MemRefDialect", "arith::ArithDialect",
"LLVM::LLVMDialect", "index::IndexDialect",
"gpu::GPUDialect", "scf::SCFDialect"];
+ let options = [Option<"use64bitIndex", "use-64bit-index", "bool",
+ /*default=*/"true",
+ "Use 64-bit integers to convert index types">,
+ ];
}
#endif // MLIR_CONVERSION_PASSES
diff --git a/mlir/lib/Conversion/XeGPUToXeVM/XeGPUToXeVM.cpp b/mlir/lib/Conversion/XeGPUToXeVM/XeGPUToXeVM.cpp
index 6df209438447b..da7ade3dd3e19 100644
--- a/mlir/lib/Conversion/XeGPUToXeVM/XeGPUToXeVM.cpp
+++ b/mlir/lib/Conversion/XeGPUToXeVM/XeGPUToXeVM.cpp
@@ -1049,14 +1049,25 @@ struct ConvertXeGPUToXeVMPass
using Base::Base;
void runOnOperation() override {
- LLVMTypeConverter typeConverter(&getContext());
+ MLIRContext *context = &getContext();
+
+ // XeVM type converter is based on LLVM type converter with the
+ // following customizations.
+ // First, type conversion rules are added for xegpu custome types,
+ // TensorDescType and MemDescType.
+ // Second, MemRefType is lowered to single integer type
+ // Third, VectorType of single element or 0D is converted to vector
+ // element type. Otherwise, vector type is flatten to 1D.
+ LowerToLLVMOptions options(context);
+ options.overrideIndexBitwidth(this->use64bitIndex ? 64 : 32);
+ LLVMTypeConverter typeConverter(context, options);
+
+ Type xevmIndexType = typeConverter.convertType(IndexType::get(context));
+ Type i32Type = IntegerType::get(context, 32);
typeConverter.addConversion([&](VectorType type) -> Type {
- unsigned rank = type.getRank();
- auto elemType = type.getElementType();
- // If the element type is index, convert it to i64.
- if (llvm::isa<IndexType>(elemType))
- elemType = IntegerType::get(&getContext(), 64);
+ auto elemType = typeConverter.convertType(type.getElementType());
// If the vector rank is 0 or has a single element, return the element
+ unsigned rank = type.getRank();
if (rank == 0 || type.getNumElements() == 1)
return elemType;
// Otherwise, convert the vector to a flat vector type.
@@ -1068,17 +1079,15 @@ struct ConvertXeGPUToXeVMPass
if (type.isScattered())
return {};
if (type.getRank() == 1)
- return IntegerType::get(&getContext(), 64);
- auto i32Type = IntegerType::get(&getContext(), 32);
+ return xevmIndexType;
return VectorType::get(8, i32Type);
});
// Convert MemDescType into i32 for SLM
- typeConverter.addConversion([&](xegpu::MemDescType type) -> Type {
- return IntegerType::get(&getContext(), 32);
- });
+ typeConverter.addConversion(
+ [&](xegpu::MemDescType type) -> Type { return i32Type; });
typeConverter.addConversion([&](MemRefType type) -> Type {
- return IntegerType::get(&getContext(), (isSharedMemRef(type) ? 32 : 64));
+ return isSharedMemRef(type) ? i32Type : xevmIndexType;
});
// LLVM type converter puts unrealized casts for the following cases:
@@ -1289,14 +1298,14 @@ struct ConvertXeGPUToXeVMPass
typeConverter.addTargetMaterialization(
vectorToSingleElementMaterializationCast);
typeConverter.addTargetMaterialization(vectorToVectorMaterializationCast);
- ConversionTarget target(getContext());
+ ConversionTarget target(*context);
target.addLegalDialect<xevm::XeVMDialect, LLVM::LLVMDialect,
vector::VectorDialect, arith::ArithDialect,
memref::MemRefDialect, gpu::GPUDialect,
index::IndexDialect>();
target.addIllegalDialect<xegpu::XeGPUDialect>();
- RewritePatternSet patterns(&getContext());
+ RewritePatternSet patterns(context);
populateXeGPUToXeVMConversionPatterns(typeConverter, patterns);
scf::populateSCFStructuralTypeConversionsAndLegality(typeConverter,
patterns, target);
diff --git a/mlir/lib/Dialect/GPU/Pipelines/GPUToXeVMPipeline.cpp b/mlir/lib/Dialect/GPU/Pipelines/GPUToXeVMPipeline.cpp
index fbb7bb8aeb4bc..fb260f45e5ddd 100644
--- a/mlir/lib/Dialect/GPU/Pipelines/GPUToXeVMPipeline.cpp
+++ b/mlir/lib/Dialect/GPU/Pipelines/GPUToXeVMPipeline.cpp
@@ -97,7 +97,10 @@ void buildGPUPassPipeline(OpPassManager &pm,
pm.addNestedPass<gpu::GPUModuleOp>(xegpu::createXeGPUVectorLinearize());
}
pm.addNestedPass<gpu::GPUModuleOp>(createConvertMathToXeVM());
- pm.addNestedPass<gpu::GPUModuleOp>(createConvertXeGPUToXeVMPass());
+ ConvertXeGPUToXeVMPassOptions xegpuToXeVMOptions;
+ xegpuToXeVMOptions.use64bitIndex = options.use64bitIndex;
+ pm.addNestedPass<gpu::GPUModuleOp>(
+ createConvertXeGPUToXeVMPass(xegpuToXeVMOptions));
{
ConvertGpuOpsToLLVMSPVOpsOptions gpuToLLVMSPVOptions;
gpuToLLVMSPVOptions.use64bitIndex = options.use64bitIndex;
``````````
</details>
https://github.com/llvm/llvm-project/pull/189306
More information about the Mlir-commits
mailing list