MLIR  15.0.0git
Classes | Enumerations | Functions
mlir::sparse_tensor Namespace Reference

Classes

struct  Children
 Children subexpressions of tensor operations. More...
 
struct  LatPoint
 Lattice point. More...
 
class  Merger
 A class to handle all iteration lattice operations. More...
 
struct  SparseCompilerOptions
 Options for the "sparse-compiler" pipeline. More...
 
struct  TensorExp
 Tensor expression. Represents a MLIR expression in tensor index notation. More...
 

Enumerations

enum  Dim { kSparse, kDense, kSingle, kUndef }
 Dimension level type for a tensor (undef means index does not appear). More...
 
enum  Kind {
  kTensor = 0, kInvariant, kIndex, kAbsF,
  kAbsC, kCeilF, kFloorF, kSqrtF,
  kExpm1F, kLog1pF, kLog1pC, kSinF,
  kSinC, kTanhF, kNegF, kNegC,
  kNegI, kTruncF, kExtF, kCastFS,
  kCastFU, kCastSF, kCastUF, kCastS,
  kCastU, kCastIdx, kTruncI, kCIm,
  kCRe, kBitCast, kBinaryBranch, kUnary,
  kMulF, kMulC, kMulI, kDivF,
  kDivC, kDivS, kDivU, kAddF,
  kAddC, kAddI, kSubF, kSubC,
  kSubI, kAndI, kOrI, kXorI,
  kShrS, kShrU, kShlI, kBinary
}
 Tensor expression kind. More...
 

Functions

SparseTensorEncodingAttr getSparseTensorEncoding (Type type)
 Convenience method to get a sparse encoding attribute from a type. More...
 
void buildSparseCompiler (OpPassManager &pm, const SparseCompilerOptions &options)
 Adds the "sparse-compiler" pipeline to the OpPassManager. More...
 
void registerSparseTensorPipelines ()
 Registers all pipelines for the sparse_tensor dialect. More...
 
OverheadType overheadTypeEncoding (unsigned width)
 Converts an overhead storage bitwidth to its internal type-encoding. More...
 
OverheadType overheadTypeEncoding (Type tp)
 Converts an overhead storage type to its internal type-encoding. More...
 
Type getOverheadType (Builder &builder, OverheadType ot)
 Converts the internal type-encoding for overhead storage to an mlir::Type. More...
 
OverheadType pointerOverheadTypeEncoding (const SparseTensorEncodingAttr &enc)
 Returns the OverheadType for pointer overhead storage. More...
 
OverheadType indexOverheadTypeEncoding (const SparseTensorEncodingAttr &enc)
 Returns the OverheadType for index overhead storage. More...
 
Type getPointerOverheadType (Builder &builder, const SparseTensorEncodingAttr &enc)
 Returns the mlir::Type for pointer overhead storage. More...
 
Type getIndexOverheadType (Builder &builder, const SparseTensorEncodingAttr &enc)
 Returns the mlir::Type for index overhead storage. More...
 
StringRef overheadTypeFunctionSuffix (OverheadType ot)
 Convert OverheadType to its function-name suffix. More...
 
StringRef overheadTypeFunctionSuffix (Type overheadTp)
 Converts an overhead storage type to its function-name suffix. More...
 
PrimaryType primaryTypeEncoding (Type elemTp)
 Converts a primary storage type to its internal type-encoding. More...
 
StringRef primaryTypeFunctionSuffix (PrimaryType pt)
 Convert PrimaryType to its function-name suffix. More...
 
StringRef primaryTypeFunctionSuffix (Type elemTp)
 Converts a primary storage type to its function-name suffix. More...
 
DimLevelType dimLevelTypeEncoding (SparseTensorEncodingAttr::DimLevelType dlt)
 Converts the IR's dimension level type to its internal type-encoding. More...
 
Attribute getOneAttr (Builder &builder, Type tp)
 Generates a 1-valued attribute of the given type. More...
 
Value genIsNonzero (OpBuilder &builder, Location loc, Value v)
 Generates the comparison v != 0 where v is of numeric type. More...
 
Value constantZero (OpBuilder &builder, Location loc, Type tp)
 Generates a 0-valued constant of the given type. More...
 
Value constantOne (OpBuilder &builder, Location loc, Type tp)
 Generates a 1-valued constant of the given type. More...
 
Value constantIndex (OpBuilder &builder, Location loc, int64_t i)
 Generates a constant of index type. More...
 
Value constantI32 (OpBuilder &builder, Location loc, int32_t i)
 Generates a constant of i32 type. More...
 
