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 `setValueRange`
32      is not called for some value, it will recieve a default value of the mimimum
33      and maximum values for its type (the unbounded range).
34
35      When called on an op that also implements the RegionBranchOpInterface
36      or BranchOpInterface, this method should not attempt to infer the values
37      of the branch results, as this will be handled by the analyses that use
38      this interface.
39
40      This function will only be called when at least one result of the op is a
41      scalar integer value or the op has a region.
42
43      `argRanges` contains one `IntRangeAttrs` for each argument to the op in ODS
44       order. Non-integer arguments will have the an unbounded range of width-0
45       APInts in their `argRanges` element.
46    }],
47    "void", "inferResultRanges", (ins
48      "::llvm::ArrayRef<::mlir::ConstantIntRanges>":$argRanges,
49      "::mlir::SetIntRangeFn":$setResultRanges)
50  >];
51}
52#endif // MLIR_DIALECT_ARITHMETIC_IR_INFERINTRANGEINTERFACE
53