• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ConvertSPIRVToLLVM.h - Convert SPIR-V to LLVM dialect ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Provides patterns to convert SPIR-V dialect to LLVM dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_CONVERSION_SPIRVTOLLVM_CONVERTSPIRVTOLLVM_H
14 #define MLIR_CONVERSION_SPIRVTOLLVM_CONVERTSPIRVTOLLVM_H
15 
16 #include "mlir/Transforms/DialectConversion.h"
17 
18 namespace mlir {
19 class LLVMTypeConverter;
20 class MLIRContext;
21 class ModuleOp;
22 
23 template <typename SPIRVOp>
24 class SPIRVToLLVMConversion : public OpConversionPattern<SPIRVOp> {
25 public:
26   SPIRVToLLVMConversion(MLIRContext *context, LLVMTypeConverter &typeConverter,
27                         PatternBenefit benefit = 1)
28       : OpConversionPattern<SPIRVOp>(context, benefit),
29         typeConverter(typeConverter) {}
30 
31 protected:
32   LLVMTypeConverter &typeConverter;
33 };
34 
35 /// Encodes global variable's descriptor set and binding into its name if they
36 /// both exist.
37 void encodeBindAttribute(ModuleOp module);
38 
39 /// Populates type conversions with additional SPIR-V types.
40 void populateSPIRVToLLVMTypeConversion(LLVMTypeConverter &typeConverter);
41 
42 /// Populates the given list with patterns that convert from SPIR-V to LLVM.
43 void populateSPIRVToLLVMConversionPatterns(MLIRContext *context,
44                                            LLVMTypeConverter &typeConverter,
45                                            OwningRewritePatternList &patterns);
46 
47 /// Populates the given list with patterns for function conversion from SPIR-V
48 /// to LLVM.
49 void populateSPIRVToLLVMFunctionConversionPatterns(
50     MLIRContext *context, LLVMTypeConverter &typeConverter,
51     OwningRewritePatternList &patterns);
52 
53 /// Populates the given patterns for module conversion from SPIR-V to LLVM.
54 void populateSPIRVToLLVMModuleConversionPatterns(
55     MLIRContext *context, LLVMTypeConverter &typeConverter,
56     OwningRewritePatternList &patterns);
57 
58 } // namespace mlir
59 
60 #endif // MLIR_CONVERSION_SPIRVTOLLVM_CONVERTSPIRVTOLLVM_H
61