MLIR  20.0.0git
Functions
EmulateNarrowType.cpp File Reference
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Transforms/NarrowTypeEmulationConverter.h"
#include "mlir/Dialect/Arith/Transforms/Passes.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/Transforms/DialectConversion.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <type_traits>

Go to the source code of this file.

Functions

static LogicalResult convertCastingOp (ConversionPatternRewriter &rewriter, memref::ReinterpretCastOp::Adaptor adaptor, memref::ReinterpretCastOp op, MemRefType newTy)
 Converts a memref::ReinterpretCastOp to the converted type. More...
 
static Value getOffsetForBitwidth (Location loc, OpFoldResult srcIdx, int sourceBits, int targetBits, OpBuilder &builder)
 When data is loaded/stored in targetBits granularity, but is used in sourceBits granularity (sourceBits < targetBits), the targetBits is treated as an array of elements of width sourceBits. More...
 
static Value getSubByteWriteMask (Location loc, OpFoldResult linearizedIndices, int64_t srcBits, int64_t dstBits, Value bitwidthOffset, OpBuilder &builder)
 When writing a subbyte size, masked bitwise operations are used to only modify the relevant bits. More...
 
static Value getIndicesForLoadOrStore (OpBuilder &builder, Location loc, OpFoldResult linearizedIndex, int64_t srcBits, int64_t dstBits)
 Returns the scaled linearized index based on the srcBits and dstBits sizes. More...
 
static OpFoldResult getLinearizedSrcIndices (OpBuilder &builder, Location loc, int64_t srcBits, const SmallVector< OpFoldResult > &indices, Value memref)
 
static SmallVector< int64_t > getLinearizedShape (MemRefType ty, int srcBits, int dstBits)
 

Function Documentation

◆ convertCastingOp()

static LogicalResult convertCastingOp ( ConversionPatternRewriter rewriter,
memref::ReinterpretCastOp::Adaptor  adaptor,
memref::ReinterpretCastOp  op,
MemRefType  newTy 
)
static

Converts a memref::ReinterpretCastOp to the converted type.

The result MemRefType of the old op must have a rank and stride of 1, with static offset and size. The number of bits in the offset must evenly divide the bitwidth of the new converted type.

Definition at line 39 of file EmulateNarrowType.cpp.

References mlir::RewriterBase::notifyMatchFailure(), and mlir::RewriterBase::replaceOpWithNewOp().

◆ getIndicesForLoadOrStore()

static Value getIndicesForLoadOrStore ( OpBuilder builder,
Location  loc,
OpFoldResult  linearizedIndex,
int64_t  srcBits,
int64_t  dstBits 
)
static

Returns the scaled linearized index based on the srcBits and dstBits sizes.

The input linearizedIndex has the granularity of srcBits, and the returned index has the granularity of dstBits

Definition at line 128 of file EmulateNarrowType.cpp.

References mlir::bindSymbols(), mlir::AffineExpr::floorDiv(), mlir::Builder::getContext(), mlir::getValueOrCreateConstantIndexOp(), and mlir::affine::makeComposedFoldedAffineApply().

◆ getLinearizedShape()

static SmallVector<int64_t> getLinearizedShape ( MemRefType  ty,
int  srcBits,
int  dstBits 
)
static

◆ getLinearizedSrcIndices()

static OpFoldResult getLinearizedSrcIndices ( OpBuilder builder,
Location  loc,
int64_t  srcBits,
const SmallVector< OpFoldResult > &  indices,
Value  memref 
)
static

◆ getOffsetForBitwidth()

static Value getOffsetForBitwidth ( Location  loc,
OpFoldResult  srcIdx,
int  sourceBits,
int  targetBits,
OpBuilder builder 
)
static

When data is loaded/stored in targetBits granularity, but is used in sourceBits granularity (sourceBits < targetBits), the targetBits is treated as an array of elements of width sourceBits.

Return the bit offset of the value at position srcIdx. For example, if sourceBits equals to 4 and targetBits equals to 8, the x-th element is located at (x % 2) * 4. Because there are two elements in one i8, and one element has 4 bits.

Definition at line 90 of file EmulateNarrowType.cpp.

References mlir::bindSymbols(), mlir::OpBuilder::create(), mlir::Builder::getContext(), mlir::Builder::getIntegerType(), mlir::getValueOrCreateConstantIndexOp(), and mlir::affine::makeComposedFoldedAffineApply().

◆ getSubByteWriteMask()

static Value getSubByteWriteMask ( Location  loc,
OpFoldResult  linearizedIndices,
int64_t  srcBits,
int64_t  dstBits,
Value  bitwidthOffset,
OpBuilder builder 
)
static

When writing a subbyte size, masked bitwise operations are used to only modify the relevant bits.

This function returns an and mask for clearing the destination bits in a subbyte write. E.g., when writing to the second i4 in an i32, 0xFFFFFF0F is created.

Definition at line 109 of file EmulateNarrowType.cpp.

References mlir::OpBuilder::create(), mlir::Builder::getIntegerAttr(), and mlir::Builder::getIntegerType().