MLIR  20.0.0git
Macros | Typedefs | Functions
InferIntRangeCommon.cpp File Reference
#include "mlir/Interfaces/Utils/InferIntRangeCommon.h"
#include "mlir/Interfaces/InferIntRangeInterface.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_ref< std::optional< APInt >(const APInt &, const APInt &)>
 Function that evaluates the result of doing something on arithmetic constants and returns std::nullopt on overflow. More...
 
using ConstArithStdFn = std::function< std::optional< APInt >(const APInt &, const APInt &)>
 
using DivisionFixupFn = function_ref< std::optional< APInt >(const APInt &lhs, const APInt &rhs, const APInt &result)>
 Fix up division results (ex. More...
 

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. More...
 
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. More...
 
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??? <= a <= 0bvvvvv???, relax the bounds to 0bvvvvv000 <= a <= 0bvvvvv111, where vvvvv are the bits that both bonuds have in common. More...
 
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 28 of file InferIntRangeCommon.cpp.

Typedef Documentation

◆ ConstArithFn

using ConstArithFn = function_ref<std::optional<APInt>(const APInt &, const APInt &)>

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

Definition at line 36 of file InferIntRangeCommon.cpp.

◆ ConstArithStdFn

using ConstArithStdFn = std::function<std::optional<APInt>(const APInt &, const APInt &)>

Definition at line 38 of file InferIntRangeCommon.cpp.

◆ DivisionFixupFn

using DivisionFixupFn = function_ref<std::optional<APInt>( const APInt &lhs, const APInt &rhs, const APInt &result)>

Fix up division results (ex.

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

Definition at line 284 of file InferIntRangeCommon.cpp.

Function Documentation

◆ computeBoundsBy()

static 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 43 of file InferIntRangeCommon.cpp.

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

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

◆ inferDivSRange()

static ConstantIntRanges inferDivSRange ( const ConstantIntRanges lhs,
const ConstantIntRanges rhs,
DivisionFixupFn  fixup 
)
static

◆ inferDivURange()

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

◆ invertPredicate()

static intrange::CmpPredicate invertPredicate ( intrange::CmpPredicate  pred)
static

◆ isStaticallyTrue()

static bool isStaticallyTrue ( intrange::CmpPredicate  pred,
const ConstantIntRanges lhs,
const ConstantIntRanges rhs 
)
static

◆ minMaxBy()

static 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 56 of file InferIntRangeCommon.cpp.

References getZero(), max(), mlir::ConstantIntRanges::maxRange(), min(), and mlir::ConstantIntRanges::range().

Referenced by mlir::intrange::inferAnd(), inferDivSRange(), inferDivURange(), mlir::intrange::inferMul(), mlir::intrange::inferOr(), and mlir::intrange::inferXor().

◆ widenBitwiseBounds()

static 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 528 of file InferIntRangeCommon.cpp.

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

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