Value constantI16 (OpBuilder &builder, Location loc, int16_t i)
 Generates a constant of i16 type. More...
 
Value constantI8 (OpBuilder &builder, Location loc, int8_t i)
 Generates a constant of i8 type. More...
 
Value constantI1 (OpBuilder &builder, Location loc, bool b)
 Generates a constant of i1 type. More...
 
Value constantAction (OpBuilder &builder, Location loc, Action action)
 Generates a constant of the given Action. More...
 
Value constantOverheadTypeEncoding (OpBuilder &builder, Location loc, unsigned width)
 Generates a constant of the internal type-encoding for overhead storage. More...
 
Value constantPointerTypeEncoding (OpBuilder &builder, Location loc, const SparseTensorEncodingAttr &enc)
 Generates a constant of the internal type-encoding for pointer overhead storage. More...
 
Value constantIndexTypeEncoding (OpBuilder &builder, Location loc, const SparseTensorEncodingAttr &enc)
 Generates a constant of the internal type-encoding for index overhead storage. More...
 
Value constantPrimaryTypeEncoding (OpBuilder &builder, Location loc, Type elemTp)
 Generates a constant of the internal type-encoding for primary storage. More...
 
Value constantDimLevelTypeEncoding (OpBuilder &builder, Location loc, SparseTensorEncodingAttr::DimLevelType dlt)
 Generates a constant of the internal dimension level type encoding. More...
 
static const char * kindToOpSymbol (Kind kind)
 
static Value insertYieldOp (RewriterBase &rewriter, Location loc, Region &region, ValueRange vals)
 
static Value buildUnaryPresent (RewriterBase &rewriter, Location loc, Operation *op, Value v0)
 
static Value buildBinaryOverlap (RewriterBase &rewriter, Location loc, Operation *op, Value v0, Value v1)
 

Enumeration Type Documentation

◆ Dim

Dimension level type for a tensor (undef means index does not appear).

Enumerator
kSparse 
kDense 
kSingle 
kUndef 

Definition at line 24 of file Merger.h.

◆ Kind

Tensor expression kind.

Enumerator
kTensor 
kInvariant 
kIndex 
kAbsF 
kAbsC 
kCeilF 
kFloorF 
kSqrtF 
kExpm1F 
kLog1pF 
kLog1pC 
kSinF 
kSinC 
kTanhF 
kNegF 
kNegC 
kNegI 
kTruncF 
kExtF 
kCastFS 
kCastFU 
kCastSF 
kCastUF 
kCastS 
kCastU 
kCastIdx 
kTruncI 
kCIm 
kCRe 
kBitCast 
kBinaryBranch 
kUnary 
kMulF 
kMulC 
kMulI 
kDivF 
kDivC 
kDivS 
kDivU 
kAddF 
kAddC 
kAddI 
kSubF 
kSubC 
kSubI 
kAndI 
kOrI 
kXorI 
kShrS 
kShrU 
kShlI 
kBinary 

Definition at line 27 of file Merger.h.

Function Documentation

◆ buildBinaryOverlap()

static Value mlir::sparse_tensor::buildBinaryOverlap ( RewriterBase rewriter,
Location  loc,
Operation op,
Value  v0,
Value  v1 
)
static

Definition at line 920 of file Merger.cpp.

References insertYieldOp().

◆ buildSparseCompiler()

void mlir::sparse_tensor::buildSparseCompiler ( OpPassManager pm,
const SparseCompilerOptions options 
)

Adds the "sparse-compiler" pipeline to the OpPassManager.

This is the standard pipeline for taking sparsity-agnostic IR using the sparse-tensor type and lowering it to LLVM IR with concrete representations and algorithms for sparse tensors.

Definition at line 30 of file SparseTensorPipelines.cpp.

References mlir::OpPassManager::addNestedPass(), mlir::OpPassManager::addPass(), mlir::arith::createConstantBufferizePass(), mlir::createConvertComplexToLibmPass(), mlir::createConvertComplexToLLVMPass(), mlir::createConvertComplexToStandardPass(), mlir::createConvertFuncToLLVMPass(), mlir::createConvertLinalgToLoopsPass(), mlir::createConvertMathToLibmPass(), mlir::createConvertMathToLLVMPass(), mlir::createConvertSCFToCFPass(), mlir::createConvertVectorToLLVMPass(), mlir::createConvertVectorToSCFPass(), mlir::bufferization::createFinalizingBufferizePass(), mlir::func::createFuncBufferizePass(), mlir::createLinalgBufferizePass(), mlir::createLinalgElementwiseOpFusionPass(), mlir::createLinalgGeneralizationPass(), mlir::createLowerAffinePass(), mlir::createMemRefToLLVMPass(), mlir::createReconcileUnrealizedCastsPass(), mlir::createSparseTensorConversionPass(), mlir::createSparsificationPass(), mlir::createTensorBufferizePass(), mlir::vector::createVectorBufferizePass(), mlir::sparse_tensor::SparseCompilerOptions::lowerVectorToLLVMOptions(), mlir::sparse_tensor::SparseCompilerOptions::sparseTensorConversionOptions(), and mlir::sparse_tensor::SparseCompilerOptions::sparsificationOptions().

