MLIR  21.0.0git
VectorToSPIRVPass.cpp
Go to the documentation of this file.
1 //===- VectorToSPIRVPass.cpp - Vector 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 Vector dialect to SPIRV dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
20 #include "mlir/Pass/Pass.h"
22 
23 namespace mlir {
24 #define GEN_PASS_DEF_CONVERTVECTORTOSPIRVPASS
25 #include "mlir/Conversion/Passes.h.inc"
26 } // namespace mlir
27 
28 using namespace mlir;
29 
30 namespace {
31 struct ConvertVectorToSPIRVPass
32  : public impl::ConvertVectorToSPIRVPassBase<ConvertVectorToSPIRVPass> {
33  void runOnOperation() override;
34 };
35 } // namespace
36 
37 void ConvertVectorToSPIRVPass::runOnOperation() {
38  MLIRContext *context = &getContext();
39  Operation *op = getOperation();
40 
41  auto targetAttr = spirv::lookupTargetEnvOrDefault(op);
42  std::unique_ptr<ConversionTarget> target =
43  SPIRVConversionTarget::get(targetAttr);
44 
45  SPIRVTypeConverter typeConverter(targetAttr);
46 
47  // Use UnrealizedConversionCast as the bridge so that we don't need to pull in
48  // patterns for other dialects.
49  target->addLegalOp<UnrealizedConversionCastOp>();
50 
51  RewritePatternSet patterns(context);
53  // Used for folds, e.g. vector.extract[-1] -> ub.poison -> spirv.Undef.
55 
56  if (failed(applyPartialConversion(op, *target, std::move(patterns))))
57  return signalPassFailure();
58 }
static MLIRContext * getContext(OpFoldResult val)
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
static std::unique_ptr< SPIRVConversionTarget > get(spirv::TargetEnvAttr targetAttr)
Creates a SPIR-V conversion target for the given target environment.
Type conversion from builtin types to SPIR-V types for shader interface.
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
void populateUBToSPIRVConversionPatterns(const SPIRVTypeConverter &converter, RewritePatternSet &patterns)
Definition: UBToSPIRV.cpp:76
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.
void populateVectorToSPIRVPatterns(const SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating Vector Ops to SPIR-V ops.