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 class ModuleOp;
30 class Operation;
31 class RewritePatternSet;
32 class TypeConverter;
33 
34 class Pass;
35 
36 namespace gpu {
37 enum class AddressSpace : uint32_t;
38 class GPUModuleOp;
39 } // namespace gpu
40 
41 namespace LLVM {
42 class LLVMDialect;
43 } // namespace LLVM
44 
45 #define GEN_PASS_DECL_GPUTOLLVMCONVERSIONPASS
46 #include "mlir/Conversion/Passes.h.inc"
47 
48 using LoweringCallback = std::function<std::unique_ptr<llvm::Module>(
49  Operation *, llvm::LLVMContext &, StringRef)>;
50 
52  FunctionCallBuilder(StringRef functionName, Type returnType,
53  ArrayRef<Type> argumentTypes)
54  : functionName(functionName),
55  functionType(LLVM::LLVMFunctionType::get(returnType, argumentTypes)) {}
56  LLVM::CallOp create(Location loc, OpBuilder &builder,
57  ArrayRef<Value> arguments) const;
58 
59  StringRef functionName;
60  LLVM::LLVMFunctionType functionType;
61 };
62 
63 /// Collect a set of patterns to convert from the GPU dialect to LLVM and
64 /// populate converter for gpu types.
66  RewritePatternSet &patterns,
67  bool kernelBarePtrCallConv = 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: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:70
std::function< std::unique_ptr< llvm::Module >(Operation *, llvm::LLVMContext &, StringRef)> LoweringCallback
Definition: GPUCommonPass.h:49
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...
void populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, bool kernelBarePtrCallConv=false)
Collect a set of patterns to convert from the GPU dialect to LLVM and populate converter for gpu type...
FunctionCallBuilder(StringRef functionName, Type returnType, ArrayRef< Type > argumentTypes)
Definition: GPUCommonPass.h:52
LLVM::LLVMFunctionType functionType
Definition: GPUCommonPass.h:60