@@ -336,12 +336,15 @@ class DynamicType
336
336
337
337
// / The definition of a dynamic op. A dynamic op is an op that is defined at
338
338
// / runtime, and that can be registered at runtime by an extensible dialect (a
339
- // / dialect inheriting ExtensibleDialect). This class stores the functions that
340
- // / are in the OperationName class, and in addition defines the TypeID of the op
341
- // / that will be defined.
342
- // / Each dynamic operation definition refers to one instance of this class.
343
- class DynamicOpDefinition {
339
+ // / dialect inheriting ExtensibleDialect). This class implements the method
340
+ // / exposed by the OperationName class, and in addition defines the TypeID of
341
+ // / the op that will be defined. Each dynamic operation definition refers to one
342
+ // / instance of this class.
343
+ class DynamicOpDefinition : public OperationName ::Impl {
344
344
public:
345
+ using GetCanonicalizationPatternsFn =
346
+ llvm::unique_function<void (RewritePatternSet &, MLIRContext *) const >;
347
+
345
348
// / Create a new op at runtime. The op is registered only after passing it to
346
349
// / the dialect using registerDynamicOp.
347
350
static std::unique_ptr<DynamicOpDefinition>
@@ -361,8 +364,7 @@ class DynamicOpDefinition {
361
364
OperationName::ParseAssemblyFn &&parseFn,
362
365
OperationName::PrintAssemblyFn &&printFn,
363
366
OperationName::FoldHookFn &&foldHookFn,
364
- OperationName::GetCanonicalizationPatternsFn
365
- &&getCanonicalizationPatternsFn,
367
+ GetCanonicalizationPatternsFn &&getCanonicalizationPatternsFn,
366
368
OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrsFn);
367
369
368
370
// / Returns the op typeID.
@@ -400,9 +402,8 @@ class DynamicOpDefinition {
400
402
401
403
// / Set the hook returning any canonicalization pattern rewrites that the op
402
404
// / supports, for use by the canonicalization pass.
403
- void
404
- setGetCanonicalizationPatternsFn (OperationName::GetCanonicalizationPatternsFn
405
- &&getCanonicalizationPatterns) {
405
+ void setGetCanonicalizationPatternsFn (
406
+ GetCanonicalizationPatternsFn &&getCanonicalizationPatterns) {
406
407
getCanonicalizationPatternsFn = std::move (getCanonicalizationPatterns);
407
408
}
408
409
@@ -412,6 +413,29 @@ class DynamicOpDefinition {
412
413
populateDefaultAttrsFn = std::move (populateDefaultAttrs);
413
414
}
414
415
416
+ LogicalResult foldHook (Operation *op, ArrayRef<Attribute> attrs,
417
+ SmallVectorImpl<OpFoldResult> &results) final {
418
+ return foldHookFn (op, attrs, results);
419
+ }
420
+ void getCanonicalizationPatterns (RewritePatternSet &set,
421
+ MLIRContext *context) final {
422
+ getCanonicalizationPatternsFn (set, context);
423
+ }
424
+ bool hasTrait (TypeID id) final { return false ; }
425
+ OperationName::ParseAssemblyFn getParseAssemblyFn () final { return parseFn; }
426
+ void populateDefaultAttrs (const OperationName &name,
427
+ NamedAttrList &attrs) final {
428
+ populateDefaultAttrsFn (name, attrs);
429
+ }
430
+ void printAssembly (Operation *op, OpAsmPrinter &printer,
431
+ StringRef name) final {
432
+ printFn (op, printer, name);
433
+ }
434
+ LogicalResult verifyInvariants (Operation *op) final { return verifyFn (op); }
435
+ LogicalResult verifyRegionInvariants (Operation *op) final {
436
+ return verifyRegionFn (op);
437
+ }
438
+
415
439
private:
416
440
DynamicOpDefinition (
417
441
StringRef name, ExtensibleDialect *dialect,
@@ -420,26 +444,18 @@ class DynamicOpDefinition {
420
444
OperationName::ParseAssemblyFn &&parseFn,
421
445
OperationName::PrintAssemblyFn &&printFn,
422
446
OperationName::FoldHookFn &&foldHookFn,
423
- OperationName::GetCanonicalizationPatternsFn
424
- &&getCanonicalizationPatternsFn,
447
+ GetCanonicalizationPatternsFn &&getCanonicalizationPatternsFn,
425
448
OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrsFn);
426
449
427
- // / Unique identifier for this operation.
428
- TypeID typeID;
429
-
430
- // / Name of the operation.
431
- // / The name is prefixed with the dialect name.
432
- std::string name;
433
-
434
450
// / Dialect defining this operation.
435
- ExtensibleDialect *dialect ;
451
+ ExtensibleDialect *getdialect () ;
436
452
437
453
OperationName::VerifyInvariantsFn verifyFn;
438
454
OperationName::VerifyRegionInvariantsFn verifyRegionFn;
439
455
OperationName::ParseAssemblyFn parseFn;
440
456
OperationName::PrintAssemblyFn printFn;
441
457
OperationName::FoldHookFn foldHookFn;
442
- OperationName:: GetCanonicalizationPatternsFn getCanonicalizationPatternsFn;
458
+ GetCanonicalizationPatternsFn getCanonicalizationPatternsFn;
443
459
OperationName::PopulateDefaultAttrsFn populateDefaultAttrsFn;
444
460
445
461
friend ExtensibleDialect;
0 commit comments