@@ -292,11 +292,10 @@ class BufferDeallocation {
292
292
FailureOr<Operation *> handleInterface (RegionBranchOpInterface op);
293
293
294
294
// / If the private-function-dynamic-ownership pass option is enabled and the
295
- // / called function is private, additional arguments and results are added for
296
- // / each MemRef argument/result to pass the dynamic ownership indicator along.
297
- // / Otherwise, updates the ownership map and list of memrefs to be deallocated
298
- // / according to the function boundary ABI, i.e., assume ownership of all
299
- // / returned MemRefs.
295
+ // / called function is private, additional results are added for each MemRef
296
+ // / result to pass the dynamic ownership indicator along. Otherwise, updates
297
+ // / the ownership map and list of memrefs to be deallocated according to the
298
+ // / function boundary ABI, i.e., assume ownership of all returned MemRefs.
300
299
// /
301
300
// / Example (assume `private-function-dynamic-ownership` is enabled):
302
301
// / ```
@@ -309,17 +308,15 @@ class BufferDeallocation {
309
308
// / becomes
310
309
// / ```
311
310
// / func.func @f(%arg0: memref<2xi32>) -> memref<2xi32> {...}
312
- // / func.func private @g(%arg0: memref<2xi32>) -> memref<2xi32> {...}
311
+ // / func.func private @g(%arg0: memref<2xi32>) -> ( memref<2xi32>, i1) {...}
313
312
// /
314
313
// / %ret_f = func.call @f(%memref) : (memref<2xi32>) -> memref<2xi32>
315
314
// / // set ownership(%ret_f) := true
316
315
// / // remember to deallocate %ret_f
317
316
// /
318
- // / // (new_memref, own) = getmemrefWithUniqueOwnership(%memref)
319
- // / %ret_g:2 = func.call @g(new_memref, own) :
320
- // / (memref<2xi32>, i1) -> (memref<2xi32>, i1)
317
+ // / %ret_g:2 = func.call @g(%memref) : (memref<2xi32>) -> (memref<2xi32>, i1)
321
318
// / // set ownership(%ret_g#0) := %ret_g#1
322
- // / // remember to deallocate %ret_g
319
+ // / // remember to deallocate %ret_g if it comes with ownership
323
320
// / ```
324
321
FailureOr<Operation *> handleInterface (CallOpInterface op);
325
322
@@ -444,8 +441,8 @@ class BufferDeallocation {
444
441
static LogicalResult verifyOperationPreconditions (Operation *op);
445
442
446
443
// / When the 'private-function-dynamic-ownership' pass option is enabled,
447
- // / additional `i1` arguments and return values are added for each MemRef
448
- // / value in the function signature. This function takes care of updating the
444
+ // / additional `i1` return values are added for each MemRef result in the
445
+ // / function signature. This function takes care of updating the
449
446
// / `function_type` attribute of the function according to the actually
450
447
// / returned values from the terminators.
451
448
static LogicalResult updateFunctionSignature (FunctionOpInterface op);
@@ -650,7 +647,7 @@ LogicalResult BufferDeallocation::deallocate(Block *block) {
650
647
651
648
// Adhere to function boundary ABI: no ownership of function argument
652
649
// MemRefs is taken.
653
- if (isFunctionWithoutDynamicOwnership (block->getParentOp ()) &&
650
+ if (isa<FunctionOpInterface> (block->getParentOp ()) &&
654
651
block->isEntryBlock ()) {
655
652
Value newArg = buildBoolValue (builder, arg.getLoc (), false );
656
653
state.updateOwnership (arg, newArg);
@@ -838,26 +835,10 @@ FailureOr<Operation *> BufferDeallocation::handleInterface(CallOpInterface op) {
838
835
isPrivate = symbol.isPrivate () && !symbol.isDeclaration ();
839
836
840
837
// If the private-function-dynamic-ownership option is enabled and we are
841
- // calling a private function, we need to add an additional `i1`
842
- // argument/result for each MemRef argument/result to dynamically pass the
843
- // current ownership indicator rather than adhering to the function boundary
844
- // ABI.
838
+ // calling a private function, we need to add an additional `i1` result for
839
+ // each MemRef result to dynamically pass the current ownership indicator
840
+ // rather than adhering to the function boundary ABI.
845
841
if (options.privateFuncDynamicOwnership && isPrivate) {
846
- SmallVector<Value> newOperands, ownershipIndicatorsToAdd;
847
- for (Value operand : op.getArgOperands ()) {
848
- if (!isMemref (operand)) {
849
- newOperands.push_back (operand);
850
- continue ;
851
- }
852
- auto [memref, condition] =
853
- materializeUniqueOwnership (builder, operand, op->getBlock ());
854
- newOperands.push_back (memref);
855
- ownershipIndicatorsToAdd.push_back (condition);
856
- }
857
- newOperands.append (ownershipIndicatorsToAdd.begin (),
858
- ownershipIndicatorsToAdd.end ());
859
- op.getArgOperandsMutable ().assign (newOperands);
860
-
861
842
unsigned numMemrefs = llvm::count_if (op->getResults (), isMemref);
862
843
SmallVector<Type> ownershipTypesToAppend (numMemrefs, builder.getI1Type ());
863
844
unsigned ownershipCounter = op->getNumResults ();
0 commit comments