Fix GCC build problem with 288f05f related to SmallVector. (#116958)
[llvm-project.git] / mlir / lib / Conversion / ControlFlowToSPIRV / ControlFlowToSPIRVPass.cpp
bloba752b82eac7c3435c4a1a5b65a557fa055555170
1 //===- ControlFlowToSPIRVPass.cpp - ControlFlow to SPIR-V Pass ------------===//
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 ControlFlow dialect to SPIR-V dialect.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h"
15 #include "mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.h"
16 #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
17 #include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
19 namespace mlir {
20 #define GEN_PASS_DEF_CONVERTCONTROLFLOWTOSPIRV
21 #include "mlir/Conversion/Passes.h.inc"
22 } // namespace mlir
24 using namespace mlir;
26 namespace {
27 /// A pass converting MLIR ControlFlow operations into the SPIR-V dialect.
28 class ConvertControlFlowToSPIRVPass final
29 : public impl::ConvertControlFlowToSPIRVBase<
30 ConvertControlFlowToSPIRVPass> {
31 void runOnOperation() override;
33 } // namespace
35 void ConvertControlFlowToSPIRVPass::runOnOperation() {
36 MLIRContext *context = &getContext();
37 Operation *op = getOperation();
39 auto targetAttr = spirv::lookupTargetEnvOrDefault(op);
40 std::unique_ptr<ConversionTarget> target =
41 SPIRVConversionTarget::get(targetAttr);
43 SPIRVConversionOptions options;
44 options.emulateLT32BitScalarTypes = this->emulateLT32BitScalarTypes;
45 SPIRVTypeConverter typeConverter(targetAttr, options);
47 // TODO: We should also take care of block argument type conversion.
49 RewritePatternSet patterns(context);
50 cf::populateControlFlowToSPIRVPatterns(typeConverter, patterns);
52 if (failed(applyPartialConversion(op, *target, std::move(patterns))))
53 return signalPassFailure();
56 std::unique_ptr<OperationPass<>> mlir::createConvertControlFlowToSPIRVPass() {
57 return std::make_unique<ConvertControlFlowToSPIRVPass>();