arnab-oss created this revision.
Herald added subscribers: zero9178, bzcheeseman, ThomasRaoux, sdasgup3, 
wenzhicui, wrengr, cota, mravishankar, teijeong, rdzhabarov, tatianashp, 
msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, 
arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a reviewer: aartbik.
Herald added a reviewer: bondhugula.
Herald added a project: All.
arnab-oss requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache.
Herald added a reviewer: dcaballe.
Herald added projects: clang, MLIR.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134425

Files:
  clang/docs/tools/clang-formatted-files.txt
  mlir/include/mlir/Dialect/MemRef/IR/MemRef.h
  mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
  mlir/include/mlir/Interfaces/CMakeLists.txt
  mlir/lib/Dialect/Affine/Utils/Utils.cpp
  mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
  mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
  mlir/lib/Interfaces/CMakeLists.txt
  mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
  utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
===================================================================
--- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -922,6 +922,13 @@
     ],
 )
 
+td_library(
+    name = "AllocLikeOpInterfaceTdFiles",
+    srcs = ["include/mlir/Interfaces/AllocLikeOpInterface.td"],
+    includes = ["include"],
+    deps = [":OpBaseTdFiles"],
+)
+
 td_library(
     name = "CallInterfacesTdFiles",
     srcs = ["include/mlir/Interfaces/CallInterfaces.td"],
@@ -2726,6 +2733,17 @@
     ],
 )
 
+cc_library(
+    name = "AllocLikeOpInterface",
+    srcs = ["lib/Interfaces/AllocLikeOpInterface.cpp"],
+    hdrs = ["include/mlir/Interfaces/AllocLikeOpInterface.h"],
+    includes = ["include"],
+    deps = [
+        ":AllocLikeOpInterfaceIncGen",
+        ":IR",
+    ],
+)
+
 cc_library(
     name = "DataLayoutInterfaces",
     srcs = ["lib/Interfaces/DataLayoutInterfaces.cpp"],
@@ -5301,6 +5319,24 @@
     deps = [":ViewLikeInterfaceTdFiles"],
 )
 
