MLIR  20.0.0git
Classes | Macros | Functions
PolynomialApproximation.cpp File Reference
#include <climits>
#include <cmath>
#include <cstddef>
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Math/IR/Math.h"
#include "mlir/Dialect/Math/Transforms/Approximation.h"
#include "mlir/Dialect/Math/Transforms/Passes.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/Dialect/Vector/Utils/VectorUtils.h"
#include "mlir/Dialect/X86Vector/X86VectorDialect.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/MathExtras.h"

Go to the source code of this file.

Classes

struct  VectorShape
 

Macros

#define LN2_VALUE    0.693147180559945309417232121458176568075500134360255254120680009493393621L
 
#define LOG2E_VALUE    1.442695040888963407359924681001892137426645954152985934135449406931109219L
 
#define TWO_OVER_PI    0.6366197723675813430755350534900574481378385829618257949906693762L
 
#define PI_OVER_2    1.5707963267948966192313216916397514420985846996875529104874722961L
 

Functions

static std::optional< VectorShapevectorShape (Type type)
 
static std::optional< VectorShapevectorShape (Value value)
 
static Type broadcast (Type type, std::optional< VectorShape > shape)
 
static Value broadcast (ImplicitLocOpBuilder &builder, Value value, std::optional< VectorShape > shape)
 
static Value handleMultidimensionalVectors (ImplicitLocOpBuilder &builder, ValueRange operands, int64_t vectorWidth, llvm::function_ref< Value(ValueRange)> compute)
 
static Value floatCst (ImplicitLocOpBuilder &builder, float value, Type elementType)
 
static Value f32Cst (ImplicitLocOpBuilder &builder, double value)
 
static Value i32Cst (ImplicitLocOpBuilder &builder, int32_t value)
 
static Value f32FromBits (ImplicitLocOpBuilder &builder, uint32_t bits)
 
static Value min (ImplicitLocOpBuilder &builder, Value value, Value bound)
 
static Value max (ImplicitLocOpBuilder &builder, Value value, Value bound)
 
static Value clamp (ImplicitLocOpBuilder &builder, Value value, Value lowerBound, Value upperBound)
 
static std::pair< Value, Valuefrexp (ImplicitLocOpBuilder &builder, Value arg, bool isPositive=false)
 
static Value exp2I32 (ImplicitLocOpBuilder &builder, Value arg)
 
template<typename T >
LogicalResult insertCasts (Operation *op, PatternRewriter &rewriter)
 

Macro Definition Documentation

◆ LN2_VALUE

#define LN2_VALUE    0.693147180559945309417232121458176568075500134360255254120680009493393621L

Definition at line 614 of file PolynomialApproximation.cpp.

◆ LOG2E_VALUE

#define LOG2E_VALUE    1.442695040888963407359924681001892137426645954152985934135449406931109219L

Definition at line 616 of file PolynomialApproximation.cpp.

◆ PI_OVER_2

#define PI_OVER_2    1.5707963267948966192313216916397514420985846996875529104874722961L

Definition at line 1374 of file PolynomialApproximation.cpp.

◆ TWO_OVER_PI

#define TWO_OVER_PI    0.6366197723675813430755350534900574481378385829618257949906693762L

Definition at line 1372 of file PolynomialApproximation.cpp.

Function Documentation

◆ broadcast() [1/2]

static Value broadcast ( ImplicitLocOpBuilder builder,
Value  value,
std::optional< VectorShape shape 
)
static

◆ broadcast() [2/2]

static Type broadcast ( Type  type,
std::optional< VectorShape shape 
)
static

◆ clamp()

static Value clamp ( ImplicitLocOpBuilder builder,
Value  value,
Value  lowerBound,
Value  upperBound 
)
static

Definition at line 216 of file PolynomialApproximation.cpp.

References max(), and min().

Referenced by createLinalgBodyCalculationForElementwiseOp(), and wmmaPushOutputOperand().

◆ exp2I32()

