xref: /llvm-project/mlir/include/mlir/Interfaces/InferIntRangeInterface.td (revision 6aeea700df6f3f8db9e6a79be4aa593c6fcc7d18)
1//===- InferIntRangeInterface.td - Integer Range Inference --*- 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// Defines the interface for range analysis on scalar integers
10//
11//===-----------------------------------------------------===//
12
13#ifndef MLIR_INTERFACES_INFERINTRANGEINTERFACE
14#define MLIR_INTERFACES_INFERINTRANGEINTERFACE
15
16include "mlir/IR/OpBase.td"
17
18def InferIntRangeInterface : OpInterface<"InferIntRangeInterface"> {
19  let description = [{
20    Allows operations to participate in range analysis for scalar integer values by
21    providing a methods that allows them to specify lower and upper bounds on their
22    result(s) given lower and upper bounds on their input(s) if known.
23  }];
24  let cppNamespace = "::mlir";
25
26  let methods = [
27    InterfaceMethod<[{
28      Infer the bounds on the results of this op given the bounds on its arguments.
29      For each result value or block argument (that isn't a branch argument,
30      since the dataflow analysis handles those case), the method should call
31      `setValueRange` with that `Value` as an argument. When implemented,
32      `setValueRange` should be called on all result values for the operation.
33      When operations take non-integer inputs, the
34     `inferResultRangesFromOptional` method should be implemented instead.
35
36      When called on an op that also implements the RegionBranchOpInterface
37      or BranchOpInterface, this method should not attempt to infer the values
38      of the branch results, as this will be handled by the analyses that use
39      this interface.
40
41      This function will only be called when at least one result of the op is a
42      scalar integer value or the op has a region.
43    }],
44    /*retTy=*/"void",
45    /*methodName=*/"inferResultRanges",
46    /*args=*/(ins "::llvm::ArrayRef<::mlir::ConstantIntRanges>":$argRanges,
47                  "::mlir::SetIntRangeFn":$setResultRanges),
48    /*methodBody=*/"",
49    /*defaultImplementation=*/[{
50      ::mlir::intrange::detail::defaultInferResultRangesFromOptional($_op,
51                                                                     argRanges,
52                                                                     setResultRanges);
53    }]>,
54
55    InterfaceMethod<[{
56      Infer the bounds on the results of this op given the lattice representation
57      of the bounds for its arguments. For each result value or block argument
58      (that isn't a branch argument, since the dataflow analysis handles
59      those case), the method should call `setValueRange` with that `Value`
60      as an argument. When implemented, `setValueRange` should be called on
61      all result values for the operation.
62
63      This method allows for more precise implementations when operations
64      want to reason about inputs which may be undefined during the analysis.
65    }],
66    /*retTy=*/"void",
67    /*methodName=*/"inferResultRangesFromOptional",
68    /*args=*/(ins "::llvm::ArrayRef<::mlir::IntegerValueRange>":$argRanges,
69                  "::mlir::SetIntLatticeFn":$setResultRanges),
70    /*methodBody=*/"",
71    /*defaultImplementation=*/[{
72      ::mlir::intrange::detail::defaultInferResultRanges($_op,
73                                                         argRanges,
74                                                         setResultRanges);
75    }]>
76  ];
77}
78#endif // MLIR_INTERFACES_INFERINTRANGEINTERFACE
79