[Mlir-commits] [mlir] [MLIR][GPU-LLVM] Add in-pass signature update option for opencl kernels (PR #105664)
Petr Kurapov
llvmlistbot at llvm.org
Thu Sep 19 03:03:23 PDT 2024
================
@@ -325,16 +359,45 @@ struct GPUToLLVMSPVConversionPass final
LLVMTypeConverter converter(context, options);
LLVMConversionTarget target(*context);
+ if (forceOpenclAddressSpaces) {
+ MemorySpaceToOpenCLMemorySpaceConverter converter;
+ AttrTypeReplacer replacer;
+ replacer.addReplacement([&converter](BaseMemRefType origType)
+ -> std::optional<BaseMemRefType> {
+ return converter.convertType<BaseMemRefType>(origType);
+ });
+
+ replacer.recursivelyReplaceElementsIn(getOperation(),
+ /*replaceAttrs=*/true,
+ /*replaceLocs=*/false,
+ /*replaceTypes=*/true);
+ }
+
target.addIllegalOp<gpu::BarrierOp, gpu::BlockDimOp, gpu::BlockIdOp,
gpu::GPUFuncOp, gpu::GlobalIdOp, gpu::GridDimOp,
gpu::ReturnOp, gpu::ShuffleOp, gpu::ThreadIdOp>();
populateGpuToLLVMSPVConversionPatterns(converter, patterns);
+ populateFuncToLLVMConversionPatterns(converter, patterns);
+ populateFinalizeMemRefToLLVMConversionPatterns(converter, patterns);
populateGpuMemorySpaceAttributeConversions(converter);
if (failed(applyPartialConversion(getOperation(), target,
std::move(patterns))))
signalPassFailure();
+
+ // `func.func`s are not handled by the lowering, so need a proper calling
+ // convention set separately.
+ getOperation().walk([](LLVM::LLVMFuncOp f) {
+ if (f.getCConv() == LLVM::CConv::C) {
+ f.setCConv(LLVM::CConv::SPIR_FUNC);
+ }
+ });
+ getOperation().walk([](LLVM::CallOp c) {
+ if (c.getCConv() == LLVM::CConv::C) {
+ c.setCConv(LLVM::CConv::SPIR_FUNC);
+ }
+ });
----------------
kurapov-peter wrote:
removed
https://github.com/llvm/llvm-project/pull/105664
More information about the Mlir-commits
mailing list