1//===-- BufferDeallocationOpInterface.td -------------------*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#ifndef BUFFER_DEALLOCATION_OP_INTERFACE 10#define BUFFER_DEALLOCATION_OP_INTERFACE 11 12include "mlir/IR/OpBase.td" 13 14def BufferDeallocationOpInterface : 15 OpInterface<"BufferDeallocationOpInterface"> { 16 let description = [{ 17 An op interface for Buffer Deallocation. Ops that implement this interface 18 can provide custom logic for computing the ownership of OpResults, modify 19 the operation to properly pass the ownership values around, and insert 20 `bufferization.dealloc` operations when necessary. 21 }]; 22 let cppNamespace = "::mlir::bufferization"; 23 let methods = [ 24 InterfaceMethod< 25 /*desc=*/[{ 26 This method takes the current deallocation state and transformation 27 options and updates the deallocation state as necessary for the 28 operation implementing this interface. It may also insert 29 `bufferization.dealloc` operations and rebuild itself with different 30 result types. For operations implementing this interface all other 31 interface handlers (e.g., default handlers for interfaces like 32 RegionBranchOpInterface, CallOpInterface, etc.) are skipped by the 33 deallocation pass. On success, either the current operation or one of 34 the newly inserted operations is returned from which on the driver 35 should continue the processing. On failure, the deallocation pass 36 will terminate. It is recommended to emit a useful error message in 37 that case. 38 }], 39 /*retType=*/"FailureOr<Operation *>", 40 /*methodName=*/"process", 41 /*args=*/(ins "DeallocationState &":$state, 42 "const DeallocationOptions &":$options)>, 43 InterfaceMethod< 44 /*desc=*/[{ 45 This method allows the implementing operation to specify custom logic 46 to materialize an ownership indicator value for the given MemRef typed 47 value it defines (including block arguments of nested regions). Since 48 the operation itself has more information about its semantics the 49 materialized IR can be more efficient compared to the default 50 implementation and avoid cloning MemRefs and/or doing alias checking 51 at runtime. 52 Note that the same logic could also be implemented in the 'process' 53 method above, however, the IR is always materialized then. If 54 it's desirable to only materialize the IR to compute an updated 55 ownership indicator when needed, it should be implemented using this 56 method (which is especially important if operations are created that 57 cannot be easily canonicalized away anymore). 58 }], 59 /*retType=*/"std::pair<Value, Value>", 60 /*methodName=*/"materializeUniqueOwnershipForMemref", 61 /*args=*/(ins "DeallocationState &":$state, 62 "const DeallocationOptions &":$options, 63 "OpBuilder &":$builder, 64 "Value":$memref), 65 /*methodBody=*/[{}], 66 /*defaultImplementation=*/[{ 67 return state.getMemrefWithUniqueOwnership( 68 builder, memref, memref.getParentBlock()); 69 }]>, 70 ]; 71} 72 73#endif // BUFFER_DEALLOCATION_OP_INTERFACE 74