MLIR 23.0.0git
CodegenUtils.h
Go to the documentation of this file.
1//===- CodegenUtils.h - Utilities for generating MLIR -----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This header file defines utilities for generating MLIR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_CODEGENUTILS_H_
14#define MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_CODEGENUTILS_H_
15
24#include "mlir/IR/Builders.h"
25
26namespace mlir {
27
28class Location;
29class Type;
30class Value;
31
32namespace sparse_tensor {
33
34/// Shorthand aliases for the `emitCInterface` argument to `getFunc()`,
35/// `createFuncCall()`, and `replaceOpWithFuncCall()`.
36enum class EmitCInterface : bool { Off = false, On = true };
37
38//===----------------------------------------------------------------------===//
39// ExecutionEngine/SparseTensorUtils helper functions.
40//===----------------------------------------------------------------------===//
41
42/// Converts an overhead storage bitwidth to its internal type-encoding.
44
45/// Converts an overhead storage type to its internal type-encoding.
47
48/// Converts the internal type-encoding for overhead storage to an mlir::Type.
50
51/// Returns the OverheadType for position overhead storage.
52OverheadType posTypeEncoding(SparseTensorEncodingAttr enc);
53
54/// Returns the OverheadType for coordinate overhead storage.
55OverheadType crdTypeEncoding(SparseTensorEncodingAttr enc);
56
57/// Convert OverheadType to its function-name suffix.
59
60/// Converts an overhead storage type to its function-name suffix.
61StringRef overheadTypeFunctionSuffix(Type overheadTp);
62
63/// Returns true if the given type is a valid sparse tensor element type
64/// supported by the runtime library (i.e., maps to a PrimaryType).
65/// Use this to guard calls to primaryTypeEncoding() with invalid types.
66bool isValidPrimaryType(Type elemTp);
67
68/// Converts a primary storage type to its internal type-encoding.
70
71/// Convert PrimaryType to its function-name suffix.
73
74/// Converts a primary storage type to its function-name suffix.
75StringRef primaryTypeFunctionSuffix(Type elemTp);
76
77//===----------------------------------------------------------------------===//
78// Misc code generators and utilities.
79//===----------------------------------------------------------------------===//
80
81/// A helper class to simplify lowering operations with/without function calls.
82template <class SubClass>
84public:
85 FuncCallOrInlineGenerator(TypeRange retTypes, ValueRange params, bool genCall)
86 : retTypes(retTypes), params(params), genCall(genCall) {}
87
88 // The main API invoked by clients, which abstracts away the details of
89 // creating function calls from clients.
91 if (!genCall)
92 return genImplementation(retTypes, params, builder, loc);
93
94 // Looks up the function.
95 std::string funcName = getMangledFuncName();
96 ModuleOp module = getParentOpOf<ModuleOp>(builder);
97 MLIRContext *context = module.getContext();
98 auto result = SymbolRefAttr::get(context, funcName);
99 auto func = module.lookupSymbol<func::FuncOp>(result.getAttr());
100
101 if (!func) {
102 // Create the function if not already exist.
103 OpBuilder::InsertionGuard insertionGuard(builder);
104 builder.setInsertionPoint(getParentOpOf<func::FuncOp>(builder));
105 func = func::FuncOp::create(
106 builder, loc, funcName,
107 FunctionType::get(context, params.getTypes(), retTypes));
108 func.setPrivate();
109 // Set the insertion point to the body of the function.
110 Block *entryBB = func.addEntryBlock();
111 builder.setInsertionPointToStart(entryBB);
112 ValueRange args = entryBB->getArguments();
113 // Delegates to user to generate the actually implementation.
115 genImplementation(retTypes, args, builder, loc);
116 func::ReturnOp::create(builder, loc, result);
117 }
118 // Returns the CallOp result.
119 func::CallOp call = func::CallOp::create(builder, loc, func, params);
120 return call.getResults();
121 }
122
123private:
124 template <class OpTp>
125 OpTp getParentOpOf(OpBuilder &builder) {
126 return builder.getInsertionBlock()->getParent()->getParentOfType<OpTp>();
127 }
128
129 // CRTP: get the mangled function name (only called when genCall=true).
130 std::string getMangledFuncName() {
131 return static_cast<SubClass *>(this)->getMangledFuncName();
132 }
133
134 // CRTP: Client implementation.
135 SmallVector<Value> genImplementation(TypeRange retTypes, ValueRange params,
136 OpBuilder &builder, Location loc) {
137 return static_cast<SubClass *>(this)->genImplementation(retTypes, params,
138 builder, loc);
139 }
140
141private:
142 TypeRange retTypes; // The types of all returned results
143 ValueRange params; // The values of all input parameters
144 bool genCall; // Should the implemetantion be wrapped in a function
145};
146
147/// Add type casting between arith and index types when needed.
148Value genCast(OpBuilder &builder, Location loc, Value value, Type dstTy);
149
150/// Add conversion from scalar to given type (possibly a 0-rank tensor).
151Value genScalarToTensor(OpBuilder &builder, Location loc, Value elem,
152 Type dstTp);
153
154/// Generates a pointer/index load from the sparse storage scheme. Narrower
155/// data types need to be zero extended before casting the value into the
156/// index type used for looping and indexing.
157Value genIndexLoad(OpBuilder &builder, Location loc, Value mem, ValueRange s);
158
159/// Generates a 1-valued attribute of the given type. This supports
160/// all the same types as `getZeroAttr`; however, unlike `getZeroAttr`,
161/// for unsupported types we raise `llvm_unreachable` rather than
162/// returning a null attribute.
163TypedAttr getOneAttr(Builder &builder, Type tp);
164
165/// Generates the comparison `v != 0` where `v` is of numeric type.
166/// For floating types, we use the "unordered" comparator (i.e., returns
167/// true if `v` is NaN).
168Value genIsNonzero(OpBuilder &builder, Location loc, Value v);
169
170/// Computes the shape of destination tensor of a reshape operator. This is only
171/// used when operands have dynamic shape. The shape of the destination is
172/// stored into dstShape.
173void genReshapeDstShape(OpBuilder &builder, Location loc,
174 SmallVectorImpl<Value> &dstShape,
175 ArrayRef<Value> srcShape, ArrayRef<Size> staticDstShape,
176 ArrayRef<ReassociationIndices> reassociation);
177
178/// Reshape coordinates during a reshaping operation.
179void reshapeCvs(OpBuilder &builder, Location loc,
180 ArrayRef<ReassociationIndices> reassociation,
181 ValueRange srcSizes, ValueRange srcCvs, // NOLINT
182 ValueRange dstSizes, SmallVectorImpl<Value> &dstCvs);
183
184/// Returns a function reference (first hit also inserts into module). Sets
185/// the "_emit_c_interface" on the function declaration when requested,
186/// so that LLVM lowering generates a wrapper function that takes care
187/// of ABI complications with passing in and returning MemRefs to C functions.
188FlatSymbolRefAttr getFunc(ModuleOp module, StringRef name, TypeRange resultType,
189 ValueRange operands, EmitCInterface emitCInterface);
190
191/// Creates a `CallOp` to the function reference returned by `getFunc()` in
192/// the builder's module.
193func::CallOp createFuncCall(OpBuilder &builder, Location loc, StringRef name,
194 TypeRange resultType, ValueRange operands,
195 EmitCInterface emitCInterface);
196
197/// Returns the equivalent of `void*` for opaque arguments to the
198/// execution engine.
199Type getOpaquePointerType(MLIRContext *ctx);
200Type getOpaquePointerType(Builder &builder);
201
202/// Generates an uninitialized temporary buffer of the given size and
203/// type, but returns it as type `memref<? x $tp>` (rather than as type
204/// `memref<$sz x $tp>`).
205Value genAlloca(OpBuilder &builder, Location loc, Value sz, Type tp);
206
207/// Generates an uninitialized temporary buffer of the given size and
208/// type, and returns it as type `memref<? x $tp>` (staticShape=false) or
209/// `memref<$sz x $tp>` (staticShape=true).
210Value genAlloca(OpBuilder &builder, Location loc, unsigned sz, Type tp,
211 bool staticShape = false);
212
213/// Generates an uninitialized temporary buffer with room for one value
214/// of the given type, and returns the `memref<$tp>`.
215Value genAllocaScalar(OpBuilder &builder, Location loc, Type tp);
216
217/// Generates a temporary buffer, initializes it with the given contents,
218/// and returns it as type `memref<? x $tp>` (rather than specifying the
219/// size of the buffer).
220Value allocaBuffer(OpBuilder &builder, Location loc, ValueRange values);
221
222/// Generates code to allocate a buffer of the given type, and zero
223/// initialize it. If the buffer type has any dynamic sizes, then the
224/// `sizes` parameter should be as filled by sizesFromPtr(); that way
225/// we can reuse the genDimSizeCall() results generated by sizesFromPtr().
226Value allocDenseTensor(OpBuilder &builder, Location loc,
227 RankedTensorType tensorTp, ValueRange sizes);
228
229/// Generates code to deallocate a dense buffer.
230void deallocDenseTensor(OpBuilder &builder, Location loc, Value buffer);
231
232/// Populates given sizes array from dense tensor or sparse tensor constant.
233void sizesFromSrc(OpBuilder &builder, SmallVectorImpl<Value> &sizes,
234 Location loc, Value src);
235
236/// Scans to top of generated loop.
237Operation *getTop(Operation *op);
238
239/// Iterate over a sparse constant, generates constantOp for value
240/// and coordinates. E.g.,
241/// sparse<[ [0], [28], [31] ],
242/// [ (-5.13, 2.0), (3.0, 4.0), (5.0, 6.0) ] >
243/// =>
244/// %c1 = arith.constant 0
245/// %v1 = complex.constant (5.13, 2.0)
246/// callback({%c1}, %v1)
247///
248/// %c2 = arith.constant 28
249/// %v2 = complex.constant (3.0, 4.0)
250/// callback({%c2}, %v2)
251///
252/// %c3 = arith.constant 31
253/// %v3 = complex.constant (5.0, 6.0)
254/// callback({%c3}, %v3)
256 OpBuilder &builder, Location loc, SparseElementsAttr attr, AffineMap order,
257 function_ref<void(ArrayRef<Value>, Value)> callback);
258
259/// Loads `size`-many values from the memref, which must have rank-1 and
260/// size greater-or-equal to `size`. If the optional `(offsetIdx,offsetVal)`
261/// arguments are provided, then the `offsetVal` will be added to the
262/// `offsetIdx`-th value after loading.
263SmallVector<Value> loadAll(OpBuilder &builder, Location loc, size_t size,
264 Value mem, size_t offsetIdx = 0,
265 Value offsetVal = Value());
266
267/// Stores all the values of `vs` into the memref `mem`, which must have
268/// rank-1 and size greater-or-equal to `vs.size()`. If the optional
269/// `(offsetIdx,offsetVal)` arguments are provided, then the `offsetVal`
270/// will be added to the `offsetIdx`-th value before storing.
271void storeAll(OpBuilder &builder, Location loc, Value mem, ValueRange vs,
272 size_t offsetIdx = 0, Value offsetVal = Value());
273
274// Generates code to cast a tensor to a memref.
275TypedValue<BaseMemRefType> genToMemref(OpBuilder &builder, Location loc,
276 Value tensor);
277
278/// Generates code to retrieve the slice offset for the sparse tensor slice,
279/// return a constant if the offset is statically known.
280Value createOrFoldSliceOffsetOp(OpBuilder &builder, Location loc, Value tensor,
281 Dimension dim);
282
283/// Generates code to retrieve the slice slice for the sparse tensor slice,
284/// return a constant if the offset is statically known.
285Value createOrFoldSliceStrideOp(OpBuilder &builder, Location loc, Value tensor,
286 Dimension dim);
287
288/// Generates code that opens a reader and sets the dimension sizes.
289Value genReader(OpBuilder &builder, Location loc, SparseTensorType stt,
290 Value tensor,
291 /*out*/ SmallVectorImpl<Value> &dimSizesValues,
292 /*out*/ Value &dimSizesBuffer);
293
294/// Generates code to set up the buffer parameters for a map.
295Value genMapBuffers(OpBuilder &builder, Location loc, SparseTensorType stt,
296 ArrayRef<Value> dimSizesValues, Value dimSizesBuffer,
297 /*out*/ SmallVectorImpl<Value> &lvlSizesValues,
298 /*out*/ Value &dim2lvlBuffer,
299 /*out*/ Value &lvl2dimBuffer);
300
301//===----------------------------------------------------------------------===//
302// Inlined constant generators.
303//
304// All these functions are just wrappers to improve code legibility;
305// therefore, we mark them as `inline` to avoid introducing any additional
306// overhead due to the legibility. Ideally these should move upstream.
307//
308//===----------------------------------------------------------------------===//
309
310/// Generates a 0-valued constant of the given type. In addition to
311/// the scalar types (`ComplexType`, `FloatType`, `IndexType`,
312/// `IntegerType`), this also works for `RankedTensorType` and `VectorType`
313/// (for which it generates a constant `DenseElementsAttr` of zeros).
314inline Value constantZero(OpBuilder &builder, Location loc, Type tp) {
315 if (auto ctp = dyn_cast<ComplexType>(tp)) {
316 auto zeroe = builder.getZeroAttr(ctp.getElementType());
317 auto zeroa = builder.getArrayAttr({zeroe, zeroe});
318 return complex::ConstantOp::create(builder, loc, tp, zeroa);
319 }
320 return arith::ConstantOp::create(builder, loc, tp, builder.getZeroAttr(tp));
321}
322
323/// Generates a 1-valued constant of the given type. This supports all
324/// the same types as `constantZero`.
325inline Value constantOne(OpBuilder &builder, Location loc, Type tp) {
326 if (auto ctp = dyn_cast<ComplexType>(tp)) {
327 auto zeroe = builder.getZeroAttr(ctp.getElementType());
328 auto onee = getOneAttr(builder, ctp.getElementType());
329 auto zeroa = builder.getArrayAttr({onee, zeroe});
330 return complex::ConstantOp::create(builder, loc, tp, zeroa);
331 }
332 return arith::ConstantOp::create(builder, loc, tp, getOneAttr(builder, tp));
333}
334
335/// Generates a constant of `index` type.
336inline Value constantIndex(OpBuilder &builder, Location loc, int64_t i) {
337 return arith::ConstantIndexOp::create(builder, loc, i);
338}
339
340/// Generates a constant of `i64` type.
341inline Value constantI64(OpBuilder &builder, Location loc, int64_t i) {
342 return arith::ConstantIntOp::create(builder, loc, i, 64);
343}
344
345/// Generates a constant of `i32` type.
346inline Value constantI32(OpBuilder &builder, Location loc, int32_t i) {
347 return arith::ConstantIntOp::create(builder, loc, i, 32);
348}
349
350/// Generates a constant of `i16` type.
351inline Value constantI16(OpBuilder &builder, Location loc, int16_t i) {
352 return arith::ConstantIntOp::create(builder, loc, i, 16);
353}
354
355/// Generates a constant of `i8` type.
356inline Value constantI8(OpBuilder &builder, Location loc, int8_t i) {
357 return arith::ConstantIntOp::create(builder, loc, i, 8);
358}
359
360/// Generates a constant of `i1` type.
361inline Value constantI1(OpBuilder &builder, Location loc, bool b) {
362 return arith::ConstantIntOp::create(builder, loc, b, 1);
363}
364
365/// Generates a constant of the given `Action`.
366inline Value constantAction(OpBuilder &builder, Location loc, Action action) {
367 return constantI32(builder, loc, static_cast<uint32_t>(action));
368}
369
370/// Generates a constant of the internal type-encoding for overhead storage.
372 unsigned width) {
373 return constantI32(builder, loc,
374 static_cast<uint32_t>(overheadTypeEncoding(width)));
375}
376
377/// Generates a constant of the internal type-encoding for position
378/// overhead storage.
380 SparseTensorEncodingAttr enc) {
381 return constantOverheadTypeEncoding(builder, loc, enc.getPosWidth());
382}
383
384/// Generates a constant of the internal type-encoding for coordinate
385/// overhead storage.
387 SparseTensorEncodingAttr enc) {
388 return constantOverheadTypeEncoding(builder, loc, enc.getCrdWidth());
389}
390
391/// Generates a constant of the internal type-encoding for primary storage.
393 Type elemTp) {
394 return constantI32(builder, loc,
395 static_cast<uint32_t>(primaryTypeEncoding(elemTp)));
396}
397
398/// Generates a constant of the internal dimension level type encoding.
400 LevelType lt) {
401 return constantI64(builder, loc, static_cast<uint64_t>(lt));
402}
403
404// Generates a constant from a validated value carrying attribute.
405inline Value genValFromAttr(OpBuilder &builder, Location loc, Attribute attr) {
406 if (auto complexAttr = dyn_cast<complex::NumberAttr>(attr)) {
407 Type tp = cast<ComplexType>(complexAttr.getType()).getElementType();
408 return complex::ConstantOp::create(
409 builder, loc, complexAttr.getType(),
410 builder.getArrayAttr({FloatAttr::get(tp, complexAttr.getReal()),
411 FloatAttr::get(tp, complexAttr.getImag())}));
412 }
413 return arith::ConstantOp::create(builder, loc, cast<TypedAttr>(attr));
414}
415
416// TODO: is this at the right place?
418 auto rtp = dyn_cast<RankedTensorType>(type);
419 return !rtp || rtp.getRank() == 0;
420}
421
422} // namespace sparse_tensor
423} // namespace mlir
424
425#endif // MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_CODEGENUTILS_H_
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
Attributes are known-constant values of operations.
Definition Attributes.h:25
Block represents an ordered list of Operations.
Definition Block.h:33
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
Definition Block.cpp:27
BlockArgListType getArguments()
Definition Block.h:97
This class is a general helper class for creating context-global objects like types,...
Definition Builders.h:51
TypedAttr getZeroAttr(Type type)
Definition Builders.cpp:328
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
Definition Builders.cpp:270
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
RAII guard to reset the insertion point of the builder when destroyed.
Definition Builders.h:350
This class helps build Operations.
Definition Builders.h:209
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
Definition Builders.h:433
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Definition Builders.h:400
Block * getInsertionBlock() const
Return the block the current insertion point belongs to.
Definition Builders.h:444
ParentT getParentOfType()
Find the first parent operation of the given type, or nullptr if there is no ancestor operation.
Definition Region.h:205
This class provides an abstraction over the various different ranges of value types.
Definition TypeRange.h:37
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:387
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
static ConstantIndexOp create(OpBuilder &builder, Location location, int64_t value)
Definition ArithOps.cpp:363
static ConstantIntOp create(OpBuilder &builder, Location location, int64_t value, unsigned width)
Definition ArithOps.cpp:262
FuncCallOrInlineGenerator(TypeRange retTypes, ValueRange params, bool genCall)
SmallVector< Value > genCallOrInline(OpBuilder &builder, Location loc)
A wrapper around RankedTensorType, which has three goals:
TypedAttr getOneAttr(Builder &builder, Type tp)
Generates a 1-valued attribute of the given type.
FlatSymbolRefAttr getFunc(ModuleOp module, StringRef name, TypeRange resultType, ValueRange operands, EmitCInterface emitCInterface)
Returns a function reference (first hit also inserts into module).
Value genAllocaScalar(OpBuilder &builder, Location loc, Type tp)
Generates an uninitialized temporary buffer with room for one value of the given type,...
Value constantIndex(OpBuilder &builder, Location loc, int64_t i)
Generates a constant of index type.
void foreachInSparseConstant(OpBuilder &builder, Location loc, SparseElementsAttr attr, AffineMap order, function_ref< void(ArrayRef< Value >, Value)> callback)
Iterate over a sparse constant, generates constantOp for value and coordinates.
Value constantZero(OpBuilder &builder, Location loc, Type tp)
Generates a 0-valued constant of the given type.
uint64_t Dimension
The type of dimension identifiers and dimension-ranks.
Value constantLevelTypeEncoding(OpBuilder &builder, Location loc, LevelType lt)
Generates a constant of the internal dimension level type encoding.
Value allocaBuffer(OpBuilder &builder, Location loc, ValueRange values)
Generates a temporary buffer, initializes it with the given contents, and returns it as type memref<?
Value constantPosTypeEncoding(OpBuilder &builder, Location loc, SparseTensorEncodingAttr enc)
Generates a constant of the internal type-encoding for position overhead storage.
OverheadType posTypeEncoding(SparseTensorEncodingAttr enc)
Returns the OverheadType for position overhead storage.
Value constantOne(OpBuilder &builder, Location loc, Type tp)
Generates a 1-valued constant of the given type.
OverheadType
Encoding of overhead types (both position overhead and coordinate overhead), for "overloading" @newSp...
Definition Enums.h:51
Value constantI8(OpBuilder &builder, Location loc, int8_t i)
Generates a constant of i8 type.
Action
The actions performed by @newSparseTensor.
Definition Enums.h:146
OverheadType crdTypeEncoding(SparseTensorEncodingAttr enc)
Returns the OverheadType for coordinate overhead storage.
TypedValue< BaseMemRefType > genToMemref(OpBuilder &builder, Location loc, Value tensor)
OverheadType overheadTypeEncoding(unsigned width)
Converts an overhead storage bitwidth to its internal type-encoding.
Value constantI1(OpBuilder &builder, Location loc, bool b)
Generates a constant of i1 type.
Value genIndexLoad(OpBuilder &builder, Location loc, Value mem, ValueRange s)
Generates a pointer/index load from the sparse storage scheme.
Value constantAction(OpBuilder &builder, Location loc, Action action)
Generates a constant of the given Action.
Value constantCrdTypeEncoding(OpBuilder &builder, Location loc, SparseTensorEncodingAttr enc)
Generates a constant of the internal type-encoding for coordinate overhead storage.
StringRef overheadTypeFunctionSuffix(OverheadType ot)
Convert OverheadType to its function-name suffix.
PrimaryType
Encoding of the elemental type, for "overloading" @newSparseTensor.
Definition Enums.h:82
Value genValFromAttr(OpBuilder &builder, Location loc, Attribute attr)
bool isValidPrimaryType(Type elemTp)
Returns true if the given type is a valid sparse tensor element type supported by the runtime library...
PrimaryType primaryTypeEncoding(Type elemTp)
Converts a primary storage type to its internal type-encoding.
Operation * getTop(Operation *op)
Scans to top of generated loop.
Value createOrFoldSliceStrideOp(OpBuilder &builder, Location loc, Value tensor, Dimension dim)
Generates code to retrieve the slice slice for the sparse tensor slice, return a constant if the offs...
Type getOpaquePointerType(MLIRContext *ctx)
Returns the equivalent of void* for opaque arguments to the execution engine.
Value genMapBuffers(OpBuilder &builder, Location loc, SparseTensorType stt, ArrayRef< Value > dimSizesValues, Value dimSizesBuffer, SmallVectorImpl< Value > &lvlSizesValues, Value &dim2lvlBuffer, Value &lvl2dimBuffer)
Generates code to set up the buffer parameters for a map.
Value genIsNonzero(OpBuilder &builder, Location loc, Value v)
Generates the comparison v != 0 where v is of numeric type.
Value genReader(OpBuilder &builder, Location loc, SparseTensorType stt, Value tensor, SmallVectorImpl< Value > &dimSizesValues, Value &dimSizesBuffer)
Generates code that opens a reader and sets the dimension sizes.
Value genScalarToTensor(OpBuilder &builder, Location loc, Value elem, Type dstTp)
Add conversion from scalar to given type (possibly a 0-rank tensor).
bool isZeroRankedTensorOrScalar(Type type)
void deallocDenseTensor(OpBuilder &builder, Location loc, Value buffer)
Generates code to deallocate a dense buffer.
Value genAlloca(OpBuilder &builder, Location loc, Value sz, Type tp)
Generates an uninitialized temporary buffer of the given size and type, but returns it as type memref...
Value constantOverheadTypeEncoding(OpBuilder &builder, Location loc, unsigned width)
Generates a constant of the internal type-encoding for overhead storage.
SmallVector< Value > loadAll(OpBuilder &builder, Location loc, size_t size, Value mem, size_t offsetIdx=0, Value offsetVal=Value())
Loads size-many values from the memref, which must have rank-1 and size greater-or-equal to size.
void genReshapeDstShape(OpBuilder &builder, Location loc, SmallVectorImpl< Value > &dstShape, ArrayRef< Value > srcShape, ArrayRef< Size > staticDstShape, ArrayRef< ReassociationIndices > reassociation)
Computes the shape of destination tensor of a reshape operator.
Value constantI64(OpBuilder &builder, Location loc, int64_t i)
Generates a constant of i64 type.
void reshapeCvs(OpBuilder &builder, Location loc, ArrayRef< ReassociationIndices > reassociation, ValueRange srcSizes, ValueRange srcCvs, ValueRange dstSizes, SmallVectorImpl< Value > &dstCvs)
Reshape coordinates during a reshaping operation.
Value constantI16(OpBuilder &builder, Location loc, int16_t i)
Generates a constant of i16 type.
func::CallOp createFuncCall(OpBuilder &builder, Location loc, StringRef name, TypeRange resultType, ValueRange operands, EmitCInterface emitCInterface)
Creates a CallOp to the function reference returned by getFunc() in the builder's module.
Value genCast(OpBuilder &builder, Location loc, Value value, Type dstTy)
Add type casting between arith and index types when needed.
StringRef primaryTypeFunctionSuffix(PrimaryType pt)
Convert PrimaryType to its function-name suffix.
Value createOrFoldSliceOffsetOp(OpBuilder &builder, Location loc, Value tensor, Dimension dim)
Generates code to retrieve the slice offset for the sparse tensor slice, return a constant if the off...
Value constantI32(OpBuilder &builder, Location loc, int32_t i)
Generates a constant of i32 type.
Value constantPrimaryTypeEncoding(OpBuilder &builder, Location loc, Type elemTp)
Generates a constant of the internal type-encoding for primary storage.
void sizesFromSrc(OpBuilder &builder, SmallVectorImpl< Value > &sizes, Location loc, Value src)
Populates given sizes array from dense tensor or sparse tensor constant.
Type getOverheadType(Builder &builder, OverheadType ot)
Converts the internal type-encoding for overhead storage to an mlir::Type.
EmitCInterface
Shorthand aliases for the emitCInterface argument to getFunc(), createFuncCall(), and replaceOpWithFu...
Value allocDenseTensor(OpBuilder &builder, Location loc, RankedTensorType tensorTp, ValueRange sizes)
Generates code to allocate a buffer of the given type, and zero initialize it.
void storeAll(OpBuilder &builder, Location loc, Value mem, ValueRange vs, size_t offsetIdx=0, Value offsetVal=Value())
Stores all the values of vs into the memref mem, which must have rank-1 and size greater-or-equal to ...
Include the generated interface declarations.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.
Definition Value.h:497
llvm::function_ref< Fn > function_ref
Definition LLVM.h:144
This enum defines all the sparse representations supportable by the SparseTensor dialect.
Definition Enums.h:238