MLIR  20.0.0git
MemRefToSPIRV.h
Go to the documentation of this file.
1 //===- MemRefToSPIRV.h - MemRef to SPIR-V Patterns --------------*- C++ -*-===//
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 //
9 // Provides patterns to convert MemRef dialect to SPIR-V dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRV_H
14 #define MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRV_H
15 
18 #include <memory>
19 
20 namespace mlir {
21 class SPIRVTypeConverter;
22 
23 namespace spirv {
24 /// Mapping from numeric MemRef memory spaces into SPIR-V symbolic ones.
26  std::function<std::optional<spirv::StorageClass>(Attribute)>;
27 
28 /// Maps MemRef memory spaces to storage classes for Vulkan-flavored SPIR-V
29 /// using the default rule. Returns std::nullopt if the memory space is unknown.
30 std::optional<spirv::StorageClass>
32 /// Maps storage classes for Vulkan-flavored SPIR-V to MemRef memory spaces
33 /// using the default rule. Returns std::nullopt if the storage class is
34 /// unsupported.
35 std::optional<unsigned> mapVulkanStorageClassToMemorySpace(spirv::StorageClass);
36 
37 /// Maps MemRef memory spaces to storage classes for OpenCL-flavored SPIR-V
38 /// using the default rule. Returns std::nullopt if the memory space is unknown.
39 std::optional<spirv::StorageClass>
41 /// Maps storage classes for OpenCL-flavored SPIR-V to MemRef memory spaces
42 /// using the default rule. Returns std::nullopt if the storage class is
43 /// unsupported.
44 std::optional<unsigned> mapOpenCLStorageClassToMemorySpace(spirv::StorageClass);
45 
46 /// Type converter for converting numeric MemRef memory spaces into SPIR-V
47 /// symbolic ones.
49 public:
51  const MemorySpaceToStorageClassMap &memorySpaceMap);
52 
53 private:
54  MemorySpaceToStorageClassMap memorySpaceMap;
55 };
56 
57 /// Creates the target that populates legality of ops with MemRef types.
58 std::unique_ptr<ConversionTarget>
60 
61 /// Converts all MemRef types and attributes in the op, as decided by the
62 /// `typeConverter`.
64  Operation *op, MemorySpaceToStorageClassConverter &typeConverter);
65 
66 } // namespace spirv
67 
68 /// Appends to a pattern list additional patterns for translating MemRef ops
69 /// to SPIR-V ops.
70 void populateMemRefToSPIRVPatterns(const SPIRVTypeConverter &typeConverter,
71  RewritePatternSet &patterns);
72 
73 } // namespace mlir
74 
75 #endif // MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRV_H
Attributes are known-constant values of operations.
Definition: Attributes.h:25
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Type conversion from builtin types to SPIR-V types for shader interface.
Type conversion class.
Type converter for converting numeric MemRef memory spaces into SPIR-V symbolic ones.
Definition: MemRefToSPIRV.h:48
MemorySpaceToStorageClassConverter(const MemorySpaceToStorageClassMap &memorySpaceMap)
std::unique_ptr< ConversionTarget > getMemorySpaceToStorageClassTarget(MLIRContext &)
Creates the target that populates legality of ops with MemRef types.
std::function< std::optional< spirv::StorageClass >(Attribute)> MemorySpaceToStorageClassMap
Mapping from numeric MemRef memory spaces into SPIR-V symbolic ones.
Definition: MemRefToSPIRV.h:26
void convertMemRefTypesAndAttrs(Operation *op, MemorySpaceToStorageClassConverter &typeConverter)
Converts all MemRef types and attributes in the op, as decided by the typeConverter.
std::optional< spirv::StorageClass > mapMemorySpaceToOpenCLStorageClass(Attribute)
Maps MemRef memory spaces to storage classes for OpenCL-flavored SPIR-V using the default rule.
std::optional< unsigned > mapVulkanStorageClassToMemorySpace(spirv::StorageClass)
Maps storage classes for Vulkan-flavored SPIR-V to MemRef memory spaces using the default rule.
std::optional< unsigned > mapOpenCLStorageClassToMemorySpace(spirv::StorageClass)
Maps storage classes for OpenCL-flavored SPIR-V to MemRef memory spaces using the default rule.
std::optional< spirv::StorageClass > mapMemorySpaceToVulkanStorageClass(Attribute)
Maps MemRef memory spaces to storage classes for Vulkan-flavored SPIR-V using the default rule.
Include the generated interface declarations.
void populateMemRefToSPIRVPatterns(const SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating MemRef ops to SPIR-V ops.