[Mlir-commits] [mlir] 7d85560 - [mlir] Add populateGpuToLLVMConversionPatterns function

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Aug 1 01:56:02 PDT 2021


Author: Butygin
Date: 2021-08-01T11:51:21+03:00
New Revision: 7d855605830f4a524f02b09d6891b351ff716782

URL: https://github.com/llvm/llvm-project/commit/7d855605830f4a524f02b09d6891b351ff716782
DIFF: https://github.com/llvm/llvm-project/commit/7d855605830f4a524f02b09d6891b351ff716782.diff

LOG: [mlir] Add populateGpuToLLVMConversionPatterns function

Differential Revision: https://reviews.llvm.org/D107218

Added: 
    

Modified: 
    mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
    mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
index 708a3fe0b23ee..a87158658d837 100644
--- a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
+++ b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
@@ -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).
 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
 
 #endif // MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_

diff  --git a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
index 3dfed5fec7a26..242d331ca76a8 100644
--- a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
+++ b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
@@ -323,21 +323,7 @@ void GpuToLLVMConversionPass::runOnOperation() {
   populateStdToLLVMConversionPatterns(converter, patterns);
   populateAsyncStructuralTypeConversionsAndLegality(converter, patterns,
                                                     target);
-
-  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());
+  populateGpuToLLVMConversionPatterns(converter, patterns, gpuBinaryAnnotation);
 
   if (failed(
           applyPartialConversion(getOperation(), target, std::move(patterns))))
@@ -804,3 +790,22 @@ std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
 mlir::createGpuToLLVMConversionPass() {
   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());
+}


        


More information about the Mlir-commits mailing list