static Value exp2I32 ( ImplicitLocOpBuilder builder,
Value  arg 
)
static

◆ f32Cst()

static Value f32Cst ( ImplicitLocOpBuilder builder,
double  value 
)
static

◆ f32FromBits()

static Value f32FromBits ( ImplicitLocOpBuilder builder,
uint32_t  bits 
)
static

◆ floatCst()

static Value floatCst ( ImplicitLocOpBuilder builder,
float  value,
Type  elementType 
)
static

◆ frexp()

static std::pair<Value, Value> frexp ( ImplicitLocOpBuilder builder,
Value  arg,
bool  isPositive = false 
)
static

◆ handleMultidimensionalVectors()

static Value handleMultidimensionalVectors ( ImplicitLocOpBuilder builder,
ValueRange  operands,
int64_t  vectorWidth,
llvm::function_ref< Value(ValueRange)>  compute 
)
static

◆ i32Cst()

static Value i32Cst ( ImplicitLocOpBuilder builder,
int32_t  value 
)
static

◆ insertCasts()

template<typename T >
LogicalResult insertCasts ( Operation op,
PatternRewriter rewriter 
)

◆ max()

static Value max ( ImplicitLocOpBuilder builder,
Value  value,
Value  bound 
)
static

Definition at line 209 of file PolynomialApproximation.cpp.

References mlir::ImplicitLocOpBuilder::create().

Referenced by mlir::AllocationOpLLVMLowering::alignedAllocationGetAlignment(), mlir::tensor::bubbleUpPadSlice(), mlir::tosa::buildQTypeFromMinMax(), buildSubAndExpOp(), calculateStructAlignment(), mlir::sparse_tensor::detail::checkedMul(), mlir::sparse_tensor::detail::checkOverflowCast(), clamp(), mlir::tosa::clampFloatHelper(), clampInput(), mlir::tosa::clampIntHelper(), computeDirectionVector(), computeMultiplierAndShiftTosaScale16(), computeMultiplierAndShiftTosaScale32(), mlir::presburger::IntegerRelation::computeVolume(), createLinalgBodyCalculationForElementwiseOp(), declareReduction(), executeGetOperandsResults(), generateFusedElementwiseOpRegion(), mlir::quant::CalibratedQuantizedType::get(), mlir::quant::CalibratedQuantizedType::getChecked(), getDefaultStorageParams(), mlir::affine::NestedPattern::getDepth(), mlir::affine::getInnermostCommonLoopDepth(), mlir::affine::getLargestDivisorOfTripCount(), mlir::AffineMap::getLargestKnownDivisorOfMapExprs(), getLocationFromLoc(), mlir::getMaxDimAndSymbol(), getMaxPosOfType(), mlir::presburger::detail::getNonOrthogonalVector(), mlir::detail::PassOptions::getOptionWidth(), mlir::affine::getPerfectlyNestedLoops(), getSemiAffineExprFromFlatForm(), mlir::LLVM::LLVMStructType::getTypeSizeInBits(), mlir::presburger::PresburgerSpace::getVarKindOverlap(), handleByValArgument(), isFusionProfitable(), isIntegerArrayAttrConfinedToRange(), isIntegerArrayAttrConfinedToShape(), mlir::AffineMap::isPermutationOfMinorIdentityWithBroadcasting(), isPrimitiveNthRootOfUnity(), isSumOfIntegerArrayAttrConfinedToShape(), loopScheduling(), mlir::gpu::index_lowering::OpLowering< Op, XOp, YOp, ZOp >::matchAndRewrite(), ClampClampOptimization::matchAndRewrite(), mlir::presburger::Matrix< T >::Matrix(), maybeConstantDimsAttr(), minMaxBy(), mlirCalibratedQuantizedTypeGet(), parseAndVerify< unsigned >(), parseCalibratedType(), parseExpressedTypeAndRange(), mlir::detail::Parser::parseIntegerInDimensionList(), mlir::detail::Parser::parseStridedLayoutAttr(), mlir::printRegisteredPasses(), mlir::ConstantIntRanges::range(), mlir::affine::FlatAffineRelation::removeVarRange(), mlir::InlinerConfig::setMaxInliningIterations(), specializeForLoopForUnrolling(), specializeParallelLoopForUnrolling(), mlir::OpTrait::util::staticallyKnownBroadcastable(), staticallyOutOfBounds(), mlir::affine::substWithMin(), mlir::raw_indented_ostream::unindent(), mlir::presburger::IntegerRelation::unionBoundingBox(), mlir::quant::CalibratedQuantizedType::verifyInvariants(), mlir::linalg::detail::verifyStructuredOpInterface(), mlir::dataflow::IntegerRangeAnalysis::visitNonControlFlowArguments(), and mlir::quant::UniformQuantizedValueConverter::~UniformQuantizedValueConverter().

