MLIR 24.0.0git
TosaToLinalg.h
Go to the documentation of this file.
1//===- TosaToLinalg.h - TOSA optimization pass declarations ---------------===//
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 declares the passes for the TOSA Linalg Dialect in MLIR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_CONVERSION_TOSATOLINALG_TOSATOLINALG_H
14#define MLIR_CONVERSION_TOSATOLINALG_TOSATOLINALG_H
15
19#include "mlir/Pass/Pass.h"
20#include "llvm/ADT/DenseMap.h"
21
22#include <optional>
23#include <utility>
24
25namespace mlir {
26#define GEN_PASS_DECL_TOSATOLINALG
27#define GEN_PASS_DECL_TOSATOLINALGNAMED
28#include "mlir/Conversion/Passes.h.inc"
29
30namespace tosa {
31std::unique_ptr<Pass>
32createTosaToLinalg(const TosaToLinalgOptions &options = TosaToLinalgOptions());
33std::unique_ptr<Pass> createTosaToLinalgNamed(
34 const TosaToLinalgNamedOptions &options = TosaToLinalgNamedOptions());
35
36/// Populates passes to convert from TOSA to Linalg. At the end of
37/// the pass, the function will only contain linalg ops or standard ops if the
38/// pipeline succeeds. The option to disable decompositions is available for
39/// benchmarking performance improvements from the canonicalizations.
41 OpPassManager &pm, const TosaToLinalgOptions &options,
42 const TosaToLinalgNamedOptions &tosaToLinalgNamedOptions =
43 TosaToLinalgNamedOptions(),
44 // Note: Default to 'none' level unless otherwise specified.
45 std::optional<tosa::TosaValidationOptions> validationOptions =
46 tosa::TosaValidationOptions{false, false},
47 std::optional<TosaAttachTargetOptions> attachTargetOptions = std::nullopt);
48
49/// Populates TOSA to linalg pipelines
50/// Currently, this includes only the "tosa-to-linalg-pipeline".
52
53/// Populates conversion passes from TOSA dialect to Linalg dialect.
55 const TypeConverter &converter, RewritePatternSet *patterns,
56 const TosaToLinalgOptions &options = TosaToLinalgOptions());
57
58/// Populates conversion passes from TOSA dialect to Linalg named operations.
60 const TypeConverter &converter, RewritePatternSet *patterns,
61 const TosaToLinalgNamedOptions &options);
62
63/// Returns the `linalg.elementwise` kind that the TosaToLinalgNamed conversion
64/// lowers `op` to, or std::nullopt if `op` has no such counterpart.
65std::optional<linalg::ElementwiseKind>
67
68/// Caches the `arith.constant index` values created for a set of dimension
69/// indices so that broadcasting helpers can avoid emitting redundant
70/// constants. Callers own the pool and reuse it across related queries.
72
73/// Compute the broadcasted runtime size of dimension `dim` of an elementwise
74/// operation whose `operands` all share the same rank (TOSA's
75/// `SameOperandsAndResultRank` and `ResultsBroadcastableShape` traits). The
76/// returned size is either a static `IndexAttr` or an SSA `Value` holding the
77/// runtime size, so dynamic dimensions (fixed rank, unknown size) are handled
78/// correctly. The second element of the pair is the operand that solely
79/// determines the size, or nullptr when it is inferred from several operands.
80/// `indexPool` caches constant index values across calls.
81std::pair<OpFoldResult, Value>
82computeTargetSize(PatternRewriter &rewriter, Location loc, IndexPool &indexPool,
83 ValueRange operands, int64_t dim);
84} // namespace tosa
85} // namespace mlir
86
87#endif // MLIR_CONVERSION_TOSATOLINALG_TOSATOLINALG_H
static llvm::ManagedStatic< PassManagerOptions > options
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:392
llvm::DenseMap< int64_t, Value > IndexPool
Caches the arith.constant index values created for a set of dimension indices so that broadcasting he...
std::unique_ptr< Pass > createTosaToLinalgNamed(const TosaToLinalgNamedOptions &options=TosaToLinalgNamedOptions())
void addTosaToLinalgPasses(OpPassManager &pm, const TosaToLinalgOptions &options, const TosaToLinalgNamedOptions &tosaToLinalgNamedOptions=TosaToLinalgNamedOptions(), std::optional< tosa::TosaValidationOptions > validationOptions=tosa::TosaValidationOptions{false, false}, std::optional< TosaAttachTargetOptions > attachTargetOptions=std::nullopt)
Populates passes to convert from TOSA to Linalg.
std::pair< OpFoldResult, Value > computeTargetSize(PatternRewriter &rewriter, Location loc, IndexPool &indexPool, ValueRange operands, int64_t dim)
Compute the broadcasted runtime size of dimension dim of an elementwise operation whose operands all ...
std::unique_ptr< Pass > createTosaToLinalg(const TosaToLinalgOptions &options=TosaToLinalgOptions())
void populateTosaToLinalgConversionPatterns(const TypeConverter &converter, RewritePatternSet *patterns, const TosaToLinalgOptions &options=TosaToLinalgOptions())
Populates conversion passes from TOSA dialect to Linalg dialect.
void registerTosaToLinalgPipelines()
Populates TOSA to linalg pipelines Currently, this includes only the "tosa-to-linalg-pipeline".
void populateTosaToLinalgNamedConversionPatterns(const TypeConverter &converter, RewritePatternSet *patterns, const TosaToLinalgNamedOptions &options)
Populates conversion passes from TOSA dialect to Linalg named operations.
std::optional< linalg::ElementwiseKind > isConvertibleToLinalgElementwise(Operation *op)
Returns the linalg.elementwise kind that the TosaToLinalgNamed conversion lowers op to,...
Include the generated interface declarations.