MLIR  19.0.0git
Macros | Functions
IndexOps.cpp File Reference
#include "mlir/Dialect/Index/IR/IndexOps.h"
#include "mlir/Dialect/Index/IR/IndexAttrs.h"
#include "mlir/Dialect/Index/IR/IndexDialect.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/Utils/InferIntRangeCommon.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/TypeSwitch.h"
#include "mlir/Dialect/Index/IR/IndexOps.cpp.inc"

Go to the source code of this file.

Macros

#define GET_OP_LIST
 
#define GET_OP_CLASSES
 

Functions

static OpFoldResult foldBinaryOpUnchecked (ArrayRef< Attribute > operands, function_ref< std::optional< APInt >(const APInt &, const APInt &)> calculate)
 Fold an index operation irrespective of the target bitwidth. More...
 
static OpFoldResult foldBinaryOpChecked (ArrayRef< Attribute > operands, function_ref< std::optional< APInt >(const APInt &, const APInt &lhs)> calculate)
 Fold an index operation only if the truncated 64-bit result matches the 32-bit result for operations that don't satisfy the above property. More...
 
static std::optional< APInt > calculateCeilDivS (const APInt &n, const APInt &m)
 Compute ceildivs(n, m) as x = m > 0 ? -1 : 1 and then n*m > 0 ? (n+x)/m + 1 : -(-n/m). More...
 
static std::optional< APInt > calculateFloorDivS (const APInt &n, const APInt &m)
 Compute floordivs(n, m) as x = m < 0 ? 1 : -1 and then n*m < 0 ? -1 - (x-n)/m : n/m. More...
 
static OpFoldResult foldCastOp (Attribute input, Type type, function_ref< APInt(const APInt &, unsigned)> extFn, function_ref< APInt(const APInt &, unsigned)> extOrTruncFn)
 
bool compareIndices (const APInt &lhs, const APInt &rhs, IndexCmpPredicate pred)
 Compare two integers according to the comparison predicate. More...
 
static std::optional< bool > foldCmpOfMaxOrMin (Operation *lhsOp, const APInt &cstA, const APInt &cstB, unsigned width, IndexCmpPredicate pred)
 cmp(max/min(x, cstA), cstB) can be folded to a constant depending on the values of cstA and cstB, the max or min operation, and the comparison predicate. More...
 
static bool compareSameArgs (IndexCmpPredicate pred)
 Return the result of cmp(pred, x, x) More...
 

Macro Definition Documentation

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 700 of file IndexOps.cpp.

◆ GET_OP_LIST

#define GET_OP_LIST

Function Documentation

◆ calculateCeilDivS()

static std::optional<APInt> calculateCeilDivS ( const APInt &  n,
const APInt &  m 
)
static

Compute ceildivs(n, m) as x = m > 0 ? -1 : 1 and then n*m > 0 ? (n+x)/m + 1 : -(-n/m).

Definition at line 217 of file IndexOps.cpp.

◆ calculateFloorDivS()

static std::optional<APInt> calculateFloorDivS ( const APInt &  n,
const APInt &  m 
)
static

Compute floordivs(n, m) as x = m < 0 ? 1 : -1 and then n*m < 0 ? -1 - (x-n)/m : n/m.

Definition at line 268 of file IndexOps.cpp.

◆ compareIndices()

bool compareIndices ( const APInt &  lhs,
const APInt &  rhs,
IndexCmpPredicate  pred 
)

Compare two integers according to the comparison predicate.

Definition at line 525 of file IndexOps.cpp.

◆ compareSameArgs()

static bool compareSameArgs ( IndexCmpPredicate  pred)
static

Return the result of cmp(pred, x, x)

Definition at line 582 of file IndexOps.cpp.

◆ foldBinaryOpChecked()

static OpFoldResult foldBinaryOpChecked ( ArrayRef< Attribute operands,
function_ref< std::optional< APInt >(const APInt &, const APInt &lhs)>  calculate 
)
static

Fold an index operation only if the truncated 64-bit result matches the 32-bit result for operations that don't satisfy the above property.

These are operations where the upper bits of the operands can affect the lower bits of the results.

The function accepts a lambda that computes the integer result in both 64-bit and 32-bit. If either call returns std::nullopt, the operation is not folded.

Definition at line 95 of file IndexOps.cpp.

References mlir::get().

◆ foldBinaryOpUnchecked()

static OpFoldResult foldBinaryOpUnchecked ( ArrayRef< Attribute operands,
function_ref< std::optional< APInt >(const APInt &, const APInt &)>  calculate 
)
static

Fold an index operation irrespective of the target bitwidth.

The operation must satisfy the property:

trunc(f(a, b)) = f(trunc(a), trunc(b))

For all values of a and b. The function accepts a lambda that computes the integer result, which in turn must satisfy the above property.

Definition at line 69 of file IndexOps.cpp.

References mlir::get().

◆ foldCastOp()

static OpFoldResult foldCastOp ( Attribute  input,
Type  type,
function_ref< APInt(const APInt &, unsigned)>  extFn,
function_ref< APInt(const APInt &, unsigned)>  extOrTruncFn 
)
static

Definition at line 448 of file IndexOps.cpp.

References mlir::get().

◆ foldCmpOfMaxOrMin()

static std::optional<bool> foldCmpOfMaxOrMin ( Operation lhsOp,
const APInt &  cstA,
const APInt &  cstB,
unsigned  width,
IndexCmpPredicate  pred 
)
static

cmp(max/min(x, cstA), cstB) can be folded to a constant depending on the values of cstA and cstB, the max or min operation, and the comparison predicate.

Check whether the value folds in both 32-bit and 64-bit arithmetic and to the same value.

Definition at line 556 of file IndexOps.cpp.