MLIR 23.0.0git
BuiltinDialectBytecode.cpp
Go to the documentation of this file.
1//===- BuiltinDialectBytecode.cpp - Builtin Bytecode Implementation -------===//
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
10#include "AttributeDetail.h"
12#include "mlir/IR/AffineExpr.h"
13#include "mlir/IR/AffineMap.h"
17#include "mlir/IR/Diagnostics.h"
19#include "mlir/IR/Location.h"
20#include "mlir/Support/LLVM.h"
21#include "llvm/ADT/TypeSwitch.h"
22#include <cstdint>
23
24using namespace mlir;
25
26//===----------------------------------------------------------------------===//
27// BuiltinDialectBytecodeInterface
28//===----------------------------------------------------------------------===//
29
30namespace {
31
32//===----------------------------------------------------------------------===//
33// Utility functions
34//===----------------------------------------------------------------------===//
35
36// TODO: Move these to separate file.
37
38// Returns the bitwidth if known, else return std::nullopt.
39static std::optional<unsigned> getIntegerBitWidth(DialectBytecodeReader &reader,
40 Type type) {
41 if (auto intType = dyn_cast<IntegerType>(type))
42 return intType.getWidth();
43 if (llvm::isa<IndexType>(type))
44 return IndexType::kInternalStorageBitWidth;
45 reader.emitError()
46 << "expected integer or index type for IntegerAttr, but got: " << type;
47 return std::nullopt;
48}
49
50static LogicalResult readAPIntWithKnownWidth(DialectBytecodeReader &reader,
51 Type type, FailureOr<APInt> &val) {
52 std::optional<unsigned> bitWidth = getIntegerBitWidth(reader, type);
53 // getIntegerBitWidth returns std::nullopt and emits an error for unsupported
54 // types. Bail out early to avoid creating a zero-width APInt with a non-zero
55 // value.
56 if (!bitWidth)
57 return failure();
58 val = reader.readAPIntWithKnownWidth(*bitWidth);
59 return val;
60}
61
62static LogicalResult
63readAPFloatWithKnownSemantics(DialectBytecodeReader &reader, Type type,
64 FailureOr<APFloat> &val) {
65 auto ftype = dyn_cast<FloatType>(type);
66 if (!ftype)
67 return failure();
68 val = reader.readAPFloatWithKnownSemantics(ftype.getFloatSemantics());
69 return success();
70}
71
72LogicalResult
73readPotentiallySplatString(DialectBytecodeReader &reader, ShapedType type,
74 bool isSplat,
75 SmallVectorImpl<StringRef> &rawStringData) {
76 rawStringData.resize(isSplat ? 1 : type.getNumElements());
77 for (StringRef &value : rawStringData)
78 if (failed(reader.readString(value)))
79 return failure();
80 return success();
81}
82
83static void writePotentiallySplatString(DialectBytecodeWriter &writer,
84 DenseStringElementsAttr attr) {
85 bool isSplat = attr.isSplat();
86 if (isSplat)
87 return writer.writeOwnedString(attr.getRawStringData().front());
88
89 for (StringRef str : attr.getRawStringData())
90 writer.writeOwnedString(str);
91}
92
93//===----------------------------------------------------------------------===//
94// AffineExpr / AffineMap bytecode helpers
95//===----------------------------------------------------------------------===//
96
97// AffineExpr kind encoding:
98// Extra kinds may be appended here but the existing ones and their ordering
99// should not be changed.
100enum class AffineExprBytecodeKind : uint64_t {
101 DimId = 0,
102 SymbolId = 1,
103 Constant = 2,
104 Add = 3,
105 Mul = 4,
106 Mod = 5,
107 FloorDiv = 6,
108 CeilDiv = 7
109};
110
111// AffineMap kind encoding. These are packed into the low 2 bits of the header
112// varint and fixed.
113enum class AffineMapBytecodeKind : unsigned {
114 Identity = 0,
115 Permutation = 1,
116 ProjectedPermutation = 2,
117 General = 3
118};
119
120/// Convert a binary AffineExprKind to its bytecode wire encoding.
121static AffineExprBytecodeKind toBytecodeKind(AffineExprKind k) {
122 switch (k) {
124 return AffineExprBytecodeKind::Add;
126 return AffineExprBytecodeKind::Mul;
128 return AffineExprBytecodeKind::Mod;
130 return AffineExprBytecodeKind::FloorDiv;
132 return AffineExprBytecodeKind::CeilDiv;
133 default:
134 llvm_unreachable("not a binary AffineExprKind");
135 }
136}
137
138/// Convert a bytecode wire value back to a binary AffineExprKind.
139/// Caller must guarantee `kind` is one of the binary operator values.
140static AffineExprKind fromBytecodeKind(uint64_t kind) {
141 switch (kind) {
142 case static_cast<uint64_t>(AffineExprBytecodeKind::Add):
143 return AffineExprKind::Add;
144 case static_cast<uint64_t>(AffineExprBytecodeKind::Mul):
145 return AffineExprKind::Mul;
146 case static_cast<uint64_t>(AffineExprBytecodeKind::Mod):
147 return AffineExprKind::Mod;
148 case static_cast<uint64_t>(AffineExprBytecodeKind::FloorDiv):
149 return AffineExprKind::FloorDiv;
150 case static_cast<uint64_t>(AffineExprBytecodeKind::CeilDiv):
151 return AffineExprKind::CeilDiv;
152 }
153 llvm_unreachable("not a binary AffineExprBytecodeKind");
154}
155
156/// Read a single AffineExpr using iterative prefix decoding. The wire format
157/// is prefix order (operator and then children), which is self-delimiting.
158/// Instead of C++ recursion the reader uses an explicit work stack, bounding
159/// memory to O(depth) and eliminating stack-overflow risk on malicious input.
160static FailureOr<AffineExpr> readAffineExpr(DialectBytecodeReader &reader,
161 MLIRContext *context) {
162 // A work-stack item is either ReadOperand (0) or a combine marker whose
163 // payload is an AffineExprKind.
164 struct WorkItem {
165 bool isCombine;
166 AffineExprKind combineKind; // only valid when isCombine == true
167 static WorkItem read() { return {false, {}}; }
168 static WorkItem combine(AffineExprKind k) { return {true, k}; }
169 };
170
173 work.push_back(WorkItem::read());
174
175 while (!work.empty()) {
176 // Bound total iterations to catch malformed input.
177 if (work.size() > 128)
178 return reader.emitError("AffineExpr work stack overflow"), failure();
179
180 WorkItem item = work.pop_back_val();
181
182 if (item.isCombine) {
183 // Pop two operands and combine.
184 if (operands.size() < 2)
185 return reader.emitError("malformed AffineExpr: operand underflow"),
186 failure();
187 AffineExpr rhs = operands.pop_back_val();
188 AffineExpr lhs = operands.pop_back_val();
189 operands.push_back(getAffineBinaryOpExpr(item.combineKind, lhs, rhs));
190 continue;
191 }
192
193 // ReadOperand: read the next token.
194 uint64_t kind;
195 if (failed(reader.readVarInt(kind)))
196 return failure();
197
198 // Switch on the raw uint64_t to keep the default case valid for
199 // unknown/future wire values without triggering -Wcovered-switch-default.
200 switch (kind) {
201 case static_cast<uint64_t>(AffineExprBytecodeKind::DimId): {
202 uint64_t position;
203 if (failed(reader.readVarInt(position)))
204 return failure();
205 operands.push_back(getAffineDimExpr(position, context));
206 break;
207 }
208 case static_cast<uint64_t>(AffineExprBytecodeKind::SymbolId): {
209 uint64_t position;
210 if (failed(reader.readVarInt(position)))
211 return failure();
212 operands.push_back(getAffineSymbolExpr(position, context));
213 break;
214 }
215 case static_cast<uint64_t>(AffineExprBytecodeKind::Constant): {
216 int64_t value;
217 if (failed(reader.readSignedVarInt(value)))
218 return failure();
219 operands.push_back(getAffineConstantExpr(value, context));
220 break;
221 }
222 case static_cast<uint64_t>(AffineExprBytecodeKind::Add):
223 case static_cast<uint64_t>(AffineExprBytecodeKind::Mul):
224 case static_cast<uint64_t>(AffineExprBytecodeKind::Mod):
225 case static_cast<uint64_t>(AffineExprBytecodeKind::FloorDiv):
226 case static_cast<uint64_t>(AffineExprBytecodeKind::CeilDiv): {
227 // Schedule: read RHS, read LHS, then combine.
228 // Work stack is LIFO, so push in reverse order.
229 work.push_back(WorkItem::combine(fromBytecodeKind(kind)));
230 work.push_back(WorkItem::read()); // RHS
231 work.push_back(WorkItem::read()); // LHS
232 break;
233 }
234 default:
235 return reader.emitError("unknown AffineExpr kind: ") << kind, failure();
236 }
237 }
238
239 if (operands.size() != 1)
240 return reader.emitError("malformed AffineExpr: expected single result"),
241 failure();
242
243 return operands.front();
244}
245
246/// Write an AffineExpr in prefix order (operator first, then children).
247static void writeAffineExpr(DialectBytecodeWriter &writer, AffineExpr expr) {
248 switch (expr.getKind()) {
250 writer.writeVarInt(static_cast<uint64_t>(AffineExprBytecodeKind::DimId));
251 writer.writeVarInt(cast<AffineDimExpr>(expr).getPosition());
252 break;
254 writer.writeVarInt(static_cast<uint64_t>(AffineExprBytecodeKind::SymbolId));
255 writer.writeVarInt(cast<AffineSymbolExpr>(expr).getPosition());
256 break;
258 writer.writeVarInt(static_cast<uint64_t>(AffineExprBytecodeKind::Constant));
259 writer.writeSignedVarInt(cast<AffineConstantExpr>(expr).getValue());
260 break;
266 // Write operator first (prefix order).
267 writer.writeVarInt(static_cast<uint64_t>(toBytecodeKind(expr.getKind())));
268 auto binExpr = cast<AffineBinaryOpExpr>(expr);
269 writeAffineExpr(writer, binExpr.getLHS());
270 writeAffineExpr(writer, binExpr.getRHS());
271 break;
272 }
273 }
274}
275
276/// Read an AffineMap with packed kind header.
277///
278/// AffineMap :=
279/// header(varint) // (numDims << 2) | mapKind
280/// payload // depends on mapKind
281///
282/// The header is there for concise encoding of the most common occuring cases.
283///
284/// mapKind = header & 0x3:
285/// Identity(0): no further data
286/// Permutation(1): positions(varint*)
287/// ProjectedPermutation(2): numResults(varint), positions(varint*)
288/// General(3): numSymbols(varint), numResults(varint), results(AffineExpr*)
289static LogicalResult readAffineMap(DialectBytecodeReader &reader,
290 MLIRContext *context, AffineMap &map) {
291 uint64_t header;
292 if (failed(reader.readVarInt(header)))
293 return failure();
294
295 // Keep as unsigned to avoid -Wcovered-switch-default below.
296 unsigned mapKind = header & 0x3;
297 unsigned numDims = header >> 2;
298
299 switch (mapKind) {
300 case static_cast<unsigned>(AffineMapBytecodeKind::Identity):
301 map = AffineMap::getMultiDimIdentityMap(numDims, context);
302 return success();
303
304 case static_cast<unsigned>(AffineMapBytecodeKind::Permutation): {
305 SmallVector<unsigned> perm(numDims);
306 for (unsigned i = 0; i < numDims; ++i) {
307 uint64_t pos;
308 if (failed(reader.readVarInt(pos)))
309 return failure();
310 perm[i] = pos;
311 }
312 map = AffineMap::getPermutationMap(perm, context);
313 return success();
314 }
315
316 case static_cast<unsigned>(AffineMapBytecodeKind::ProjectedPermutation): {
317 uint64_t numResults;
318 if (failed(reader.readVarInt(numResults)))
319 return failure();
321 results.reserve(numResults);
322 for (uint64_t i = 0; i < numResults; ++i) {
323 uint64_t pos;
324 if (failed(reader.readVarInt(pos)))
325 return failure();
326 results.push_back(getAffineDimExpr(pos, context));
327 }
328 map = AffineMap::get(numDims, /*numSymbols=*/0, results, context);
329 return success();
330 }
331
332 case static_cast<unsigned>(AffineMapBytecodeKind::General): {
333 uint64_t numSymbols, numResults;
334 if (failed(reader.readVarInt(numSymbols)) ||
335 failed(reader.readVarInt(numResults)))
336 return failure();
338 results.reserve(numResults);
339 for (uint64_t i = 0; i < numResults; ++i) {
340 auto expr = readAffineExpr(reader, context);
341 if (failed(expr))
342 return failure();
343 results.push_back(*expr);
344 }
345 map = AffineMap::get(numDims, numSymbols, results, context);
346 return success();
347 }
348
349 default:
350 return reader.emitError("unknown AffineMap kind: ")
351 << static_cast<unsigned>(mapKind),
352 failure();
353 }
354}
355
356/// Write an AffineMap with packed kind header (see readAffineMap for format).
357static void writeAffineMap(DialectBytecodeWriter &writer, AffineMapAttr attr) {
358 AffineMap map = attr.getValue();
359 unsigned numDims = map.getNumDims();
360
361 // Identity maps: (d0, d1, ..., d_{n-1}) -> (d0, d1, ..., d_{n-1})
362 // Note: isIdentity() does not check numSymbols, so guard explicitly.
363 if (map.getNumSymbols() == 0 && map.isIdentity()) {
364 writer.writeVarInt((numDims << 2) |
365 static_cast<unsigned>(AffineMapBytecodeKind::Identity));
366 return;
367 }
368
369 // Permutation maps: numResults == numDims, each result is a unique dim
370 if (map.isPermutation()) {
371 writer.writeVarInt(
372 (numDims << 2) |
373 static_cast<unsigned>(AffineMapBytecodeKind::Permutation));
374 for (unsigned i = 0; i < map.getNumResults(); ++i)
375 writer.writeVarInt(map.getDimPosition(i));
376 return;
377 }
378
379 // Projected permutation maps (symbol-less): subset of dims
380 if (map.getNumSymbols() == 0 && map.isProjectedPermutation()) {
381 writer.writeVarInt(
382 (numDims << 2) |
383 static_cast<unsigned>(AffineMapBytecodeKind::ProjectedPermutation));
384 writer.writeVarInt(map.getNumResults());
385 for (unsigned i = 0; i < map.getNumResults(); ++i)
386 writer.writeVarInt(map.getDimPosition(i));
387 return;
388 }
389
390 // General case
391 writer.writeVarInt((numDims << 2) |
392 static_cast<unsigned>(AffineMapBytecodeKind::General));
393 writer.writeVarInt(map.getNumSymbols());
394 writer.writeVarInt(map.getNumResults());
395 for (AffineExpr expr : map.getResults())
396 writeAffineExpr(writer, expr);
397}
398
399static FileLineColRange getFileLineColRange(MLIRContext *context,
400 StringAttr filename,
401 ArrayRef<uint64_t> lineCols) {
402 switch (lineCols.size()) {
403 case 0:
404 return FileLineColRange::get(filename);
405 case 1:
406 return FileLineColRange::get(filename, lineCols[0]);
407 case 2:
408 return FileLineColRange::get(filename, lineCols[0], lineCols[1]);
409 case 3:
410 return FileLineColRange::get(filename, lineCols[0], lineCols[1],
411 lineCols[2]);
412 case 4:
413 return FileLineColRange::get(filename, lineCols[0], lineCols[1],
414 lineCols[2], lineCols[3]);
415 default:
416 return {};
417 }
418}
419
420static LogicalResult
421readFileLineColRangeLocs(DialectBytecodeReader &reader,
422 SmallVectorImpl<uint64_t> &lineCols) {
423 return reader.readList(
424 lineCols, [&reader](uint64_t &val) { return reader.readVarInt(val); });
425}
426
427static void writeFileLineColRangeLocs(DialectBytecodeWriter &writer,
428 FileLineColRange range) {
429 if (range.getStartLine() == 0 && range.getStartColumn() == 0 &&
430 range.getEndLine() == 0 && range.getEndColumn() == 0) {
431 writer.writeVarInt(0);
432 return;
433 }
434 if (range.getStartColumn() == 0 &&
435 range.getStartLine() == range.getEndLine()) {
436 writer.writeVarInt(1);
437 writer.writeVarInt(range.getStartLine());
438 return;
439 }
440 // The single file:line:col is handled by other writer, but checked here for
441 // completeness.
442 if (range.getEndColumn() == range.getStartColumn() &&
443 range.getStartLine() == range.getEndLine()) {
444 writer.writeVarInt(2);
445 writer.writeVarInt(range.getStartLine());
446 writer.writeVarInt(range.getStartColumn());
447 return;
448 }
449 if (range.getStartLine() == range.getEndLine()) {
450 writer.writeVarInt(3);
451 writer.writeVarInt(range.getStartLine());
452 writer.writeVarInt(range.getStartColumn());
453 writer.writeVarInt(range.getEndColumn());
454 return;
455 }
456 writer.writeVarInt(4);
457 writer.writeVarInt(range.getStartLine());
458 writer.writeVarInt(range.getStartColumn());
459 writer.writeVarInt(range.getEndLine());
460 writer.writeVarInt(range.getEndColumn());
461}
462
463static LogicalResult
464readDenseTypedElementsAttr(DialectBytecodeReader &reader, ShapedType type,
465 SmallVectorImpl<char> &rawData) {
466 // Validate that the element type implements DenseElementTypeInterface.
467 // Without this check, downstream code unconditionally calls
468 // getDenseElementBitWidth() which asserts on unsupported types.
469 if (!llvm::isa<DenseElementType>(type.getElementType())) {
470 reader.emitError() << "DenseTypedElementsAttr element type must implement "
471 "DenseElementTypeInterface, but got: "
472 << type.getElementType();
473 return failure();
474 }
475
476 ArrayRef<char> blob;
477 if (failed(reader.readBlob(blob)))
478 return failure();
479
480 // If the type is not i1, just copy the blob.
481 if (!type.getElementType().isInteger(1)) {
482 rawData.append(blob.begin(), blob.end());
483 return success();
484 }
485
486 // Check to see if this is using the packed format.
487 // Note: this could be asserted instead as this should be the case. But we
488 // did have period where the unpacked was being serialized, this enables
489 // consuming those still and the check for which case we are in is pretty
490 // cheap.
491 size_t numElements = type.getNumElements();
492 size_t packedSize = llvm::divideCeil(numElements, 8);
493
494 // Unpack splats to single element 0x01 to match unpacked splat format.
495 if (blob.size() == 1 && blob[0] == static_cast<char>(~0x00)) {
496 rawData.resize(1);
497 rawData[0] = 0x01;
498 return success();
499 }
500
501 // Unpack the blob if it's packed.
502 // Splat and blob.size() == packedSize for all N<=8 elements are ambiguous,
503 // non 0xFF means not splat so must be unpacked.
504 if (blob.size() == packedSize && blob.size() != numElements) {
505 rawData.resize(numElements);
506 for (size_t i = 0; i < numElements; ++i)
507 rawData[i] = (blob[i / 8] & (1 << (i % 8))) ? 1 : 0;
508 return success();
509 }
510 // Otherwise, fallback to the default behavior.
511 rawData.append(blob.begin(), blob.end());
512 return success();
513}
514
515static void writeDenseTypedElementsAttr(DialectBytecodeWriter &writer,
517 // Check to see if this is an i1 dense attribute.
518 if (attr.getElementType().isInteger(1)) {
519 // Pack the data.
521 ArrayRef<char> rawData = attr.getRawData();
522
523 // If the attribute is a splat, we can just splat the value directly.
524 // Use 0xFF to avoid ambiguity with packed format of <=8 elements,
525 // written ~0x00 to ensure proper compilation with signed chars.
526 if (attr.isSplat()) {
527 data.resize(1);
528 data[0] = rawData[0] ? ~0x00 : 0x00;
529 writer.writeUnownedBlob(data);
530 return;
531 }
532
533 size_t numElements = attr.getNumElements();
534 data.resize(llvm::divideCeil(numElements, 8));
535 // Otherwise, pack the data manually.
536 for (size_t i = 0; i < numElements; ++i)
537 if (rawData[i])
538 data[i / 8] |= (1 << (i % 8));
539 writer.writeUnownedBlob(data);
540 return;
541 }
542
543 writer.writeOwnedBlob(attr.getRawData());
544}
545
546#include "mlir/IR/BuiltinDialectBytecode.cpp.inc"
547
548/// This class implements the bytecode interface for the builtin dialect.
549struct BuiltinDialectBytecodeInterface : public BytecodeDialectInterface {
550 BuiltinDialectBytecodeInterface(Dialect *dialect)
551 : BytecodeDialectInterface(dialect) {}
552
553 //===--------------------------------------------------------------------===//
554 // Attributes
555
556 Attribute readAttribute(DialectBytecodeReader &reader) const override {
557 return ::readAttribute(getContext(), reader);
558 }
559
560 LogicalResult writeAttribute(Attribute attr,
561 DialectBytecodeWriter &writer) const override {
562 return ::writeAttribute(attr, writer);
563 }
564
565 //===--------------------------------------------------------------------===//
566 // Types
567
568 Type readType(DialectBytecodeReader &reader) const override {
569 return ::readType(getContext(), reader);
570 }
571
572 LogicalResult writeType(Type type,
573 DialectBytecodeWriter &writer) const override {
574 return ::writeType(type, writer);
575 }
576
577 //===--------------------------------------------------------------------===//
578 // Version
579
580 void writeVersion(DialectBytecodeWriter &writer) const override {
581 auto configVersion = writer.getDialectVersion(getDialect()->getNamespace());
582 // Write version set in config.
583 if (succeeded(configVersion)) {
584 auto *version =
585 static_cast<const BuiltinDialectVersion *>(*configVersion);
586 writer.writeVarInt(static_cast<uint64_t>(version->getVersion()));
587 return;
588 }
589 // Else, write current set version version if not 0.
590 if (auto version = cast<BuiltinDialect>(getDialect())->getVersion();
591 version && version->getVersion() > 0) {
592 writer.writeVarInt(static_cast<uint64_t>(version->getVersion()));
593 }
594 }
595
596 std::unique_ptr<DialectVersion>
597 readVersion(DialectBytecodeReader &reader) const override {
598 uint64_t version;
599 if (failed(reader.readVarInt(version)))
600 return nullptr;
601
602 auto dialectVersion = std::make_unique<BuiltinDialectVersion>(version);
603 if (BuiltinDialectVersion::getCurrentVersion() < *dialectVersion) {
604 reader.emitError()
605 << "reading newer builtin dialect version than supported";
606 return nullptr;
607 }
608
609 return dialectVersion;
610 }
611};
612} // namespace
613
614void builtin_dialect_detail::addBytecodeInterface(BuiltinDialect *dialect) {
615 dialect->addInterfaces<BuiltinDialectBytecodeInterface>();
616}
return success()
lhs
b getContext())
Base type for affine expression.
Definition AffineExpr.h:68
AffineExprKind getKind() const
Return the classification for this type.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition AffineMap.h:46
unsigned getDimPosition(unsigned idx) const
Extracts the position of the dimensional expression at the given result, when the caller knows it is ...
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
bool isProjectedPermutation(bool allowZeroInResults=false) const
Returns true if the AffineMap represents a subset (i.e.
unsigned getNumSymbols() const
unsigned getNumDims() const
ArrayRef< AffineExpr > getResults() const
unsigned getNumResults() const
static AffineMap getPermutationMap(ArrayRef< unsigned > permutation, MLIRContext *context)
Returns an AffineMap representing a permutation.
bool isIdentity() const
Returns true if this affine map is an identity affine map.
bool isPermutation() const
Returns true if the AffineMap represents a symbol-less permutation map.
This class defines a virtual interface for reading a bytecode stream, providing hooks into the byteco...
virtual LogicalResult readBlob(ArrayRef< char > &result)=0
Read a blob from the bytecode.
virtual LogicalResult readVarInt(uint64_t &result)=0
Read a variable width integer.
virtual FailureOr< APInt > readAPIntWithKnownWidth(unsigned bitWidth)=0
Read an APInt that is known to have been encoded with the given width.
virtual InFlightDiagnostic emitError(const Twine &msg={}) const =0
Emit an error to the reader.
virtual LogicalResult readString(StringRef &result)=0
Read a string from the bytecode.
virtual LogicalResult readSignedVarInt(int64_t &result)=0
Read a signed variable width integer.
LogicalResult readList(SmallVectorImpl< T > &result, CallbackFn &&callback)
Read out a list of elements, invoking the provided callback for each element.
virtual FailureOr< APFloat > readAPFloatWithKnownSemantics(const llvm::fltSemantics &semantics)=0
Read an APFloat that is known to have been encoded with the given semantics.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
virtual FailureOr< const DialectVersion * > getDialectVersion(StringRef dialectName) const =0
Retrieve the dialect version by name if available.
virtual void writeVarInt(uint64_t value)=0
Write a variable width integer to the output stream.
virtual void writeUnownedBlob(ArrayRef< char > blob)=0
Write a blob to the bytecode, which is not owned by the caller.
virtual void writeOwnedBlob(ArrayRef< char > blob)=0
Write a blob to the bytecode, which is owned by the caller and is guaranteed to not die before the en...
virtual void writeSignedVarInt(int64_t value)=0
Write a signed variable width integer to the output stream.
virtual void writeOwnedString(StringRef str)=0
Write a string to the bytecode, which is owned by the caller and is guaranteed to not die before the ...
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
void addBytecodeInterface(BuiltinDialect *dialect)
Add the interfaces necessary for encoding the builtin dialect components in bytecode.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:717
OwningOpRef< spirv::ModuleOp > combine(ArrayRef< spirv::ModuleOp > inputModules, OpBuilder &combinedModuleBuilder, SymbolRenameListener symRenameListener)
Combines a list of SPIR-V inputModules into one.
Include the generated interface declarations.
AffineExprKind
Definition AffineExpr.h:40
@ CeilDiv
RHS of ceildiv is always a constant or a symbolic expression.
Definition AffineExpr.h:50
@ Mul
RHS of mul is always a constant or a symbolic expression.
Definition AffineExpr.h:43
@ Mod
RHS of mod is always a constant or a symbolic expression with a positive value.
Definition AffineExpr.h:46
@ DimId
Dimensional identifier.
Definition AffineExpr.h:59
@ FloorDiv
RHS of floordiv is always a constant or a symbolic expression.
Definition AffineExpr.h:48
@ Constant
Constant integer.
Definition AffineExpr.h:57
@ SymbolId
Symbolic identifier.
Definition AffineExpr.h:61
AffineExpr getAffineBinaryOpExpr(AffineExprKind kind, AffineExpr lhs, AffineExpr rhs)
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
static BuiltinDialectVersion getCurrentVersion()