|
MLIR 24.0.0git
|
#include <cassert>#include <cstdint>#include <functional>#include <type_traits>#include <utility>#include "mlir/Dialect/Arith/IR/Arith.h"#include "mlir/Dialect/CommonFolders.h"#include "mlir/Dialect/UB/IR/UBMatchers.h"#include "mlir/IR/Builders.h"#include "mlir/IR/BuiltinAttributeInterfaces.h"#include "mlir/IR/BuiltinAttributes.h"#include "mlir/IR/Matchers.h"#include "mlir/IR/OpImplementation.h"#include "mlir/IR/PatternMatch.h"#include "mlir/IR/TypeUtilities.h"#include "mlir/Support/LogicalResult.h"#include "llvm/ADT/APFloat.h"#include "llvm/ADT/APInt.h"#include "llvm/ADT/APSInt.h"#include "llvm/ADT/FloatingPointMode.h"#include "llvm/ADT/STLExtras.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/TypeSwitch.h"#include "ArithCanonicalization.inc"#include "mlir/Dialect/Arith/IR/ArithOps.cpp.inc"#include "mlir/Dialect/Arith/IR/ArithOpsEnums.cpp.inc"Go to the source code of this file.
Classes | |
| class | CmpFIntToFPConst |
| struct | SelectToExtUI |
Macros | |
| #define | GET_OP_CLASSES |
Typedefs | |
| using | OverflowCheckedBinaryOp = APInt (APInt::*)(const APInt &, bool &) const |
| template<typename... Types> | |
| using | type_list = std::tuple<Types...> * |
Functions | |
| static IntegerAttr | applyToIntegerAttrs (PatternRewriter &builder, Value res, Attribute lhs, Attribute rhs, function_ref< APInt(const APInt &, const APInt &)> binFn) |
| static IntegerAttr | addIntegerAttrs (PatternRewriter &builder, Value res, Attribute lhs, Attribute rhs) |
| static IntegerAttr | subIntegerAttrs (PatternRewriter &builder, Value res, Attribute lhs, Attribute rhs) |
| static IntegerAttr | mulIntegerAttrs (PatternRewriter &builder, Value res, Attribute lhs, Attribute rhs) |
| static IntegerAttr | andIntegerAttrs (PatternRewriter &builder, Value res, Attribute lhs, Attribute rhs) |
| static IntegerAttr | orIntegerAttrs (PatternRewriter &builder, Value res, Attribute lhs, Attribute rhs) |
| static IntegerAttr | xorIntegerAttrs (PatternRewriter &builder, Value res, Attribute lhs, Attribute rhs) |
| static IntegerOverflowFlagsAttr | mergeOverflowFlags (IntegerOverflowFlagsAttr val1, IntegerOverflowFlagsAttr val2) |
| static IntegerOverflowFlagsAttr | mergeOverflowFlagsForReassociation (IntegerOverflowFlagsAttr val1, IntegerOverflowFlagsAttr val2, Attribute lhs, Attribute rhs, OverflowCheckedBinaryOp signedOp, OverflowCheckedBinaryOp unsignedOp) |
| static llvm::RoundingMode | convertArithRoundingModeToLLVMIR (std::optional< RoundingMode > roundingMode) |
| Equivalent to convertRoundingModeToLLVM(convertArithRoundingModeToLLVM(roundingMode)). | |
| static arith::CmpIPredicateAttr | invertPredicate (arith::CmpIPredicateAttr pred) |
| static int64_t | getScalarOrElementWidth (Type type) |
| static int64_t | getScalarOrElementWidth (Value value) |
| static FailureOr< APInt > | getIntOrSplatIntValue (Attribute attr) |
| static Attribute | getBoolAttribute (Type type, bool value) |
| static Attribute | getIntegerAttrOfType (Type type, int64_t value) |
| Return a scalar or splat integer attribute of type (an integer/index type or a shaped type thereof) holding value. | |
| static Type | getI1SameShape (Type type) |
| Return the type of the same shape (scalar, vector or tensor) containing i1. | |
| static APInt | calculateUnsignedOverflow (const APInt &sum, const APInt &operand) |
| static APInt | calculateUnsignedBorrow (const APInt &lhs, const APInt &rhs) |
| static Value | foldDivMul (Value lhs, Value rhs, arith::IntegerOverflowFlags ovfFlags) |
| Fold (a * b) / b -> a | |
| static Speculation::Speculatability | getDivUISpeculatability (Value divisor) |
| Returns whether an unsigned division by divisor is speculatable. | |
| static Speculation::Speculatability | getDivSISpeculatability (Value divisor) |
| Returns whether a signed division by divisor is speculatable. | |
| template<typename OpTy> | |
| static Value | foldIdempotentOfSameOp (OpTy op) |
| Fold op(a, op(a, b)) to op(a, b) for an associative, commutative and idempotent op (e.g. | |
| template<typename... ShapedTypes, typename... ElementTypes> | |
| static Type | getUnderlyingType (Type type, type_list< ShapedTypes... >, type_list< ElementTypes... >) |
| Returns a non-null type only if the provided type is one of the allowed types or one of the allowed shaped types of the allowed types. | |
| template<typename... ElementTypes> | |
| static Type | getTypeIfLike (Type type) |
| Get allowed underlying types for vectors and tensors. | |
| template<typename... ElementTypes> | |
| static Type | getTypeIfLikeOrMemRef (Type type) |
| Get allowed underlying types for vectors, tensors, and memrefs. | |
| static bool | hasSameEncoding (Type typeA, Type typeB) |
| Return false if both types are ranked tensor with mismatching encoding. | |
| static bool | areValidCastInputsAndOutputs (TypeRange inputs, TypeRange outputs) |
| template<typename ValType, typename Op> | |
| static LogicalResult | verifyExtOp (Op op) |
| template<typename ValType, typename Op> | |
| static LogicalResult | verifyTruncateOp (Op op) |
| template<template< typename > class WidthComparator, typename... ElementTypes> | |
| static bool | checkWidthChangeCast (TypeRange inputs, TypeRange outputs) |
| Validate a cast that changes the width of a type. | |
| static FailureOr< APFloat > | convertFloatValue (APFloat sourceValue, const llvm::fltSemantics &targetSemantics, llvm::RoundingMode roundingMode=kDefaultRoundingMode) |
| Attempts to convert sourceValue to an APFloat value with targetSemantics and roundingMode, without any information loss. | |
| static Attribute | foldScalingCastOp (Attribute inAttr, Attribute scaleAttr, Type resultType, function_ref< std::optional< APFloat >(const APFloat &, const APFloat &)> calculate) |
| Fold calculate element-wise over the operands of a scaling cast op. | |
| static bool | isFoldableScalingScale (Value scale) |
| Only scales that already are f8E8M0FNU fold. | |
| template<typename From, typename To> | |
| static bool | checkIntFloatCast (TypeRange inputs, TypeRange outputs) |
| static unsigned | getIndexCastWidth (Type t) |
Return the bit-width of t for the purpose of index_cast width checks. | |
| static bool | areIndexCastCompatible (TypeRange inputs, TypeRange outputs) |
| static bool | applyCmpPredicateToEqualOperands (arith::CmpIPredicate predicate) |
| Returns true if the predicate is true for two equal operands. | |
| static std::optional< int64_t > | getIntegerWidth (Type t) |
Variables | |
| static constexpr llvm::RoundingMode | kDefaultRoundingMode |
| Default rounding mode according to default LLVM floating-point environment. | |
| #define GET_OP_CLASSES |
Definition at line 3553 of file ArithOps.cpp.
| using OverflowCheckedBinaryOp = APInt (APInt::*)(const APInt &, bool &) const |
Definition at line 95 of file ArithOps.cpp.
| using type_list = std::tuple<Types...> * |
Definition at line 1729 of file ArithOps.cpp.
|
static |
Definition at line 56 of file ArithOps.cpp.
References applyToIntegerAttrs().
|
static |
Definition at line 71 of file ArithOps.cpp.
References applyToIntegerAttrs().
|
static |
Returns true if the predicate is true for two equal operands.
Definition at line 2594 of file ArithOps.cpp.
|
static |
Definition at line 47 of file ArithOps.cpp.
Referenced by addIntegerAttrs(), andIntegerAttrs(), mulIntegerAttrs(), orIntegerAttrs(), subIntegerAttrs(), and xorIntegerAttrs().
Definition at line 2417 of file ArithOps.cpp.
References areValidCastInputsAndOutputs(), getTypeIfLikeOrMemRef(), mlir::Type::isIndex(), and mlir::Type::isSignlessInteger().
Definition at line 1771 of file ArithOps.cpp.
References hasSameEncoding(), and mlir::verifyCompatibleShapes().
Referenced by areIndexCastCompatible(), checkIntFloatCast(), and checkWidthChangeCast().
|
static |
Definition at line 572 of file ArithOps.cpp.
|
static |
Definition at line 508 of file ArithOps.cpp.
|
static |
Definition at line 2291 of file ArithOps.cpp.
References areValidCastInputsAndOutputs(), and getTypeIfLike().
|
static |
Validate a cast that changes the width of a type.
Definition at line 1813 of file ArithOps.cpp.
References areValidCastInputsAndOutputs(), and getTypeIfLike().
|
static |
Equivalent to convertRoundingModeToLLVM(convertArithRoundingModeToLLVM(roundingMode)).
Not possible to implement as chain of calls as this would introduce a circular dependency with MLIRArithAttrToLLVMConversion and make arith depend on the LLVM dialect and on translation to LLVM.
Definition at line 164 of file ArithOps.cpp.
References kDefaultRoundingMode.
|
static |
Attempts to convert sourceValue to an APFloat value with targetSemantics and roundingMode, without any information loss.
Definition at line 1829 of file ArithOps.cpp.
References kDefaultRoundingMode.
|
static |
Fold op(a, op(a, b)) to op(a, b) for an associative, commutative and idempotent op (e.g.
and, or).
Definition at line 1174 of file ArithOps.cpp.
|
static |
Fold calculate element-wise over the operands of a scaling cast op.
The constFoldBinaryOp helpers cannot be used: they bail out unless both operands have the same type, and in and scale never do.
Definition at line 1963 of file ArithOps.cpp.
References mlir::DenseElementsAttr::get(), and result.
Definition at line 207 of file ArithOps.cpp.
References mlir::BoolAttr::get(), mlir::DenseElementsAttr::get(), and mlir::Type::getContext().
|
static |
Returns whether a signed division by divisor is speculatable.
This function conservatively assumes that all signed division by -1 are not speculatable.
Definition at line 938 of file ArithOps.cpp.
References mlir::m_IntRangeWithoutNegOneS(), mlir::m_IntRangeWithoutZeroS(), mlir::matchPattern(), mlir::Speculation::NotSpeculatable, and mlir::Speculation::Speculatable.
|
static |
Returns whether an unsigned division by divisor is speculatable.
Definition at line 884 of file ArithOps.cpp.
References mlir::m_IntRangeWithoutZeroU(), mlir::matchPattern(), mlir::Speculation::NotSpeculatable, and mlir::Speculation::Speculatable.
Return the type of the same shape (scalar, vector or tensor) containing i1.
Definition at line 244 of file ArithOps.cpp.
References mlir::Type::getContext().
Return the bit-width of t for the purpose of index_cast width checks.
For vector types use the element type; index maps to its internal storage width (64 on all current targets).
Definition at line 2411 of file ArithOps.cpp.
References mlir::getElementTypeOrSelf().
Return a scalar or splat integer attribute of type (an integer/index type or a shaped type thereof) holding value.
Returns a null attribute for shaped types with a dynamic shape, so callers can bail out of folding.
Definition at line 221 of file ArithOps.cpp.
References mlir::DenseElementsAttr::get(), and mlir::getElementTypeOrSelf().
Definition at line 2612 of file ArithOps.cpp.
|
static |
Definition at line 199 of file ArithOps.cpp.
References mlir::m_ConstantInt(), and mlir::matchPattern().
Definition at line 187 of file ArithOps.cpp.
References mlir::getElementTypeOrSelf(), mlir::Type::getIntOrFloatBitWidth(), and mlir::Type::isIntOrFloat().
Referenced by getScalarOrElementWidth().
Definition at line 195 of file ArithOps.cpp.
References getScalarOrElementWidth(), and mlir::Value::getType().
Get allowed underlying types for vectors and tensors.
Definition at line 1749 of file ArithOps.cpp.
References getUnderlyingType().
Referenced by checkIntFloatCast(), and checkWidthChangeCast().
Get allowed underlying types for vectors, tensors, and memrefs.
Definition at line 1756 of file ArithOps.cpp.
References getUnderlyingType().
Referenced by areIndexCastCompatible().
|
static |
Returns a non-null type only if the provided type is one of the allowed types or one of the allowed shaped types of the allowed types.
Returns the element type if a valid shaped type is provided.
Definition at line 1735 of file ArithOps.cpp.
References mlir::getElementTypeOrSelf().
Referenced by getTypeIfLike(), and getTypeIfLikeOrMemRef().
Return false if both types are ranked tensor with mismatching encoding.
Definition at line 1763 of file ArithOps.cpp.
Referenced by areValidCastInputsAndOutputs().
|
static |
Definition at line 182 of file ArithOps.cpp.
References mlir::arith::invertPredicate().
Only scales that already are f8E8M0FNU fold.
What a wider scale means is unsettled – the tree does not say whether truncating one to f8E8M0FNU rounds or takes its exponent – so a folder should not settle it, see https://github.com/llvm/llvm-project/issues/215295.
Definition at line 2020 of file ArithOps.cpp.
References mlir::getElementTypeOrSelf(), and mlir::Value::getType().
|
static |
Definition at line 89 of file ArithOps.cpp.
|
static |
Definition at line 100 of file ArithOps.cpp.
|
static |
Definition at line 66 of file ArithOps.cpp.
References applyToIntegerAttrs().
|
static |
Definition at line 76 of file ArithOps.cpp.
References applyToIntegerAttrs().
|
static |
Definition at line 61 of file ArithOps.cpp.
References applyToIntegerAttrs().
Definition at line 1785 of file ArithOps.cpp.
References mlir::OpState::emitError(), mlir::getElementTypeOrSelf(), and success().
Definition at line 1799 of file ArithOps.cpp.
References mlir::OpState::emitError(), mlir::getElementTypeOrSelf(), and success().
|
static |
Definition at line 81 of file ArithOps.cpp.
References applyToIntegerAttrs().
|
staticconstexpr |
Default rounding mode according to default LLVM floating-point environment.
Definition at line 39 of file ArithOps.cpp.
Referenced by convertArithRoundingModeToLLVMIR(), and convertFloatValue().