MLIR  19.0.0git
Namespaces | Macros | Functions
EmulateWideInt.cpp File Reference
#include "mlir/Dialect/Arith/Transforms/Passes.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Transforms/WideIntEmulationConverter.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Func/Transforms/FuncConversions.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/TypeUtilities.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/ADT/APInt.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include "mlir/Dialect/Arith/Transforms/Passes.h.inc"

Go to the source code of this file.

Namespaces

 mlir
 Include the generated interface declarations.
 
 mlir::arith
 

Macros

#define GEN_PASS_DEF_ARITHEMULATEWIDEINT
 

Functions

static std::pair< APInt, APInt > getHalves (const APInt &value, unsigned newBitWidth)
 Returns N bottom and N top bits from value, where N = newBitWidth. More...
 
static Type reduceInnermostDim (VectorType type)
 Returns the type with the last (innermost) dimension reduced to x1. More...
 
static Value extractLastDimSlice (ConversionPatternRewriter &rewriter, Location loc, Value input, int64_t lastOffset)
 Extracts the input vector slice with elements at the last dimension offset by lastOffset. More...
 
static std::pair< Value, ValueextractLastDimHalves (ConversionPatternRewriter &rewriter, Location loc, Value input)
 Extracts two vector slices from the input whose type is vector<...x2T>, with the first element at offset 0 and the second element at offset 1. More...
 
static Value dropTrailingX1Dim (ConversionPatternRewriter &rewriter, Location loc, Value input)
 
static Value appendX1Dim (ConversionPatternRewriter &rewriter, Location loc, Value input)
 Performs a vector shape cast to append an x1 dimension. More...
 
static Value insertLastDimSlice (ConversionPatternRewriter &rewriter, Location loc, Value source, Value dest, int64_t lastOffset)
 Inserts the source vector slice into the dest vector at offset lastOffset in the last dimension. More...
 
static Value constructResultVector (ConversionPatternRewriter &rewriter, Location loc, VectorType resultType, ValueRange resultComponents)
 Constructs a new vector of type resultType by creating a series of insertions of resultComponents, each at the next offset of the last vector dimension. More...
 

Macro Definition Documentation

◆ GEN_PASS_DEF_ARITHEMULATEWIDEINT

#define GEN_PASS_DEF_ARITHEMULATEWIDEINT

Definition at line 27 of file EmulateWideInt.cpp.

Function Documentation

◆ appendX1Dim()

static Value appendX1Dim ( ConversionPatternRewriter rewriter,
Location  loc,
Value  input 
)
static

Performs a vector shape cast to append an x1 dimension.

If the input is a scalar, this is a noop.

Definition at line 115 of file EmulateWideInt.cpp.

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

◆ constructResultVector()

static Value constructResultVector ( ConversionPatternRewriter rewriter,
Location  loc,
VectorType  resultType,
ValueRange  resultComponents 
)
static

Constructs a new vector of type resultType by creating a series of insertions of resultComponents, each at the next offset of the last vector dimension.

When all resultComponents are scalars, the result type is vector<NxT>; when resultComponents are vector<...x1xT>s, the result type is vector<...xNxT>, where N is the number of resultComponents.

Definition at line 154 of file EmulateWideInt.cpp.

References mlir::createScalarOrSplatConstant(), mlir::detail::enumerate(), and insertLastDimSlice().

◆ dropTrailingX1Dim()

static Value dropTrailingX1Dim ( ConversionPatternRewriter rewriter,
Location  loc,
Value  input 
)
static

Definition at line 98 of file EmulateWideInt.cpp.

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

◆ extractLastDimHalves()

static std::pair<Value, Value> extractLastDimHalves ( ConversionPatternRewriter rewriter,
Location  loc,
Value  input 
)
static

Extracts two vector slices from the input whose type is vector<...x2T>, with the first element at offset 0 and the second element at offset 1.

Definition at line 90 of file EmulateWideInt.cpp.

References extractLastDimSlice().

◆ extractLastDimSlice()

static Value extractLastDimSlice ( ConversionPatternRewriter rewriter,
Location  loc,
Value  input,
int64_t  lastOffset 
)
static

Extracts the input vector slice with elements at the last dimension offset by lastOffset.

Returns a value of vector type with the last dimension reduced to x1 or fully scalarized, e.g.:

  • vector<3x2xi16> --> vector<3x1xi16>
  • vector<2xi16> --> i16

Definition at line 67 of file EmulateWideInt.cpp.

References mlir::OpBuilder::create(), and mlir::Value::getType().

Referenced by extractLastDimHalves().

◆ getHalves()

static std::pair<APInt, APInt> getHalves ( const APInt &  value,
unsigned  newBitWidth 
)
static

Returns N bottom and N top bits from value, where N = newBitWidth.

Treats value as a 2*N bits-wide integer. The bottom bits are returned in the first pair element, while the top bits in the second one.

Definition at line 41 of file EmulateWideInt.cpp.

◆ insertLastDimSlice()

static Value insertLastDimSlice ( ConversionPatternRewriter rewriter,
Location  loc,
Value  source,
Value  dest,
int64_t  lastOffset 
)
static

Inserts the source vector slice into the dest vector at offset lastOffset in the last dimension.

source can be a scalar when dest is a 1D vector.

Definition at line 131 of file EmulateWideInt.cpp.

References mlir::OpBuilder::create(), and mlir::Value::getType().

Referenced by constructResultVector().

◆ reduceInnermostDim()

static Type reduceInnermostDim ( VectorType  type)
static

Returns the type with the last (innermost) dimension reduced to x1.

Scalarizes 1D vector inputs to match how we extract/insert vector values, e.g.:

  • vector<3x2xi16> --> vector<3x1xi16>
  • vector<2xi16> --> i16

Definition at line 53 of file EmulateWideInt.cpp.

References mlir::get().