File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -504,18 +504,20 @@ class OpBuilder : public Builder {
504
504
template <typename OpTy, typename ... Args>
505
505
void createOrFold (SmallVectorImpl<Value> &results, Location location,
506
506
Args &&...args) {
507
- // Create the operation without using 'create' as we don't want to
508
- // insert it yet .
507
+ // Create the operation without using 'create' as we want to control when
508
+ // the listener is notified .
509
509
OperationState state (location,
510
510
getCheckRegisteredInfo<OpTy>(location.getContext ()));
511
511
OpTy::build (*this , state, std::forward<Args>(args)...);
512
512
Operation *op = Operation::create (state);
513
+ if (block)
514
+ block->getOperations ().insert (insertPoint, op);
513
515
514
- // Fold the operation. If successful destroy it, otherwise insert it .
516
+ // Fold the operation. If successful erase it, otherwise notify .
515
517
if (succeeded (tryFold (op, results)))
516
- op->destroy ();
517
- else
518
- insert (op);
518
+ op->erase ();
519
+ else if (listener)
520
+ listener-> notifyOperationInserted (op);
519
521
}
520
522
521
523
// / Overload to create or fold a single result operation.
Original file line number Diff line number Diff line change @@ -529,6 +529,11 @@ LogicalResult TestOpWithVariadicResultsAndFolder::fold(
529
529
}
530
530
531
531
OpFoldResult TestOpInPlaceFold::fold (FoldAdaptor adaptor) {
532
+ // Exercise the fact that an operation created with createOrFold should be
533
+ // allowed to access its parent block.
534
+ assert (getOperation ()->getBlock () &&
535
+ " expected that operation is not unlinked" );
536
+
532
537
if (adaptor.getOp () && !getProperties ().attr ) {
533
538
// The folder adds "attr" if not present.
534
539
getProperties ().attr = dyn_cast_or_null<IntegerAttr>(adaptor.getOp ());
You can’t perform that action at this time.
0 commit comments