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