@@ -340,6 +340,29 @@ Value createAttrConstraint(OpBuilder &builder, tblgen::Constraint constraint) {
340340 return createPredicate (builder, constraint.getPredicate ());
341341}
342342
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+
343366// / Returns the name of the operation without the dialect prefix.
344367static StringRef getOperatorName (tblgen::Operator &tblgenOp) {
345368 StringRef opName = tblgenOp.getDef ().getValueAsString (" opName" );
@@ -406,6 +429,12 @@ irdl::OperationOp createIRDLOperation(OpBuilder &builder,
406429 attrNames.push_back (StringAttr::get (ctx, namedAttr.name ));
407430 }
408431
432+ SmallVector<Value> regions;
433+ for (auto namedRegion : tblgenOp.getRegions ()) {
434+ regions.push_back (
435+ createRegionConstraint (consBuilder, namedRegion.constraint ));
436+ }
437+
409438 // Create the operands and results operations.
410439 if (!operands.empty ())
411440 consBuilder.create <irdl::OperandsOp>(UnknownLoc::get (ctx), operands,
@@ -416,6 +445,8 @@ irdl::OperationOp createIRDLOperation(OpBuilder &builder,
416445 if (!attributes.empty ())
417446 consBuilder.create <irdl::AttributesOp>(UnknownLoc::get (ctx), attributes,
418447 ArrayAttr::get (ctx, attrNames));
448+ if (!regions.empty ())
449+ consBuilder.create <irdl::RegionsOp>(UnknownLoc::get (ctx), regions);
419450
420451 return op;
421452}
0 commit comments