MLIR 22.0.0git
MemRefToSPIRVPass.cpp
Go to the documentation of this file.
1//===- MemRefToSPIRVPass.cpp - MemRef to SPIR-V Passes ----------------===//
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// This file implements a pass to convert standard dialect to SPIR-V dialect.
10//
11//===----------------------------------------------------------------------===//
12
14
18
19namespace mlir {
20#define GEN_PASS_DEF_CONVERTMEMREFTOSPIRVPASS
21#include "mlir/Conversion/Passes.h.inc"
22} // namespace mlir
23
24using namespace mlir;
25
26namespace {
27/// A pass converting MLIR MemRef operations into the SPIR-V dialect.
28class ConvertMemRefToSPIRVPass
29 : public impl::ConvertMemRefToSPIRVPassBase<ConvertMemRefToSPIRVPass> {
30 using Base::Base;
31 void runOnOperation() override;
32};
33} // namespace
34
35void ConvertMemRefToSPIRVPass::runOnOperation() {
36 MLIRContext *context = &getContext();
37 Operation *op = getOperation();
38
39 auto targetAttr = spirv::lookupTargetEnvOrDefault(op);
40 std::unique_ptr<ConversionTarget> target =
42
43 SPIRVConversionOptions options;
44 options.boolNumBits = this->boolNumBits;
45 options.use64bitIndex = this->use64bitIndex;
46 SPIRVTypeConverter typeConverter(targetAttr, options);
47
48 // Use UnrealizedConversionCast as the bridge so that we don't need to pull in
49 // patterns for other dialects.
50 target->addLegalOp<UnrealizedConversionCastOp>();
51
52 RewritePatternSet patterns(context);
54
55 if (failed(applyPartialConversion(op, *target, std::move(patterns))))
56 return signalPassFailure();
57}
b getContext())
static llvm::ManagedStatic< PassManagerOptions > options
static std::unique_ptr< SPIRVConversionTarget > get(spirv::TargetEnvAttr targetAttr)
Creates a SPIR-V conversion target for the given target environment.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:561
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
void populateMemRefToSPIRVPatterns(const SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating MemRef ops to SPIR-V ops.