How to use replaceAllUsesWith to well erase an Operation?

Hello.
I have a MLIR function:
func @SingleSWLayer(%arg0: memref<1000xf16>, %arg1: memref<1000xf16>) → memref<1000xf16> {
%0 = Dialect.AnOperation inputs(%arg0 : memref<1000xf16>) outputs(%arg1 : memref<1000xf16>) → memref<1000xf16>
return %0 : memref<1000xf16>
}

I want to erase Operation %0. But for doing this I need to get rid of the use %0 in return %0.
What operation would you advise me to create to replace with %0? I need to have a code something like this:
    // create the new Operation:
    newOperation = bld.create<...>(getLoc(), ...);
    // oldOperation is %0
    oldOperation.replaceAllUsesWith(newOperation);
    oldOperation.erase();

(We do this to avoid the error: 'Dialect.AnOperation' op operation destroyed but still has uses).

Please let me know what actual mlir::Operation should be newOperation? Should it be a NoOperation, if such exists?

Thank you very much,
Alex

Before thinking about working around the “operation destroyed but still has uses” error message, what is the result you want to get? You’re showing an IR where the function needs to return a value, can you show the end result IR you desire to obtain here?

Hello.
I solved the issue. So no more help is required.

Just for information, the end IR looks like this (note that I replaced Dialect.AnOperation with a call to MyFunc, that has the same signature as Dialect.AnOperation):
    func @SingleSWLayer(%arg0: memref<1000xf16>, %arg1: memref<1000xf16>) -> memref<1000xf16> {
      %0 = call @MyFunc(%arg0, %arg1) : (memref<1000xf16>, memref<1000xf16>) -> memref<1000xf16>
      return %0 : memref<1000xf16>
    }

Thank you,
Alex

Out of curiosity, how does this solve your problem? Don’t you have the exact same question in this IR, of how to remove %0?