MLIR
22.0.0git
|
#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/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... | |
#define GET_OP_CLASSES |
Definition at line 762 of file IndexOps.cpp.
#define GET_OP_LIST |
|
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 250 of file IndexOps.cpp.
|
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 301 of file IndexOps.cpp.
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 125 of file IndexOps.cpp.
References mlir::OpBuilder::createOrFold(), mlir::Value::getDefiningOp(), mlir::m_Constant(), mlir::matchPattern(), mlir::RewriterBase::notifyMatchFailure(), and mlir::RewriterBase::replaceOpWithNewOp().
bool compareIndices | ( | const APInt & | lhs, |
const APInt & | rhs, | ||
IndexCmpPredicate | pred | ||
) |
Compare two integers according to the comparison predicate.
Definition at line 586 of file IndexOps.cpp.
|
static |
Return the result of cmp(pred, x, x)
Definition at line 643 of file IndexOps.cpp.
|
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 94 of file IndexOps.cpp.
References mlir::get().
|
static |
Fold an index operation irrespective of the target bitwidth.
The operation must satisfy the property:
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 68 of file IndexOps.cpp.
References mlir::get().
|
static |
Definition at line 509 of file IndexOps.cpp.
References mlir::get().
|
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 617 of file IndexOps.cpp.
References mlir::intrange::evaluatePred().