@@ -321,55 +321,78 @@ TEST(InterfaceAttachment, Operation) {
321
321
ASSERT_FALSE (isa<TestExternalOpInterface>(otherModuleOp.getOperation ()));
322
322
}
323
323
324
+ template <class ConcreteOp >
324
325
struct TestExternalTestOpModel
325
- : public TestExternalOpInterface::ExternalModel<TestExternalTestOpModel,
326
- test::OpJ > {
326
+ : public TestExternalOpInterface::ExternalModel<
327
+ TestExternalTestOpModel<ConcreteOp>, ConcreteOp > {
327
328
unsigned getNameLengthPlusArg (Operation *op, unsigned arg) const {
328
329
return op->getName ().getStringRef ().size () + arg;
329
330
}
330
331
331
332
static unsigned getNameLengthPlusArgTwice (unsigned arg) {
332
- return test::OpJ ::getOperationName ().size () + 2 * arg;
333
+ return ConcreteOp ::getOperationName ().size () + 2 * arg;
333
334
}
334
335
};
335
336
336
337
TEST (InterfaceAttachment, OperationDelayedContextConstruct) {
337
338
DialectRegistry registry;
338
339
registry.insert <test::TestDialect>();
339
340
registry.addOpInterface <ModuleOp, TestExternalOpModel>();
340
- registry.addOpInterface <test::OpJ, TestExternalTestOpModel>();
341
+ registry.addOpInterface <test::OpJ, TestExternalTestOpModel<test::OpJ>>();
342
+ registry.addOpInterface <test::OpH, TestExternalTestOpModel<test::OpH>>();
341
343
342
344
// Construct the context directly from a registry. The interfaces are expected
343
345
// to be readily available on operations.
344
346
MLIRContext context (registry);
345
347
context.loadDialect <test::TestDialect>();
348
+
346
349
ModuleOp module = ModuleOp::create (UnknownLoc::get (&context));
347
350
OpBuilder builder (module);
348
- auto op =
351
+ auto opJ =
349
352
builder.create <test::OpJ>(builder.getUnknownLoc (), builder.getI32Type ());
353
+ auto opH =
354
+ builder.create <test::OpH>(builder.getUnknownLoc (), opJ.getResult ());
355
+ auto opI =
356
+ builder.create <test::OpI>(builder.getUnknownLoc (), opJ.getResult ());
357
+
350
358
EXPECT_TRUE (isa<TestExternalOpInterface>(module.getOperation ()));
351
- EXPECT_TRUE (isa<TestExternalOpInterface>(op.getOperation ()));
359
+ EXPECT_TRUE (isa<TestExternalOpInterface>(opJ.getOperation ()));
360
+ EXPECT_TRUE (isa<TestExternalOpInterface>(opH.getOperation ()));
361
+ EXPECT_FALSE (isa<TestExternalOpInterface>(opI.getOperation ()));
352
362
}
353
363
354
364
TEST (InterfaceAttachment, OperationDelayedContextAppend) {
355
365
DialectRegistry registry;
356
366
registry.insert <test::TestDialect>();
357
367
registry.addOpInterface <ModuleOp, TestExternalOpModel>();
358
- registry.addOpInterface <test::OpJ, TestExternalTestOpModel>();
368
+ registry.addOpInterface <test::OpJ, TestExternalTestOpModel<test::OpJ>>();
369
+ registry.addOpInterface <test::OpH, TestExternalTestOpModel<test::OpH>>();
359
370
360
371
// Construct the context, create ops, and only then append the registry. The
361
372
// interfaces are expected to be available after appending the registry.
362
373
MLIRContext context;
363
374
context.loadDialect <test::TestDialect>();
375
+
364
376
ModuleOp module = ModuleOp::create (UnknownLoc::get (&context));
365
377
OpBuilder builder (module);
366
- auto op =
378
+ auto opJ =
367
379
builder.create <test::OpJ>(builder.getUnknownLoc (), builder.getI32Type ());
380
+ auto opH =
381
+ builder.create <test::OpH>(builder.getUnknownLoc (), opJ.getResult ());
382
+ auto opI =
383
+ builder.create <test::OpI>(builder.getUnknownLoc (), opJ.getResult ());
384
+
368
385
EXPECT_FALSE (isa<TestExternalOpInterface>(module.getOperation ()));
369
- EXPECT_FALSE (isa<TestExternalOpInterface>(op.getOperation ()));
386
+ EXPECT_FALSE (isa<TestExternalOpInterface>(opJ.getOperation ()));
387
+ EXPECT_FALSE (isa<TestExternalOpInterface>(opH.getOperation ()));
388
+ EXPECT_FALSE (isa<TestExternalOpInterface>(opI.getOperation ()));
389
+
370
390
context.appendDialectRegistry (registry);
391
+
371
392
EXPECT_TRUE (isa<TestExternalOpInterface>(module.getOperation ()));
372
- EXPECT_TRUE (isa<TestExternalOpInterface>(op.getOperation ()));
393
+ EXPECT_TRUE (isa<TestExternalOpInterface>(opJ.getOperation ()));
394
+ EXPECT_TRUE (isa<TestExternalOpInterface>(opH.getOperation ()));
395
+ EXPECT_FALSE (isa<TestExternalOpInterface>(opI.getOperation ()));
373
396
}
374
397
375
398
} // end namespace
0 commit comments