[mlir] Add populateGpuToLLVMConversionPatterns function

Differential Revision: https://reviews.llvm.org/D107218
This commit is contained in:
Butygin 2021-07-28 22:31:26 +03:00
parent a5a5e73353
commit 7d85560583
2 changed files with 26 additions and 15 deletions

View File

@ -52,6 +52,12 @@ using LoweringCallback = std::function<std::unique_ptr<llvm::Module>(
/// typed ABI on top of GPU runtimes such as CUDA or ROCm (HIP). /// typed ABI on top of GPU runtimes such as CUDA or ROCm (HIP).
std::unique_ptr<OperationPass<ModuleOp>> createGpuToLLVMConversionPass(); std::unique_ptr<OperationPass<ModuleOp>> createGpuToLLVMConversionPass();
/// Collect a set of patterns to convert from the GPU dialect to LLVM and
/// populate converter for gpu types.
void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter,
OwningRewritePatternList &patterns,
StringRef gpuBinaryAnnotation = {});
} // namespace mlir } // namespace mlir
#endif // MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_ #endif // MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_

View File

@ -323,21 +323,7 @@ void GpuToLLVMConversionPass::runOnOperation() {
populateStdToLLVMConversionPatterns(converter, patterns); populateStdToLLVMConversionPatterns(converter, patterns);
populateAsyncStructuralTypeConversionsAndLegality(converter, patterns, populateAsyncStructuralTypeConversionsAndLegality(converter, patterns,
target); target);
populateGpuToLLVMConversionPatterns(converter, patterns, gpuBinaryAnnotation);
converter.addConversion(
[context = &converter.getContext()](gpu::AsyncTokenType type) -> Type {
return LLVM::LLVMPointerType::get(IntegerType::get(context, 8));
});
patterns.add<ConvertAllocOpToGpuRuntimeCallPattern,
ConvertDeallocOpToGpuRuntimeCallPattern,
ConvertHostRegisterOpToGpuRuntimeCallPattern,
ConvertMemcpyOpToGpuRuntimeCallPattern,
ConvertWaitAsyncOpToGpuRuntimeCallPattern,
ConvertWaitOpToGpuRuntimeCallPattern,
ConvertAsyncYieldToGpuRuntimeCallPattern>(converter);
patterns.add<ConvertLaunchFuncOpToGpuRuntimeCallPattern>(converter,
gpuBinaryAnnotation);
patterns.add<EraseGpuModuleOpPattern>(&converter.getContext());
if (failed( if (failed(
applyPartialConversion(getOperation(), target, std::move(patterns)))) applyPartialConversion(getOperation(), target, std::move(patterns))))
@ -804,3 +790,22 @@ std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
mlir::createGpuToLLVMConversionPass() { mlir::createGpuToLLVMConversionPass() {
return std::make_unique<GpuToLLVMConversionPass>(); return std::make_unique<GpuToLLVMConversionPass>();
} }
void mlir::populateGpuToLLVMConversionPatterns(
LLVMTypeConverter &converter, OwningRewritePatternList &patterns,
StringRef gpuBinaryAnnotation) {
converter.addConversion(
[context = &converter.getContext()](gpu::AsyncTokenType type) -> Type {
return LLVM::LLVMPointerType::get(IntegerType::get(context, 8));
});
patterns.add<ConvertAllocOpToGpuRuntimeCallPattern,
ConvertDeallocOpToGpuRuntimeCallPattern,
ConvertHostRegisterOpToGpuRuntimeCallPattern,
ConvertMemcpyOpToGpuRuntimeCallPattern,
ConvertWaitAsyncOpToGpuRuntimeCallPattern,
ConvertWaitOpToGpuRuntimeCallPattern,
ConvertAsyncYieldToGpuRuntimeCallPattern>(converter);
patterns.add<ConvertLaunchFuncOpToGpuRuntimeCallPattern>(converter,
gpuBinaryAnnotation);
patterns.add<EraseGpuModuleOpPattern>(&converter.getContext());
}