MLIR  18.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"
12 #include "mlir/IR/BuiltinTypes.h"
13 #include "mlir/IR/Dialect.h"
14 #include "mlir/IR/IRMapping.h"
15 #include "mlir/IR/IntegerSet.h"
16 #include "mlir/IR/Matchers.h"
17 #include "mlir/IR/SymbolTable.h"
18 #include "llvm/ADT/SmallVectorExtras.h"
19 #include "llvm/Support/raw_ostream.h"
20 
21 using namespace mlir;
22 
23 //===----------------------------------------------------------------------===//
24 // Locations.
25 //===----------------------------------------------------------------------===//
26 
28 
30  return FusedLoc::get(locs, metadata, context);
31 }
32 
33 //===----------------------------------------------------------------------===//
34 // Types.
35 //===----------------------------------------------------------------------===//
36 
39 }
40 
43 }
44 
47 }
48 
51 }
52 
55 }
56 
58 
60 
62 
64 
66 
68 
70 
72 
73 IntegerType Builder::getI1Type() { return IntegerType::get(context, 1); }
74 
75 IntegerType Builder::getI2Type() { return IntegerType::get(context, 2); }
76 
77 IntegerType Builder::getI4Type() { return IntegerType::get(context, 4); }
78 
79 IntegerType Builder::getI8Type() { return IntegerType::get(context, 8); }
80 
81 IntegerType Builder::getI16Type() { return IntegerType::get(context, 16); }
82 
83 IntegerType Builder::getI32Type() { return IntegerType::get(context, 32); }
84 
85 IntegerType Builder::getI64Type() { return IntegerType::get(context, 64); }
86 
87 IntegerType Builder::getIntegerType(unsigned width) {
88  return IntegerType::get(context, width);
89 }
90 
91 IntegerType Builder::getIntegerType(unsigned width, bool isSigned) {
92  return IntegerType::get(
93  context, width, isSigned ? IntegerType::Signed : IntegerType::Unsigned);
94 }
95 
96 FunctionType Builder::getFunctionType(TypeRange inputs, TypeRange results) {
97  return FunctionType::get(context, inputs, results);
98 }
99 
100 TupleType Builder::getTupleType(TypeRange elementTypes) {
101  return TupleType::get(context, elementTypes);
102 }
103 
105 
106 //===----------------------------------------------------------------------===//
107 // Attributes.
108 //===----------------------------------------------------------------------===//
109 
111  return NamedAttribute(getStringAttr(name), val);
112 }
113 
115 
117  return BoolAttr::get(context, value);
118 }
119 
121  return DictionaryAttr::get(context, value);
122 }
123 
124 IntegerAttr Builder::getIndexAttr(int64_t value) {
125  return IntegerAttr::get(getIndexType(), APInt(64, value));
126 }
127 
128 IntegerAttr Builder::getI64IntegerAttr(int64_t value) {
129  return IntegerAttr::get(getIntegerType(64), APInt(64, value));
130 }
131 
134  VectorType::get(static_cast<int64_t>(values.size()), getI1Type()),
135  values);
136 }
137 
140  VectorType::get(static_cast<int64_t>(values.size()), getIntegerType(32)),
141  values);
142 }
143 
146  VectorType::get(static_cast<int64_t>(values.size()), getIntegerType(64)),
147  values);
148 }
149 
152  VectorType::get(static_cast<int64_t>(values.size()), getIndexType()),
153  values);
154 }
155 
158  VectorType::get(static_cast<float>(values.size()), getF32Type()), values);
159 }
160 
163  VectorType::get(static_cast<double>(values.size()), getF64Type()),
164  values);
165 }
166 
168  return DenseBoolArrayAttr::get(context, values);
169 }
170 
172  return DenseI8ArrayAttr::get(context, values);
173 }
174 
176  return DenseI16ArrayAttr::get(context, values);
177 }
178 
180  return DenseI32ArrayAttr::get(context, values);
181 }
182 
184  return DenseI64ArrayAttr::get(context, values);
185 }
186 
188  return DenseF32ArrayAttr::get(context, values);
189 }
190 
192  return DenseF64ArrayAttr::get(context, values);
193 }
194 
197  RankedTensorType::get(static_cast<int64_t>(values.size()),
198  getIntegerType(32)),
199  values);
200 }
201 
204  RankedTensorType::get(static_cast<int64_t>(values.size()),
205  getIntegerType(64)),
206  values);
207 }
208 
211  RankedTensorType::get(static_cast<int64_t>(values.size()),
212  getIndexType()),
213  values);
214 }
215 
216 IntegerAttr Builder::getI32IntegerAttr(int32_t value) {
217  return IntegerAttr::get(getIntegerType(32), APInt(32, value));
218 }
219 
220 IntegerAttr Builder::getSI32IntegerAttr(int32_t value) {
221  return IntegerAttr::get(getIntegerType(32, /*isSigned=*/true),
222  APInt(32, value, /*isSigned=*/true));
223 }
224 
225 IntegerAttr Builder::getUI32IntegerAttr(uint32_t value) {
226  return IntegerAttr::get(getIntegerType(32, /*isSigned=*/false),
227  APInt(32, (uint64_t)value, /*isSigned=*/false));
228 }
229 
230 IntegerAttr Builder::getI16IntegerAttr(int16_t value) {
231  return IntegerAttr::get(getIntegerType(16), APInt(16, value));
232 }
233 
234 IntegerAttr Builder::getI8IntegerAttr(int8_t value) {
235  return IntegerAttr::get(getIntegerType(8), APInt(8, value));
236 }
237 
238 IntegerAttr Builder::getIntegerAttr(Type type, int64_t value) {
239  if (type.isIndex())
240  return IntegerAttr::get(type, APInt(64, value));
241  return IntegerAttr::get(
242  type, APInt(type.getIntOrFloatBitWidth(), value, type.isSignedInteger()));
243 }
244 
245 IntegerAttr Builder::getIntegerAttr(Type type, const APInt &value) {
246  return IntegerAttr::get(type, value);
247 }
248 
249 FloatAttr Builder::getF64FloatAttr(double value) {
250  return FloatAttr::get(getF64Type(), APFloat(value));
251 }
252 
253 FloatAttr Builder::getF32FloatAttr(float value) {
254  return FloatAttr::get(getF32Type(), APFloat(value));
255 }
256 
257 FloatAttr Builder::getF16FloatAttr(float value) {
258  return FloatAttr::get(getF16Type(), value);
259 }
260 
261 FloatAttr Builder::getFloatAttr(Type type, double value) {
262  return FloatAttr::get(type, value);
263 }
264 
265 FloatAttr Builder::getFloatAttr(Type type, const APFloat &value) {
266  return FloatAttr::get(type, value);
267 }
268 
269 StringAttr Builder::getStringAttr(const Twine &bytes) {
270  return StringAttr::get(context, bytes);
271 }
272 
274  return ArrayAttr::get(context, value);
275 }
276 
278  auto attrs = llvm::map_to_vector<8>(
279  values, [this](bool v) -> Attribute { return getBoolAttr(v); });
280  return getArrayAttr(attrs);
281 }
282 
284  auto attrs = llvm::map_to_vector<8>(
285  values, [this](int32_t v) -> Attribute { return getI32IntegerAttr(v); });
286  return getArrayAttr(attrs);
287 }
289  auto attrs = llvm::map_to_vector<8>(
290  values, [this](int64_t v) -> Attribute { return getI64IntegerAttr(v); });
291  return getArrayAttr(attrs);
292 }
293 
295  auto attrs = llvm::map_to_vector<8>(values, [this](int64_t v) -> Attribute {
297  });
298  return getArrayAttr(attrs);
299 }
300 
302  auto attrs = llvm::map_to_vector<8>(
303  values, [this](float v) -> Attribute { return getF32FloatAttr(v); });
304  return getArrayAttr(attrs);
305 }
306 
308  auto attrs = llvm::map_to_vector<8>(
309  values, [this](double v) -> Attribute { return getF64FloatAttr(v); });
310  return getArrayAttr(attrs);
311 }
312 
314  auto attrs = llvm::map_to_vector<8>(
315  values, [this](StringRef v) -> Attribute { return getStringAttr(v); });
316  return getArrayAttr(attrs);
317 }
318 
320  auto attrs = llvm::map_to_vector<8>(
321  values, [](Type v) -> Attribute { return TypeAttr::get(v); });
322  return getArrayAttr(attrs);
323 }
324 
326  auto attrs = llvm::map_to_vector<8>(
327  values, [](AffineMap v) -> Attribute { return AffineMapAttr::get(v); });
328  return getArrayAttr(attrs);
329 }
330 
331 TypedAttr Builder::getZeroAttr(Type type) {
332  if (llvm::isa<FloatType>(type))
333  return getFloatAttr(type, 0.0);
334  if (llvm::isa<IndexType>(type))
335  return getIndexAttr(0);
336  if (llvm::dyn_cast<IntegerType>(type))
337  return getIntegerAttr(type,
338  APInt(llvm::cast<IntegerType>(type).getWidth(), 0));
339  if (llvm::isa<RankedTensorType, VectorType>(type)) {
340  auto vtType = llvm::cast<ShapedType>(type);
341  auto element = getZeroAttr(vtType.getElementType());
342  if (!element)
343  return {};
344  return DenseElementsAttr::get(vtType, element);
345  }
346  return {};
347 }
348 
349 //===----------------------------------------------------------------------===//
350 // Affine Expressions, Affine Maps, and Integer Sets.
351 //===----------------------------------------------------------------------===//
352 
354  return mlir::getAffineDimExpr(position, context);
355 }
356 
358  return mlir::getAffineSymbolExpr(position, context);
359 }
360 
362  return mlir::getAffineConstantExpr(constant, context);
363 }
364 
366 
368  return AffineMap::get(/*dimCount=*/0, /*symbolCount=*/0,
369  getAffineConstantExpr(val));
370 }
371 
373  return AffineMap::get(/*dimCount=*/1, /*symbolCount=*/0, getAffineDimExpr(0));
374 }
375 
378  dimExprs.reserve(rank);
379  for (unsigned i = 0; i < rank; ++i)
380  dimExprs.push_back(getAffineDimExpr(i));
381  return AffineMap::get(/*dimCount=*/rank, /*symbolCount=*/0, dimExprs,
382  context);
383 }
384 
386  return AffineMap::get(/*dimCount=*/0, /*symbolCount=*/1,
388 }
389 
391  // expr = d0 + shift.
392  auto expr = getAffineDimExpr(0) + shift;
393  return AffineMap::get(/*dimCount=*/1, /*symbolCount=*/0, expr);
394 }
395 
397  SmallVector<AffineExpr, 4> shiftedResults;
398  shiftedResults.reserve(map.getNumResults());
399  for (auto resultExpr : map.getResults())
400  shiftedResults.push_back(resultExpr + shift);
401  return AffineMap::get(map.getNumDims(), map.getNumSymbols(), shiftedResults,
402  context);
403 }
404 
405 //===----------------------------------------------------------------------===//
406 // OpBuilder
407 //===----------------------------------------------------------------------===//
408 
409 /// Insert the given operation at the current insertion point and return it.
411  if (block)
412  block->getOperations().insert(insertPoint, op);
413 
414  if (listener)
416  return op;
417 }
418 
420  TypeRange argTypes, ArrayRef<Location> locs) {
421  assert(parent && "expected valid parent region");
422  assert(argTypes.size() == locs.size() && "argument location mismatch");
423  if (insertPt == Region::iterator())
424  insertPt = parent->end();
425 
426  Block *b = new Block();
427  b->addArguments(argTypes, locs);
428  parent->getBlocks().insert(insertPt, b);
430 
431  if (listener)
433  return b;
434 }
435 
436 /// Add new block with 'argTypes' arguments and set the insertion point to the
437 /// end of it. The block is placed before 'insertBefore'.
438 Block *OpBuilder::createBlock(Block *insertBefore, TypeRange argTypes,
439  ArrayRef<Location> locs) {
440  assert(insertBefore && "expected valid insertion block");
441  return createBlock(insertBefore->getParent(), Region::iterator(insertBefore),
442  argTypes, locs);
443 }
444 
445 /// Create an operation given the fields represented as an OperationState.
447  return insert(Operation::create(state));
448 }
449 
450 /// Creates an operation with the given fields.
451 Operation *OpBuilder::create(Location loc, StringAttr opName,
452  ValueRange operands, TypeRange types,
453  ArrayRef<NamedAttribute> attributes,
454  BlockRange successors,
455  MutableArrayRef<std::unique_ptr<Region>> regions) {
456  OperationState state(loc, opName, operands, types, attributes, successors,
457  regions);
458  return create(state);
459 }
460 
461 /// Attempts to fold the given operation and places new results within
462 /// 'results'. Returns success if the operation was folded, failure otherwise.
463 /// Note: This function does not erase the operation on a successful fold.
466  ResultRange opResults = op->getResults();
467 
468  results.reserve(opResults.size());
469  auto cleanupFailure = [&] {
470  results.assign(opResults.begin(), opResults.end());
471  return failure();
472  };
473 
474  // If this operation is already a constant, there is nothing to do.
475  if (matchPattern(op, m_Constant()))
476  return cleanupFailure();
477 
478  // Try to fold the operation.
479  SmallVector<OpFoldResult, 4> foldResults;
480  if (failed(op->fold(foldResults)) || foldResults.empty())
481  return cleanupFailure();
482 
483  // A temporary builder used for creating constants during folding.
484  OpBuilder cstBuilder(context);
485  SmallVector<Operation *, 1> generatedConstants;
486 
487  // Populate the results with the folded results.
488  Dialect *dialect = op->getDialect();
489  for (auto it : llvm::zip(foldResults, opResults.getTypes())) {
490  Type expectedType = std::get<1>(it);
491 
492  // Normal values get pushed back directly.
493  if (auto value = llvm::dyn_cast_if_present<Value>(std::get<0>(it))) {
494  if (value.getType() != expectedType)
495  return cleanupFailure();
496 
497  results.push_back(value);
498  continue;
499  }
500 
501  // Otherwise, try to materialize a constant operation.
502  if (!dialect)
503  return cleanupFailure();
504 
505  // Ask the dialect to materialize a constant operation for this value.
506  Attribute attr = std::get<0>(it).get<Attribute>();
507  auto *constOp = dialect->materializeConstant(cstBuilder, attr, expectedType,
508  op->getLoc());
509  if (!constOp) {
510  // Erase any generated constants.
511  for (Operation *cst : generatedConstants)
512  cst->erase();
513  return cleanupFailure();
514  }
515  assert(matchPattern(constOp, m_Constant()));
516 
517  generatedConstants.push_back(constOp);
518  results.push_back(constOp->getResult(0));
519  }
520 
521  // If we were successful, insert any generated constants.
522  for (Operation *cst : generatedConstants)
523  insert(cst);
524 
525  return success();
526 }
527 
529  Operation *newOp = op.clone(mapper);
530  // The `insert` call below handles the notification for inserting `newOp`
531  // itself. But if `newOp` has any regions, we need to notify the listener
532  // about any ops that got inserted inside those regions as part of cloning.
533  if (listener) {
534  auto walkFn = [&](Operation *walkedOp) {
536  };
537  for (Region &region : newOp->getRegions())
538  region.walk(walkFn);
539  }
540  return insert(newOp);
541 }
542 
544  IRMapping mapper;
545  return clone(op, mapper);
546 }
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:44
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
unsigned getNumSymbols() const
Definition: AffineMap.cpp:341
unsigned getNumDims() const
Definition: AffineMap.cpp:337
ArrayRef< AffineExpr > getResults() const
Definition: AffineMap.cpp:350
unsigned getNumResults() const
Definition: AffineMap.cpp:345
Attributes are known-constant values of operations.
Definition: Attributes.h:25
This class provides an abstraction over the different types of ranges over Blocks.
Definition: BlockSupport.h:106
Block represents an ordered list of Operations.
Definition: Block.h:30
iterator_range< args_iterator > addArguments(TypeRange types, ArrayRef< Location > locs)
Add one argument to the argument list for each type specified in the list.
Definition: Block.cpp:154
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
Definition: Block.cpp:26
OpListType & getOperations()
Definition: Block.h:130
Special case of IntegerAttr to represent boolean integers, i.e., signless i1 integers.
static BoolAttr get(MLIRContext *context, bool value)
FloatType getFloat8E5M2Type()
Definition: Builders.cpp:37
IntegerAttr getIndexAttr(int64_t value)
Definition: Builders.cpp:124
AffineMap getSingleDimShiftAffineMap(int64_t shift)
Returns a map that shifts its (single) input dimension by 'shift'.
Definition: Builders.cpp:390
IntegerType getI16Type()
Definition: Builders.cpp:81
UnitAttr getUnitAttr()
Definition: Builders.cpp:114
ArrayAttr getIndexArrayAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:294
DenseF64ArrayAttr getDenseF64ArrayAttr(ArrayRef< double > values)
Definition: Builders.cpp:191
IntegerType getI2Type()
Definition: Builders.cpp:75
FloatType getF80Type()
Definition: Builders.cpp:67
FloatType getF128Type()
Definition: Builders.cpp:69
DenseI8ArrayAttr getDenseI8ArrayAttr(ArrayRef< int8_t > values)
Definition: Builders.cpp:171
IntegerAttr getI32IntegerAttr(int32_t value)
Definition: Builders.cpp:216
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
Definition: Builders.cpp:179
DenseIntElementsAttr getBoolVectorAttr(ArrayRef< bool > values)
Vector-typed DenseIntElementsAttr getters. values must not be empty.
Definition: Builders.cpp:132
FloatType getF32Type()
Definition: Builders.cpp:63
FloatType getTF32Type()
Definition: Builders.cpp:61
TupleType getTupleType(TypeRange elementTypes)
Definition: Builders.cpp:100
IntegerAttr getIntegerAttr(Type type, int64_t value)
Definition: Builders.cpp:238
FloatAttr getF64FloatAttr(double value)
Definition: Builders.cpp:249
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:396
FloatType getFloat8E4M3B11FNUZType()
Definition: Builders.cpp:53
ArrayAttr getI32ArrayAttr(ArrayRef< int32_t > values)
Definition: Builders.cpp:283
DenseI64ArrayAttr getDenseI64ArrayAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:183
FloatAttr getF16FloatAttr(float value)
Definition: Builders.cpp:257
AffineMap getDimIdentityMap()
Definition: Builders.cpp:372
AffineMap getMultiDimIdentityMap(unsigned rank)
Definition: Builders.cpp:376
IntegerAttr getI16IntegerAttr(int16_t value)
Definition: Builders.cpp:230
DenseI16ArrayAttr getDenseI16ArrayAttr(ArrayRef< int16_t > values)
Definition: Builders.cpp:175
AffineExpr getAffineSymbolExpr(unsigned position)
Definition: Builders.cpp:357
DenseFPElementsAttr getF32VectorAttr(ArrayRef< float > values)
Definition: Builders.cpp:156
FloatAttr getFloatAttr(Type type, double value)
Definition: Builders.cpp:261
AffineExpr getAffineConstantExpr(int64_t constant)
Definition: Builders.cpp:361
DenseIntElementsAttr getI32TensorAttr(ArrayRef< int32_t > values)
Tensor-typed DenseIntElementsAttr getters.
Definition: Builders.cpp:195
FunctionType getFunctionType(TypeRange inputs, TypeRange results)
Definition: Builders.cpp:96
IntegerType getI64Type()
Definition: Builders.cpp:85
IntegerType getI32Type()
Definition: Builders.cpp:83
IntegerAttr getI64IntegerAttr(int64_t value)
Definition: Builders.cpp:128
IntegerType getIntegerType(unsigned width)
Definition: Builders.cpp:87
NoneType getNoneType()
Definition: Builders.cpp:104
DenseIntElementsAttr getI64TensorAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:202
BoolAttr getBoolAttr(bool value)
Definition: Builders.cpp:116
IntegerType getI4Type()
Definition: Builders.cpp:77
StringAttr getStringAttr(const Twine &bytes)
Definition: Builders.cpp:269
MLIRContext * context
Definition: Builders.h:201
AffineMap getEmptyAffineMap()
Returns a zero result affine map with no dimensions or symbols: () -> ().
Definition: Builders.cpp:365
IntegerAttr getSI32IntegerAttr(int32_t value)
Signed and unsigned integer attribute getters.
Definition: Builders.cpp:220
TypedAttr getZeroAttr(Type type)
Definition: Builders.cpp:331
FloatType getF16Type()
Definition: Builders.cpp:59
Location getFusedLoc(ArrayRef< Location > locs, Attribute metadata=Attribute())
Definition: Builders.cpp:29
FloatType getBF16Type()
Definition: Builders.cpp:57
AffineExpr getAffineDimExpr(unsigned position)
Definition: Builders.cpp:353
DenseIntElementsAttr getIndexTensorAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:209
AffineMap getConstantAffineMap(int64_t val)
Returns a single constant result affine map with 0 dimensions and 0 symbols.
Definition: Builders.cpp:367
MLIRContext * getContext() const
Definition: Builders.h:55
ArrayAttr getTypeArrayAttr(TypeRange values)
Definition: Builders.cpp:319
DenseIntElementsAttr getI32VectorAttr(ArrayRef< int32_t > values)
Definition: Builders.cpp:138
DenseF32ArrayAttr getDenseF32ArrayAttr(ArrayRef< float > values)
Definition: Builders.cpp:187
FloatType getFloat8E4M3FNType()
Definition: Builders.cpp:41
DenseIntElementsAttr getI64VectorAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:144
AffineMap getSymbolIdentityMap()
Definition: Builders.cpp:385
ArrayAttr getF64ArrayAttr(ArrayRef< double > values)
Definition: Builders.cpp:307
IntegerType getI1Type()
Definition: Builders.cpp:73
DenseFPElementsAttr getF64VectorAttr(ArrayRef< double > values)
Definition: Builders.cpp:161
Location getUnknownLoc()
Definition: Builders.cpp:27
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
Definition: Builders.cpp:273
DenseBoolArrayAttr getDenseBoolArrayAttr(ArrayRef< bool > values)
Tensor-typed DenseArrayAttr getters.
Definition: Builders.cpp:167
FloatType getFloat8E4M3FNUZType()
Definition: Builders.cpp:49
ArrayAttr getI64ArrayAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:288
IndexType getIndexType()
Definition: Builders.cpp:71
IntegerType getI8Type()
Definition: Builders.cpp:79
FloatAttr getF32FloatAttr(float value)
Definition: Builders.cpp:253
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
Definition: Builders.cpp:120
NamedAttribute getNamedAttr(StringRef name, Attribute val)
Definition: Builders.cpp:110
IntegerAttr getUI32IntegerAttr(uint32_t value)
Definition: Builders.cpp:225
FloatType getFloat8E5M2FNUZType()
Definition: Builders.cpp:45
IntegerAttr getI8IntegerAttr(int8_t value)
Definition: Builders.cpp:234
ArrayAttr getF32ArrayAttr(ArrayRef< float > values)
Definition: Builders.cpp:301
FloatType getF64Type()
Definition: Builders.cpp:65
ArrayAttr getBoolArrayAttr(ArrayRef< bool > values)
Definition: Builders.cpp:277
ArrayAttr getStrArrayAttr(ArrayRef< StringRef > values)
Definition: Builders.cpp:313
DenseIntElementsAttr getIndexVectorAttr(ArrayRef< int64_t > values)
Definition: Builders.cpp:150
ArrayAttr getAffineMapArrayAttr(ArrayRef< AffineMap > values)
Definition: Builders.cpp:325
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:41
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:86
static FloatType getF64(MLIRContext *ctx)
Definition: BuiltinTypes.h:473
static FloatType getFloat8E5M2(MLIRContext *ctx)
Definition: BuiltinTypes.h:437
static FloatType getF80(MLIRContext *ctx)
Definition: BuiltinTypes.h:477
static FloatType getFloat8E4M3FN(MLIRContext *ctx)
Definition: BuiltinTypes.h:441
static FloatType getF16(MLIRContext *ctx)
Definition: BuiltinTypes.h:461
static FloatType getTF32(MLIRContext *ctx)
Definition: BuiltinTypes.h:465
static FloatType getBF16(MLIRContext *ctx)
Definition: BuiltinTypes.h:457
static FloatType getFloat8E4M3FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:449
static FloatType getFloat8E4M3B11FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:453
static FloatType getFloat8E5M2FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:445
static FloatType getF128(MLIRContext *ctx)
Definition: BuiltinTypes.h:481
static FloatType getF32(MLIRContext *ctx)
Definition: BuiltinTypes.h:469
This is a utility class for mapping one set of IR entities to another.
Definition: IRMapping.h:26
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
NamedAttribute represents a combination of a name and an Attribute value.
Definition: Attributes.h:198
This class helps build Operations.
Definition: Builders.h:206
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:528
void setInsertionPointToEnd(Block *block)
Sets the insertion point to the end of the specified block.
Definition: Builders.h:421
Listener * listener
The optional listener for events of this builder.
Definition: Builders.h:572
Block * createBlock(Region *parent, Region::iterator insertPt={}, TypeRange argTypes=std::nullopt, ArrayRef< Location > locs=std::nullopt)
Add new block with 'argTypes' arguments and set the insertion point to the end of it.
Definition: Builders.cpp:419
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition: Builders.cpp:446
LogicalResult tryFold(Operation *op, SmallVectorImpl< Value > &results)
Attempts to fold the given operation and places new results within 'results'.
Definition: Builders.cpp:464
Operation * insert(Operation *op)
Insert the given operation at the current insertion point and return it.
Definition: Builders.cpp:410
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
LogicalResult fold(ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
Attempt to fold this operation with the specified constant operand values.
Definition: Operation.cpp:610
Dialect * getDialect()
Return the dialect this operation is associated with, or nullptr if the associated dialect is not loa...
Definition: Operation.h:220
Operation * clone(IRMapping &mapper, CloneOptions options=CloneOptions::all())
Create a deep copy of this operation, remapping any operands that use values outside of the operation...
Definition: Operation.cpp:686
Location getLoc()
The source location the operation was defined or derived from.
Definition: Operation.h:223
static Operation * create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, NamedAttrList &&attributes, OpaqueProperties properties, BlockRange successors, unsigned numRegions)
Create a new Operation with the specific fields.
Definition: Operation.cpp:66
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
Definition: Operation.h:655
result_range getResults()
Definition: Operation.h:410
void erase()
Remove this operation from its parent block and delete it.
Definition: Operation.cpp:538
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
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:233
type_range getTypes() const
Definition: ValueRange.cpp:35
This class provides an abstraction over the various different ranges of value types.
Definition: TypeRange.h:36
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:77
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:123
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:372
Base class for DenseArrayAttr that is instantiated and specialized for each supported element type be...
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< T > content)
Builder from ArrayRef<T>.
This header declares functions that assist transformations in the MemRef dialect.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
Definition: Matchers.h:401
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
AffineExpr getAffineConstantExpr(int64_t constant, MLIRContext *context)
Definition: AffineExpr.cpp:527
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
detail::constant_op_matcher m_Constant()
Matches a constant foldable operation.
Definition: Matchers.h:310
AffineExpr getAffineDimExpr(unsigned position, MLIRContext *context)
These free functions allow clients of the API to not use classes in detail.
Definition: AffineExpr.cpp:502
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
AffineExpr getAffineSymbolExpr(unsigned position, MLIRContext *context)
Definition: AffineExpr.cpp:512
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
virtual void notifyBlockCreated(Block *block)
Notification handler for when a block is created using the builder.
Definition: Builders.h:294
virtual void notifyOperationInserted(Operation *op)
Notification handler for when an operation is inserted into the builder.
Definition: Builders.h:290
This represents an operation in an abstracted form, suitable for use with the builder APIs.