+gentbl_cc_library(
+    name = "AllocLikeOpInterfaceIncGen",
+    strip_include_prefix = "include",
+    tbl_outs = [
+        (
+            ["-gen-op-interface-decls"],
+            "include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+        ),
+        (
+            ["-gen-op-interface-defs"],
+            "include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+        ),
+    ],
+    tblgen = ":mlir-tblgen",
+    td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+    deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
     name = "CopyOpInterfaceIncGen",
     strip_include_prefix = "include",
@@ -8766,6 +8802,24 @@
     ],
 )
 
+gentbl_cc_library(
+    name = "AllocLikeOpInterfaceIncGen",
+    strip_include_prefix = "include",
+    tbl_outs = [
+        (
+            ["-gen-op-interface-decls"],
+            "include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+        ),
+        (
+            ["-gen-op-interface-defs"],
+            "include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+        ),
+    ],
+    tblgen = ":mlir-tblgen",
+    td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+    deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
     name = "MemRefBaseIncGen",
     strip_include_prefix = "include",
@@ -8823,6 +8877,7 @@
     ],
     includes = ["include"],
     deps = [
+        ":AllocLikeOpInterface",
         ":ArithmeticDialect",
         ":ArithmeticUtils",
         ":ControlFlowInterfaces",
Index: mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
===================================================================
--- mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
+++ mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
@@ -8,6 +8,7 @@
 
 #include <type_traits>
 
+#include "mlir/Analysis/AffineAnalysis.h"
 #include "mlir/Analysis/SliceAnalysis.h"
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
Index: mlir/lib/Interfaces/CMakeLists.txt
===================================================================
--- mlir/lib/Interfaces/CMakeLists.txt
+++ mlir/lib/Interfaces/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_OPTIONAL_SOURCES
+  AllocLikeOpInterface.cpp
   CallInterfaces.cpp
   CastInterfaces.cpp
   ControlFlowInterfaces.cpp
@@ -31,6 +32,7 @@
 endfunction(add_mlir_interface_library)
 
 
+add_mlir_interface_library(AllocLikeOpInterface)
 add_mlir_interface_library(CallInterfaces)
 add_mlir_interface_library(CastInterfaces)
 add_mlir_interface_library(ControlFlowInterfaces)
Index: mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
===================================================================
--- mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
+++ mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
@@ -1157,9 +1157,12 @@
     return failure();
 
   // Transfer into `view`.
-  Value viewOrAlloc = xferOp.getSource();
-  if (!viewOrAlloc.getDefiningOp<memref::ViewOp>() &&
-      !viewOrAlloc.getDefiningOp<memref::AllocOp>())
+  Value viewOrAlloc = xferOp.source();
+  Operation *viewOrAllocDefOp = viewOrAlloc.getDefiningOp();
+  if (!viewOrAllocDefOp)
+    return failure();
+  if (!isa<memref::ViewOp>(viewOrAllocDefOp) &&
+      !hasSingleEffect<MemoryEffects::Allocate>(viewOrAllocDefOp))
     return failure();
 
   LDBG(viewOrAlloc);
@@ -1240,9 +1243,12 @@
     return failure();
 
   // Transfer into `viewOrAlloc`.
-  Value viewOrAlloc = xferOp.getSource();
-  if (!viewOrAlloc.getDefiningOp<memref::ViewOp>() &&
-      !viewOrAlloc.getDefiningOp<memref::AllocOp>())
+  Value viewOrAlloc = xferOp.source();
+  auto viewOrAllocDefOp = viewOrAlloc.getDefiningOp();
+  if (!viewOrAllocDefOp)
+    return failure();
+  if (!isa<memref::ViewOp>(viewOrAllocDefOp) &&
+      !hasSingleEffect<MemoryEffects::Allocate>(viewOrAllocDefOp))
     return failure();
 
   // Ensure there is exactly one subview of `viewOrAlloc` defining `subView`.
Index: mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
===================================================================
--- mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
+++ mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
@@ -52,7 +52,6 @@
 
 #include "mlir/Dialect/Bufferization/Transforms/Passes.h"
 
-#include "mlir/Dialect/Bufferization/IR/AllocationOpInterface.h"
 #include "mlir/Dialect/Bufferization/IR/Bufferization.h"
 #include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
Index: mlir/lib/Dialect/Affine/Utils/Utils.cpp
===================================================================
--- mlir/lib/Dialect/Affine/Utils/Utils.cpp
+++ mlir/lib/Dialect/Affine/Utils/Utils.cpp
@@ -1067,7 +1067,8 @@
   for (auto memref : memrefsToErase) {
     // If the memref hasn't been locally alloc'ed, skip.
     Operation *defOp = memref.getDefiningOp();
-    if (!defOp || !hasSingleEffect<MemoryEffects::Allocate>(defOp, memref))
+    if (!defOp || (!hasSingleEffect<MemoryEffects::Allocate>(defOp) &&
+                   !isa<memref::GetGlobalOp>(defOp)))
       // TODO: if the memref was returned by a 'call' operation, we
       // could still erase it if the call had no side-effects.
       continue;
Index: mlir/include/mlir/Interfaces/CMakeLists.txt
===================================================================
--- mlir/include/mlir/Interfaces/CMakeLists.txt
+++ mlir/include/mlir/Interfaces/CMakeLists.txt
@@ -1,3 +1,4 @@
+add_mlir_interface(AllocLikeOpInterface)
 add_mlir_interface(CallInterfaces)
 add_mlir_interface(CastInterfaces)
 add_mlir_interface(ControlFlowInterfaces)
Index: mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
===================================================================
--- mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -11,6 +11,8 @@
 
 include "mlir/Dialect/Arithmetic/IR/ArithmeticBase.td"
 include "mlir/Dialect/MemRef/IR/MemRefBase.td"
+include "mlir/IR/OpBase.td"
+include "mlir/Interfaces/AllocLikeOpInterface.td"
 include "mlir/Interfaces/CastInterfaces.td"
 include "mlir/Interfaces/ControlFlowInterfaces.td"
 include "mlir/Interfaces/CopyOpInterface.td"
@@ -59,6 +61,7 @@
                   list<Trait> traits = []> :
     MemRef_Op<mnemonic,
     !listconcat([
+      AllocLikeOpInterface,
       AttrSizedOperandSegments
     ], traits)> {
 
@@ -97,6 +100,24 @@
     static StringRef getAlignmentAttrStrName() { return "alignment"; }
 
     MemRefType getType() { return getResult().getType().cast<MemRefType>(); }
+
+    /// Returns the dynamic sizes for this alloc operation if specified.
+    operand_range getDynamicSizes() { return dynamicSizes(); }
+
+    /// Returns the symbol operands for this alloc operation if specified.
+    operand_range getSymbolOperands() { return symbolOperands(); }
+
+    /// Returns the allocated memref.
+    Value getMemref() { return memref(); }
+
+    /// Returns the alignment of the allocated memref.
+    uint64_t getAlignmentAttr() { return alignment().getValue(); }
+
+    /// Sets alignment value for the allocated memref.
+    void setAlignmentAttr(unsigned requiredAlignment) { 
+      OpBuilder b(memref().getContext());
+      alignmentAttr(b.getI64IntegerAttr(requiredAlignment)); 
+    }
   }];
 
   let assemblyFormat = [{
Index: mlir/include/mlir/Dialect/MemRef/IR/MemRef.h
===================================================================
--- mlir/include/mlir/Dialect/MemRef/IR/MemRef.h
+++ mlir/include/mlir/Dialect/MemRef/IR/MemRef.h
@@ -11,6 +11,7 @@
 
 #include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
 #include "mlir/IR/Dialect.h"
+#include "mlir/Interfaces/AllocLikeOpInterface.h"
 #include "mlir/Interfaces/CallInterfaces.h"
 #include "mlir/Interfaces/CastInterfaces.h"
 #include "mlir/Interfaces/ControlFlowInterfaces.h"
Index: clang/docs/tools/clang-formatted-files.txt
===================================================================
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -7777,6 +7777,7 @@
 mlir/include/mlir/ExecutionEngine/OptUtils.h
 mlir/include/mlir/ExecutionEngine/RunnerUtils.h
 mlir/include/mlir/ExecutionEngine/SparseTensorUtils.h
+mlir/include/mlir/Interfaces/AllocLikeOpInterface.h
 mlir/include/mlir/Interfaces/CallInterfaces.h
 mlir/include/mlir/Interfaces/CastInterfaces.h
 mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
@@ -8299,6 +8300,7 @@
 mlir/lib/ExecutionEngine/RocmRuntimeWrappers.cpp
 mlir/lib/ExecutionEngine/RunnerUtils.cpp
 mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
+mlir/lib/Interfaces/AllocLikeOpInterface.cpp
 mlir/lib/Interfaces/CallInterfaces.cpp
 mlir/lib/Interfaces/CastInterfaces.cpp
 mlir/lib/Interfaces/ControlFlowInterfaces.cpp
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to