1cae4067eSGeorge Mitenkov //===- ConvertLaunchFuncToLLVMCalls.cpp - MLIR GPU launch to LLVM pass ----===// 2cae4067eSGeorge Mitenkov // 3cae4067eSGeorge Mitenkov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4cae4067eSGeorge Mitenkov // See https://llvm.org/LICENSE.txt for license information. 5cae4067eSGeorge Mitenkov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6cae4067eSGeorge Mitenkov // 7cae4067eSGeorge Mitenkov //===----------------------------------------------------------------------===// 8cae4067eSGeorge Mitenkov // 9cae4067eSGeorge Mitenkov // This file implements passes to convert `gpu.launch_func` op into a sequence 10cae4067eSGeorge Mitenkov // of LLVM calls that emulate the host and device sides. 11cae4067eSGeorge Mitenkov // 12cae4067eSGeorge Mitenkov //===----------------------------------------------------------------------===// 13cae4067eSGeorge Mitenkov 14cae4067eSGeorge Mitenkov #include "../PassDetail.h" 15b5d847b1SAlex Zinenko #include "mlir/Conversion/LLVMCommon/LoweringOptions.h" 16*75e5f0aaSAlex Zinenko #include "mlir/Conversion/LLVMCommon/Pattern.h" 17b5d847b1SAlex Zinenko #include "mlir/Conversion/LLVMCommon/TypeConverter.h" 18*75e5f0aaSAlex Zinenko #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" 19930c74f1SLei Zhang #include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVM.h" 20930c74f1SLei Zhang #include "mlir/Conversion/SPIRVToLLVM/SPIRVToLLVMPass.h" 21cae4067eSGeorge Mitenkov #include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h" 22cae4067eSGeorge Mitenkov #include "mlir/Dialect/GPU/GPUDialect.h" 23cae4067eSGeorge Mitenkov #include "mlir/Dialect/LLVMIR/LLVMDialect.h" 2401178654SLei Zhang #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h" 25cae4067eSGeorge Mitenkov #include "mlir/Dialect/StandardOps/IR/Ops.h" 2665fcddffSRiver Riddle #include "mlir/IR/BuiltinOps.h" 27cae4067eSGeorge Mitenkov #include "mlir/IR/SymbolTable.h" 28cae4067eSGeorge Mitenkov #include "mlir/Transforms/DialectConversion.h" 29cae4067eSGeorge Mitenkov 30cae4067eSGeorge Mitenkov #include "llvm/ADT/DenseMap.h" 3156f987faSNico Weber #include "llvm/ADT/StringExtras.h" 32cae4067eSGeorge Mitenkov #include "llvm/Support/FormatVariadic.h" 33cae4067eSGeorge Mitenkov 34cae4067eSGeorge Mitenkov using namespace mlir; 35cae4067eSGeorge Mitenkov 36cae4067eSGeorge Mitenkov static constexpr const char kSPIRVModule[] = "__spv__"; 37cae4067eSGeorge Mitenkov 38cae4067eSGeorge Mitenkov //===----------------------------------------------------------------------===// 39cae4067eSGeorge Mitenkov // Utility functions 40cae4067eSGeorge Mitenkov //===----------------------------------------------------------------------===// 41cae4067eSGeorge Mitenkov 42cae4067eSGeorge Mitenkov /// Returns the string name of the `DescriptorSet` decoration. 43cae4067eSGeorge Mitenkov static std::string descriptorSetName() { 44cae4067eSGeorge Mitenkov return llvm::convertToSnakeFromCamelCase( 45cae4067eSGeorge Mitenkov stringifyDecoration(spirv::Decoration::DescriptorSet)); 46cae4067eSGeorge Mitenkov } 47cae4067eSGeorge Mitenkov 48cae4067eSGeorge Mitenkov /// Returns the string name of the `Binding` decoration. 49cae4067eSGeorge Mitenkov static std::string bindingName() { 50cae4067eSGeorge Mitenkov return llvm::convertToSnakeFromCamelCase( 51cae4067eSGeorge Mitenkov stringifyDecoration(spirv::Decoration::Binding)); 52cae4067eSGeorge Mitenkov } 53cae4067eSGeorge Mitenkov 54cae4067eSGeorge Mitenkov /// Calculates the index of the kernel's operand that is represented by the 55cae4067eSGeorge Mitenkov /// given global variable with the `bind` attribute. We assume that the index of 56cae4067eSGeorge Mitenkov /// each kernel's operand is mapped to (descriptorSet, binding) by the map: 57cae4067eSGeorge Mitenkov /// i -> (0, i) 58cae4067eSGeorge Mitenkov /// which is implemented under `LowerABIAttributesPass`. 59cae4067eSGeorge Mitenkov static unsigned calculateGlobalIndex(spirv::GlobalVariableOp op) { 600bf4a82aSChristian Sigg IntegerAttr binding = op->getAttrOfType<IntegerAttr>(bindingName()); 61cae4067eSGeorge Mitenkov return binding.getInt(); 62cae4067eSGeorge Mitenkov } 63cae4067eSGeorge Mitenkov 64cae4067eSGeorge Mitenkov /// Copies the given number of bytes from src to dst pointers. 65cae4067eSGeorge Mitenkov static void copy(Location loc, Value dst, Value src, Value size, 66cae4067eSGeorge Mitenkov OpBuilder &builder) { 67cae4067eSGeorge Mitenkov MLIRContext *context = builder.getContext(); 682230bf99SAlex Zinenko auto llvmI1Type = IntegerType::get(context, 1); 69cae4067eSGeorge Mitenkov Value isVolatile = builder.create<LLVM::ConstantOp>( 70cae4067eSGeorge Mitenkov loc, llvmI1Type, builder.getBoolAttr(false)); 71cae4067eSGeorge Mitenkov builder.create<LLVM::MemcpyOp>(loc, dst, src, size, isVolatile); 72cae4067eSGeorge Mitenkov } 73cae4067eSGeorge Mitenkov 74cae4067eSGeorge Mitenkov /// Encodes the binding and descriptor set numbers into a new symbolic name. 75cae4067eSGeorge Mitenkov /// The name is specified by 76cae4067eSGeorge Mitenkov /// {kernel_module_name}_{variable_name}_descriptor_set{ds}_binding{b} 77cae4067eSGeorge Mitenkov /// to avoid symbolic conflicts, where 'ds' and 'b' are descriptor set and 78cae4067eSGeorge Mitenkov /// binding numbers. 79cae4067eSGeorge Mitenkov static std::string 80cae4067eSGeorge Mitenkov createGlobalVariableWithBindName(spirv::GlobalVariableOp op, 81cae4067eSGeorge Mitenkov StringRef kernelModuleName) { 82cae4067eSGeorge Mitenkov IntegerAttr descriptorSet = 830bf4a82aSChristian Sigg op->getAttrOfType<IntegerAttr>(descriptorSetName()); 840bf4a82aSChristian Sigg IntegerAttr binding = op->getAttrOfType<IntegerAttr>(bindingName()); 85cae4067eSGeorge Mitenkov return llvm::formatv("{0}_{1}_descriptor_set{2}_binding{3}", 86cae4067eSGeorge Mitenkov kernelModuleName.str(), op.sym_name().str(), 87cae4067eSGeorge Mitenkov std::to_string(descriptorSet.getInt()), 88cae4067eSGeorge Mitenkov std::to_string(binding.getInt())); 89cae4067eSGeorge Mitenkov } 90cae4067eSGeorge Mitenkov 91cae4067eSGeorge Mitenkov /// Returns true if the given global variable has both a descriptor set number 92cae4067eSGeorge Mitenkov /// and a binding number. 93cae4067eSGeorge Mitenkov static bool hasDescriptorSetAndBinding(spirv::GlobalVariableOp op) { 94cae4067eSGeorge Mitenkov IntegerAttr descriptorSet = 950bf4a82aSChristian Sigg op->getAttrOfType<IntegerAttr>(descriptorSetName()); 960bf4a82aSChristian Sigg IntegerAttr binding = op->getAttrOfType<IntegerAttr>(bindingName()); 97cae4067eSGeorge Mitenkov return descriptorSet && binding; 98cae4067eSGeorge Mitenkov } 99cae4067eSGeorge Mitenkov 100cae4067eSGeorge Mitenkov /// Fills `globalVariableMap` with SPIR-V global variables that represent kernel 101cae4067eSGeorge Mitenkov /// arguments from the given SPIR-V module. We assume that the module contains a 102c74eb466SKareemErgawy-TomTom /// single entry point function. Hence, all `spv.GlobalVariable`s with a bind 103cae4067eSGeorge Mitenkov /// attribute are kernel arguments. 104cae4067eSGeorge Mitenkov static LogicalResult getKernelGlobalVariables( 105cae4067eSGeorge Mitenkov spirv::ModuleOp module, 106cae4067eSGeorge Mitenkov DenseMap<uint32_t, spirv::GlobalVariableOp> &globalVariableMap) { 107cae4067eSGeorge Mitenkov auto entryPoints = module.getOps<spirv::EntryPointOp>(); 108cae4067eSGeorge Mitenkov if (!llvm::hasSingleElement(entryPoints)) { 109cae4067eSGeorge Mitenkov return module.emitError( 110cae4067eSGeorge Mitenkov "The module must contain exactly one entry point function"); 111cae4067eSGeorge Mitenkov } 112cae4067eSGeorge Mitenkov auto globalVariables = module.getOps<spirv::GlobalVariableOp>(); 113cae4067eSGeorge Mitenkov for (auto globalOp : globalVariables) { 114cae4067eSGeorge Mitenkov if (hasDescriptorSetAndBinding(globalOp)) 115cae4067eSGeorge Mitenkov globalVariableMap[calculateGlobalIndex(globalOp)] = globalOp; 116cae4067eSGeorge Mitenkov } 117cae4067eSGeorge Mitenkov return success(); 118cae4067eSGeorge Mitenkov } 119cae4067eSGeorge Mitenkov 120cae4067eSGeorge Mitenkov /// Encodes the SPIR-V module's symbolic name into the name of the entry point 121cae4067eSGeorge Mitenkov /// function. 122cae4067eSGeorge Mitenkov static LogicalResult encodeKernelName(spirv::ModuleOp module) { 123cae4067eSGeorge Mitenkov StringRef spvModuleName = module.sym_name().getValue(); 124cae4067eSGeorge Mitenkov // We already know that the module contains exactly one entry point function 125cae4067eSGeorge Mitenkov // based on `getKernelGlobalVariables()` call. Update this function's name 126cae4067eSGeorge Mitenkov // to: 127cae4067eSGeorge Mitenkov // {spv_module_name}_{function_name} 128cae4067eSGeorge Mitenkov auto entryPoint = *module.getOps<spirv::EntryPointOp>().begin(); 129cae4067eSGeorge Mitenkov StringRef funcName = entryPoint.fn(); 130cae4067eSGeorge Mitenkov auto funcOp = module.lookupSymbol<spirv::FuncOp>(funcName); 131cae4067eSGeorge Mitenkov std::string newFuncName = spvModuleName.str() + "_" + funcName.str(); 132cae4067eSGeorge Mitenkov if (failed(SymbolTable::replaceAllSymbolUses(funcOp, newFuncName, module))) 133cae4067eSGeorge Mitenkov return failure(); 134cae4067eSGeorge Mitenkov SymbolTable::setSymbolName(funcOp, newFuncName); 135cae4067eSGeorge Mitenkov return success(); 136cae4067eSGeorge Mitenkov } 137cae4067eSGeorge Mitenkov 138cae4067eSGeorge Mitenkov //===----------------------------------------------------------------------===// 139cae4067eSGeorge Mitenkov // Conversion patterns 140cae4067eSGeorge Mitenkov //===----------------------------------------------------------------------===// 141cae4067eSGeorge Mitenkov 142cae4067eSGeorge Mitenkov namespace { 143cae4067eSGeorge Mitenkov 144cae4067eSGeorge Mitenkov /// Structure to group information about the variables being copied. 145cae4067eSGeorge Mitenkov struct CopyInfo { 146cae4067eSGeorge Mitenkov Value dst; 147cae4067eSGeorge Mitenkov Value src; 148cae4067eSGeorge Mitenkov Value size; 149cae4067eSGeorge Mitenkov }; 150cae4067eSGeorge Mitenkov 151cae4067eSGeorge Mitenkov /// This pattern emulates a call to the kernel in LLVM dialect. For that, we 152cae4067eSGeorge Mitenkov /// copy the data to the global variable (emulating device side), call the 153cae4067eSGeorge Mitenkov /// kernel as a normal void LLVM function, and copy the data back (emulating the 154cae4067eSGeorge Mitenkov /// host side). 155cae4067eSGeorge Mitenkov class GPULaunchLowering : public ConvertOpToLLVMPattern<gpu::LaunchFuncOp> { 156cae4067eSGeorge Mitenkov using ConvertOpToLLVMPattern<gpu::LaunchFuncOp>::ConvertOpToLLVMPattern; 157cae4067eSGeorge Mitenkov 158cae4067eSGeorge Mitenkov LogicalResult 159acb69f3bSChristian Sigg matchAndRewrite(gpu::LaunchFuncOp launchOp, ArrayRef<Value> operands, 160cae4067eSGeorge Mitenkov ConversionPatternRewriter &rewriter) const override { 161acb69f3bSChristian Sigg auto *op = launchOp.getOperation(); 162cae4067eSGeorge Mitenkov MLIRContext *context = rewriter.getContext(); 1630bf4a82aSChristian Sigg auto module = launchOp->getParentOfType<ModuleOp>(); 164cae4067eSGeorge Mitenkov 165cae4067eSGeorge Mitenkov // Get the SPIR-V module that represents the gpu kernel module. The module 166cae4067eSGeorge Mitenkov // is named: 167cae4067eSGeorge Mitenkov // __spv__{kernel_module_name} 168cae4067eSGeorge Mitenkov // based on GPU to SPIR-V conversion. 169cae4067eSGeorge Mitenkov StringRef kernelModuleName = launchOp.getKernelModuleName(); 170cae4067eSGeorge Mitenkov std::string spvModuleName = kSPIRVModule + kernelModuleName.str(); 171cae4067eSGeorge Mitenkov auto spvModule = module.lookupSymbol<spirv::ModuleOp>(spvModuleName); 172cae4067eSGeorge Mitenkov if (!spvModule) { 173cae4067eSGeorge Mitenkov return launchOp.emitOpError("SPIR-V kernel module '") 174cae4067eSGeorge Mitenkov << spvModuleName << "' is not found"; 175cae4067eSGeorge Mitenkov } 176cae4067eSGeorge Mitenkov 177cae4067eSGeorge Mitenkov // Declare kernel function in the main module so that it later can be linked 178cae4067eSGeorge Mitenkov // with its definition from the kernel module. We know that the kernel 179cae4067eSGeorge Mitenkov // function would have no arguments and the data is passed via global 180cae4067eSGeorge Mitenkov // variables. The name of the kernel will be 181cae4067eSGeorge Mitenkov // {spv_module_name}_{kernel_function_name} 182cae4067eSGeorge Mitenkov // to avoid symbolic name conflicts. 183cae4067eSGeorge Mitenkov StringRef kernelFuncName = launchOp.getKernelName(); 184cae4067eSGeorge Mitenkov std::string newKernelFuncName = spvModuleName + "_" + kernelFuncName.str(); 185cae4067eSGeorge Mitenkov auto kernelFunc = module.lookupSymbol<LLVM::LLVMFuncOp>(newKernelFuncName); 186cae4067eSGeorge Mitenkov if (!kernelFunc) { 187cae4067eSGeorge Mitenkov OpBuilder::InsertionGuard guard(rewriter); 188cae4067eSGeorge Mitenkov rewriter.setInsertionPointToStart(module.getBody()); 189cae4067eSGeorge Mitenkov kernelFunc = rewriter.create<LLVM::LLVMFuncOp>( 190cae4067eSGeorge Mitenkov rewriter.getUnknownLoc(), newKernelFuncName, 1917ed9cfc7SAlex Zinenko LLVM::LLVMFunctionType::get(LLVM::LLVMVoidType::get(context), 192c69c9e0fSAlex Zinenko ArrayRef<Type>())); 193cae4067eSGeorge Mitenkov rewriter.setInsertionPoint(launchOp); 194cae4067eSGeorge Mitenkov } 195cae4067eSGeorge Mitenkov 196cae4067eSGeorge Mitenkov // Get all global variables associated with the kernel operands. 197cae4067eSGeorge Mitenkov DenseMap<uint32_t, spirv::GlobalVariableOp> globalVariableMap; 198cae4067eSGeorge Mitenkov if (failed(getKernelGlobalVariables(spvModule, globalVariableMap))) 199cae4067eSGeorge Mitenkov return failure(); 200cae4067eSGeorge Mitenkov 201cae4067eSGeorge Mitenkov // Traverse kernel operands that were converted to MemRefDescriptors. For 202cae4067eSGeorge Mitenkov // each operand, create a global variable and copy data from operand to it. 203cae4067eSGeorge Mitenkov Location loc = launchOp.getLoc(); 204cae4067eSGeorge Mitenkov SmallVector<CopyInfo, 4> copyInfo; 205cae4067eSGeorge Mitenkov auto numKernelOperands = launchOp.getNumKernelOperands(); 206cae4067eSGeorge Mitenkov auto kernelOperands = operands.take_back(numKernelOperands); 207cae4067eSGeorge Mitenkov for (auto operand : llvm::enumerate(kernelOperands)) { 208f88fab50SKazuaki Ishizaki // Check if the kernel's operand is a ranked memref. 209cae4067eSGeorge Mitenkov auto memRefType = launchOp.getKernelOperand(operand.index()) 210cae4067eSGeorge Mitenkov .getType() 211cae4067eSGeorge Mitenkov .dyn_cast<MemRefType>(); 212cae4067eSGeorge Mitenkov if (!memRefType) 213cae4067eSGeorge Mitenkov return failure(); 214cae4067eSGeorge Mitenkov 215cae4067eSGeorge Mitenkov // Calculate the size of the memref and get the pointer to the allocated 216cae4067eSGeorge Mitenkov // buffer. 217cae4067eSGeorge Mitenkov SmallVector<Value, 4> sizes; 218bedaad44SChristian Sigg SmallVector<Value, 4> strides; 219bedaad44SChristian Sigg Value sizeBytes; 220d59ddba7SChristian Sigg getMemRefDescriptorSizes(loc, memRefType, {}, rewriter, sizes, strides, 221d59ddba7SChristian Sigg sizeBytes); 222cae4067eSGeorge Mitenkov MemRefDescriptor descriptor(operand.value()); 223cae4067eSGeorge Mitenkov Value src = descriptor.allocatedPtr(rewriter, loc); 224cae4067eSGeorge Mitenkov 225cae4067eSGeorge Mitenkov // Get the global variable in the SPIR-V module that is associated with 226cae4067eSGeorge Mitenkov // the kernel operand. Construct its new name and create a corresponding 227cae4067eSGeorge Mitenkov // LLVM dialect global variable. 228cae4067eSGeorge Mitenkov spirv::GlobalVariableOp spirvGlobal = globalVariableMap[operand.index()]; 229cae4067eSGeorge Mitenkov auto pointeeType = 230cae4067eSGeorge Mitenkov spirvGlobal.type().cast<spirv::PointerType>().getPointeeType(); 231dcec2ca5SChristian Sigg auto dstGlobalType = typeConverter->convertType(pointeeType); 232cae4067eSGeorge Mitenkov if (!dstGlobalType) 233cae4067eSGeorge Mitenkov return failure(); 234cae4067eSGeorge Mitenkov std::string name = 235cae4067eSGeorge Mitenkov createGlobalVariableWithBindName(spirvGlobal, spvModuleName); 236cae4067eSGeorge Mitenkov // Check if this variable has already been created. 237cae4067eSGeorge Mitenkov auto dstGlobal = module.lookupSymbol<LLVM::GlobalOp>(name); 238cae4067eSGeorge Mitenkov if (!dstGlobal) { 239cae4067eSGeorge Mitenkov OpBuilder::InsertionGuard guard(rewriter); 240cae4067eSGeorge Mitenkov rewriter.setInsertionPointToStart(module.getBody()); 241cae4067eSGeorge Mitenkov dstGlobal = rewriter.create<LLVM::GlobalOp>( 242c69c9e0fSAlex Zinenko loc, dstGlobalType, 2439a0ea599SDumitru Potop /*isConstant=*/false, LLVM::Linkage::Linkonce, name, Attribute(), 2449a0ea599SDumitru Potop /*alignment=*/0); 245cae4067eSGeorge Mitenkov rewriter.setInsertionPoint(launchOp); 246cae4067eSGeorge Mitenkov } 247cae4067eSGeorge Mitenkov 248cae4067eSGeorge Mitenkov // Copy the data from src operand pointer to dst global variable. Save 249cae4067eSGeorge Mitenkov // src, dst and size so that we can copy data back after emulating the 250cae4067eSGeorge Mitenkov // kernel call. 251cae4067eSGeorge Mitenkov Value dst = rewriter.create<LLVM::AddressOfOp>(loc, dstGlobal); 252bedaad44SChristian Sigg copy(loc, dst, src, sizeBytes, rewriter); 253cae4067eSGeorge Mitenkov 254cae4067eSGeorge Mitenkov CopyInfo info; 255cae4067eSGeorge Mitenkov info.dst = dst; 256cae4067eSGeorge Mitenkov info.src = src; 257bedaad44SChristian Sigg info.size = sizeBytes; 258cae4067eSGeorge Mitenkov copyInfo.push_back(info); 259cae4067eSGeorge Mitenkov } 260cae4067eSGeorge Mitenkov // Create a call to the kernel and copy the data back. 261cae4067eSGeorge Mitenkov rewriter.replaceOpWithNewOp<LLVM::CallOp>(op, kernelFunc, 262cae4067eSGeorge Mitenkov ArrayRef<Value>()); 263cae4067eSGeorge Mitenkov for (CopyInfo info : copyInfo) 264cae4067eSGeorge Mitenkov copy(loc, info.src, info.dst, info.size, rewriter); 265cae4067eSGeorge Mitenkov return success(); 266cae4067eSGeorge Mitenkov } 267cae4067eSGeorge Mitenkov }; 268cae4067eSGeorge Mitenkov 269cae4067eSGeorge Mitenkov class LowerHostCodeToLLVM 270cae4067eSGeorge Mitenkov : public LowerHostCodeToLLVMBase<LowerHostCodeToLLVM> { 271cae4067eSGeorge Mitenkov public: 272cae4067eSGeorge Mitenkov void runOnOperation() override { 273cae4067eSGeorge Mitenkov ModuleOp module = getOperation(); 274cae4067eSGeorge Mitenkov 275cae4067eSGeorge Mitenkov // Erase the GPU module. 276cae4067eSGeorge Mitenkov for (auto gpuModule : 277cae4067eSGeorge Mitenkov llvm::make_early_inc_range(module.getOps<gpu::GPUModuleOp>())) 278cae4067eSGeorge Mitenkov gpuModule.erase(); 279cae4067eSGeorge Mitenkov 280cae4067eSGeorge Mitenkov // Specify options to lower Standard to LLVM and pull in the conversion 281cae4067eSGeorge Mitenkov // patterns. 282b3386a73SAlex Zinenko LowerToLLVMOptions options(module.getContext()); 283b3386a73SAlex Zinenko options.emitCWrappers = true; 284cae4067eSGeorge Mitenkov auto *context = module.getContext(); 285dc4e913bSChris Lattner RewritePatternSet patterns(context); 286cae4067eSGeorge Mitenkov LLVMTypeConverter typeConverter(context, options); 287*75e5f0aaSAlex Zinenko populateMemRefToLLVMConversionPatterns(typeConverter, patterns); 288cae4067eSGeorge Mitenkov populateStdToLLVMConversionPatterns(typeConverter, patterns); 289dc4e913bSChris Lattner patterns.add<GPULaunchLowering>(typeConverter); 290cae4067eSGeorge Mitenkov 291cae4067eSGeorge Mitenkov // Pull in SPIR-V type conversion patterns to convert SPIR-V global 292cae4067eSGeorge Mitenkov // variable's type to LLVM dialect type. 293cae4067eSGeorge Mitenkov populateSPIRVToLLVMTypeConversion(typeConverter); 294cae4067eSGeorge Mitenkov 295cae4067eSGeorge Mitenkov ConversionTarget target(*context); 296cae4067eSGeorge Mitenkov target.addLegalDialect<LLVM::LLVMDialect>(); 2973fffffa8SRiver Riddle if (failed(applyPartialConversion(module, target, std::move(patterns)))) 298cae4067eSGeorge Mitenkov signalPassFailure(); 299cae4067eSGeorge Mitenkov 300cae4067eSGeorge Mitenkov // Finally, modify the kernel function in SPIR-V modules to avoid symbolic 301cae4067eSGeorge Mitenkov // conflicts. 302cae4067eSGeorge Mitenkov for (auto spvModule : module.getOps<spirv::ModuleOp>()) 303e21adfa3SRiver Riddle (void)encodeKernelName(spvModule); 304cae4067eSGeorge Mitenkov } 305cae4067eSGeorge Mitenkov }; 306cae4067eSGeorge Mitenkov } // namespace 307cae4067eSGeorge Mitenkov 308cae4067eSGeorge Mitenkov std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> 309cae4067eSGeorge Mitenkov mlir::createLowerHostCodeToLLVMPass() { 310cae4067eSGeorge Mitenkov return std::make_unique<LowerHostCodeToLLVM>(); 311cae4067eSGeorge Mitenkov } 312