MLIR 22.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
19namespace llvm {
20class LLVMContext;
21class Module;
22} // namespace llvm
23
24namespace mlir {
25
27class Location;
28class ModuleOp;
29class Operation;
31class TypeConverter;
32
33class Pass;
34
35namespace gpu {
36enum class AddressSpace : uint32_t;
37class GPUModuleOp;
38} // namespace gpu
39
40namespace LLVM {
41class LLVMDialect;
42} // namespace LLVM
43
44#define GEN_PASS_DECL_GPUTOLLVMCONVERSIONPASS
45#include "mlir/Conversion/Passes.h.inc"
46
47using LoweringCallback = std::function<std::unique_ptr<llvm::Module>(
48 Operation *, llvm::LLVMContext &, StringRef)>;
49
51 FunctionCallBuilder(StringRef functionName, Type returnType,
52 ArrayRef<Type> argumentTypes)
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.
70using 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.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:207
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
The abstract base pass class.
Definition Pass.h:51
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< std::unique_ptr< llvm::Module >( Operation *, llvm::LLVMContext &, StringRef)> LoweringCallback
std::function< unsigned(gpu::AddressSpace)> MemorySpaceMapping
A function that maps a MemorySpace enum to a target-specific integer value.
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)
LLVM::LLVMFunctionType functionType
LLVM::CallOp create(Location loc, OpBuilder &builder, ArrayRef< Value > arguments) const