@@ -340,6 +340,29 @@ Value createAttrConstraint(OpBuilder &builder, tblgen::Constraint constraint) {
340
340
return createPredicate (builder, constraint.getPredicate ());
341
341
}
342
342
343
+ Value createRegionConstraint (OpBuilder &builder, tblgen::Region constraint) {
344
+ MLIRContext *ctx = builder.getContext ();
345
+ const Record &predRec = constraint.getDef ();
346
+
347
+ if (predRec.getName () == " AnyRegion" ) {
348
+ ValueRange entryBlockArgs = {};
349
+ auto op =
350
+ builder.create <irdl::RegionOp>(UnknownLoc::get (ctx), entryBlockArgs);
351
+ return op.getResult ();
352
+ }
353
+
354
+ if (predRec.isSubClassOf (" SizedRegion" )) {
355
+ ValueRange entryBlockArgs = {};
356
+ auto ty = IntegerType::get (ctx, 32 );
357
+ auto op = builder.create <irdl::RegionOp>(
358
+ UnknownLoc::get (ctx), entryBlockArgs,
359
+ IntegerAttr::get (ty, predRec.getValueAsInt (" blocks" )));
360
+ return op.getResult ();
361
+ }
362
+
363
+ return createPredicate (builder, constraint.getPredicate ());
364
+ }
365
+
343
366
// / Returns the name of the operation without the dialect prefix.
344
367
static StringRef getOperatorName (tblgen::Operator &tblgenOp) {
345
368
StringRef opName = tblgenOp.getDef ().getValueAsString (" opName" );
@@ -406,6 +429,12 @@ irdl::OperationOp createIRDLOperation(OpBuilder &builder,
406
429
attrNames.push_back (StringAttr::get (ctx, namedAttr.name ));
407
430
}
408
431
432
+ SmallVector<Value> regions;
433
+ for (auto namedRegion : tblgenOp.getRegions ()) {
434
+ regions.push_back (
435
+ createRegionConstraint (consBuilder, namedRegion.constraint ));
436
+ }
437
+
409
438
// Create the operands and results operations.
410
439
if (!operands.empty ())
411
440
consBuilder.create <irdl::OperandsOp>(UnknownLoc::get (ctx), operands,
@@ -416,6 +445,8 @@ irdl::OperationOp createIRDLOperation(OpBuilder &builder,
416
445
if (!attributes.empty ())
417
446
consBuilder.create <irdl::AttributesOp>(UnknownLoc::get (ctx), attributes,
418
447
ArrayAttr::get (ctx, attrNames));
448
+ if (!regions.empty ())
449
+ consBuilder.create <irdl::RegionsOp>(UnknownLoc::get (ctx), regions);
419
450
420
451
return op;
421
452
}
0 commit comments