MLIR  21.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 
19 namespace llvm {
20 class LLVMContext;
21 class Module;
22 } // namespace llvm
23 
24 namespace mlir {
25 
26 class LLVMTypeConverter;
27 class Location;
28 class ModuleOp;
29 class Operation;
30 class RewritePatternSet;
31 class TypeConverter;
32 
33 class Pass;
34 
35 namespace gpu {
36 enum class AddressSpace : uint32_t;
37 class GPUModuleOp;
38 } // namespace gpu
39 
40 namespace LLVM {
41 class LLVMDialect;
42 } // namespace LLVM
43 
44 #define GEN_PASS_DECL_GPUTOLLVMCONVERSIONPASS
45 #include "mlir/Conversion/Passes.h.inc"
46 
47 using LoweringCallback = std::function<std::unique_ptr<llvm::Module>(
48  Operation *, llvm::LLVMContext &, StringRef)>;
49 
51  FunctionCallBuilder(StringRef functionName, Type returnType,
52  ArrayRef<Type> argumentTypes)
53  : functionName(functionName),
54  functionType(LLVM::LLVMFunctionType::get(returnType, argumentTypes)) {}
55  LLVM::CallOp create(Location loc, OpBuilder &builder,
56  ArrayRef<Value> arguments) const;
57 
58  StringRef functionName;
59  LLVM::LLVMFunctionType functionType;
60 };
61 
62 /// Collect a set of patterns to convert from the GPU dialect to LLVM and
63 /// populate converter for gpu types.
66  bool kernelBarePtrCallConv = false,
67  bool kernelIntersperseSizeCallConv = false);
68 
69 /// A function that maps a MemorySpace enum to a target-specific integer value.
70 using MemorySpaceMapping = std::function<unsigned(gpu::AddressSpace)>;
71 
72 /// Populates memory space attribute conversion rules for lowering
73 /// gpu.address_space to integer values.
75  TypeConverter &typeConverter, const MemorySpaceMapping &mapping);
76 } // namespace mlir
77 
78 #endif // MLIR_CONVERSION_GPUCOMMON_GPUCOMMONPASS_H_
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:35
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:66
This class helps build Operations.
Definition: Builders.h:204
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
The OpAsmOpInterface, see OpAsmInterface.td for more details.
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:70
std::function< std::unique_ptr< llvm::Module >(Operation *, llvm::LLVMContext &, StringRef)> LoweringCallback
Definition: GPUCommonPass.h:48
void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, bool kernelBarePtrCallConv=false, bool kernelIntersperseSizeCallConv=false)
Collect a set of patterns to convert from the GPU dialect to LLVM and populate converter for gpu type...
const FrozenRewritePatternSet & patterns
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...
FunctionCallBuilder(StringRef functionName, Type returnType, ArrayRef< Type > argumentTypes)
Definition: GPUCommonPass.h:51
LLVM::LLVMFunctionType functionType
Definition: GPUCommonPass.h:59