1 //===- SPIRVToLLVM.h - SPIR-V to LLVM Patterns ------------------*- 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_SPIRVTOLLVM_H 14 #define MLIR_CONVERSION_SPIRVTOLLVM_SPIRVTOLLVM_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(LLVMTypeConverter &typeConverter, 44 RewritePatternSet &patterns); 45 46 /// Populates the given list with patterns for function conversion from SPIR-V 47 /// to LLVM. 48 void populateSPIRVToLLVMFunctionConversionPatterns( 49 LLVMTypeConverter &typeConverter, RewritePatternSet &patterns); 50 51 /// Populates the given patterns for module conversion from SPIR-V to LLVM. 52 void populateSPIRVToLLVMModuleConversionPatterns( 53 LLVMTypeConverter &typeConverter, RewritePatternSet &patterns); 54 55 } // namespace mlir 56 57 #endif // MLIR_CONVERSION_SPIRVTOLLVM_SPIRVTOLLVM_H 58