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