Referenced by mlir::sparse_tensor::SparseCompilerOptions::lowerVectorToLLVMOptions(), and registerSparseTensorPipelines().

◆ buildUnaryPresent()

static Value mlir::sparse_tensor::buildUnaryPresent ( RewriterBase rewriter,
Location  loc,
Operation op,
Value  v0 
)
static

Definition at line 906 of file Merger.cpp.

References insertYieldOp().

◆ constantAction()

Value mlir::sparse_tensor::constantAction ( OpBuilder builder,
Location  loc,
Action  action 
)
inline

Generates a constant of the given Action.

Definition at line 156 of file CodegenUtils.h.

References constantI32().

◆ constantDimLevelTypeEncoding()

Value mlir::sparse_tensor::constantDimLevelTypeEncoding ( OpBuilder builder,
Location  loc,
SparseTensorEncodingAttr::DimLevelType  dlt 
)
inline

Generates a constant of the internal dimension level type encoding.

Definition at line 190 of file CodegenUtils.h.

References constantI8(), and dimLevelTypeEncoding().

◆ constantI1()

Value mlir::sparse_tensor::constantI1 ( OpBuilder builder,
Location  loc,
bool  b 
)
inline

Generates a constant of i1 type.

Definition at line 151 of file CodegenUtils.h.

References mlir::OpBuilder::create().

Referenced by genIf(), and genVectorMask().

◆ constantI16()

Value mlir::sparse_tensor::constantI16 ( OpBuilder builder,
Location  loc,
int16_t  i 
)
inline

Generates a constant of i16 type.

Definition at line 141 of file CodegenUtils.h.

References mlir::OpBuilder::create().

◆ constantI32()

Value mlir::sparse_tensor::constantI32 ( OpBuilder builder,
Location  loc,
int32_t  i 
)
inline

Generates a constant of i32 type.

Definition at line 136 of file CodegenUtils.h.

References mlir::OpBuilder::create().

Referenced by constantAction(), constantOverheadTypeEncoding(), and constantPrimaryTypeEncoding().

◆ constantI8()

Value mlir::sparse_tensor::constantI8 ( OpBuilder builder,
Location  loc,
int8_t  i 
)
inline

Generates a constant of i8 type.

Definition at line 146 of file CodegenUtils.h.

References mlir::OpBuilder::create().

Referenced by constantDimLevelTypeEncoding().

◆ constantIndex()

Value mlir::sparse_tensor::constantIndex ( OpBuilder builder,
Location  loc,
int64_t  i 
)
inline

◆ constantIndexTypeEncoding()

Value mlir::sparse_tensor::constantIndexTypeEncoding ( OpBuilder builder,
Location  loc,
const SparseTensorEncodingAttr &  enc 
)
inline

Generates a constant of the internal type-encoding for index overhead storage.

Definition at line 176 of file CodegenUtils.h.

References constantOverheadTypeEncoding().

◆ constantOne()

Value mlir::sparse_tensor::constantOne ( OpBuilder builder,
Location  loc,
Type  tp 
)
inline

Generates a 1-valued constant of the given type.

This supports all the same types as constantZero.

Definition at line 120 of file CodegenUtils.h.

References mlir::OpBuilder::create(), mlir::Type::dyn_cast(), mlir::Builder::getArrayAttr(), getOneAttr(), and mlir::Builder::getZeroAttr().

Referenced by genVectorReducInit(), and processParallelLoop().

◆ constantOverheadTypeEncoding()

Value mlir::sparse_tensor::constantOverheadTypeEncoding ( OpBuilder builder,
Location  loc,
unsigned  width 
)
inline

Generates a constant of the internal type-encoding for overhead storage.

Definition at line 161 of file CodegenUtils.h.

References constantI32(), and overheadTypeEncoding().

Referenced by constantIndexTypeEncoding(), and constantPointerTypeEncoding().

◆ constantPointerTypeEncoding()

Value mlir::sparse_tensor::constantPointerTypeEncoding ( OpBuilder builder,
Location  loc,
const SparseTensorEncodingAttr &  enc 
)
inline

