MLIR 22.0.0git
InferIntRangeCommon.cpp File Reference
#include "mlir/Interfaces/Utils/InferIntRangeCommon.h"
#include "mlir/Interfaces/InferIntRangeInterface.h"
#include "mlir/Interfaces/ShapedOpInterfaces.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include <iterator>
#include <optional>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "int-range-analysis"

Typedefs

using ConstArithFn
 Function that evaluates the result of doing something on arithmetic constants and returns std::nullopt on overflow.
using ConstArithStdFn
using DivisionFixupFn
 Fix up division results (ex.

Functions

static ConstantIntRanges computeBoundsBy (ConstArithFn op, const APInt &minLeft, const APInt &minRight, const APInt &maxLeft, const APInt &maxRight, bool isSigned)
 Compute op(minLeft, minRight) and op(maxLeft, maxRight) if possible, If either computation overflows, make the result unbounded.
static ConstantIntRanges minMaxBy (ConstArithFn op, ArrayRef< APInt > lhs, ArrayRef< APInt > rhs, bool isSigned)
 Compute the minimum and maximum of (op(l, r) for l in lhs for r in rhs), ignoring unbounded values.
static ConstantIntRanges inferDivURange (const ConstantIntRanges &lhs, const ConstantIntRanges &rhs, DivisionFixupFn fixup)
static ConstantIntRanges inferDivSRange (const ConstantIntRanges &lhs, const ConstantIntRanges &rhs, DivisionFixupFn fixup)
static std::tuple< APInt, APInt > widenBitwiseBounds (const ConstantIntRanges &bound)
 "Widen" bounds - if 0bvvvvv?
static APInt getVaryingBitsMask (const ConstantIntRanges &bound)
 Get bitmask of all bits which can change while iterating in [bound.umin(), bound.umax()].
static intrange::CmpPredicate invertPredicate (intrange::CmpPredicate pred)
static bool isStaticallyTrue (intrange::CmpPredicate pred, const ConstantIntRanges &lhs, const ConstantIntRanges &rhs)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "int-range-analysis"

Definition at line 29 of file InferIntRangeCommon.cpp.

Typedef Documentation

◆ ConstArithFn

using ConstArithFn
Initial value:
function_ref<std::optional<APInt>(const APInt &, const APInt &)>
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152

Function that evaluates the result of doing something on arithmetic constants and returns std::nullopt on overflow.

Definition at line 37 of file InferIntRangeCommon.cpp.

◆ ConstArithStdFn

Initial value:
std::function<std::optional<APInt>(const APInt &, const APInt &)>

Definition at line 39 of file InferIntRangeCommon.cpp.

◆ DivisionFixupFn

Initial value:
const APInt &lhs, const APInt &rhs, const APInt &result)>
lhs

Fix up division results (ex.

for ceiling and floor), returning an APInt if there has been no overflow

Definition at line 285 of file InferIntRangeCommon.cpp.

Function Documentation

◆ computeBoundsBy()

ConstantIntRanges computeBoundsBy ( ConstArithFn op,
const APInt & minLeft,
const APInt & minRight,
const APInt & maxLeft,
const APInt & maxRight,
bool isSigned )
static

Compute op(minLeft, minRight) and op(maxLeft, maxRight) if possible, If either computation overflows, make the result unbounded.

Definition at line 44 of file InferIntRangeCommon.cpp.

References mlir::ConstantIntRanges::maxRange(), and mlir::ConstantIntRanges::range().

Referenced by mlir::intrange::inferAdd(), and mlir::intrange::inferSub().

◆ getVaryingBitsMask()

APInt getVaryingBitsMask ( const ConstantIntRanges & bound)
static

Get bitmask of all bits which can change while iterating in [bound.umin(), bound.umax()].

Definition at line 569 of file InferIntRangeCommon.cpp.

References mlir::ConstantIntRanges::umax(), and mlir::ConstantIntRanges::umin().

Referenced by mlir::intrange::inferXor().

◆ inferDivSRange()

◆ inferDivURange()

ConstantIntRanges inferDivURange ( const ConstantIntRanges & lhs,
const ConstantIntRanges & rhs,
DivisionFixupFn fixup )
static

◆ invertPredicate()

◆ isStaticallyTrue()

◆ minMaxBy()

ConstantIntRanges minMaxBy ( ConstArithFn op,
ArrayRef< APInt > lhs,
ArrayRef< APInt > rhs,
bool isSigned )
static

Compute the minimum and maximum of (op(l, r) for l in lhs for r in rhs), ignoring unbounded values.

Returns the maximal range if op overflows.

Definition at line 57 of file InferIntRangeCommon.cpp.

References lhs, max(), mlir::ConstantIntRanges::maxRange(), min(), mlir::ConstantIntRanges::range(), result, and rhs.

Referenced by mlir::intrange::inferAnd(), inferDivSRange(), inferDivURange(), mlir::intrange::inferMul(), mlir::intrange::inferOr(), mlir::intrange::inferShl(), mlir::intrange::inferShrS(), and mlir::intrange::inferShrU().

◆ widenBitwiseBounds()

std::tuple< APInt, APInt > widenBitwiseBounds ( const ConstantIntRanges & bound)
static

"Widen" bounds - if 0bvvvvv?

?? <= a <= 0bvvvvv???, relax the bounds to 0bvvvvv000 <= a <= 0bvvvvv111, where vvvvv are the bits that both bonuds have in common. This gives us a consertive approximation for what values can be passed to bitwise operations.

Definition at line 536 of file InferIntRangeCommon.cpp.

References mlir::ConstantIntRanges::umax(), and mlir::ConstantIntRanges::umin().

Referenced by mlir::intrange::inferAnd(), and mlir::intrange::inferOr().