MLIR 23.0.0git
Builders.cpp
Go to the documentation of this file.
1//===- Builders.cpp - Helpers for constructing MLIR Classes ---------------===//
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#include "mlir/IR/Builders.h"
10#include "mlir/IR/AffineExpr.h"
11#include "mlir/IR/AffineMap.h"
13#include "mlir/IR/Dialect.h"
14#include "mlir/IR/IRMapping.h"
15#include "mlir/IR/Matchers.h"
16#include "llvm/ADT/SmallVectorExtras.h"
17#include "llvm/Support/DebugLog.h"
18
19using namespace mlir;
20
21//===----------------------------------------------------------------------===//
22// Locations.
23//===----------------------------------------------------------------------===//
24
25Location Builder::getUnknownLoc() { return UnknownLoc::get(context); }
26
28 return FusedLoc::get(locs, metadata, context);
29}
30
31//===----------------------------------------------------------------------===//
32// Types.
33//===----------------------------------------------------------------------===//
34
35FloatType Builder::getF8E8M0Type() { return Float8E8M0FNUType::get(context); }
36
37FloatType Builder::getF8E4M3FNType() { return Float8E4M3FNType::get(context); }
38
39FloatType Builder::getF8E5M2Type() { return Float8E5M2Type::get(context); }
40
41FloatType Builder::getBF16Type() { return BFloat16Type::get(context); }
42
43FloatType Builder::getF16Type() { return Float16Type::get(context); }
44
45FloatType Builder::getTF32Type() { return FloatTF32Type::get(context); }
46
47FloatType Builder::getF32Type() { return Float32Type::get(context); }
48
49FloatType Builder::getF64Type() { return Float64Type::get(context); }
50
51FloatType Builder::getF80Type() { return Float80Type::get(context); }
52
53FloatType Builder::getF128Type() { return Float128Type::get(context); }
54
55IndexType Builder::getIndexType() { return IndexType::get(context); }
56
57IntegerType Builder::getI1Type() { return IntegerType::get(context, 1); }
58
59IntegerType Builder::getI2Type() { return IntegerType::get(context, 2); }
60
61IntegerType Builder::getI4Type() { return IntegerType::get(context, 4); }
62
63IntegerType Builder::getI8Type() { return IntegerType::get(context, 8); }
64
65IntegerType Builder::getI16Type() { return IntegerType::get(context, 16); }
66
67IntegerType Builder::getI32Type() { return IntegerType::get(context, 32); }
68
69IntegerType Builder::getI64Type() { return IntegerType::get(context, 64); }
70
71IntegerType Builder::getIntegerType(unsigned width) {
72 return IntegerType::get(context, width);
73}
74
75IntegerType Builder::getIntegerType(unsigned width, bool isSigned) {
76 return IntegerType::get(
77 context, width, isSigned ? IntegerType::Signed : IntegerType::Unsigned);
78}
79
80FunctionType Builder::getFunctionType(TypeRange inputs, TypeRange results) {
81 return FunctionType::get(context, inputs, results);
82}
83
84GraphType Builder::getGraphType(TypeRange inputs, TypeRange results) {
85 return GraphType::get(context, inputs, results);
86}
87
88TupleType Builder::getTupleType(TypeRange elementTypes) {
89 return TupleType::get(context, elementTypes);
90}
91
92NoneType Builder::getNoneType() { return NoneType::get(context); }
93
94//===----------------------------------------------------------------------===//
95// Attributes.
96//===----------------------------------------------------------------------===//
97
99 return NamedAttribute(name, val);
100}
101
102UnitAttr Builder::getUnitAttr() { return UnitAttr::get(context); }
103
105 return BoolAttr::get(context, value);
106}
107
109 return DictionaryAttr::get(context, value);
110}
111
112IntegerAttr Builder::getIndexAttr(int64_t value) {
113 return IntegerAttr::get(getIndexType(), APInt(64, value));
114}
115
117 return IntegerAttr::get(getIntegerType(64), APInt(64, value));
118}
119
122 VectorType::get(static_cast<int64_t>(values.size()), getI1Type()),
123 values);
124}
125
128 VectorType::get(static_cast<int64_t>(values.size()), getIntegerType(32)),
129 values);
130}
131
134 VectorType::get(static_cast<int64_t>(values.size()), getIntegerType(64)),
135 values);
136}
137
140 VectorType::get(static_cast<int64_t>(values.size()), getIndexType()),
141 values);
142}
143
146 VectorType::get(static_cast<float>(values.size()), getF32Type()), values);
147}
148
151 VectorType::get(static_cast<double>(values.size()), getF64Type()),
152 values);
153}
154
158
162
166
170
174
178
182
185 RankedTensorType::get(static_cast<int64_t>(values.size()),
186 getIntegerType(32)),
187 values);
188}
189
192 RankedTensorType::get(static_cast<int64_t>(values.size()),
193 getIntegerType(64)),
194 values);
195}
196
199 RankedTensorType::get(static_cast<int64_t>(values.size()),
200 getIndexType()),
201 values);
202}
203
204IntegerAttr Builder::getI32IntegerAttr(int32_t value) {
205 // The APInt always uses isSigned=true here because we accept the value
206 // as int32_t.
207 return IntegerAttr::get(getIntegerType(32),
208 APInt(32, value, /*isSigned=*/true));
209}
210
211IntegerAttr Builder::getSI32IntegerAttr(int32_t value) {
212 return IntegerAttr::get(getIntegerType(32, /*isSigned=*/true),
213 APInt(32, value, /*isSigned=*/true));
214}
215
216IntegerAttr Builder::getUI32IntegerAttr(uint32_t value) {
217 return IntegerAttr::get(getIntegerType(32, /*isSigned=*/false),
218 APInt(32, (uint64_t)value, /*isSigned=*/false));
219}
220
221IntegerAttr Builder::getI16IntegerAttr(int16_t value) {
222 return IntegerAttr::get(getIntegerType(16),
223 APInt(16, value, /*isSigned=*/true));
224}
225
226IntegerAttr Builder::getI8IntegerAttr(int8_t value) {
227 // The APInt always uses isSigned=true here because we accept the value
228 // as int8_t.
229 return IntegerAttr::get(getIntegerType(8),
230 APInt(8, value, /*isSigned=*/true));
231}
232
233IntegerAttr Builder::getIntegerAttr(Type type, int64_t value) {
234 if (type.isIndex())
235 return IntegerAttr::get(type, APInt(64, value));
236 // TODO: Avoid implicit trunc?
237 // See https://github.com/llvm/llvm-project/issues/112510.
238 return IntegerAttr::get(type, APInt(type.getIntOrFloatBitWidth(), value,
239 type.isSignedInteger(),
240 /*implicitTrunc=*/true));
241}
242
243IntegerAttr Builder::getIntegerAttr(Type type, const APInt &value) {
244 return IntegerAttr::get(type, value);
245}
246
247FloatAttr Builder::getF64FloatAttr(double value) {
248 return FloatAttr::get(getF64Type(), APFloat(value));
249}
250
251FloatAttr Builder::getF32FloatAttr(float value) {
252 return FloatAttr::get(getF32Type(), APFloat(value));
253}
254
255FloatAttr Builder::getF16FloatAttr(float value) {
256 return FloatAttr::get(getF16Type(), value);
257}
258
259FloatAttr Builder::getFloatAttr(Type type, double value) {
260 return FloatAttr::get(type, value);
261}
262
263FloatAttr Builder::getFloatAttr(Type type, const APFloat &value) {
264 return FloatAttr::get(type, value);
265}
266
267StringAttr Builder::getStringAttr(const Twine &bytes) {
268 return StringAttr::get(context, bytes);
269}
270
272 return ArrayAttr::get(context, value);
273}
274
276 auto attrs = llvm::map_to_vector<8>(
277 values, [this](bool v) -> Attribute { return getBoolAttr(v); });
278 return getArrayAttr(attrs);
279}
280
282 auto attrs = llvm::map_to_vector<8>(
283 values, [this](int32_t v) -> Attribute { return getI32IntegerAttr(v); });
284 return getArrayAttr(attrs);
285}
287 auto attrs = llvm::map_to_vector<8>(
288 values, [this](int64_t v) -> Attribute { return getI64IntegerAttr(v); });
289 return getArrayAttr(attrs);
290}
291
293 auto attrs = llvm::map_to_vector<8>(values, [this](int64_t v) -> Attribute {
294 return getIntegerAttr(IndexType::get(getContext()), v);
295 });
296 return getArrayAttr(attrs);
297}
298
300 auto attrs = llvm::map_to_vector<8>(
301 values, [this](float v) -> Attribute { return getF32FloatAttr(v); });
302 return getArrayAttr(attrs);
303}
304
306 auto attrs = llvm::map_to_vector<8>(
307 values, [this](double v) -> Attribute { return getF64FloatAttr(v); });
308 return getArrayAttr(attrs);
309}
310
312 auto attrs = llvm::map_to_vector<8>(
313 values, [this](StringRef v) -> Attribute { return getStringAttr(v); });
314 return getArrayAttr(attrs);
315}
316
318 auto attrs = llvm::map_to_vector<8>(
319 values, [](Type v) -> Attribute { return TypeAttr::get(v); });
320 return getArrayAttr(attrs);
321}
322
324 auto attrs = llvm::map_to_vector<8>(
325 values, [](AffineMap v) -> Attribute { return AffineMapAttr::get(v); });
326 return getArrayAttr(attrs);
327}
328
329TypedAttr Builder::getZeroAttr(Type type) {
330 if (llvm::isa<FloatType>(type))
331 return getFloatAttr(type, 0.0);
332 if (llvm::isa<IndexType>(type))
333 return getIndexAttr(0);
334 if (llvm::dyn_cast<IntegerType>(type))
335 return getIntegerAttr(type,
336 APInt(llvm::cast<IntegerType>(type).getWidth(), 0));
337 if (llvm::isa<RankedTensorType, VectorType>(type)) {
338 auto vtType = llvm::cast<ShapedType>(type);
339 auto element = getZeroAttr(vtType.getElementType());
340 if (!element)
341 return {};
342 return DenseElementsAttr::get(vtType, element);
343 }
344 return {};
345}
346
347TypedAttr Builder::getOneAttr(Type type) {
348 if (llvm::isa<FloatType>(type))
349 return getFloatAttr(type, 1.0);
350 if (llvm::isa<IndexType>(type))
351 return getIndexAttr(1);
352 if (llvm::dyn_cast<IntegerType>(type))
353 return getIntegerAttr(type,
354 APInt(llvm::cast<IntegerType>(type).getWidth(), 1));
355 if (llvm::isa<RankedTensorType, VectorType>(type)) {
356 auto vtType = llvm::cast<ShapedType>(type);
357 auto element = getOneAttr(vtType.getElementType());
358 if (!element)
359 return {};
360 return DenseElementsAttr::get(vtType, element);
361 }
362 return {};
363}
364
365//===----------------------------------------------------------------------===//
366// Affine Expressions, Affine Maps, and Integer Sets.
367//===----------------------------------------------------------------------===//
368
370 return mlir::getAffineDimExpr(position, context);
371}
372
374 return mlir::getAffineSymbolExpr(position, context);
375}
376
380
382
384 return AffineMap::get(/*dimCount=*/0, /*symbolCount=*/0,
386}
387
389 return AffineMap::get(/*dimCount=*/1, /*symbolCount=*/0, getAffineDimExpr(0));
390}
391
394 dimExprs.reserve(rank);
395 for (unsigned i = 0; i < rank; ++i)
396 dimExprs.push_back(getAffineDimExpr(i));
397 return AffineMap::get(/*dimCount=*/rank, /*symbolCount=*/0, dimExprs,
398 context);
399}
400
402 return AffineMap::get(/*dimCount=*/0, /*symbolCount=*/1,
404}
405
407 // expr = d0 + shift.
408 auto expr = getAffineDimExpr(0) + shift;
409 return AffineMap::get(/*dimCount=*/1, /*symbolCount=*/0, expr);
410}
411
413 SmallVector<AffineExpr, 4> shiftedResults;
414 shiftedResults.reserve(map.getNumResults());
415 for (auto resultExpr : map.getResults())
416 shiftedResults.push_back(resultExpr + shift);
417 return AffineMap::get(map.getNumDims(), map.getNumSymbols(), shiftedResults,
418 context);
419}
420
421//===----------------------------------------------------------------------===//
422// OpBuilder
423//===----------------------------------------------------------------------===//
424
425/// Insert the given operation at the current insertion point and return it.
427 if (block) {
428 block->getOperations().insert(insertPoint, op);
429 if (listener)
430 listener->notifyOperationInserted(op, /*previous=*/{});
431 }
432 return op;
433}
434
436 TypeRange argTypes, ArrayRef<Location> locs) {
437 assert(parent && "expected valid parent region");
438 assert(argTypes.size() == locs.size() && "argument location mismatch");
439 if (insertPt == Region::iterator())
440 insertPt = parent->end();
441
442 Block *b = new Block();
443 b->addArguments(argTypes, locs);
444 parent->getBlocks().insert(insertPt, b);
446
447 if (listener)
448 listener->notifyBlockInserted(b, /*previous=*/nullptr, /*previousIt=*/{});
449 return b;
450}
451
452/// Add new block with 'argTypes' arguments and set the insertion point to the
453/// end of it. The block is placed before 'insertBefore'.
455 ArrayRef<Location> locs) {
456 assert(insertBefore && "expected valid insertion block");
457 return createBlock(insertBefore->getParent(), Region::iterator(insertBefore),
458 argTypes, locs);
459}
460
461/// Create an operation given the fields represented as an OperationState.
463 return insert(Operation::create(state));
464}
465
466/// Creates an operation with the given fields.
467Operation *OpBuilder::create(Location loc, StringAttr opName,
468 ValueRange operands, TypeRange types,
469 ArrayRef<NamedAttribute> attributes,
470 BlockRange successors,
471 MutableArrayRef<std::unique_ptr<Region>> regions) {
472 OperationState state(loc, opName, operands, types, attributes, successors,
473 regions);
474 return create(state);
475}
476
477LogicalResult
479 SmallVectorImpl<Operation *> *materializedConstants) {
480 assert(results.empty() && "expected empty results");
481 ResultRange opResults = op->getResults();
482
483 results.reserve(opResults.size());
484 auto cleanupFailure = [&] {
485 results.clear();
486 return failure();
487 };
488
489 // If this operation is already a constant, there is nothing to do.
490 if (matchPattern(op, m_Constant()))
491 return cleanupFailure();
492
493 // Try to fold the operation.
495 LDBG() << "Trying to fold: "
496 << OpWithFlags(op, OpPrintingFlags().skipRegions());
497 if (failed(op->fold(foldResults)))
498 return cleanupFailure();
499
500 int count = 0;
501 do {
502 LDBG() << "Folded in place #" << count
503 << " times: " << OpWithFlags(op, OpPrintingFlags().skipRegions());
504 count++;
505 } while (foldResults.empty() && succeeded(op->fold(foldResults)));
506
507 // An in-place fold does not require generation of any constants.
508 if (foldResults.empty())
509 return success();
510
511 // A temporary builder used for creating constants during folding.
512 OpBuilder cstBuilder(context);
513 SmallVector<Operation *, 1> generatedConstants;
514
515 // Populate the results with the folded results.
516 Dialect *dialect = op->getDialect();
517 for (auto [foldResult, expectedType] :
518 llvm::zip_equal(foldResults, opResults.getTypes())) {
519
520 // Normal values get pushed back directly.
521 if (auto value = llvm::dyn_cast_if_present<Value>(foldResult)) {
522 results.push_back(value);
523 continue;
524 }
525
526 // Otherwise, try to materialize a constant operation.
527 if (!dialect)
528 return cleanupFailure();
529
530 // Ask the dialect to materialize a constant operation for this value.
531 Attribute attr = cast<Attribute>(foldResult);
532 auto *constOp = dialect->materializeConstant(cstBuilder, attr, expectedType,
533 op->getLoc());
534 if (!constOp) {
535 // Erase any generated constants.
536 for (Operation *cst : generatedConstants)
537 cst->erase();
538 return cleanupFailure();
539 }
540 assert(matchPattern(constOp, m_Constant()));
541
542 generatedConstants.push_back(constOp);
543 results.push_back(constOp->getResult(0));
544 }
545
546 // If we were successful, insert any generated constants.
547 for (Operation *cst : generatedConstants)
548 insert(cst);
549
550 // Return materialized constant operations.
551 if (materializedConstants)
552 *materializedConstants = std::move(generatedConstants);
553
554 return success();
555}
556
557/// Helper function that sends block insertion notifications for every block
558/// that is directly nested in the given op.
560 OpBuilder::Listener *listener) {
561 for (Region &r : op->getRegions())
562 for (Block &b : r.getBlocks())
563 listener->notifyBlockInserted(&b, /*previous=*/nullptr,
564 /*previousIt=*/{});
565}
566
568 Operation *newOp = op.clone(mapper);
569 newOp = insert(newOp);
570
571 // The `insert` call above handles the notification for inserting `newOp`
572 // itself. But if `newOp` has any regions, we need to notify the listener
573 // about any ops that got inserted inside those regions as part of cloning.
574 if (listener) {
575 // The `insert` call above notifies about op insertion, but not about block
576 // insertion.
578 auto walkFn = [&](Operation *walkedOp) {
579 listener->notifyOperationInserted(walkedOp, /*previous=*/{});
581 };
582 for (Region &region : newOp->getRegions())
583 region.walk<WalkOrder::PreOrder>(walkFn);
584 }
585
586 return newOp;
587}
588
590 IRMapping mapper;
591 return clone(op, mapper);
592}
593
595 Region::iterator before, IRMapping &mapping) {
596 region.cloneInto(&parent, before, mapping);
597
598 // Fast path: If no listener is attached, there is no more work to do.
599 if (!listener)
600 return;
601
602 // Notify about op/block insertion.
603 for (auto it = mapping.lookup(&region.front())->getIterator(); it != before;
604 ++it) {
605 listener->notifyBlockInserted(&*it, /*previous=*/nullptr,
606 /*previousIt=*/{});
607 it->walk<WalkOrder::PreOrder>([&](Operation *walkedOp) {
608 listener->notifyOperationInserted(walkedOp, /*previous=*/{});
610 });
611 }
612}
613
615 Region::iterator before) {
616 IRMapping mapping;
617 cloneRegionBefore(region, parent, before, mapping);
618}
619
621 cloneRegionBefore(region, *before->getParent(), before->getIterator());
622}
return success()
static void notifyBlockInsertions(Operation *op, OpBuilder::Listener *listener)
Helper function that sends block insertion notifications for every block that is directly nested in t...
Definition Builders.cpp:559
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
Base type for affine expression.
Definition AffineExpr.h:68
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition AffineMap.h:46
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
unsigned getNumSymbols() const
unsigned getNumDims() const
ArrayRef< AffineExpr > getResults() const
unsigned getNumResults() const
Attributes are known-constant values of operations.
Definition Attributes.h:25
This class provides an abstraction over the different types of ranges over Blocks.
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
Special case of IntegerAttr to represent boolean integers, i.e., signless i1 integers.
static BoolAttr get(MLIRContext *context, bool value)
IntegerAttr getIndexAttr(int64_t value)
Definition Builders.cpp:112
AffineMap getSingleDimShiftAffineMap(int64_t shift)
Returns a map that shifts its (single) input dimension by 'shift'.
Definition Builders.cpp:406
IntegerType getI16Type()
Definition Builders.cpp:65
UnitAttr getUnitAttr()
Definition Builders.cpp:102
ArrayAttr getIndexArrayAttr(ArrayRef< int64_t > values)
Definition Builders.cpp:292
DenseF64ArrayAttr getDenseF64ArrayAttr(ArrayRef< double > values)
Definition Builders.cpp:179
IntegerType getI2Type()
Definition Builders.cpp:59
FloatType getF80Type()
Definition Builders.cpp:51
FloatType getF128Type()
Definition Builders.cpp:53
DenseI8ArrayAttr getDenseI8ArrayAttr(ArrayRef< int8_t > values)
Definition Builders.cpp:159
IntegerAttr getI32IntegerAttr(int32_t value)
Definition Builders.cpp:204
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
Definition Builders.cpp:167
DenseIntElementsAttr getBoolVectorAttr(ArrayRef< bool > values)
Vector-typed DenseIntElementsAttr getters. values must not be empty.
Definition Builders.cpp:120
FloatType getF32Type()
Definition Builders.cpp:47
FloatType getTF32Type()
Definition Builders.cpp:45
TupleType getTupleType(TypeRange elementTypes)
Definition Builders.cpp:88
IntegerAttr getIntegerAttr(Type type, int64_t value)
Definition Builders.cpp:233
FloatAttr getF64FloatAttr(double value)
Definition Builders.cpp:247
AffineMap getShiftedAffineMap(AffineMap map, int64_t shift)
Returns an affine map that is a translation (shift) of all result expressions in 'map' by 'shift'.
Definition Builders.cpp:412
ArrayAttr getI32ArrayAttr(ArrayRef< int32_t > values)
Definition Builders.cpp:281
DenseI64ArrayAttr getDenseI64ArrayAttr(ArrayRef< int64_t > values)
Definition Builders.cpp:171
FloatAttr getF16FloatAttr(float value)
Definition Builders.cpp:255
FloatType getF8E5M2Type()
Definition Builders.cpp:39
AffineMap getDimIdentityMap()
Definition Builders.cpp:388
AffineMap getMultiDimIdentityMap(unsigned rank)
Definition Builders.cpp:392
IntegerAttr getI16IntegerAttr(int16_t value)
Definition Builders.cpp:221
DenseI16ArrayAttr getDenseI16ArrayAttr(ArrayRef< int16_t > values)
Definition Builders.cpp:163
AffineExpr getAffineSymbolExpr(unsigned position)
Definition Builders.cpp:373
DenseFPElementsAttr getF32VectorAttr(ArrayRef< float > values)
Definition Builders.cpp:144
FloatAttr getFloatAttr(Type type, double value)
Definition Builders.cpp:259
AffineExpr getAffineConstantExpr(int64_t constant)
Definition Builders.cpp:377
DenseIntElementsAttr getI32TensorAttr(ArrayRef< int32_t > values)
Tensor-typed DenseIntElementsAttr getters.
Definition Builders.cpp:183
FunctionType getFunctionType(TypeRange inputs, TypeRange results)
Definition Builders.cpp:80
IntegerType getI64Type()
Definition Builders.cpp:69
IntegerType getI32Type()
Definition Builders.cpp:67
IntegerAttr getI64IntegerAttr(int64_t value)
Definition Builders.cpp:116
IntegerType getIntegerType(unsigned width)
Definition Builders.cpp:71
NoneType getNoneType()
Definition Builders.cpp:92
DenseIntElementsAttr getI64TensorAttr(ArrayRef< int64_t > values)
Definition Builders.cpp:190
BoolAttr getBoolAttr(bool value)
Definition Builders.cpp:104
IntegerType getI4Type()
Definition Builders.cpp:61
StringAttr getStringAttr(const Twine &bytes)
Definition Builders.cpp:267
MLIRContext * context
Definition Builders.h:204
AffineMap getEmptyAffineMap()
Returns a zero result affine map with no dimensions or symbols: () -> ().
Definition Builders.cpp:381
IntegerAttr getSI32IntegerAttr(int32_t value)
Signed and unsigned integer attribute getters.
Definition Builders.cpp:211
GraphType getGraphType(TypeRange inputs, TypeRange results)
Definition Builders.cpp:84
TypedAttr getZeroAttr(Type type)
Definition Builders.cpp:329
FloatType getF16Type()
Definition Builders.cpp:43
Location getFusedLoc(ArrayRef< Location > locs, Attribute metadata=Attribute())
Definition Builders.cpp:27
FloatType getBF16Type()
Definition Builders.cpp:41
AffineExpr getAffineDimExpr(unsigned position)
Definition Builders.cpp:369
DenseIntElementsAttr getIndexTensorAttr(ArrayRef< int64_t > values)
Definition Builders.cpp:197
AffineMap getConstantAffineMap(int64_t val)
Returns a single constant result affine map with 0 dimensions and 0 symbols.
Definition Builders.cpp:383
ArrayAttr getTypeArrayAttr(TypeRange values)
Definition Builders.cpp:317
FloatType getF8E8M0Type()
Definition Builders.cpp:35
DenseIntElementsAttr getI32VectorAttr(ArrayRef< int32_t > values)
Definition Builders.cpp:126
DenseF32ArrayAttr getDenseF32ArrayAttr(ArrayRef< float > values)
Definition Builders.cpp:175
DenseIntElementsAttr getI64VectorAttr(ArrayRef< int64_t > values)
Definition Builders.cpp:132
AffineMap getSymbolIdentityMap()
Definition Builders.cpp:401
ArrayAttr getF64ArrayAttr(ArrayRef< double > values)
Definition Builders.cpp:305
IntegerType getI1Type()
Definition Builders.cpp:57
DenseFPElementsAttr getF64VectorAttr(ArrayRef< double > values)
Definition Builders.cpp:149
Location getUnknownLoc()
Definition Builders.cpp:25
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
Definition Builders.cpp:271
MLIRContext * getContext() const
Definition Builders.h:56
DenseBoolArrayAttr getDenseBoolArrayAttr(ArrayRef< bool > values)
Tensor-typed DenseArrayAttr getters.
Definition Builders.cpp:155
ArrayAttr getI64ArrayAttr(ArrayRef< int64_t > values)
Definition Builders.cpp:286
IndexType getIndexType()
Definition Builders.cpp:55
IntegerType getI8Type()
Definition Builders.cpp:63
FloatAttr getF32FloatAttr(float value)
Definition Builders.cpp:251
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
Definition Builders.cpp:108
FloatType getF8E4M3FNType()
Definition Builders.cpp:37
NamedAttribute getNamedAttr(StringRef name, Attribute val)
Definition Builders.cpp:98
IntegerAttr getUI32IntegerAttr(uint32_t value)
Definition Builders.cpp:216
IntegerAttr getI8IntegerAttr(int8_t value)
Definition Builders.cpp:226
ArrayAttr getF32ArrayAttr(ArrayRef< float > values)
Definition Builders.cpp:299
FloatType getF64Type()
Definition Builders.cpp:49
ArrayAttr getBoolArrayAttr(ArrayRef< bool > values)
Definition Builders.cpp:275
ArrayAttr getStrArrayAttr(ArrayRef< StringRef > values)
Definition Builders.cpp:311
DenseIntElementsAttr getIndexVectorAttr(ArrayRef< int64_t > values)
Definition Builders.cpp:138
ArrayAttr getAffineMapArrayAttr(ArrayRef< AffineMap > values)
Definition Builders.cpp:323
TypedAttr getOneAttr(Type type)
Definition Builders.cpp:347
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
An attribute that represents a reference to a dense float vector or tensor object.
static DenseFPElementsAttr get(const ShapedType &type, Arg &&arg)
Get an instance of a DenseFPElementsAttr with the given arguments.
An attribute that represents a reference to a dense integer vector or tensor object.
static DenseIntElementsAttr get(const ShapedType &type, Arg &&arg)
Get an instance of a DenseIntElementsAttr with the given arguments.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition Dialect.h:38
virtual Operation * materializeConstant(OpBuilder &builder, Attribute value, Type type, Location loc)
Registered hook to materialize a single constant operation from a given attribute value with the desi...
Definition Dialect.h:83
This is a utility class for mapping one set of IR entities to another.
Definition IRMapping.h:26
auto lookup(T from) const
Lookup a mapped value within the map.
Definition IRMapping.h:72
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
NamedAttribute represents a combination of a name and an Attribute value.
Definition Attributes.h:164
This class helps build Operations.
Definition Builders.h:209
Block * createBlock(Region *parent, Region::iterator insertPt={}, TypeRange argTypes={}, ArrayRef< Location > locs={})
Add new block with 'argTypes' arguments and set the insertion point to the end of it.
Definition Builders.cpp:435
Operation * clone(Operation &op, IRMapping &mapper)
Creates a deep copy of the specified operation, remapping any operands that use values outside of the...
Definition Builders.cpp:567
void setInsertionPointToEnd(Block *block)
Sets the insertion point to the end of the specified block.
Definition Builders.h:438
void cloneRegionBefore(Region &region, Region &parent, Region::iterator before, IRMapping &mapping)
Clone the blocks that belong to "region" before the given position in another region "parent".
Definition Builders.cpp:594
LogicalResult tryFold(Operation *op, SmallVectorImpl< Value > &results, SmallVectorImpl< Operation * > *materializedConstants=nullptr)
Attempts to fold the given operation and places new results within results.
Definition Builders.cpp:478
Listener * listener
The optional listener for events of this builder.
Definition Builders.h:619
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition Builders.cpp:462
Operation * clone(Operation &op)
Definition Builders.cpp:589
Operation * insert(Operation *op)
Insert the given operation at the current insertion point and return it.
Definition Builders.cpp:426
Set of flags used to control the behavior of the various IR print methods (e.g.
A wrapper class that allows for printing an operation with a set of flags, useful to act as a "stream...
Definition Operation.h:1142
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
Dialect * getDialect()
Return the dialect this operation is associated with, or nullptr if the associated dialect is not loa...
Definition Operation.h:237
LogicalResult fold(ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
Attempt to fold this operation with the specified constant operand values.
Location getLoc()
The source location the operation was defined or derived from.
Definition Operation.h:240
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
Definition Operation.h:702
static Operation * create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, NamedAttrList &&attributes, PropertyRef properties, BlockRange successors, unsigned numRegions)
Create a new Operation with the specific fields.
Definition Operation.cpp:65
result_range getResults()
Definition Operation.h:440
Operation * clone(IRMapping &mapper, const CloneOptions &options=CloneOptions::all())
Create a deep copy of this operation, remapping any operands that use values outside of the operation...
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
Block & front()
Definition Region.h:65
void cloneInto(Region *dest, IRMapping &mapper)
Clone the internal blocks from this region into dest.
Definition Region.cpp:70
iterator end()
Definition Region.h:56
BlockListType & getBlocks()
Definition Region.h:45
BlockListType::iterator iterator
Definition Region.h:52
This class implements the result iterators for the Operation class.
Definition ValueRange.h:248
type_range getTypes() const
This class provides an abstraction over the various different ranges of value types.
Definition TypeRange.h:40
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
bool isSignedInteger() const
Return true if this is a signed integer type (with the specified width).
Definition Types.cpp:78
bool isIndex() const
Definition Types.cpp:56
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
Definition Types.cpp:124
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:389
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< bool > content)
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
Definition Matchers.h:490
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
detail::DenseArrayAttrImpl< int8_t > DenseI8ArrayAttr
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
detail::DenseArrayAttrImpl< double > DenseF64ArrayAttr
detail::DenseArrayAttrImpl< bool > DenseBoolArrayAttr
detail::DenseArrayAttrImpl< float > DenseF32ArrayAttr
detail::constant_op_matcher m_Constant()
Matches a constant foldable operation.
Definition Matchers.h:369
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
detail::DenseArrayAttrImpl< int16_t > DenseI16ArrayAttr
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
This class represents a listener that may be used to hook into various actions within an OpBuilder.
Definition Builders.h:287
virtual void notifyBlockInserted(Block *block, Region *previous, Region::iterator previousIt)
Notify the listener that the specified block was inserted.
Definition Builders.h:310
This represents an operation in an abstracted form, suitable for use with the builder APIs.