@@ -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,33 @@ 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 {
426
+ return [&](OpAsmParser &parser, OperationState &state) {
427
+ return parseFn (parser, state);
428
+ };
429
+ }
430
+ void populateDefaultAttrs (const OperationName &name,
431
+ NamedAttrList &attrs) final {
432
+ populateDefaultAttrsFn (name, attrs);
433
+ }
434
+ void printAssembly (Operation *op, OpAsmPrinter &printer,
435
+ StringRef name) final {
436
+ printFn (op, printer, name);
437
+ }
438
+ LogicalResult verifyInvariants (Operation *op) final { return verifyFn (op); }
439
+ LogicalResult verifyRegionInvariants (Operation *op) final {
440
+ return verifyRegionFn (op);
441
+ }
442
+
415
443
private:
416
444
DynamicOpDefinition (
417
445
StringRef name, ExtensibleDialect *dialect,
@@ -420,26 +448,18 @@ class DynamicOpDefinition {
420
448
OperationName::ParseAssemblyFn &&parseFn,
421
449
OperationName::PrintAssemblyFn &&printFn,
422
450
OperationName::FoldHookFn &&foldHookFn,
423
- OperationName::GetCanonicalizationPatternsFn
424
- &&getCanonicalizationPatternsFn,
451
+ GetCanonicalizationPatternsFn &&getCanonicalizationPatternsFn,
425
452
OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrsFn);
426
453
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
454
// / Dialect defining this operation.
435
- ExtensibleDialect *dialect ;
455
+ ExtensibleDialect *getdialect () ;
436
456
437
457
OperationName::VerifyInvariantsFn verifyFn;
438
458
OperationName::VerifyRegionInvariantsFn verifyRegionFn;
439
459
OperationName::ParseAssemblyFn parseFn;
440
460
OperationName::PrintAssemblyFn printFn;
441
461
OperationName::FoldHookFn foldHookFn;
442
- OperationName:: GetCanonicalizationPatternsFn getCanonicalizationPatternsFn;
462
+ GetCanonicalizationPatternsFn getCanonicalizationPatternsFn;
443
463
OperationName::PopulateDefaultAttrsFn populateDefaultAttrsFn;
444
464
445
465
friend ExtensibleDialect;
0 commit comments