@@ -1813,6 +1813,8 @@ void AffineForOp::build(OpBuilder &builder, OperationState &result,
18131813 " upper bound operand count does not match the affine map" );
18141814 assert (step > 0 && " step has to be a positive integer constant" );
18151815
1816+ OpBuilder::InsertionGuard guard (builder);
1817+
18161818 // Set variadic segment sizes.
18171819 result.addAttribute (
18181820 getOperandSegmentSizeAttr (),
@@ -1841,12 +1843,11 @@ void AffineForOp::build(OpBuilder &builder, OperationState &result,
18411843 // Create a region and a block for the body. The argument of the region is
18421844 // the loop induction variable.
18431845 Region *bodyRegion = result.addRegion ();
1844- bodyRegion->push_back (new Block);
1845- Block &bodyBlock = bodyRegion->front ();
1846+ Block *bodyBlock = builder.createBlock (bodyRegion);
18461847 Value inductionVar =
1847- bodyBlock. addArgument (builder.getIndexType (), result.location );
1848+ bodyBlock-> addArgument (builder.getIndexType (), result.location );
18481849 for (Value val : iterArgs)
1849- bodyBlock. addArgument (val.getType (), val.getLoc ());
1850+ bodyBlock-> addArgument (val.getType (), val.getLoc ());
18501851
18511852 // Create the default terminator if the builder is not provided and if the
18521853 // iteration arguments are not provided. Otherwise, leave this to the caller
@@ -1855,9 +1856,9 @@ void AffineForOp::build(OpBuilder &builder, OperationState &result,
18551856 ensureTerminator (*bodyRegion, builder, result.location );
18561857 } else if (bodyBuilder) {
18571858 OpBuilder::InsertionGuard guard (builder);
1858- builder.setInsertionPointToStart (& bodyBlock);
1859+ builder.setInsertionPointToStart (bodyBlock);
18591860 bodyBuilder (builder, result.location , inductionVar,
1860- bodyBlock. getArguments ().drop_front ());
1861+ bodyBlock-> getArguments ().drop_front ());
18611862 }
18621863}
18631864
@@ -2895,18 +2896,20 @@ void AffineIfOp::build(OpBuilder &builder, OperationState &result,
28952896 TypeRange resultTypes, IntegerSet set, ValueRange args,
28962897 bool withElseRegion) {
28972898 assert (resultTypes.empty () || withElseRegion);
2899+ OpBuilder::InsertionGuard guard (builder);
2900+
28982901 result.addTypes (resultTypes);
28992902 result.addOperands (args);
29002903 result.addAttribute (getConditionAttrStrName (), IntegerSetAttr::get (set));
29012904
29022905 Region *thenRegion = result.addRegion ();
2903- thenRegion-> push_back ( new Block () );
2906+ builder. createBlock (thenRegion );
29042907 if (resultTypes.empty ())
29052908 AffineIfOp::ensureTerminator (*thenRegion, builder, result.location );
29062909
29072910 Region *elseRegion = result.addRegion ();
29082911 if (withElseRegion) {
2909- elseRegion-> push_back ( new Block () );
2912+ builder. createBlock (elseRegion );
29102913 if (resultTypes.empty ())
29112914 AffineIfOp::ensureTerminator (*elseRegion, builder, result.location );
29122915 }
@@ -3693,6 +3696,7 @@ void AffineParallelOp::build(OpBuilder &builder, OperationState &result,
36933696 " expected upper bound maps to have as many inputs as upper bound "
36943697 " operands" );
36953698
3699+ OpBuilder::InsertionGuard guard (builder);
36963700 result.addTypes (resultTypes);
36973701
36983702 // Convert the reductions to integer attributes.
@@ -3738,11 +3742,11 @@ void AffineParallelOp::build(OpBuilder &builder, OperationState &result,
37383742
37393743 // Create a region and a block for the body.
37403744 auto *bodyRegion = result.addRegion ();
3741- auto *body = new Block ();
3745+ Block *body = builder.createBlock (bodyRegion);
3746+
37423747 // Add all the block arguments.
37433748 for (unsigned i = 0 , e = steps.size (); i < e; ++i)
37443749 body->addArgument (IndexType::get (builder.getContext ()), result.location );
3745- bodyRegion->push_back (body);
37463750 if (resultTypes.empty ())
37473751 ensureTerminator (*bodyRegion, builder, result.location );
37483752}
0 commit comments