brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 46bdf22 Raw
52 lines · cpp
1//===- TosaToArithPass.cpp - Lowering Tosa to Linalg 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-exception6//7//===----------------------------------------------------------------------===//8//9// This transformation pass legalizes Tosa operations to the Arith dialect.10//11//===----------------------------------------------------------------------===//12 13#include "mlir/Conversion/TosaToArith/TosaToArith.h"14 15#include "mlir/Dialect/Arith/IR/Arith.h"16#include "mlir/Dialect/Tosa/IR/TosaOps.h"17#include "mlir/IR/PatternMatch.h"18#include "mlir/Transforms/DialectConversion.h"19 20namespace mlir {21#define GEN_PASS_DEF_TOSATOARITHPASS22#include "mlir/Conversion/Passes.h.inc"23} // namespace mlir24 25using namespace mlir;26using namespace tosa;27 28namespace {29struct TosaToArith : public impl::TosaToArithPassBase<TosaToArith> {30  using Base::Base;31 32  void runOnOperation() override {33    RewritePatternSet patterns(&getContext());34    ConversionTarget target(getContext());35    target.addIllegalOp<tosa::ConstOp>();36    target.addLegalDialect<arith::ArithDialect>();37 38    mlir::tosa::populateTosaToArithConversionPatterns(&patterns);39 40    if (this->includeApplyRescale) {41      mlir::tosa::populateTosaRescaleToArithConversionPatterns(&patterns,42                                                               this->use32Bit);43      target.addIllegalOp<tosa::ApplyScaleOp>();44    }45 46    if (failed(applyPartialConversion(getOperation(), target,47                                      std::move(patterns))))48      signalPassFailure();49  }50};51} // namespace52