[Mlir-commits] [mlir] [mlir] Implement a memory-space cast bubbling-down transform (PR #159454)
Fabian Mora
llvmlistbot at llvm.org
Fri Sep 19 13:24:12 PDT 2025
================
@@ -0,0 +1,117 @@
+//===- MemOpInterfaces.td - Memory operation interfaces -----*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains interfaces for operations that interact with memory.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_INTERFACES_MEMOPINTERFACES_TD
+#define MLIR_INTERFACES_MEMOPINTERFACES_TD
+
+include "mlir/IR/OpBase.td"
+include "mlir/Interfaces/SideEffectInterfaces.td"
+
+def MemorySpaceCastConsumerOpInterface :
+ OpInterface<"MemorySpaceCastConsumerOpInterface"> {
+ let description = [{
+ An interface for operations that can consume memory-space cast-like
+ operations.
+ }];
+ let cppNamespace = "::mlir";
+ let methods = [
+ InterfaceMethod<[{
+ Attempt to bubble-down the incoming cast-like operands. On success
+ returns any new results, and whether the operation was modified in
+ place, otherwise it returns failure.
+ If new results are produced, these must be compatible with the original
+ operation results.
+
+ If the operation was not modified in place, then the interface
+ guarantees it is valid to erase the original operation.
+ If the operation was modified in place, then the interface must
+ guarantee no operations were created by the method, and that no further
+ IR modification is necessary.
+
+ Any implementations of this method must not erase/replace the original
+ operation, instead it is the caller responsibility to erase or replace
+ the op with the results provided by the method.
+
+ Finally, any implementations of this method have to guarantee that the
+ IR remains valid at all times.
+ }],
+ "::llvm::FailureOr<std::pair<::llvm::SmallVector<::mlir::Value>, bool>>",
----------------
fabianmcg wrote:
There can be lifetime issues, there are no guarantees the method didn't add more ops and it's using results from those.
>Yes, but either you do an in-place modification and return no results, or you require replacement and return results to replace yourself with.
That's not possible, because you won't be able to distinguish ops that return no results from those that do.
https://github.com/llvm/llvm-project/pull/159454
More information about the Mlir-commits
mailing list