xref: /llvm-project/mlir/include/mlir/Dialect/Arith/Transforms/Passes.td (revision 9f0f6df03b1f6bc4feac8ca5670638b005d20d96)
1//===-- Passes.td - Arith pass definition file --------*- tablegen -*-===//
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#ifndef MLIR_DIALECT_ARITH_TRANSFORMS_PASSES
10#define MLIR_DIALECT_ARITH_TRANSFORMS_PASSES
11
12include "mlir/Pass/PassBase.td"
13
14def ArithExpandOpsPass : Pass<"arith-expand"> {
15  let summary = "Legalize Arith ops to be convertible to LLVM.";
16  let dependentDialects = ["vector::VectorDialect"];
17  let options = [
18    Option<"includeBf16", "include-bf16", "bool", /*default=*/"false",
19           "Enable the BF16 expansion patterns">,
20  ];
21}
22
23def ArithUnsignedWhenEquivalent : Pass<"arith-unsigned-when-equivalent"> {
24  let summary = "Replace signed ops with unsigned ones where they are proven equivalent";
25  let description = [{
26    Replace signed ops with their unsigned equivalents when integer range analysis
27    determines that their arguments and results are all guaranteed to be
28    non-negative when interpreted as signed integers. When this occurs,
29    we know that the semantics of the signed and unsigned operations are the same,
30    since they share the same behavior when their operands and results  are in the
31    range [0, signed_max(type)].
32
33    The affect ops include division, remainder, shifts, min, max, and integer
34    comparisons.
35  }];
36  let constructor = "mlir::arith::createArithUnsignedWhenEquivalentPass()";
37}
38
39def ArithIntRangeOpts : Pass<"int-range-optimizations"> {
40  let summary = "Do optimizations based on integer range analysis";
41  let description = [{
42    This pass runs integer range analysis and apllies optimizations based on its
43    results. It replaces operations with known-constant results with said constants,
44    rewrites `(0 <= %x < D) mod D` to `%x`.
45  }];
46  // Explicitly depend on "arith" because this pass could create operations in
47  // `arith` out of thin air in some cases.
48  let dependentDialects = [
49    "::mlir::arith::ArithDialect"
50  ];
51}
52
53def ArithIntRangeNarrowing : Pass<"arith-int-range-narrowing"> {
54  let summary = "Reduce integer operations bitwidth based on integer range analysis";
55  let description = [{
56    This pass runs integer range analysis and tries to narrow arith ops to the
57    specified bitwidth based on its results.
58
59    `bitwidthsSupported` assumed to be not wider than `index` type.
60    TODO: get index width from DLTI.
61  }];
62
63  let options = [
64    ListOption<"bitwidthsSupported", "int-bitwidths-supported", "unsigned",
65               "Integer bitwidths supported">,
66  ];
67
68  // Explicitly depend on "arith" because this pass could create operations in
69  // `arith` out of thin air in some cases.
70  let dependentDialects = [
71    "::mlir::arith::ArithDialect"
72  ];
73}
74
75def ArithEmulateUnsupportedFloats : Pass<"arith-emulate-unsupported-floats"> {
76  let summary = "Emulate operations on unsupported floats with extf/truncf";
77  let description = [{
78    Emulate arith and vector floating point operations that use float types
79    which are unspported on a target by inserting extf/truncf pairs around all
80    such operations in order to produce arithmetic that can be performed while
81    preserving the original rounding behavior.
82
83    This pass does not attempt to reason about the operations being performed
84    to determine when type conversions can be elided.
85  }];
86
87  let options = [
88    ListOption<"sourceTypeStrs", "source-types", "std::string",
89      "MLIR types without arithmetic support on a given target">,
90    Option<"targetTypeStr", "target-type", "std::string", "\"f32\"",
91      "MLIR type to convert the unsupported source types to">,
92  ];
93
94  let dependentDialects = ["vector::VectorDialect"];
95}
96
97def ArithEmulateWideInt : Pass<"arith-emulate-wide-int"> {
98  let summary = "Emulate 2*N-bit integer operations using N-bit operations";
99  let description = [{
100    Emulate arith integer operations that use too wide integer types with
101    equivalent operations on supported narrow integer types. This is done by
102    splitting original integer values into two halves.
103
104    This pass is intended preserve semantics but not necessarily provide the
105    most efficient implementation.
106    TODO: Optimize op emulation.
107
108    Currently, only power-of-two integer bitwidths are supported.
109  }];
110  let options = [
111    Option<"widestIntSupported", "widest-int-supported", "unsigned",
112           /*default=*/"32", "Widest integer type supported by the target">,
113  ];
114  let dependentDialects = ["vector::VectorDialect"];
115}
116
117#endif // MLIR_DIALECT_ARITH_TRANSFORMS_PASSES
118