MLIR  20.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...
 
template<typename BinaryOp >
LogicalResult canonicalizeAssociativeCommutativeBinaryOp (BinaryOp op, PatternRewriter &rewriter)
 Helper for associative and commutative binary ops that can be transformed: x = op(v, c1); y = op(x, c2) -> tmp = op(c1, c2); y = op(v, tmp) where c1 and c2 are constants. 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 763 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 251 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 302 of file IndexOps.cpp.

◆ canonicalizeAssociativeCommutativeBinaryOp()

template<typename BinaryOp >
LogicalResult canonicalizeAssociativeCommutativeBinaryOp ( BinaryOp  op,
PatternRewriter rewriter 
)

Helper for associative and commutative binary ops that can be transformed: x = op(v, c1); y = op(x, c2) -> tmp = op(c1, c2); y = op(v, tmp) where c1 and c2 are constants.

It is expected that tmp will be folded.

Definition at line 126 of file IndexOps.cpp.

References mlir::OpBuilder::createOrFold(), mlir::Value::getDefiningOp(), mlir::m_Constant(), mlir::matchPattern(), mlir::RewriterBase::notifyMatchFailure(), and mlir::RewriterBase::replaceOpWithNewOp().

◆ compareIndices()

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

Compare two integers according to the comparison predicate.

Definition at line 587 of file IndexOps.cpp.

◆ compareSameArgs()

static bool compareSameArgs ( IndexCmpPredicate  pred)
static

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

Definition at line 644 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 510 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 618 of file IndexOps.cpp.

References mlir::intrange::evaluatePred().