@@ -166,10 +166,8 @@ namespace {
166166// / program have a corresponding de-allocation.
167167class BufferDeallocation {
168168public:
169- BufferDeallocation (Operation *op, bool privateFuncDynamicOwnership)
170- : state(op) {
171- options.privateFuncDynamicOwnership = privateFuncDynamicOwnership;
172- }
169+ BufferDeallocation (Operation *op, DeallocationOptions options)
170+ : state(op), options(options) {}
173171
174172 // / Performs the actual placement/creation of all dealloc operations.
175173 LogicalResult deallocate (FunctionOpInterface op);
@@ -586,13 +584,9 @@ BufferDeallocation::updateFunctionSignature(FunctionOpInterface op) {
586584 if (!returnOperandTypes.empty ())
587585 resultTypes = returnOperandTypes[0 ];
588586
589- // TODO: it would be nice if the FunctionOpInterface had a method to not only
590- // get the function type but also set it.
591- op->setAttr (
592- " function_type" ,
593- TypeAttr::get (FunctionType::get (
594- op->getContext (), op.getFunctionBody ().front ().getArgumentTypes (),
595- resultTypes)));
587+ op.setFunctionTypeAttr (TypeAttr::get (FunctionType::get (
588+ op->getContext (), op.getFunctionBody ().front ().getArgumentTypes (),
589+ resultTypes)));
596590
597591 return success ();
598592}
@@ -1027,17 +1021,20 @@ struct OwnershipBasedBufferDeallocationPass
10271021 : public bufferization::impl::OwnershipBasedBufferDeallocationBase<
10281022 OwnershipBasedBufferDeallocationPass> {
10291023 OwnershipBasedBufferDeallocationPass () = default ;
1030- OwnershipBasedBufferDeallocationPass (bool privateFuncDynamicOwnership )
1024+ OwnershipBasedBufferDeallocationPass (DeallocationOptions options )
10311025 : OwnershipBasedBufferDeallocationPass() {
1032- this ->privateFuncDynamicOwnership .setValue (privateFuncDynamicOwnership);
1026+ this ->privateFuncDynamicOwnership .setValue (
1027+ options.privateFuncDynamicOwnership );
10331028 }
10341029 void runOnOperation () override {
1030+ DeallocationOptions options;
1031+ options.privateFuncDynamicOwnership = privateFuncDynamicOwnership;
1032+
10351033 auto status = getOperation ()->walk ([&](func::FuncOp func) {
10361034 if (func.isExternal ())
10371035 return WalkResult::skip ();
10381036
1039- if (failed (deallocateBuffersOwnershipBased (func,
1040- privateFuncDynamicOwnership)))
1037+ if (failed (deallocateBuffersOwnershipBased (func, options)))
10411038 return WalkResult::interrupt ();
10421039
10431040 return WalkResult::advance ();
@@ -1053,10 +1050,11 @@ struct OwnershipBasedBufferDeallocationPass
10531050// Implement bufferization API
10541051// ===----------------------------------------------------------------------===//
10551052
1056- LogicalResult bufferization::deallocateBuffersOwnershipBased (
1057- FunctionOpInterface op, bool privateFuncDynamicOwnership) {
1053+ LogicalResult
1054+ bufferization::deallocateBuffersOwnershipBased (FunctionOpInterface op,
1055+ DeallocationOptions options) {
10581056 // Gather all required allocation nodes and prepare the deallocation phase.
1059- BufferDeallocation deallocation (op, privateFuncDynamicOwnership );
1057+ BufferDeallocation deallocation (op, options );
10601058
10611059 // Place all required temporary clone and dealloc nodes.
10621060 return deallocation.deallocate (op);
@@ -1068,7 +1066,6 @@ LogicalResult bufferization::deallocateBuffersOwnershipBased(
10681066
10691067std::unique_ptr<Pass>
10701068mlir::bufferization::createOwnershipBasedBufferDeallocationPass (
1071- bool privateFuncDynamicOwnership) {
1072- return std::make_unique<OwnershipBasedBufferDeallocationPass>(
1073- privateFuncDynamicOwnership);
1069+ DeallocationOptions options) {
1070+ return std::make_unique<OwnershipBasedBufferDeallocationPass>(options);
10741071}
0 commit comments