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