Skip to content

Commit 2ec340b

Browse files
author
git apple-llvm automerger
committed
Merge commit '26be7fe27c66' from llvm.org/main into next
2 parents cf2b0dc + 26be7fe commit 2ec340b

File tree

16 files changed

+1017
-768
lines changed

16 files changed

+1017
-768
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
16+
#include "mlir/Transforms/DialectConversion.h"
17+
18+
namespace mlir {
19+
class SPIRVTypeConverter;
20+
21+
/// Appends to a pattern list additional patterns for translating MemRef ops
22+
/// to SPIR-V ops.
23+
void populateMemRefToSPIRVPatterns(SPIRVTypeConverter &typeConverter,
24+
RewritePatternSet &patterns);
25+
26+
} // namespace mlir
27+
28+
#endif // MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRV_H
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===- MemRefToSPIRVPass.h - MemRef to SPIR-V Passes ------------*- 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 passes to convert MemRef dialect to SPIR-V dialect.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRVPASS_H
14+
#define MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRVPASS_H
15+
16+
#include "mlir/Pass/Pass.h"
17+
18+
namespace mlir {
19+
20+
/// Creates a pass to convert MemRef ops to SPIR-V ops.
21+
std::unique_ptr<OperationPass<ModuleOp>> createConvertMemRefToSPIRVPass();
22+
23+
} // namespace mlir
24+
25+
#endif // MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRVPASS_H

mlir/include/mlir/Conversion/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "mlir/Conversion/MathToLibm/MathToLibm.h"
2727
#include "mlir/Conversion/MathToSPIRV/MathToSPIRVPass.h"
2828
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
29+
#include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.h"
2930
#include "mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h"
3031
#include "mlir/Conversion/OpenACCToSCF/ConvertOpenACCToSCF.h"
3132
#include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h"

mlir/include/mlir/Conversion/Passes.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ def ConvertMemRefToLLVM : Pass<"convert-memref-to-llvm", "ModuleOp"> {
296296
];
297297
}
298298

299+
//===----------------------------------------------------------------------===//
300+
// MemRefToSPIRV
301+
//===----------------------------------------------------------------------===//
302+
303+
def ConvertMemRefToSPIRV : Pass<"convert-memref-to-spirv", "ModuleOp"> {
304+
let summary = "Convert MemRef dialect to SPIR-V dialect";
305+
let constructor = "mlir::createConvertMemRefToSPIRVPass()";
306+
let dependentDialects = ["spirv::SPIRVDialect"];
307+
}
308+
299309
//===----------------------------------------------------------------------===//
300310
// OpenACCToSCF
301311
//===----------------------------------------------------------------------===//

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_subdirectory(MathToLibm)
1616
add_subdirectory(MathToLLVM)
1717
add_subdirectory(MathToSPIRV)
1818
add_subdirectory(MemRefToLLVM)
19+
add_subdirectory(MemRefToSPIRV)
1920
add_subdirectory(OpenACCToLLVM)
2021
add_subdirectory(OpenACCToSCF)
2122
add_subdirectory(OpenMPToLLVM)

mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "../PassDetail.h"
1717
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRV.h"
18+
#include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRV.h"
1819
#include "mlir/Conversion/StandardToSPIRV/StandardToSPIRV.h"
1920
#include "mlir/Dialect/GPU/GPUDialect.h"
2021
#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
@@ -59,6 +60,10 @@ void GPUToSPIRVPass::runOnOperation() {
5960
SPIRVTypeConverter typeConverter(targetAttr);
6061
RewritePatternSet patterns(context);
6162
populateGPUToSPIRVPatterns(typeConverter, patterns);
63+
64+
// TODO: Change SPIR-V conversion to be progressive and remove the following
65+
// patterns.
66+
populateMemRefToSPIRVPatterns(typeConverter, patterns);
6267
populateStandardToSPIRVPatterns(typeConverter, patterns);
6368

6469
if (failed(applyFullConversion(kernelModules, *target, std::move(patterns))))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
add_mlir_conversion_library(MLIRMemRefToSPIRV
2+
MemRefToSPIRV.cpp
3+
MemRefToSPIRVPass.cpp
4+
5+
ADDITIONAL_HEADER_DIRS
6+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SPIRV
7+
${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
8+
9+
DEPENDS
10+
MLIRConversionPassIncGen
11+
12+
LINK_LIBS PUBLIC
13+
MLIRIR
14+
MLIRMemRef
15+
MLIRPass
16+
MLIRSPIRV
17+
MLIRSPIRVConversion
18+
MLIRSupport
19+
MLIRTransformUtils
20+
)
21+

0 commit comments

Comments
 (0)