Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers ...
[llvm-project.git] / mlir / lib / Conversion / TosaToSCF / TosaToSCFPass.cpp
blobd14535029132f4b90cef36586a3b76391f957ccb
1 //===- TosaToSCFPass.cpp - Lowering Tosa to SCF Dialect -------------------===//
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 transformation pass legalizes Tosa operations to the SCF dialect.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Conversion/TosaToSCF/TosaToSCF.h"
15 #include "mlir/Dialect/Func/IR/FuncOps.h"
16 #include "mlir/Dialect/SCF/IR/SCF.h"
17 #include "mlir/Dialect/Tensor/IR/Tensor.h"
18 #include "mlir/Dialect/Tosa/IR/TosaOps.h"
19 #include "mlir/Dialect/Tosa/Transforms/Passes.h"
20 #include "mlir/IR/PatternMatch.h"
21 #include "mlir/Pass/PassManager.h"
22 #include "mlir/Transforms/DialectConversion.h"
23 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
25 namespace mlir {
26 #define GEN_PASS_DEF_TOSATOSCF
27 #include "mlir/Conversion/Passes.h.inc"
28 } // namespace mlir
30 using namespace mlir;
31 using namespace tosa;
33 namespace {
34 struct TosaToSCF : public impl::TosaToSCFBase<TosaToSCF> {
35 public:
36 void runOnOperation() override {
37 RewritePatternSet patterns(&getContext());
38 ConversionTarget target(getContext());
39 target.addLegalDialect<tensor::TensorDialect, scf::SCFDialect>();
40 target.addIllegalOp<tosa::IfOp, tosa::ScatterOp, tosa::WhileOp>();
41 target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
43 auto *op = getOperation();
44 mlir::tosa::populateTosaToSCFConversionPatterns(&patterns);
45 if (failed(applyPartialConversion(op, target, std::move(patterns))))
46 signalPassFailure();
49 } // namespace
51 std::unique_ptr<Pass> mlir::tosa::createTosaToSCF() {
52 return std::make_unique<TosaToSCF>();
55 void mlir::tosa::addTosaToSCFPasses(OpPassManager &pm) {
56 pm.addNestedPass<func::FuncOp>(createTosaToSCF());