Generates a constant of the internal type-encoding for pointer overhead storage.

Definition at line 169 of file CodegenUtils.h.

References constantOverheadTypeEncoding().

◆ constantPrimaryTypeEncoding()

Value mlir::sparse_tensor::constantPrimaryTypeEncoding ( OpBuilder builder,
Location  loc,
Type  elemTp 
)
inline

Generates a constant of the internal type-encoding for primary storage.

Definition at line 182 of file CodegenUtils.h.

References constantI32(), and primaryTypeEncoding().

◆ constantZero()

Value mlir::sparse_tensor::constantZero ( OpBuilder builder,
Location  loc,
Type  tp 
)
inline

Generates a 0-valued constant of the given type.

In addition to the scalar types (ComplexType, `FloatType, IndexType, IntegerType), this also works for RankedTensorType and VectorType (for which it generates a constant DenseElementsAttr of zeros).

Definition at line 109 of file CodegenUtils.h.

References mlir::OpBuilder::create(), mlir::Type::dyn_cast(), mlir::Builder::getArrayAttr(), and mlir::Builder::getZeroAttr().

Referenced by genInsertionLoad(), genIsNonzero(), genOutputBuffer(), genVectorLoad(), and genVectorReducInit().

◆ dimLevelTypeEncoding()

DimLevelType mlir::sparse_tensor::dimLevelTypeEncoding ( SparseTensorEncodingAttr::DimLevelType  dlt)

Converts the IR's dimension level type to its internal type-encoding.

Definition at line 150 of file CodegenUtils.cpp.

References kCompressed, kDense, and kSingleton.

Referenced by constantDimLevelTypeEncoding().

◆ genIsNonzero()

Value mlir::sparse_tensor::genIsNonzero ( OpBuilder builder,
mlir::Location  loc,
Value  v 
)

Generates the comparison v != 0 where v is of numeric type.

For floating types, we use the "unordered" comparator (i.e., returns true if v is NaN).

Definition at line 182 of file CodegenUtils.cpp.

References constantZero(), mlir::OpBuilder::create(), mlir::Type::dyn_cast(), mlir::Value::getType(), mlir::Type::isa(), and mlir::Type::isIntOrIndex().

◆ getIndexOverheadType()

Type mlir::sparse_tensor::getIndexOverheadType ( Builder builder,
const SparseTensorEncodingAttr &  enc 
)

Returns the mlir::Type for index overhead storage.

Definition at line 76 of file CodegenUtils.cpp.

References getOverheadType(), and indexOverheadTypeEncoding().

Referenced by genBuffers().

◆ getOneAttr()

mlir::Attribute mlir::sparse_tensor::getOneAttr ( Builder builder,
Type  tp 
)

Generates a 1-valued attribute of the given type.

This supports all the same types as getZeroAttr; however, unlike getZeroAttr, for unsupported types we raise llvm_unreachable rather than returning a null attribute.

Definition at line 167 of file CodegenUtils.cpp.

References mlir::Type::cast(), mlir::Type::dyn_cast(), mlir::DenseElementsAttr::get(), mlir::Builder::getFloatAttr(), mlir::Builder::getIndexAttr(), mlir::Builder::getIntegerAttr(), and mlir::Type::isa().

Referenced by constantOne().

◆ getOverheadType()

Type mlir::sparse_tensor::getOverheadType ( Builder builder,
OverheadType  ot 
)

Converts the internal type-encoding for overhead storage to an mlir::Type.

Definition at line 45 of file CodegenUtils.cpp.

References mlir::Builder::getIndexType(), mlir::Builder::getIntegerType(), kIndex, kU16, kU32, kU64, and kU8.

Referenced by getIndexOverheadType(), and getPointerOverheadType().

◆ getPointerOverheadType()

Type mlir::sparse_tensor::getPointerOverheadType ( Builder builder,
const SparseTensorEncodingAttr &  enc 
)

Returns the mlir::Type for pointer overhead storage.

Definition at line 71 of file CodegenUtils.cpp.

References getOverheadType(), and pointerOverheadTypeEncoding().

Referenced by genBuffers().

◆ getSparseTensorEncoding()

SparseTensorEncodingAttr mlir::sparse_tensor::getSparseTensorEncoding ( Type  type)

Convenience method to get a sparse encoding attribute from a type.

Returns null-attribute for any type without an encoding.

Definition at line 184 of file SparseTensorDialect.cpp.

References mlir::Type::dyn_cast().

Referenced by collapseGenericOpIterationDims(), computeIterationGraph(), denseUnitStrides(), findSparseAnnotations(), genBuffers(), genIndex(), genInvariants(), genSubscript(), getGenericEffectsImpl(), isMatchingWidth(), and isSparseTensor().

◆ indexOverheadTypeEncoding()

OverheadType mlir::sparse_tensor::indexOverheadTypeEncoding ( const SparseTensorEncodingAttr &  enc)

Returns the OverheadType for index overhead storage.

Definition at line 66 of file CodegenUtils.cpp.

References overheadTypeEncoding().

Referenced by getIndexOverheadType().

◆ insertYieldOp()

static Value mlir::sparse_tensor::insertYieldOp ( RewriterBase rewriter,
Location  loc,
Region region,
ValueRange  vals 
)
static

◆ kindToOpSymbol()

static const char* mlir::sparse_tensor::kindToOpSymbol ( Kind  kind)
static

Definition at line 347 of file Merger.cpp.

◆ overheadTypeEncoding() [1/2]

OverheadType mlir::sparse_tensor::overheadTypeEncoding ( unsigned  width)

Converts an overhead storage bitwidth to its internal type-encoding.

Definition at line 21 of file CodegenUtils.cpp.

References kIndex, kU16, kU32, kU64, and kU8.

Referenced by constantOverheadTypeEncoding(), indexOverheadTypeEncoding(), overheadTypeEncoding(), overheadTypeFunctionSuffix(), and pointerOverheadTypeEncoding().

◆ overheadTypeEncoding() [2/2]

OverheadType mlir::sparse_tensor::overheadTypeEncoding ( Type  tp)

Converts an overhead storage type to its internal type-encoding.

Definition at line 37 of file CodegenUtils.cpp.

References mlir::Type::dyn_cast(), mlir::Type::isIndex(), kIndex, and overheadTypeEncoding().

◆ overheadTypeFunctionSuffix() [1/2]

StringRef mlir::sparse_tensor::overheadTypeFunctionSuffix ( OverheadType  ot)

Convert OverheadType to its function-name suffix.

Definition at line 81 of file CodegenUtils.cpp.

References kIndex, kU16, kU32, kU64, and kU8.

Referenced by overheadTypeFunctionSuffix().

◆ overheadTypeFunctionSuffix() [2/2]

StringRef mlir::sparse_tensor::overheadTypeFunctionSuffix ( Type  overheadTp)

Converts an overhead storage type to its function-name suffix.

Definition at line 97 of file CodegenUtils.cpp.

References overheadTypeEncoding(), and overheadTypeFunctionSuffix().

◆ pointerOverheadTypeEncoding()

OverheadType mlir::sparse_tensor::pointerOverheadTypeEncoding ( const SparseTensorEncodingAttr &  enc)

Returns the OverheadType for pointer overhead storage.

Definition at line 61 of file CodegenUtils.cpp.

References overheadTypeEncoding().

Referenced by getPointerOverheadType().

◆ primaryTypeEncoding()

PrimaryType mlir::sparse_tensor::primaryTypeEncoding ( Type  elemTp)

Converts a primary storage type to its internal type-encoding.

Definition at line 101 of file CodegenUtils.cpp.

References mlir::Type::dyn_cast(), mlir::Type::isF32(), mlir::Type::isF64(), mlir::Type::isInteger(), kC32, kC64, kF32, kF64, kI16, kI32, kI64, and kI8.

Referenced by constantPrimaryTypeEncoding(), and primaryTypeFunctionSuffix().

◆ primaryTypeFunctionSuffix() [1/2]

StringRef mlir::sparse_tensor::primaryTypeFunctionSuffix ( PrimaryType  pt)

Convert PrimaryType to its function-name suffix.

Definition at line 124 of file CodegenUtils.cpp.

References kC32, kC64, kF32, kF64, kI16, kI32, kI64, and kI8.

Referenced by primaryTypeFunctionSuffix().

◆ primaryTypeFunctionSuffix() [2/2]

StringRef mlir::sparse_tensor::primaryTypeFunctionSuffix ( Type  elemTp)

Converts a primary storage type to its function-name suffix.

Definition at line 146 of file CodegenUtils.cpp.

References primaryTypeEncoding(), and primaryTypeFunctionSuffix().

◆ registerSparseTensorPipelines()

void mlir::sparse_tensor::registerSparseTensorPipelines ( )

Registers all pipelines for the sparse_tensor dialect.

At present, this includes only "sparse-compiler".

Definition at line 64 of file SparseTensorPipelines.cpp.

References buildSparseCompiler().

Referenced by mlir::sparse_tensor::SparseCompilerOptions::lowerVectorToLLVMOptions(), and mlir::registerAllPasses().