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