MLIR: include/mlir/IR/OperationSupport.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #ifndef MLIR_IR_OPERATIONSUPPORT_H
15 #define MLIR_IR_OPERATIONSUPPORT_H
16
27 #include "llvm/ADT/BitmaskEnum.h"
28 #include "llvm/ADT/PointerUnion.h"
29 #include "llvm/ADT/STLFunctionalExtras.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include "llvm/Support/PointerLikeTypeTraits.h"
32 #include "llvm/Support/TrailingObjects.h"
33 #include
34 #include
35
36 namespace llvm {
37 class BitVector;
38 }
39
40 namespace mlir {
41 class Dialect;
42 class DictionaryAttr;
43 class ElementsAttr;
44 struct EmptyProperties;
45 class MutableOperandRangeRange;
46 class NamedAttrList;
47 class Operation;
48 struct OperationState;
49 class OpAsmParser;
50 class OpAsmPrinter;
51 class OperandRange;
52 class OperandRangeRange;
53 class OpFoldResult;
54 class Pattern;
55 class Region;
56 class ResultRange;
57 class RewritePattern;
58 class RewritePatternSet;
61 class ValueRange;
62 template
63 class ValueTypeRange;
64
65
66
67
68
69
70
72 public:
74 operator bool() const { return properties != nullptr; }
75 template
77 return static_cast<Dest>(const_cast<void *>(properties));
78 }
79
80 private:
81 void *properties;
82 };
83
84
85
86
87
89 public:
90 using FoldHookFn = llvm::unique_function<LogicalResult(
95
96
102 llvm::unique_function<LogicalResult(Operation *) const>;
104 llvm::unique_function<LogicalResult(Operation *) const>;
105
106
107
108
109
123
125 StringRef name) = 0;
129 virtual LogicalResult
138 virtual LogicalResult
145 };
146
147 public:
149 public:
156
157
164
165 protected:
166
167
168
169
171
172
174
175
176
177
178
180
181
183
184
185
186
188
190 };
191
192 protected:
193
205
207 StringRef name) final;
210 LogicalResult
219 LogicalResult
226 };
227
228 public:
230
231
233
234
235
237
238
239
240 std::optional getRegisteredInfo() const;
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
264 }
265
266
267
271 }
272
273
274
275
276 template <template class Trait>
278 return hasTrait(TypeID::get());
279 }
281
282
283
284
285 template <template class Trait>
288 }
291 }
292
293
296 }
297
298
299
302 }
303
304
306 StringRef defaultDialect) const {
308 }
309
310
311
312
315 }
318 }
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
338 }
339
340
341
342
343 template
346 }
347
348
349
350 template <typename... Models>
352
355 ...);
356
358 }
359
360
361
362 template
366 hasInterface();
367 }
368
369
370 template
373 }
376 }
377
378
379
380
381 template
384 }
387 }
388
389
390
392 StringRef name) const {
394 }
395
398 }
399
402 }
403
404
405
406 LogicalResult
410 }
411
414 }
415
416
419 }
420
421
424 }
425
426
429 }
430
431
434 }
435
436
442 }
443
446 }
447
450 }
451
454 }
455
456
457
461 }
462
463
465
466
468
469
471
472
474
475
477
478 void print(raw_ostream &os) const;
479 void dump() const;
480
481
482
486 const_cast<Impl *>(reinterpret_cast<const Impl *>(pointer)));
487 }
488
491
492 protected:
496
497 private:
498
499 Impl *impl = nullptr;
500
501
505 };
506
509 return os;
510 }
511
512
515 }
516
517
518
519
520
521
522
523
524
526 public:
527
528
529 template
532 : Impl(ConcreteOp::getOperationName(), dialect,
536 return ConcreteOp::getFoldHookFn()(op, attrs, results);
537 }
540 ConcreteOp::getCanonicalizationPatterns(set, context);
541 }
542 bool hasTrait(TypeID id) final { return ConcreteOp::getHasTraitFn()(id); }
545 }
548 ConcreteOp::populateDefaultAttrs(name, attrs);
549 }
551 StringRef name) final {
552 ConcreteOp::getPrintAssemblyFn()(op, printer, name);
553 }
555 return ConcreteOp::getVerifyInvariantsFn()(op);
556 }
558 return ConcreteOp::getVerifyRegionInvariantsFn()(op);
559 }
560
561
562
564 decltype(std::declval().getProperties())>;
565
567 StringRef name) final {
569 auto concreteOp = cast(op);
570 return ConcreteOp::getInherentAttr(concreteOp->getContext(),
571 concreteOp.getProperties(), name);
572 }
573
574
575 return cast(op)->getDiscardableAttr(name);
576 }
580 auto concreteOp = cast(op);
581 return ConcreteOp::setInherentAttr(concreteOp.getProperties(), name,
582 value);
583 }
584
585
586 return cast(op)->setDiscardableAttr(name, value);
587 }
590 auto concreteOp = cast(op);
591 ConcreteOp::populateInherentAttrs(concreteOp->getContext(),
592 concreteOp.getProperties(), attrs);
593 }
594 }
595 LogicalResult
599 return ConcreteOp::verifyInherentAttrs(opName, attributes, emitError);
600 return success();
601 }
602
604 typename ConcreteOp::template InferredProperties,
606
610 return 0;
611 }
615 typename ConcreteOp::template InferredProperties;
616 if (init)
618 else
621 ConcreteOp::populateDefaultProperties(opName,
623 }
626 }
630 ConcreteOp::populateDefaultProperties(opName,
632 }
633
634 LogicalResult
640 return ConcreteOp::setPropertiesFromAttr(*p, attr, emitError);
641 }
642 emitError() << "this operation does not support properties";
643 return failure();
644 }
647 auto concreteOp = cast(op);
648 return ConcreteOp::getPropertiesAsAttr(concreteOp->getContext(),
649 concreteOp.getProperties());
650 }
651 return {};
652 }
656 } else {
657 return true;
658 }
659 }
662 }
665 return ConcreteOp::computePropertiesHash(*prop.as<Properties *>());
666
667 return {};
668 }
669 };
670
671
672
673 static std::optional lookup(StringRef name,
675
676
677
678 static std::optional lookup(TypeID typeID,
680
681
682
683
684 template
686 insert(std::make_unique<Model>(&dialect), T::getAttributeNames());
687 }
688
689
690 static void insert(std::unique_ptrOperationName::Impl ownedImpl,
692
693
695
696
697
700 const_cast<Impl *>(reinterpret_cast<const Impl *>(pointer)));
701 }
702
703 private:
705
706
707 friend OperationName;
708 };
709
710 inline std::optional
713 : std::optional();
714 }
715
716
717
718
719
720
721
722 namespace impl {
723
724
725 template <typename IteratorT, typename NameT>
726 std::pair<IteratorT, bool> findAttrUnsorted(IteratorT first, IteratorT last,
727 NameT name) {
728 for (auto it = first; it != last; ++it)
729 if (it->getName() == name)
730 return {it, true};
731 return {last, false};
732 }
733
734
735
736
737
738 template
739 std::pair<IteratorT, bool> findAttrSorted(IteratorT first, IteratorT last,
740 StringRef name) {
741 ptrdiff_t length = std::distance(first, last);
742
743 while (length > 0) {
744 ptrdiff_t half = length / 2;
745 IteratorT mid = first + half;
746 int compare = mid->getName().strref().compare(name);
748 first = mid + 1;
749 length = length - half - 1;
750 } else if (compare > 0) {
751 length = half;
752 } else {
753 return {mid, true};
754 }
755 }
756 return {first, false};
757 }
758
759
760
761
762 template
763 std::pair<IteratorT, bool> findAttrSorted(IteratorT first, IteratorT last,
764 StringAttr name) {
765 constexpr unsigned kSmallAttributeList = 16;
766 if (std::distance(first, last) > kSmallAttributeList)
769 }
770
771
772
773 template <typename IteratorT, typename NameT>
775 std::pair<IteratorT, bool> result = findAttrSorted(first, last, name);
776 return result.second ? result.first->getValue() : Attribute();
777 }
778
779
780
781 template <typename IteratorT, typename NameT>
782 std::optional
784 std::pair<IteratorT, bool> result = findAttrSorted(first, last, name);
785 return result.second ? *result.first : std::optional();
786 }
787
788 }
789
790
791
792
793
794
795
797 public:
803
809
810 template
813
815 return !(*this == other);
816 }
818 return attrs == other.attrs;
819 }
820
821
824 }
825
826
829 }
830
831
833
834
835 template
836 void append(RangeT &&newAttributes) {
837 append(std::begin(newAttributes), std::end(newAttributes));
838 }
839
840
841 template <typename IteratorT,
842 typename = std::enable_if_t<std::is_convertible<
843 typename std::iterator_traits::iterator_category,
844 std::input_iterator_tag>::value>>
845 void append(IteratorT inStart, IteratorT inEnd) {
846
847
848 dictionarySorted.setPointerAndInt(nullptr, false);
849 attrs.append(inStart, inEnd);
850 }
851
852
854
855
857 assign(range.begin(), range.end());
858 }
859
861 attrs.clear();
862 dictionarySorted.setPointerAndInt(nullptr, false);
863 }
864
865 bool empty() const { return attrs.empty(); }
866
868
869
871
872
874
875
876
877 std::optional findDuplicate() const;
878
879
880
882
883
885
886
889
890
891 std::optional getNamed(StringRef name) const;
892 std::optional getNamed(StringAttr name) const;
893
894
895
896
897
900
901
902
903
906
911
914
915 private:
916
917 bool isSorted() const { return dictionarySorted.getInt(); }
918
919
920 Attribute eraseImpl(SmallVectorImpl::iterator it);
921
922
923 template <typename AttrListT, typename NameT>
924 static auto findAttr(AttrListT &attrs, NameT name) {
925 return attrs.isSorted()
928 }
929
930
931 mutable SmallVector<NamedAttribute, 4> attrs;
932
933
934
935
936 mutable llvm::PointerIntPair<Attribute, 1, bool> dictionarySorted;
937 };
938
939
940
941
942
943
944
945
946
951
954
956
958
959
960
961
962
963
964
966
967 private:
972 propertiesSetter;
974
975 public:
978
982 MutableArrayRef<std::unique_ptr> regions = {});
984 TypeRange types, ArrayRef attributes = {},
986 MutableArrayRef<std::unique_ptr> regions = {});
992
993
994
995 template
997 if (!properties) {
998 T *p = new T{};
999 properties = p;
1000 #if defined(__clang__)
1001 #if __has_warning("-Wdangling-assignment-gsl")
1002 #pragma clang diagnostic push
1003
1004 #pragma clang diagnostic ignored "-Wdangling-assignment-gsl"
1005 #endif
1006 #endif
1008 delete prop.as<const T *>();
1009 };
1012 *newProp.as<T *>() = *prop.as<const T *>();
1013 };
1014 #if defined(__clang__)
1015 #if __has_warning("-Wdangling-assignment-gsl")
1016 #pragma clang diagnostic pop
1017 #endif
1018 #endif
1019 propertiesId = TypeID::get();
1020 }
1021 assert(propertiesId == TypeID::get() && "Inconsistent properties");
1022 return *properties.as<T *>();
1023 }
1025
1026
1027
1028 LogicalResult
1031
1032
1033
1034
1035
1036
1037 template
1039 assert(!properties &&
1040 "Can't provide a properties struct when one has been allocated");
1041 properties = &newProperties;
1042 #if defined(__clang__)
1043 #if __has_warning("-Wdangling-assignment-gsl")
1044 #pragma clang diagnostic push
1045
1046 #pragma clang diagnostic ignored "-Wdangling-assignment-gsl"
1047 #endif
1048 #endif
1052 *newProp.as<T *>() = *prop.as<const T *>();
1053 };
1054 #if defined(__clang__)
1055 #if __has_warning("-Wdangling-assignment-gsl")
1056 #pragma clang diagnostic pop
1057 #endif
1058 #endif
1059 propertiesId = TypeID::get();
1060 }
1061
1063
1065 types.append(newTypes.begin(), newTypes.end());
1066 }
1067 template
1068 std::enable_if_t<!std::is_convertible<RangeT, ArrayRef>::value>
1070 types.append(newTypes.begin(), newTypes.end());
1071 }
1072
1073
1076 }
1077
1078
1079
1081 assert(name && "attribute name cannot be null");
1082 assert(attr && "attribute cannot be null");
1084 }
1085
1086
1089 }
1090
1091
1093 assert(successor && "successor cannot be null");
1095 }
1097
1098
1099
1100
1102
1103
1104
1105
1106 void addRegion(std::unique_ptr &®ion);
1107
1108
1109
1111
1112
1114 };
1115
1116
1117
1118
1119
1120 namespace detail {
1121
1122
1124 public:
1128
1129
1130
1132
1133
1134
1135
1138
1139
1140 void eraseOperands(unsigned start, unsigned length);
1141
1142
1143
1144 void eraseOperands(const BitVector &eraseIndices);
1145
1146
1148
1149
1150 unsigned size() { return numOperands; }
1151
1152 private:
1153
1154
1156
1157
1158 unsigned capacity : 31;
1159
1160
1161 unsigned isStorageDynamic : 1;
1162
1163 unsigned numOperands;
1164
1166 };
1167 }
1168
1169
1170
1171
1172
1173
1174
1176 public:
1179
1180
1181
1182
1183
1184
1186
1187
1188
1189
1190
1193
1194
1195
1196
1197
1199
1200
1201
1202
1203
1205
1206
1208
1209
1211
1212
1214
1215
1216
1217
1218
1220
1221
1223
1224
1225
1227
1228
1230
1231
1233
1234
1236
1237
1239
1240
1242
1243
1245
1246
1248
1249
1251
1252
1254
1255
1257
1258
1260
1261
1263
1264
1266
1267
1269
1270
1271
1273
1274 private:
1275
1276
1277 std::optional<int64_t> elementsAttrElementLimit;
1278
1279
1280 std::optional<uint64_t> resourceStringCharLimit;
1281
1282
1283
1284 int64_t elementsAttrHexElementLimit = 100;
1285
1286
1287 bool printDebugInfoFlag : 1;
1288 bool printDebugInfoPrettyFormFlag : 1;
1289
1290
1291 bool printGenericOpFormFlag : 1;
1292
1293
1294 bool skipRegionsFlag : 1;
1295
1296
1297 bool assumeVerifiedFlag : 1;
1298
1299
1300 bool printLocalScope : 1;
1301
1302
1303 bool printValueUsersFlag : 1;
1304
1305
1306 bool printUniqueSSAIDsFlag : 1;
1307
1308
1309 bool useNameLocAsPrefix : 1;
1310 };
1311
1312
1313
1314
1315
1316
1317
1321
1322
1324
1325
1326
1328
1329
1331
1332 LLVM_MARK_AS_BITMASK_ENUM( IgnoreProperties)
1333 };
1334
1335
1336
1337
1342 function_refllvm::hash\_code(Value) hashResults =
1343 [](Value v) { return hash_value(v); },
1345
1346
1347
1349
1350
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371 static bool
1377 checkCommutativeEquivalent = nullptr);
1378
1379
1381
1382
1383
1390 checkCommutativeEquivalent = nullptr);
1391
1392
1395
1396
1397
1399 return success();
1400 }
1401
1402
1404 return success(lhs == rhs);
1405 }
1406 };
1407
1408
1410
1411
1412
1413
1414
1415
1416
1418 public:
1422
1424 return hash == other.hash;
1425 }
1427 return !(*this == other);
1428 }
1429
1430 private:
1431 std::array<uint8_t, 20> hash;
1432 };
1433
1434 }
1435
1436 namespace llvm {
1437 template <>
1442 }
1446 }
1449 }
1451 return lhs == rhs;
1452 }
1453 };
1454 template <>
1456 : public DenseMapInfomlir::OperationName {
1460 }
1464 }
1465 };
1466
1467 template <>
1468 struct PointerLikeTypeTraits<mlir::OperationName> {
1471 }
1474 }
1475 static constexpr int NumLowBitsAvailable =
1476 PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
1477 };
1478 template <>
1479 struct PointerLikeTypeTraits<mlir::RegisteredOperationName>
1480 : public PointerLikeTypeTraitsmlir::OperationName {
1483 }
1484 };
1485
1486 }
1487
1488 #endif
Attributes are known-constant values of operations.
MLIRContext * getContext() const
Return the context this attribute belongs to.
This class provides an abstraction over the different types of ranges over Blocks.
Block represents an ordered list of Operations.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
This class represents a diagnostic that is inflight and set to be reported.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This is the implementation of the MLIRContext class, using the pImpl idiom.
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
std::optional< NamedAttribute > getNamed(StringRef name) const
Return the specified named attribute if present, std::nullopt otherwise.
void append(IteratorT inStart, IteratorT inEnd)
Add a range of named attributes.
void assign(ArrayRef< NamedAttribute > range)
Replaces the attributes with new list of attributes.
const_iterator begin() const
void assign(const_iterator inStart, const_iterator inEnd)
Replaces the attributes with new list of attributes.
SmallVectorImpl< NamedAttribute >::const_iterator const_iterator
void append(NamedAttribute attr)
Append the given named attribute.
bool operator!=(const NamedAttrList &other) const
ArrayRef< NamedAttribute > getAttrs() const
Return all of the attributes on this operation.
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
void push_back(NamedAttribute newAttribute)
Add an attribute with the specified name.
SmallVectorImpl< NamedAttribute >::iterator iterator
const_iterator end() const
NamedAttrList(const Container &vec)
void append(StringAttr name, Attribute attr)
Add an attribute with the specified name.
void pop_back()
Pop last element from list.
bool operator==(const NamedAttrList &other) const
Attribute get(StringAttr name) const
Return the specified attribute if present, null otherwise.
Attribute erase(StringAttr name)
Erase the attribute with the given name from the list.
void append(StringRef name, Attribute attr)
Add an attribute with the specified name.
std::optional< NamedAttribute > findDuplicate() const
Returns an entry with a duplicate name the list, if it exists, else returns std::nullopt.
Attribute set(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
void append(RangeT &&newAttributes)
Add an array of named attributes.
void reserve(size_type N)
NamedAttrList & operator=(const SmallVectorImpl< NamedAttribute > &rhs)
NamedAttrList(std::nullopt_t none)
NamedAttribute represents a combination of a name and an Attribute value.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class represents an operand of an operation.
Set of flags used to control the behavior of the various IR print methods (e.g.
bool shouldElideElementsAttr(ElementsAttr attr) const
Return if the given ElementsAttr should be elided.
std::optional< int64_t > getLargeElementsAttrLimit() const
Return the size limit for printing large ElementsAttr.
bool shouldUseNameLocAsPrefix() const
Return if the printer should use NameLocs as prefixes when printing SSA IDs.
bool shouldAssumeVerified() const
Return if operation verification should be skipped.
OpPrintingFlags & printLargeElementsAttrWithHex(int64_t largeElementLimit=100)
Enables the printing of large element attributes with a hex string.
bool shouldUseLocalScope() const
Return if the printer should use local scope when dumping the IR.
bool shouldPrintDebugInfoPrettyForm() const
Return if debug information should be printed in the pretty form.
bool shouldPrintElementsAttrWithHex(ElementsAttr attr) const
Return if the given ElementsAttr should be printed as hex string.
bool shouldPrintUniqueSSAIDs() const
Return if printer should use unique SSA IDs.
bool shouldPrintValueUsers() const
Return if the printer should print users of values.
int64_t getLargeElementsAttrHexLimit() const
Return the size limit for printing large ElementsAttr as hex string.
bool shouldPrintGenericOpForm() const
Return if operations should be printed in the generic form.
OpPrintingFlags & elideLargeResourceString(int64_t largeResourceLimit=64)
Enables the elision of large resources strings by omitting them from the dialect_resources section.
bool shouldPrintDebugInfo() const
Return if debug information should be printed.
OpPrintingFlags & elideLargeElementsAttrs(int64_t largeElementLimit=16)
Enables the elision of large elements attributes by printing a lexically valid but otherwise meaningl...
OpPrintingFlags & printNameLocAsPrefix(bool enable=true)
Print SSA IDs using their NameLoc, if provided, as prefix.
OpPrintingFlags & printValueUsers(bool enable=true)
Print users of values as comments.
OpPrintingFlags & enableDebugInfo(bool enable=true, bool prettyForm=false)
Enable or disable printing of debug information (based on enable).
OpPrintingFlags()
Initialize the printing flags with default supplied by the cl::opts above.
bool shouldSkipRegions() const
Return if regions should be skipped.
OpPrintingFlags & printGenericOpForm(bool enable=true)
Always print operations in the generic form.
OpPrintingFlags(std::nullopt_t)
OpPrintingFlags & useLocalScope(bool enable=true)
Use local scope when printing the operation.
std::optional< uint64_t > getLargeResourceStringLimit() const
Return the size limit in chars for printing large resources.
OpPrintingFlags & assumeVerified(bool enable=true)
Do not verify the operation when using custom operation printers.
OpPrintingFlags & skipRegions(bool skip=true)
Skip printing regions.
OpPrintingFlags & printUniqueSSAIDs(bool enable=true)
Print unique SSA ID numbers for values, block arguments and naming conflicts across all regions.
Simple wrapper around a void* in order to express generically how to pass in op properties through AP...
OpaqueProperties(void *prop)
A unique fingerprint for a specific operation, and all of it's internal operations (if includeNested ...
OperationFingerPrint(Operation *topOp, bool includeNested=true)
bool operator!=(const OperationFingerPrint &other) const
OperationFingerPrint & operator=(const OperationFingerPrint &)=default
bool operator==(const OperationFingerPrint &other) const
OperationFingerPrint(const OperationFingerPrint &)=default
Impl(StringAttr name, Dialect *dialect, TypeID typeID, detail::InterfaceMap interfaceMap)
ArrayRef< StringAttr > attributeNames
A list of attribute names registered to this operation in StringAttr form.
StringAttr name
The name of the operation.
ArrayRef< StringAttr > getAttributeNames() const
TypeID typeID
The unique identifier of the derived Op class.
Dialect * getDialect() const
detail::InterfaceMap & getInterfaceMap()
Impl(StringRef, Dialect *dialect, TypeID typeID, detail::InterfaceMap interfaceMap)
Dialect * dialect
The following fields are only populated when the operation is registered.
detail::InterfaceMap interfaceMap
A map of interfaces that were registered to this operation.
bool isRegistered() const
Returns true if this is a registered operation.
StringAttr getName() const
void populateInherentAttrs(Operation *op, NamedAttrList &attrs) const
bool operator==(const OperationName &rhs) const
llvm::unique_function< LogicalResult(Operation *) const > VerifyInvariantsFn
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
bool operator!=(const OperationName &rhs) const
StringRef stripDialect() const
Return the operation name with dialect name stripped, if it has one.
void setInherentAttr(Operation *op, StringAttr name, Attribute value) const
Attribute getOpPropertiesAsAttribute(Operation *op) const
Return the op properties converted to an Attribute.
ArrayRef< StringAttr > getAttributeNames() const
Return the list of cached attribute names registered to this operation.
llvm::unique_function< ParseResult(OpAsmParser &, OperationState &)> ParseAssemblyFn
bool hasTrait() const
Returns true if the operation was registered with a particular trait, e.g.
bool hasPromiseOrImplementsInterface() const
Returns true if InterfaceT has been promised by the dialect or implemented.
llvm::unique_function< bool(TypeID) const > HasTraitFn
std::optional< Attribute > getInherentAttr(Operation *op, StringRef name) const
Lookup an inherent attribute by name, this method isn't recommended and may be removed in the future.
StringAttr getIdentifier() const
Return the name of this operation as a StringAttr.
void getCanonicalizationPatterns(RewritePatternSet &results, MLIRContext *context) const
This hook returns any canonicalization pattern rewrites that the operation supports,...
OperationName(Impl *impl)
ParseAssemblyFn getParseAssemblyFn() const
Return the static hook for parsing this operation assembly.
Dialect * getDialect() const
Return the dialect this operation is registered to if the dialect is loaded in the context,...
OperationName(StringRef name, MLIRContext *context)
StringRef getDialectNamespace() const
Return the name of the dialect this operation is registered to.
llvm::unique_function< LogicalResult(Operation *) const > VerifyRegionInvariantsFn
std::optional< RegisteredOperationName > getRegisteredInfo() const
If this operation is registered, returns the registered information, std::nullopt otherwise.
bool mightHaveTrait() const
Returns true if the operation might have the provided trait.
bool mightHaveTrait(TypeID traitID) const
bool hasInterface() const
Returns true if this operation has the given interface registered to it.
LogicalResult verifyInherentAttrs(NamedAttrList &attributes, function_ref< InFlightDiagnostic()> emitError) const
This method exists for backward compatibility purpose when using properties to store inherent attribu...
void initOpProperties(OpaqueProperties storage, OpaqueProperties init) const
Initialize the op properties.
llvm::unique_function< void(Operation *, OpAsmPrinter &, StringRef) const > PrintAssemblyFn
T::Concept * getInterface() const
Returns an instance of the concept object for the given interface if it was registered to this operat...
llvm::hash_code hashOpProperties(OpaqueProperties properties) const
bool isRegistered() const
Return if this operation is registered.
bool mightHaveInterface() const
Returns true if the operation might have the provided interface.
LogicalResult foldHook(Operation *op, ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results) const
This hook implements a generalized folder for this operation.
bool mightHaveInterface(TypeID interfaceID) const
bool hasTrait(TypeID traitID) const
void * getAsOpaquePointer() const
Represent the operation name as an opaque pointer.
LogicalResult verifyRegionInvariants(Operation *op) const
TypeID getTypeID() const
Return the unique identifier of the derived Op class, or null if not registered.
MLIRContext * getContext()
Return the context this operation is associated with.
void populateDefaultAttrs(NamedAttrList &attrs) const
This hook implements the method to populate defaults attributes that are unset.
llvm::unique_function< LogicalResult(Operation *, ArrayRef< Attribute >, SmallVectorImpl< OpFoldResult > &) const > FoldHookFn
LogicalResult setOpPropertiesFromAttribute(OperationName opName, OpaqueProperties properties, Attribute attr, function_ref< InFlightDiagnostic()> emitError) const
Define the op properties from the provided Attribute.
LogicalResult verifyInvariants(Operation *op) const
These hooks implement the verifiers for this operation.
llvm::unique_function< void(const OperationName &, NamedAttrList &) const > PopulateDefaultAttrsFn
void destroyOpProperties(OpaqueProperties properties) const
This hooks destroy the op properties.
bool compareOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const
int getOpPropertyByteSize() const
This hooks return the number of bytes to allocate for the op properties.
void populateDefaultProperties(OpaqueProperties properties) const
Set the default values on the ODS attribute in the properties.
void printAssembly(Operation *op, OpAsmPrinter &p, StringRef defaultDialect) const
This hook implements the AsmPrinter for this operation.
void print(raw_ostream &os) const
void copyOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const
bool hasInterface(TypeID interfaceID) const
static OperationName getFromOpaquePointer(const void *pointer)
void attachInterface()
Attach the given models as implementations of the corresponding interfaces for the concrete operation...
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This is a "type erased" representation of a registered operation.
static void insert(Dialect &dialect)
Register a new operation in a Dialect object.
static RegisteredOperationName getFromOpaquePointer(const void *pointer)
Represent the operation name as an opaque pointer.
static std::optional< RegisteredOperationName > lookup(StringRef name, MLIRContext *ctx)
Lookup the registered operation information for the given operation.
static void insert(std::unique_ptr< OperationName::Impl > ownedImpl, ArrayRef< StringRef > attrNames)
The use of this method is in general discouraged in favor of 'insert(dialect)'.
Dialect & getDialect() const
Return the dialect this operation is registered to.
This class provides an efficient unique identifier for a specific C++ type.
This class provides an abstraction over the various different ranges of value types.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
This class provides an efficient mapping between a given Interface type, and a particular implementat...
void insertModels()
Insert the given interface models.
bool contains(TypeID interfaceID) const
Returns true if the interface map contains an interface for the given id.
T::Concept * lookup() const
Returns an instance of the concept object for the given interface if it was registered to this map,...
This class handles the management of operation operands.
MutableArrayRef< OpOperand > getOperands()
Get the operation operands held by the storage.
void eraseOperands(unsigned start, unsigned length)
Erase the operands held by the storage within the given range.
unsigned size()
Return the number of operands held in the storage.
void setOperands(Operation *owner, ValueRange values)
Replace the operands contained in the storage with the ones provided in 'values'.
OperandStorage(Operation *owner, OpOperand *trailingOperands, ValueRange values)
The OpAsmOpInterface, see OpAsmInterface.td for more details.
bool hasPromisedInterface(Dialect &dialect, TypeID interfaceRequestorID, TypeID interfaceID)
Checks if a promise has been made for the interface/requestor pair.
void handleAdditionOfUndefinedPromisedInterface(Dialect &dialect, TypeID interfaceRequestorID, TypeID interfaceID)
Checks if the given interface, which is attempting to be attached, is a promised interface of this di...
std::optional< NamedAttribute > getNamedAttrFromSortedRange(IteratorT first, IteratorT last, NameT name)
Get an attribute from a sorted range of named attributes.
Attribute getAttrFromSortedRange(IteratorT first, IteratorT last, NameT name)
Get an attribute from a sorted range of named attributes.
std::pair< IteratorT, bool > findAttrSorted(IteratorT first, IteratorT last, StringRef name)
Using llvm::lower_bound requires an extra string comparison to check whether the returned iterator po...
std::pair< IteratorT, bool > findAttrUnsorted(IteratorT first, IteratorT last, NameT name)
Unsorted string search or identifier lookups are linear scans.
@ Type
An inlay hint that for a type annotation.
int compare(const Fraction &x, const Fraction &y)
Three-way comparison between two fractions.
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
llvm::function_ref< Fn > function_ref
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
llvm::hash_code hash_value(OperationName arg)
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
Enable Bitmask enums for OperationEquivalence::Flags.
static mlir::OperationName getTombstoneKey()
static mlir::OperationName getEmptyKey()
static bool isEqual(mlir::OperationName lhs, mlir::OperationName rhs)
static unsigned getHashValue(mlir::OperationName val)
static mlir::RegisteredOperationName getEmptyKey()
static mlir::RegisteredOperationName getTombstoneKey()
static mlir::OperationName getFromVoidPointer(void *P)
static void * getAsVoidPointer(mlir::OperationName I)
static mlir::RegisteredOperationName getFromVoidPointer(void *P)
Structure used by default as a "marker" when no "Properties" are set on an Operation.
This class provides utilities for computing if two operations are equivalent.
static llvm::hash_code ignoreHashValue(Value)
Helper that can be used with computeHash above to ignore operation operands/result mapping.
static bool isRegionEquivalentTo(Region *lhs, Region *rhs, function_ref< LogicalResult(Value, Value)> checkEquivalent, function_ref< void(Value, Value)> markEquivalent, OperationEquivalence::Flags flags, function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent=nullptr)
Compare two regions (including their subregions) and return if they are equivalent.
static bool isEquivalentTo(Operation *lhs, Operation *rhs, function_ref< LogicalResult(Value, Value)> checkEquivalent, function_ref< void(Value, Value)> markEquivalent=nullptr, Flags flags=Flags::None, function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent=nullptr)
Compare two operations (including their regions) and return if they are equivalent.
static llvm::hash_code directHashValue(Value v)
Helper that can be used with computeHash above to ignore operation operands/result mapping.
static LogicalResult ignoreValueEquivalence(Value lhs, Value rhs)
Helper that can be used with isEquivalentTo above to consider ops equivalent even if their operands a...
static LogicalResult exactValueMatch(Value lhs, Value rhs)
Helper that can be used with isEquivalentTo above to consider ops equivalent only if their operands a...
static llvm::hash_code computeHash(Operation *op, function_ref< llvm::hash_code(Value)> hashOperands=[](Value v) { return hash_value(v);}, function_ref< llvm::hash_code(Value)> hashResults=[](Value v) { return hash_value(v);}, Flags flags=Flags::None)
Compute a hash for the given operation.
This class represents a type erased version of an operation.
virtual void initProperties(OperationName opName, OpaqueProperties storage, OpaqueProperties init)=0
virtual void populateInherentAttrs(Operation *op, NamedAttrList &attrs)=0
virtual void deleteProperties(OpaqueProperties)=0
virtual void getCanonicalizationPatterns(RewritePatternSet &, MLIRContext *)=0
virtual OperationName::ParseAssemblyFn getParseAssemblyFn()=0
virtual void printAssembly(Operation *, OpAsmPrinter &, StringRef)=0
virtual bool hasTrait(TypeID)=0
virtual LogicalResult verifyInvariants(Operation *)=0
virtual void setInherentAttr(Operation *op, StringAttr name, Attribute value)=0
virtual LogicalResult setPropertiesFromAttr(OperationName, OpaqueProperties, Attribute, function_ref< InFlightDiagnostic()> emitError)=0
virtual void populateDefaultProperties(OperationName opName, OpaqueProperties properties)=0
virtual Attribute getPropertiesAsAttr(Operation *)=0
virtual int getOpPropertyByteSize()=0
virtual LogicalResult foldHook(Operation *, ArrayRef< Attribute >, SmallVectorImpl< OpFoldResult > &)=0
virtual bool compareProperties(OpaqueProperties, OpaqueProperties)=0
virtual void copyProperties(OpaqueProperties, OpaqueProperties)=0
virtual void populateDefaultAttrs(const OperationName &, NamedAttrList &)=0
virtual LogicalResult verifyInherentAttrs(OperationName opName, NamedAttrList &attributes, function_ref< InFlightDiagnostic()> emitError)=0
virtual llvm::hash_code hashProperties(OpaqueProperties)=0
virtual ~InterfaceConcept()=default
virtual std::optional< Attribute > getInherentAttr(Operation *, StringRef name)=0
Implementation for properties.
virtual LogicalResult verifyRegionInvariants(Operation *)=0
Default implementation for unregistered operations.
LogicalResult foldHook(Operation *, ArrayRef< Attribute >, SmallVectorImpl< OpFoldResult > &) final
llvm::hash_code hashProperties(OpaqueProperties) final
void populateInherentAttrs(Operation *op, NamedAttrList &attrs) final
void deleteProperties(OpaqueProperties) final
LogicalResult setPropertiesFromAttr(OperationName, OpaqueProperties, Attribute, function_ref< InFlightDiagnostic()> emitError) final
int getOpPropertyByteSize() final
void setInherentAttr(Operation *op, StringAttr name, Attribute value) final
void populateDefaultProperties(OperationName opName, OpaqueProperties properties) final
OperationName::ParseAssemblyFn getParseAssemblyFn() final
bool hasTrait(TypeID) final
LogicalResult verifyRegionInvariants(Operation *) final
std::optional< Attribute > getInherentAttr(Operation *op, StringRef name) final
Implementation for properties.
void getCanonicalizationPatterns(RewritePatternSet &, MLIRContext *) final
void initProperties(OperationName opName, OpaqueProperties storage, OpaqueProperties init) final
void populateDefaultAttrs(const OperationName &, NamedAttrList &) final
void printAssembly(Operation *, OpAsmPrinter &, StringRef) final
LogicalResult verifyInvariants(Operation *) final
void copyProperties(OpaqueProperties, OpaqueProperties) final
LogicalResult verifyInherentAttrs(OperationName opName, NamedAttrList &attributes, function_ref< InFlightDiagnostic()> emitError) final
Attribute getPropertiesAsAttr(Operation *) final
bool compareProperties(OpaqueProperties, OpaqueProperties) final
This represents an operation in an abstracted form, suitable for use with the builder APIs.
void addRegions(MutableArrayRef< std::unique_ptr< Region >> regions)
Take ownership of a set of regions that should be attached to the Operation.
OpaqueProperties getRawProperties()
SmallVector< Block *, 1 > successors
Successors of this operation and their respective operands.
OperationState & operator=(const OperationState &other)=delete
T & getOrAddProperties()
Get (or create) a properties of the provided type to be set on the operation on creation.
SmallVector< Value, 4 > operands
void addOperands(ValueRange newOperands)
void addAttributes(ArrayRef< NamedAttribute > newAttributes)
Add an array of named attributes.
void addAttribute(StringRef name, Attribute attr)
Add an attribute with the specified name.
void addAttribute(StringAttr name, Attribute attr)
Add an attribute with the specified name.
std::enable_if_t<!std::is_convertible< RangeT, ArrayRef< Type > >::value > addTypes(RangeT &&newTypes)
void addSuccessors(Block *successor)
Adds a successor to the operation sate. successor must not be null.
void addTypes(ArrayRef< Type > newTypes)
OperationState(OperationState &&other)=default
OperationState(const OperationState &other)=delete
SmallVector< std::unique_ptr< Region >, 1 > regions
Regions that the op will hold.
OperationState(Location location, StringRef name)
void useProperties(T &newProperties)
Attribute propertiesAttr
This Attribute is used to opaquely construct the properties of the operation.
MLIRContext * getContext() const
Get the context held by this operation state.
SmallVector< Type, 4 > types
Types of the results of this operation.
Region * addRegion()
Create a region that should be attached to the operation.
OperationState & operator=(OperationState &&other)=default
LogicalResult setProperties(Operation *op, function_ref< InFlightDiagnostic()> emitError) const
Implementation of the InterfaceConcept for operation APIs that forwarded to a concrete op implementat...
void initProperties(OperationName opName, OpaqueProperties storage, OpaqueProperties init) final
LogicalResult setPropertiesFromAttr(OperationName opName, OpaqueProperties properties, Attribute attr, function_ref< InFlightDiagnostic()> emitError) final
void copyProperties(OpaqueProperties lhs, OpaqueProperties rhs) final
bool hasTrait(TypeID id) final
void populateDefaultAttrs(const OperationName &name, NamedAttrList &attrs) final
OperationName::ParseAssemblyFn getParseAssemblyFn() final
LogicalResult verifyInvariants(Operation *op) final
void getCanonicalizationPatterns(RewritePatternSet &set, MLIRContext *context) final
LogicalResult verifyRegionInvariants(Operation *op) final
int getOpPropertyByteSize() final
void printAssembly(Operation *op, OpAsmPrinter &printer, StringRef name) final
void populateInherentAttrs(Operation *op, NamedAttrList &attrs) final
llvm::hash_code hashProperties(OpaqueProperties prop) final
static constexpr bool hasProperties
LogicalResult foldHook(Operation *op, ArrayRef< Attribute > attrs, SmallVectorImpl< OpFoldResult > &results) final
bool compareProperties(OpaqueProperties lhs, OpaqueProperties rhs) final
std::remove_reference_t< decltype(std::declval< ConcreteOp >().getProperties())> Properties
Implementation for "Properties".
Attribute getPropertiesAsAttr(Operation *op) final
LogicalResult verifyInherentAttrs(OperationName opName, NamedAttrList &attributes, function_ref< InFlightDiagnostic()> emitError) final
void populateDefaultProperties(OperationName opName, OpaqueProperties properties) final
void deleteProperties(OpaqueProperties prop) final
void setInherentAttr(Operation *op, StringAttr name, Attribute value) final
std::optional< Attribute > getInherentAttr(Operation *op, StringRef name) final
Implementation for properties.