MLIR  19.0.0git
GPUCommonPass.h
Go to the documentation of this file.
1 //===- GPUCommonPass.h - MLIR GPU runtime support -------------------------===//
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 #ifndef MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_
9 #define MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_
10 
13 #include "mlir/IR/Builders.h"
14 #include "mlir/IR/Types.h"
15 #include "mlir/Support/LLVM.h"
16 #include "llvm/ADT/StringRef.h"
17 #include <functional>
18 #include <vector>
19 
20 namespace llvm {
21 class LLVMContext;
22 class Module;
23 } // namespace llvm
24 
25 namespace mlir {
26 
27 class LLVMTypeConverter;
28 class Location;
29 struct LogicalResult;
30 class ModuleOp;
31 class Operation;
32 class RewritePatternSet;
33 class TypeConverter;
34 
35 class Pass;
36 
37 namespace gpu {
38 enum class AddressSpace : uint32_t;
39 class GPUModuleOp;
40 } // namespace gpu
41 
42 namespace LLVM {
43 class LLVMDialect;
44 } // namespace LLVM
45 
46 #define GEN_PASS_DECL_GPUTOLLVMCONVERSIONPASS
47 #include "mlir/Conversion/Passes.h.inc"
48 
49 using OwnedBlob = std::unique_ptr<std::vector<char>>;
51  std::function<OwnedBlob(const std::string &, Location, StringRef)>;
52 using LoweringCallback = std::function<std::unique_ptr<llvm::Module>(
53  Operation *, llvm::LLVMContext &, StringRef)>;
54 
56  FunctionCallBuilder(StringRef functionName, Type returnType,
57  ArrayRef<Type> argumentTypes)
58  : functionName(functionName),
59  functionType(LLVM::LLVMFunctionType::get(returnType, argumentTypes)) {}
60  LLVM::CallOp create(Location loc, OpBuilder &builder,
61  ArrayRef<Value> arguments) const;
62 
63  StringRef functionName;
64  LLVM::LLVMFunctionType functionType;
65 };
66 
67 /// Collect a set of patterns to convert from the GPU dialect to LLVM and
68 /// populate converter for gpu types.
70  LLVMTypeConverter &converter, RewritePatternSet &patterns,
71  StringRef gpuBinaryAnnotation = {}, bool kernelBarePtrCallConv = false,
72  SymbolTable *cachedModuleTable = nullptr);
73 
74 /// A function that maps a MemorySpace enum to a target-specific integer value.
75 using MemorySpaceMapping = std::function<unsigned(gpu::AddressSpace)>;
76 
77 /// Populates memory space attribute conversion rules for lowering
78 /// gpu.address_space to integer values.
80  TypeConverter &typeConverter, const MemorySpaceMapping &mapping);
81 } // namespace mlir
82 
83 #endif // MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:34
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
This class helps build Operations.
Definition: Builders.h:209
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Type conversion class.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.
std::function< unsigned(gpu::AddressSpace)> MemorySpaceMapping
A function that maps a MemorySpace enum to a target-specific integer value.
Definition: GPUCommonPass.h:75
std::function< std::unique_ptr< llvm::Module >(Operation *, llvm::LLVMContext &, StringRef)> LoweringCallback
Definition: GPUCommonPass.h:53
void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, StringRef gpuBinaryAnnotation={}, bool kernelBarePtrCallConv=false, SymbolTable *cachedModuleTable=nullptr)
Collect a set of patterns to convert from the GPU dialect to LLVM and populate converter for gpu type...
void populateGpuMemorySpaceAttributeConversions(TypeConverter &typeConverter, const MemorySpaceMapping &mapping)
Populates memory space attribute conversion rules for lowering gpu.address_space to integer values.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
std::function< OwnedBlob(const std::string &, Location, StringRef)> BlobGenerator
Definition: GPUCommonPass.h:51
std::unique_ptr< std::vector< char > > OwnedBlob
Definition: GPUCommonPass.h:49
FunctionCallBuilder(StringRef functionName, Type returnType, ArrayRef< Type > argumentTypes)
Definition: GPUCommonPass.h:56
LLVM::LLVMFunctionType functionType
Definition: GPUCommonPass.h:64