◆ min()

static Value min ( ImplicitLocOpBuilder builder,
Value  value,
Value  bound 
)
static

Definition at line 202 of file PolynomialApproximation.cpp.

References mlir::ImplicitLocOpBuilder::create().

Referenced by addOrderingConstraints(), mlir::tensor::bubbleUpPadSlice(), mlir::tosa::buildQTypeFromMinMax(), mlir::sparse_tensor::detail::checkOverflowCast(), clamp(), mlir::tosa::clampFloatHelper(), clampInput(), mlir::tosa::clampIntHelper(), computeDirectionVector(), mlir::presburger::IntegerRelation::computeVolume(), createLinalgBodyCalculationForElementwiseOp(), declareReduction(), mlir::mesh::MeshSharding::equalSplitAndPartialAxes(), mlir::sparse_tensor::genCoIteration(), mlir::quant::CalibratedQuantizedType::get(), mlir::quant::CalibratedQuantizedType::getChecked(), mlir::affine::getConstantTripCount(), getDefaultStorageParams(), mlir::affine::getInnermostCommonLoopDepth(), getMaxLoopDepth(), getNumCommonLoops(), mlir::affine::getNumCommonSurroundingLoops(), mlir::presburger::PresburgerSpace::getVarKindOverlap(), isIntegerArrayAttrConfinedToRange(), isIntegerArrayAttrConfinedToShape(), isSumOfIntegerArrayAttrConfinedToShape(), loopScheduling(), mlir::GPUPrintfOpToHIPLowering::matchAndRewrite(), mlir::gpu::index_lowering::OpLowering< Op, XOp, YOp, ZOp >::matchAndRewrite(), ClampClampOptimization::matchAndRewrite(), memsetRewire(), minMaxBy(), minMaxValueForFloat(), minMaxValueForSignedInt(), minMaxValueForUnsignedInt(), mlirCalibratedQuantizedTypeGet(), parseCalibratedType(), parseExpressedTypeAndRange(), mlir::detail::pass_options::printOptionValue(), mlir::raw_indented_ostream::printReindented(), mlir::ConstantIntRanges::range(), mlir::presburger::IntegerRelation::removeVarRange(), mlir::affine::FlatAffineRelation::removeVarRange(), specializeForLoopForUnrolling(), specializeParallelLoopForUnrolling(), mlir::affine::substWithMin(), mlir::presburger::IntegerRelation::unionBoundingBox(), mlir::quant::CalibratedQuantizedType::verifyInvariants(), mlir::linalg::detail::verifyStructuredOpInterface(), mlir::dataflow::IntegerRangeAnalysis::visitNonControlFlowArguments(), and mlir::quant::UniformQuantizedValueConverter::~UniformQuantizedValueConverter().

◆ vectorShape() [1/2]

static std::optional<VectorShape> vectorShape ( Type  type)
static

◆ vectorShape() [2/2]

static std::optional<VectorShape> vectorShape ( Value  value)
static

Definition at line 56 of file PolynomialApproximation.cpp.

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