MLIR  20.0.0git
Classes | Macros | Typedefs | Functions
ArithOps.cpp File Reference
#include <cassert>
#include <cstdint>
#include <functional>
#include <utility>
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/CommonFolders.h"
#include "mlir/Dialect/UB/IR/UBOps.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 "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/SmallString.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

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 IntegerOverflowFlagsAttr mergeOverflowFlags (IntegerOverflowFlagsAttr val1, IntegerOverflowFlagsAttr val2)
 
static llvm::RoundingMode convertArithRoundingModeToLLVMIR (RoundingMode roundingMode)
 Equivalent to convertRoundingModeToLLVM(convertArithRoundingModeToLLVM(roundingMode)). More...
 
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 Type getI1SameShape (Type type)
 Return the type of the same shape (scalar, vector or tensor) containing i1. More...
 
static APInt calculateUnsignedOverflow (const APInt &sum, const APInt &operand)
 
static APInt signedCeilNonnegInputs (const APInt &a, const APInt &b, bool &overflow)
 
static Value foldAndIofAndI (arith::AndIOp op)
 Fold and(a, and(a, b)) to and(a, b) More...
 
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. More...
 
template<typename... ElementTypes>
static Type getTypeIfLike (Type type)
 Get allowed underlying types for vectors and tensors. More...
 
template<typename... ElementTypes>
static Type getTypeIfLikeOrMemRef (Type type)
 Get allowed underlying types for vectors, tensors, and memrefs. More...
 
static bool hasSameEncoding (Type typeA, Type typeB)
 Return false if both types are ranked tensor with mismatching encoding. More...
 
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. More...
 
static FailureOr< APFloat > convertFloatValue (APFloat sourceValue, const llvm::fltSemantics &targetSemantics, llvm::RoundingMode roundingMode=llvm::RoundingMode::NearestTiesToEven)
 Attempts to convert sourceValue to an APFloat value with targetSemantics and roundingMode, without any information loss. More...
 
template<typename From , typename To >
static bool checkIntFloatCast (TypeRange inputs, TypeRange outputs)
 
static bool areIndexCastCompatible (TypeRange inputs, TypeRange outputs)
 
static bool applyCmpPredicateToEqualOperands (arith::CmpIPredicate predicate)
 Returns true if the predicate is true for two equal operands. More...
 
static std::optional< int64_t > getIntegerWidth (Type t)
 

Macro Definition Documentation

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 2638 of file ArithOps.cpp.

Typedef Documentation

◆ type_list

template<typename... Types>
using type_list = std::tuple<Types...> *

Definition at line 1219 of file ArithOps.cpp.

Function Documentation

◆ addIntegerAttrs()

static IntegerAttr addIntegerAttrs ( PatternRewriter builder,
Value  res,
Attribute  lhs,
Attribute  rhs 
)
static

Definition at line 51 of file ArithOps.cpp.

References applyToIntegerAttrs().

◆ applyCmpPredicateToEqualOperands()

static bool applyCmpPredicateToEqualOperands ( arith::CmpIPredicate  predicate)
static

Returns true if the predicate is true for two equal operands.

Definition at line 1788 of file ArithOps.cpp.

◆ applyToIntegerAttrs()

static IntegerAttr applyToIntegerAttrs ( PatternRewriter builder,
Value  res,
Attribute  lhs,
Attribute  rhs,
function_ref< APInt(const APInt &, const APInt &)>  binFn 
)
static

Definition at line 42 of file ArithOps.cpp.

References mlir::get(), and mlir::Value::getType().

Referenced by addIntegerAttrs(), mulIntegerAttrs(), and subIntegerAttrs().

◆ areIndexCastCompatible()

static bool areIndexCastCompatible ( TypeRange  inputs,
TypeRange  outputs 
)
static

◆ areValidCastInputsAndOutputs()

static bool areValidCastInputsAndOutputs ( TypeRange  inputs,
TypeRange  outputs 
)
static

◆ calculateUnsignedOverflow()

static APInt calculateUnsignedOverflow ( const APInt &  sum,
const APInt &  operand 
)
static

Definition at line 345 of file ArithOps.cpp.

References getZero().

◆ checkIntFloatCast()

template<typename From , typename To >
static bool checkIntFloatCast ( TypeRange  inputs,
TypeRange  outputs 
)
static

Definition at line 1542 of file ArithOps.cpp.

References areValidCastInputsAndOutputs().

◆ checkWidthChangeCast()

template<template< typename > class WidthComparator, typename... ElementTypes>
static bool checkWidthChangeCast ( TypeRange  inputs,
TypeRange  outputs 
)
static

Validate a cast that changes the width of a type.

Definition at line 1303 of file ArithOps.cpp.

References areValidCastInputsAndOutputs(), and getTypeIfLike().

◆ convertArithRoundingModeToLLVMIR()

