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