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