static llvm::RoundingMode convertArithRoundingModeToLLVMIR ( RoundingMode  roundingMode)
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 108 of file ArithOps.cpp.

◆ convertFloatValue()

static FailureOr<APFloat> convertFloatValue ( APFloat  sourceValue,
const llvm::fltSemantics &  targetSemantics,
llvm::RoundingMode  roundingMode = llvm::RoundingMode::NearestTiesToEven 
)
static

Attempts to convert sourceValue to an APFloat value with targetSemantics and roundingMode, without any information loss.

Definition at line 1318 of file ArithOps.cpp.

◆ foldAndIofAndI()

static Value foldAndIofAndI ( arith::AndIOp  op)
static

Fold and(a, and(a, b)) to and(a, b)

Definition at line 834 of file ArithOps.cpp.

◆ getBoolAttribute()

static Attribute getBoolAttribute ( Type  type,
bool  value 
)
static

◆ getI1SameShape()

static Type getI1SameShape ( Type  type)
static

Return the type of the same shape (scalar, vector or tensor) containing i1.

Definition at line 170 of file ArithOps.cpp.

References mlir::get(), and mlir::Type::getContext().

◆ getIntegerWidth()

static std::optional<int64_t> getIntegerWidth ( Type  t)
static

Definition at line 1806 of file ArithOps.cpp.

◆ getIntOrSplatIntValue()

static FailureOr<APInt> getIntOrSplatIntValue ( Attribute  attr)
static

Definition at line 141 of file ArithOps.cpp.

References mlir::m_ConstantInt(), and mlir::matchPattern().

◆ getScalarOrElementWidth() [1/2]

static int64_t getScalarOrElementWidth ( Type  type)
static

◆ getScalarOrElementWidth() [2/2]

static int64_t getScalarOrElementWidth ( Value  value)
static

Definition at line 137 of file ArithOps.cpp.

References getScalarOrElementWidth(), and mlir::Value::getType().

◆ getTypeIfLike()

template<typename... ElementTypes>
static Type getTypeIfLike ( Type  type)
static

Get allowed underlying types for vectors and tensors.

Definition at line 1239 of file ArithOps.cpp.

References getUnderlyingType().

Referenced by checkWidthChangeCast().

◆ getTypeIfLikeOrMemRef()

template<typename... ElementTypes>
static Type getTypeIfLikeOrMemRef ( Type  type)
static

Get allowed underlying types for vectors, tensors, and memrefs.

Definition at line 1246 of file ArithOps.cpp.

References getUnderlyingType().

◆ getUnderlyingType()

template<typename... ShapedTypes, typename... ElementTypes>
static Type getUnderlyingType ( Type  type,
type_list< ShapedTypes... >  ,
type_list< ElementTypes... >   
)
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 1225 of file ArithOps.cpp.

References mlir::getElementTypeOrSelf().

Referenced by getTypeIfLike(), and getTypeIfLikeOrMemRef().

◆ hasSameEncoding()

static bool hasSameEncoding ( Type  typeA,
Type  typeB 
)
static

Return false if both types are ranked tensor with mismatching encoding.

Definition at line 1253 of file ArithOps.cpp.

Referenced by areValidCastInputsAndOutputs().

◆ invertPredicate()

static arith::CmpIPredicateAttr invertPredicate ( arith::CmpIPredicateAttr  pred)
static

Definition at line 124 of file ArithOps.cpp.

References mlir::get(), and mlir::arith::invertPredicate().

◆ mergeOverflowFlags()

static IntegerOverflowFlagsAttr mergeOverflowFlags ( IntegerOverflowFlagsAttr  val1,
IntegerOverflowFlagsAttr  val2 
)
static

Definition at line 68 of file ArithOps.cpp.

References mlir::get().

◆ mulIntegerAttrs()

static IntegerAttr mulIntegerAttrs ( PatternRewriter builder,
Value  res,
Attribute  lhs,
Attribute  rhs 
)
static

Definition at line 61 of file ArithOps.cpp.

References applyToIntegerAttrs().

◆ signedCeilNonnegInputs()

static APInt signedCeilNonnegInputs ( const APInt &  a,
const APInt &  b,
bool &  overflow 
)
static

Definition at line 643 of file ArithOps.cpp.

◆ subIntegerAttrs()

static IntegerAttr subIntegerAttrs ( PatternRewriter builder,
Value  res,
Attribute  lhs,
Attribute  rhs 
)
static

Definition at line 56 of file ArithOps.cpp.

References applyToIntegerAttrs().

◆ verifyExtOp()

template<typename ValType , typename Op >
static LogicalResult verifyExtOp ( Op  op)
static

Definition at line 1275 of file ArithOps.cpp.

◆ verifyTruncateOp()

template<typename ValType , typename Op >
static LogicalResult verifyTruncateOp ( Op  op)
static

Definition at line 1289 of file ArithOps.cpp.