[Mlir-commits] [mlir] [mlir] Declare promised interfaces for all dialects (PR #78368)

Justin Fargnoli llvmlistbot at llvm.org
Thu Mar 14 17:49:18 PDT 2024


https://github.com/justinfargnoli updated https://github.com/llvm/llvm-project/pull/78368

>From fe9e7473a1acacc98c8c52de6362f5020c67ca86 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Thu, 11 Jan 2024 20:00:53 -0800
Subject: [PATCH 01/14] Declare Affine Interfaces

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index 8a070d25639870..fb7bfd906cc2cc 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -8,6 +8,7 @@
 
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Affine/IR/AffineValueMap.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/UB/IR/UBOps.h"
 #include "mlir/IR/AffineExprVisitor.h"
@@ -220,6 +221,9 @@ void AffineDialect::initialize() {
 #include "mlir/Dialect/Affine/IR/AffineOps.cpp.inc"
                 >();
   addInterfaces<AffineInlinerInterface>();
+  declarePromisedInterface<AffineApplyOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<AffineMaxOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<AffineMinOp, ValueBoundsOpInterface>();
 }
 
 /// Materialize a single constant operation from a given attribute value with

>From 8dc3c6af843ce1db126b85e8c323e0f5ec47c5e9 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Tue, 16 Jan 2024 15:58:28 -0800
Subject: [PATCH 02/14] Declare most other dialect interface implementations

---
 mlir/lib/Dialect/Arith/IR/ArithDialect.cpp    | 13 +++++
 .../Bufferization/IR/BufferizationDialect.cpp |  4 ++
 .../Dialect/ControlFlow/IR/ControlFlowOps.cpp |  7 +++
 mlir/lib/Dialect/GPU/IR/GPUDialect.cpp        |  2 +
 mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp  |  5 ++
 mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp  | 22 +++++++++
 mlir/lib/Dialect/SCF/IR/SCF.cpp               | 15 ++++++
 mlir/lib/Dialect/Shape/IR/Shape.cpp           |  3 ++
 .../SparseTensor/IR/SparseTensorDialect.cpp   | 25 ++++++++++
 mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp  | 47 +++++++++++++++++++
 mlir/lib/Dialect/Vector/IR/VectorOps.cpp      | 17 +++++++
 11 files changed, 160 insertions(+)

diff --git a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
index 745c5706a838ce..1c5b0d8df44ed7 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
@@ -8,7 +8,10 @@
 
 #include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/UB/IR/UBOps.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/DialectImplementation.h"
 #include "mlir/Transforms/InliningUtils.h"
@@ -46,6 +49,16 @@ void arith::ArithDialect::initialize() {
       >();
   addInterfaces<ArithInlinerInterface>();
   declarePromisedInterface<ArithDialect, ConvertToLLVMPatternInterface>();
+  declarePromisedInterface<SelectOp, bufferization::BufferDeallocationOpInterface>();
+  declarePromisedInterface<ConstantOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<IndexCastOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<SelectOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<AddIOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<ConstantOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<SubIOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<MulIOp, ValueBoundsOpInterface>();
 }
 
 /// Materialize an integer or floating point constant.
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
index e5a0c3c45b09e2..d8a38868ac862a 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
@@ -10,6 +10,7 @@
 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/IR/Bufferization.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/Interfaces/FunctionInterfaces.h"
 #include "mlir/Transforms/InliningUtils.h"
@@ -63,6 +64,9 @@ void mlir::bufferization::BufferizationDialect::initialize() {
 #include "mlir/Dialect/Bufferization/IR/BufferizationOps.cpp.inc"
       >();
   addInterfaces<BufferizationInlinerInterface>();
+  declarePromisedInterface<func::CallOp, BufferizableOpInterface>();
+  declarePromisedInterface<func::FuncOp, BufferizableOpInterface>();
+  declarePromisedInterface<func::ReturnOp, BufferizableOpInterface>();
 }
 
 LogicalResult BufferizationDialect::verifyRegionArgAttribute(
diff --git a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
index d242d75bd51fa7..95027fc52791f3 100644
--- a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
@@ -10,6 +10,8 @@
 
 #include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/IR/AffineExpr.h"
 #include "mlir/IR/AffineMap.h"
 #include "mlir/IR/Builders.h"
@@ -69,6 +71,11 @@ void ControlFlowDialect::initialize() {
       >();
   addInterfaces<ControlFlowInlinerInterface>();
   declarePromisedInterface<ControlFlowDialect, ConvertToLLVMPatternInterface>();
+  declarePromisedInterface<BranchOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<CondBranchOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<CondBranchOp,
+                           bufferization::BufferDeallocationOpInterface>();
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 33ce5c159db4f9..37297ce555efec 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -13,6 +13,7 @@
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 
 #include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/Builders.h"
@@ -215,6 +216,7 @@ void GPUDialect::initialize() {
 #include "mlir/Dialect/GPU/IR/GPUOpsAttributes.cpp.inc"
       >();
   addInterfaces<GPUInlinerInterface>();
+  declarePromisedInterface<TerminatorOp, bufferization::BufferDeallocationOpInterface>();
 }
 
 static std::string getSparseHandleKeyword(SparseHandleKind kind) {
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
index 027058d4de6328..87cd452b52c6de 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
@@ -22,6 +22,8 @@
 #include "mlir/IR/Dialect.h"
 #include "mlir/IR/DialectImplementation.h"
 #include "mlir/Interfaces/FunctionInterfaces.h"
+#include "mlir/Interfaces/SubsetOpInterface.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Parser/Parser.h"
 #include "mlir/Support/LLVM.h"
 #include "mlir/Transforms/InliningUtils.h"
@@ -125,6 +127,9 @@ void mlir::linalg::LinalgDialect::initialize() {
 #define GET_OP_LIST
 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
                             >();
+  declarePromisedInterface<CopyOp, SubsetOpInterface>();
+  declarePromisedInterface<CopyOp, SubsetInsertionOpInterface>();
+  declarePromisedInterface<IndexOp, ValueBoundsOpInterface>();
 }
 
 LogicalResult LinalgDialect::verifyOperationAttribute(Operation *op,
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
index d71669a274b8fc..47c236a267ca99 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
@@ -8,8 +8,13 @@
 
 #include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Bufferization/IR/AllocationOpInterface.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/Interfaces/MemorySlotInterfaces.h"
+#include "mlir/Interfaces/RuntimeVerifiableOpInterface.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Transforms/InliningUtils.h"
 #include <optional>
 
@@ -43,6 +48,23 @@ void mlir::memref::MemRefDialect::initialize() {
       >();
   addInterfaces<MemRefInlinerInterface>();
   declarePromisedInterface<MemRefDialect, ConvertToLLVMPatternInterface>();
+  declarePromisedInterface<AllocOp, bufferization::AllocationOpInterface>();
+  declarePromisedInterface<AllocaOp, bufferization::AllocationOpInterface>();
+  declarePromisedInterface<ReallocOp, bufferization::AllocationOpInterface>();
+  declarePromisedInterface<CastOp, RuntimeVerifiableOpInterface>();
+  declarePromisedInterface<ExpandShapeOp, RuntimeVerifiableOpInterface>();
+  declarePromisedInterface<LoadOp, RuntimeVerifiableOpInterface>();
+  declarePromisedInterface<ReinterpretCastOp, RuntimeVerifiableOpInterface>();
+  declarePromisedInterface<StoreOp, RuntimeVerifiableOpInterface>();
+  declarePromisedInterface<SubViewOp, RuntimeVerifiableOpInterface>();
+  declarePromisedInterface<AllocOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<AllocaOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<CastOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<DimOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<GetGlobalOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<RankOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<SubViewOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<MemRefType, DestructurableTypeInterface>();
 }
 
 /// Finds the unique dealloc operation (if one exists) for `allocValue`.
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 233e702dbb2292..ce75eca0e6e6c5 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -9,10 +9,13 @@
 #include "mlir/Dialect/SCF/IR/SCF.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Arith/Utils/Utils.h"
+#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/SCF/IR/DeviceMappingInterface.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/IRMapping.h"
 #include "mlir/IR/Matchers.h"
@@ -71,6 +74,18 @@ void SCFDialect::initialize() {
 #include "mlir/Dialect/SCF/IR/SCFOps.cpp.inc"
       >();
   addInterfaces<SCFInlinerInterface>();
+  declarePromisedInterface<InParallelOp, bufferization::BufferDeallocationOpInterface>();
+  declarePromisedInterface<ReduceReturnOp, bufferization::BufferDeallocationOpInterface>();
+  declarePromisedInterface<ConditionOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ExecuteRegionOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ForOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<IfOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<IndexSwitchOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ForallOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InParallelOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<WhileOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<YieldOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ForOp, ValueBoundsOpInterface>();
 }
 
 /// Default callback for IfOp builders. Inserts a yield without arguments.
diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index d9ee39a4e8dd32..1f8eb38d008eb3 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -11,6 +11,7 @@
 #include "mlir/Dialect/Shape/IR/Shape.h"
 
 #include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/CommonFolders.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/Dialect/Traits.h"
@@ -143,6 +144,8 @@ void ShapeDialect::initialize() {
   // still evolving it makes it simple to start with an unregistered ops and
   // try different variants before actually defining the op.
   allowUnknownOperations();
+  declarePromisedInterface<AssumingOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<AssumingYieldOp, bufferization::BufferizableOpInterface>();
 }
 
 Operation *ShapeDialect::materializeConstant(OpBuilder &builder,
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 7750efdd9add0f..895b31c74e5f8f 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -16,6 +16,7 @@
 #include "mlir/Dialect/SparseTensor/IR/SparseTensorType.h"
 
 #include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Utils/StaticValueUtils.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/DialectImplementation.h"
@@ -1956,6 +1957,30 @@ void SparseTensorDialect::initialize() {
 #define GET_OP_LIST
 #include "mlir/Dialect/SparseTensor/IR/SparseTensorOps.cpp.inc"
       >();
+  declarePromisedInterface<ConcatenateOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ConvertOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<LoadOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<NewOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InsertOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<NumberOfEntriesOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<AssembleOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<DisassembleOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ToCoordinatesBufferOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ToCoordinatesOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ToPositionsOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ToValuesOp,
+                           bufferization::BufferizableOpInterface>();
 }
 
 #define GET_OP_CLASSES
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
index 62032ff301bece..ad7f288f6223f2 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
@@ -8,8 +8,11 @@
 
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Complex/IR/Complex.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
+#include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
+#include "mlir/Interfaces/SubsetOpInterface.h"
 #include "mlir/Transforms/InliningUtils.h"
 
 using namespace mlir;
@@ -45,4 +48,48 @@ void TensorDialect::initialize() {
 #include "mlir/Dialect/Tensor/IR/TensorOps.cpp.inc"
       >();
   addInterfaces<TensorInlinerInterface>();
+  declarePromisedInterface<CastOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<CollapseShapeOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<DimOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<EmptyOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ExpandShapeOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ExtractSliceOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ExtractOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<FromElementsOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<GenerateOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InsertOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InsertSliceOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<PadOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ParallelInsertSliceOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<RankOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ReshapeOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<SplatOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<CollapseShapeOp,
+                           transform::FindPayloadReplacementOpInterface>();
+  declarePromisedInterface<ExpandShapeOp,
+                           transform::FindPayloadReplacementOpInterface>();
+  declarePromisedInterface<ExtractSliceOp,
+                           transform::FindPayloadReplacementOpInterface>();
+  declarePromisedInterface<InsertSliceOp,
+                           transform::FindPayloadReplacementOpInterface>();
+  declarePromisedInterface<ReshapeOp,
+                           transform::FindPayloadReplacementOpInterface>();
+  declarePromisedInterface<ExpandShapeOp, ReifyRankedShapedTypeOpInterface>();
+  declarePromisedInterface<CollapseShapeOp, ReifyRankedShapedTypeOpInterface>();
+  declarePromisedInterface<PadOp, ReifyRankedShapedTypeOpInterface>();
+  declarePromisedInterface<ExtractSliceOp, SubsetOpInterface>();
+  declarePromisedInterface<ExtractSliceOp, SubsetExtractionOpInterface>();
+  declarePromisedInterface<InsertSliceOp, SubsetOpInterface>();
+  declarePromisedInterface<InsertSliceOp, SubsetInsertionOpInterface>();
+  declarePromisedInterface<ParallelInsertSliceOp, SubsetOpInterface>();
+  declarePromisedInterface<ParallelInsertSliceOp, SubsetInsertionOpInterface>();
+  declarePromisedInterface<PadOp, TilingInterface>();
+  declarePromisedInterface<PackOp, TilingInterface>();
+  declarePromisedInterface<UnPackOp, TilingInterface>();
+  declarePromisedInterface<CastOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<DimOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<EmptyOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<ExtractSliceOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<PadOp, ValueBoundsOpInterface>();
+  declarePromisedInterface<RankOp, ValueBoundsOpInterface>();
 }
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 75f6220ad8f3fa..e842a73a1dce62 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -16,6 +16,7 @@
 #include "mlir/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h"
 #include "mlir/Dialect/Arith/IR/Arith.h"
 #include "mlir/Dialect/Arith/Utils/Utils.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/Dialect/Utils/IndexingUtils.h"
@@ -31,6 +32,7 @@
 #include "mlir/IR/OpImplementation.h"
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/IR/TypeUtilities.h"
+#include "mlir/Interfaces/SubsetOpInterface.h"
 #include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Support/LLVM.h"
 #include "mlir/Transforms/InliningUtils.h"
@@ -374,6 +376,21 @@ void VectorDialect::initialize() {
       >();
 
   addInterfaces<VectorInlinerInterface>();
+
+  declarePromisedInterface<TransferReadOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<TransferWriteOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<GatherOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<MaskOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<YieldOp, bufferization::BufferizableOpInterface>();
+
+  declarePromisedInterface<TransferReadOp, SubsetOpInterface>();
+  declarePromisedInterface<TransferReadOp, SubsetExtractionOpInterface>();
+  declarePromisedInterface<TransferWriteOp, SubsetOpInterface>();
+  declarePromisedInterface<TransferWriteOp, SubsetInsertionOpInterface>();
 }
 
 /// Materialize a single constant operation from a given attribute value with

>From d241c76bff01d51bdbe3282374c3cbd5cb5c175f Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Tue, 16 Jan 2024 16:23:49 -0800
Subject: [PATCH 03/14] clang-format changes

---
 mlir/lib/Dialect/Arith/IR/ArithDialect.cpp    |  5 +++--
 .../Bufferization/IR/BufferizationDialect.cpp |  2 +-
 mlir/lib/Dialect/GPU/IR/GPUDialect.cpp        |  3 ++-
 mlir/lib/Dialect/SCF/IR/SCF.cpp               | 20 +++++++++++-------
 mlir/lib/Dialect/Shape/IR/Shape.cpp           |  6 ++++--
 .../SparseTensor/IR/SparseTensorDialect.cpp   | 12 ++++-------
 mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp  | 21 ++++++++++++-------
 mlir/lib/Dialect/Vector/IR/VectorOps.cpp      |  6 ++----
 8 files changed, 43 insertions(+), 32 deletions(-)

diff --git a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
index 1c5b0d8df44ed7..1ebc4588bf9ea9 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
@@ -11,9 +11,9 @@
 #include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/UB/IR/UBOps.h"
-#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/DialectImplementation.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Transforms/InliningUtils.h"
 #include "llvm/ADT/TypeSwitch.h"
 
@@ -49,7 +49,8 @@ void arith::ArithDialect::initialize() {
       >();
   addInterfaces<ArithInlinerInterface>();
   declarePromisedInterface<ArithDialect, ConvertToLLVMPatternInterface>();
-  declarePromisedInterface<SelectOp, bufferization::BufferDeallocationOpInterface>();
+  declarePromisedInterface<SelectOp,
+                           bufferization::BufferDeallocationOpInterface>();
   declarePromisedInterface<ConstantOp,
                            bufferization::BufferizableOpInterface>();
   declarePromisedInterface<IndexCastOp,
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
index d8a38868ac862a..c4d91ba72daac4 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
@@ -9,8 +9,8 @@
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/IR/Bufferization.h"
-#include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/Interfaces/FunctionInterfaces.h"
 #include "mlir/Transforms/InliningUtils.h"
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 37297ce555efec..a02eca8b11790c 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -216,7 +216,8 @@ void GPUDialect::initialize() {
 #include "mlir/Dialect/GPU/IR/GPUOpsAttributes.cpp.inc"
       >();
   addInterfaces<GPUInlinerInterface>();
-  declarePromisedInterface<TerminatorOp, bufferization::BufferDeallocationOpInterface>();
+  declarePromisedInterface<TerminatorOp,
+                           bufferization::BufferDeallocationOpInterface>();
 }
 
 static std::string getSparseHandleKeyword(SparseHandleKind kind) {
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index ce75eca0e6e6c5..399df4bc22cea4 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -15,12 +15,12 @@
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/SCF/IR/DeviceMappingInterface.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
-#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/IRMapping.h"
 #include "mlir/IR/Matchers.h"
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/Interfaces/FunctionInterfaces.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Support/MathExtras.h"
 #include "mlir/Transforms/InliningUtils.h"
 #include "llvm/ADT/MapVector.h"
@@ -74,15 +74,21 @@ void SCFDialect::initialize() {
 #include "mlir/Dialect/SCF/IR/SCFOps.cpp.inc"
       >();
   addInterfaces<SCFInlinerInterface>();
-  declarePromisedInterface<InParallelOp, bufferization::BufferDeallocationOpInterface>();
-  declarePromisedInterface<ReduceReturnOp, bufferization::BufferDeallocationOpInterface>();
-  declarePromisedInterface<ConditionOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ExecuteRegionOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InParallelOp,
+                           bufferization::BufferDeallocationOpInterface>();
+  declarePromisedInterface<ReduceReturnOp,
+                           bufferization::BufferDeallocationOpInterface>();
+  declarePromisedInterface<ConditionOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ExecuteRegionOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<ForOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<IfOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<IndexSwitchOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<IndexSwitchOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<ForallOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<InParallelOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InParallelOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<WhileOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<YieldOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<ForOp, ValueBoundsOpInterface>();
diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index 1f8eb38d008eb3..76e1e3fa86fe9d 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -144,8 +144,10 @@ void ShapeDialect::initialize() {
   // still evolving it makes it simple to start with an unregistered ops and
   // try different variants before actually defining the op.
   allowUnknownOperations();
-  declarePromisedInterface<AssumingOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<AssumingYieldOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<AssumingOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<AssumingYieldOp,
+                           bufferization::BufferizableOpInterface>();
 }
 
 Operation *ShapeDialect::materializeConstant(OpBuilder &builder,
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 895b31c74e5f8f..0c0b8595ad825d 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1959,14 +1959,10 @@ void SparseTensorDialect::initialize() {
       >();
   declarePromisedInterface<ConcatenateOp,
                            bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ConvertOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<LoadOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<NewOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<InsertOp,
-                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ConvertOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<LoadOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<NewOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InsertOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<NumberOfEntriesOp,
                            bufferization::BufferizableOpInterface>();
   declarePromisedInterface<AssembleOp,
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
index ad7f288f6223f2..8c215aae62d6d2 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
@@ -49,18 +49,25 @@ void TensorDialect::initialize() {
       >();
   addInterfaces<TensorInlinerInterface>();
   declarePromisedInterface<CastOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<CollapseShapeOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<CollapseShapeOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<DimOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<EmptyOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ExpandShapeOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ExtractSliceOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ExpandShapeOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ExtractSliceOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<ExtractOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<FromElementsOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<GenerateOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<FromElementsOp,
+                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<GenerateOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<InsertOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<InsertSliceOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<InsertSliceOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<PadOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ParallelInsertSliceOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<ParallelInsertSliceOp,
+                           bufferization::BufferizableOpInterface>();
   declarePromisedInterface<RankOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<ReshapeOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<SplatOp, bufferization::BufferizableOpInterface>();
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index e842a73a1dce62..44d51a7da72d27 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -381,10 +381,8 @@ void VectorDialect::initialize() {
                            bufferization::BufferizableOpInterface>();
   declarePromisedInterface<TransferWriteOp,
                            bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<GatherOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<MaskOp,
-                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<GatherOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterface<MaskOp, bufferization::BufferizableOpInterface>();
   declarePromisedInterface<YieldOp, bufferization::BufferizableOpInterface>();
 
   declarePromisedInterface<TransferReadOp, SubsetOpInterface>();

>From 0c5d7b33a0ffb79b5f91549809a04ef6f517160c Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Tue, 16 Jan 2024 16:29:04 -0800
Subject: [PATCH 04/14] clang-format changes

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index fb7bfd906cc2cc..ae2e965bfd5068 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -8,7 +8,6 @@
 
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Affine/IR/AffineValueMap.h"
-#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/UB/IR/UBOps.h"
 #include "mlir/IR/AffineExprVisitor.h"
@@ -18,6 +17,7 @@
 #include "mlir/IR/OpDefinition.h"
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/Interfaces/ShapedOpInterfaces.h"
+#include "mlir/Interfaces/ValueBoundsOpInterface.h"
 #include "mlir/Support/MathExtras.h"
 #include "mlir/Transforms/InliningUtils.h"
 #include "llvm/ADT/ScopeExit.h"

>From 6d8516503fca5586d6842a17fa72993819367441 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Sat, 27 Jan 2024 18:32:40 -0800
Subject: [PATCH 05/14] Declare multiple interfaces at once for Linalg and Tosa

---
 mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp | 30 ++++++++++++++++++++
 mlir/lib/Dialect/Tosa/IR/TosaOps.cpp         | 20 +++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
index 87cd452b52c6de..803706d2810329 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
@@ -21,6 +21,7 @@
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/Dialect.h"
 #include "mlir/IR/DialectImplementation.h"
+#include "mlir/Interfaces/DestinationStyleOpInterface.h"
 #include "mlir/Interfaces/FunctionInterfaces.h"
 #include "mlir/Interfaces/SubsetOpInterface.h"
 #include "mlir/Interfaces/ValueBoundsOpInterface.h"
@@ -100,6 +101,25 @@ void addNamedOpBuilders(
   (addNamedOpBuilderImpl<OpTypes>(map), ...);
 }
 
+template <typename... Ops>
+struct LinalgOpInterfaceHelper {
+  static void declareOpInterface(LinalgDialect *dialect) {
+    (dialect->declarePromisedInterface<Ops, bufferization::BufferizableOpInterface>(), ...);
+  }
+};
+
+template <typename OpType>
+static void declareOne(LinalgDialect *dialect) {
+  dialect->declarePromisedInterface<OpType, TilingInterface>();
+  dialect->declarePromisedInterface<OpType, PartialReductionOpInterface>();
+}
+
+/// Variadic helper function.
+template <typename... OpTypes>
+static void declareAll(LinalgDialect *dialect) {
+  (declareOne<OpTypes>(), ...);
+}
+
 void mlir::linalg::LinalgDialect::initialize() {
   addAttributes<
 #define GET_ATTRDEF_LIST
@@ -130,6 +150,16 @@ void mlir::linalg::LinalgDialect::initialize() {
   declarePromisedInterface<CopyOp, SubsetOpInterface>();
   declarePromisedInterface<CopyOp, SubsetInsertionOpInterface>();
   declarePromisedInterface<IndexOp, ValueBoundsOpInterface>();
+
+  declareOne<linalg::GenericOp>(this);
+  declareAll<
+#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
+      >(this);
+
+  LinalgOpInterfaceHelper<
+#define GET_OP_LIST
+#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
+        >::declareOpInterface(this);
 }
 
 LogicalResult LinalgDialect::verifyOperationAttribute(Operation *op,
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 62d07859e32f6e..35b841187f218c 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "mlir/Dialect/Mesh/Interfaces/ShardingInterface.h"
 #include "mlir/Dialect/Tosa/IR/TosaOps.h"
 #include "mlir/Dialect/Quant/QuantOps.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
@@ -126,6 +127,17 @@ SmallVector<Region *> tosa::WhileOp::getLoopRegions() { return {&getBody()}; }
 // Tosa dialect initialization.
 //===----------------------------------------------------------------------===//
 
+template <typename OpType>
+static void declareElemwiseOne(TosaDialect *dialect) {
+  dialect->declarePromisedInterface<OpType, mesh::ShardingInterface>();
+}
+
+/// Variadic helper function.
+template <typename... OpTypes>
+static void declareElemwiseAll(TosaDialect *dialect) {
+  (declareElemwiseOne<OpTypes>(dialect), ...);
+}
+
 void TosaDialect::initialize() {
   addOperations<
 #define GET_OP_LIST
@@ -136,6 +148,14 @@ void TosaDialect::initialize() {
 #include "mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
       >();
   addInterfaces<TosaDialectBytecodeInterface, TosaInlinerInterface>();
+  declareElemwiseAll<ClampOp, SigmoidOp, TanhOp, AddOp, ArithmeticRightShiftOp,
+                     BitwiseAndOp, BitwiseOrOp, BitwiseXorOp, DivOp,
+                     LogicalAndOp, LogicalLeftShiftOp, LogicalRightShiftOp,
+                     LogicalOrOp, LogicalXorOp, MaximumOp, MinimumOp, MulOp,
+                     PowOp, SubOp, AbsOp, BitwiseNotOp, CeilOp, ClzOp, ExpOp,
+                     FloorOp, LogOp, LogicalNotOp, NegateOp, ReciprocalOp,
+                     RsqrtOp, SelectOp, EqualOp, GreaterOp, GreaterEqualOp>(this);
+  declarePromisedInterface<MatMulOp, mesh::ShardingInterface>();
 }
 
 Operation *TosaDialect::materializeConstant(OpBuilder &builder, Attribute value,

>From 5b43f43773442574769a47fbf0d6d808906c4cc0 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Sat, 27 Jan 2024 19:53:23 -0800
Subject: [PATCH 06/14] clang-format changes

---
 mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp | 6 ++++--
 mlir/lib/Dialect/Tosa/IR/TosaOps.cpp         | 5 +++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
index 803706d2810329..8afcd00cc58ba1 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
@@ -104,7 +104,9 @@ void addNamedOpBuilders(
 template <typename... Ops>
 struct LinalgOpInterfaceHelper {
   static void declareOpInterface(LinalgDialect *dialect) {
-    (dialect->declarePromisedInterface<Ops, bufferization::BufferizableOpInterface>(), ...);
+    (dialect->declarePromisedInterface<
+         Ops, bufferization::BufferizableOpInterface>(),
+     ...);
   }
 };
 
@@ -159,7 +161,7 @@ void mlir::linalg::LinalgDialect::initialize() {
   LinalgOpInterfaceHelper<
 #define GET_OP_LIST
 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
-        >::declareOpInterface(this);
+      >::declareOpInterface(this);
 }
 
 LogicalResult LinalgDialect::verifyOperationAttribute(Operation *op,
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 35b841187f218c..50e39caf4b68c2 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -12,8 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "mlir/Dialect/Mesh/Interfaces/ShardingInterface.h"
 #include "mlir/Dialect/Tosa/IR/TosaOps.h"
+#include "mlir/Dialect/Mesh/Interfaces/ShardingInterface.h"
 #include "mlir/Dialect/Quant/QuantOps.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/Dialect/Tosa/Utils/QuantUtils.h"
@@ -154,7 +154,8 @@ void TosaDialect::initialize() {
                      LogicalOrOp, LogicalXorOp, MaximumOp, MinimumOp, MulOp,
                      PowOp, SubOp, AbsOp, BitwiseNotOp, CeilOp, ClzOp, ExpOp,
                      FloorOp, LogOp, LogicalNotOp, NegateOp, ReciprocalOp,
-                     RsqrtOp, SelectOp, EqualOp, GreaterOp, GreaterEqualOp>(this);
+                     RsqrtOp, SelectOp, EqualOp, GreaterOp, GreaterEqualOp>(
+      this);
   declarePromisedInterface<MatMulOp, mesh::ShardingInterface>();
 }
 

>From 94cc0b66ea786123f78a4fe34d05155894b7107d Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Thu, 1 Feb 2024 19:58:52 -0800
Subject: [PATCH 07/14] Include from Tensor instead of Transform

---
 mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
index 8c215aae62d6d2..e8bb2ec96b4786 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
@@ -11,7 +11,7 @@
 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Complex/IR/Complex.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
-#include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
+#include "mlir/Dialect/Tensor/TransformOps/TensorTransformOps.h"
 #include "mlir/Interfaces/SubsetOpInterface.h"
 #include "mlir/Transforms/InliningUtils.h"
 

>From 38cdac696bcc95583fa4f9c5408f0e4fcdb26c3b Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Sun, 11 Feb 2024 14:15:49 -0800
Subject: [PATCH 08/14] Declare multiple promised interfaces at once

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp      |  5 +-
 mlir/lib/Dialect/Arith/IR/ArithDialect.cpp    | 13 ++--
 .../Bufferization/IR/BufferizationDialect.cpp |  5 +-
 .../Dialect/ControlFlow/IR/ControlFlowOps.cpp |  5 +-
 mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp  | 39 +++--------
 mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp  | 22 ++----
 mlir/lib/Dialect/SCF/IR/SCF.cpp               | 22 ++----
 mlir/lib/Dialect/Shape/IR/Shape.cpp           |  6 +-
 .../SparseTensor/IR/SparseTensorDialect.cpp   | 24 ++-----
 mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp  | 67 +++++--------------
 mlir/lib/Dialect/Tosa/IR/TosaOps.cpp          | 28 +++-----
 mlir/lib/Dialect/Vector/IR/VectorOps.cpp      | 15 ++---
 12 files changed, 68 insertions(+), 183 deletions(-)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index ae2e965bfd5068..c591e5056480ca 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -221,9 +221,8 @@ void AffineDialect::initialize() {
 #include "mlir/Dialect/Affine/IR/AffineOps.cpp.inc"
                 >();
   addInterfaces<AffineInlinerInterface>();
-  declarePromisedInterface<AffineApplyOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<AffineMaxOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<AffineMinOp, ValueBoundsOpInterface>();
+  declarePromisedInterfaces<ValueBoundsOpInterface, AffineApplyOp, AffineMaxOp,
+                            AffineMinOp>();
 }
 
 /// Materialize a single constant operation from a given attribute value with
diff --git a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
index 1ebc4588bf9ea9..6a593185ccedce 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithDialect.cpp
@@ -51,15 +51,10 @@ void arith::ArithDialect::initialize() {
   declarePromisedInterface<ArithDialect, ConvertToLLVMPatternInterface>();
   declarePromisedInterface<SelectOp,
                            bufferization::BufferDeallocationOpInterface>();
-  declarePromisedInterface<ConstantOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<IndexCastOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<SelectOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<AddIOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<ConstantOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<SubIOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<MulIOp, ValueBoundsOpInterface>();
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface, ConstantOp,
+                            IndexCastOp, SelectOp>();
+  declarePromisedInterfaces<ValueBoundsOpInterface, AddIOp, ConstantOp, SubIOp,
+                            MulIOp>();
 }
 
 /// Materialize an integer or floating point constant.
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
index c4d91ba72daac4..a03e43bc039eb6 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
@@ -64,9 +64,8 @@ void mlir::bufferization::BufferizationDialect::initialize() {
 #include "mlir/Dialect/Bufferization/IR/BufferizationOps.cpp.inc"
       >();
   addInterfaces<BufferizationInlinerInterface>();
-  declarePromisedInterface<func::CallOp, BufferizableOpInterface>();
-  declarePromisedInterface<func::FuncOp, BufferizableOpInterface>();
-  declarePromisedInterface<func::ReturnOp, BufferizableOpInterface>();
+  declarePromisedInterfaces<BufferizableOpInterface, func::CallOp, func::FuncOp,
+                            func::ReturnOp>();
 }
 
 LogicalResult BufferizationDialect::verifyRegionArgAttribute(
diff --git a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
index 95027fc52791f3..c6b02b9703e75f 100644
--- a/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp
@@ -71,9 +71,8 @@ void ControlFlowDialect::initialize() {
       >();
   addInterfaces<ControlFlowInlinerInterface>();
   declarePromisedInterface<ControlFlowDialect, ConvertToLLVMPatternInterface>();
-  declarePromisedInterface<BranchOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<CondBranchOp,
-                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface, BranchOp,
+                            CondBranchOp>();
   declarePromisedInterface<CondBranchOp,
                            bufferization::BufferDeallocationOpInterface>();
 }
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
index 8afcd00cc58ba1..a6936fde43709d 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgDialect.cpp
@@ -101,27 +101,6 @@ void addNamedOpBuilders(
   (addNamedOpBuilderImpl<OpTypes>(map), ...);
 }
 
-template <typename... Ops>
-struct LinalgOpInterfaceHelper {
-  static void declareOpInterface(LinalgDialect *dialect) {
-    (dialect->declarePromisedInterface<
-         Ops, bufferization::BufferizableOpInterface>(),
-     ...);
-  }
-};
-
-template <typename OpType>
-static void declareOne(LinalgDialect *dialect) {
-  dialect->declarePromisedInterface<OpType, TilingInterface>();
-  dialect->declarePromisedInterface<OpType, PartialReductionOpInterface>();
-}
-
-/// Variadic helper function.
-template <typename... OpTypes>
-static void declareAll(LinalgDialect *dialect) {
-  (declareOne<OpTypes>(), ...);
-}
-
 void mlir::linalg::LinalgDialect::initialize() {
   addAttributes<
 #define GET_ATTRDEF_LIST
@@ -152,16 +131,20 @@ void mlir::linalg::LinalgDialect::initialize() {
   declarePromisedInterface<CopyOp, SubsetOpInterface>();
   declarePromisedInterface<CopyOp, SubsetInsertionOpInterface>();
   declarePromisedInterface<IndexOp, ValueBoundsOpInterface>();
-
-  declareOne<linalg::GenericOp>(this);
-  declareAll<
+  declarePromisedInterface<linalg::GenericOp, TilingInterface>();
+  declarePromisedInterface<linalg::GenericOp, PartialReductionOpInterface>();
+  declarePromisedInterfaces<TilingInterface,
+#define GET_OP_LIST
 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
-      >(this);
-
-  LinalgOpInterfaceHelper<
+                            >();
+  declarePromisedInterfaces<PartialReductionOpInterface,
 #define GET_OP_LIST
 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
-      >::declareOpInterface(this);
+                            >();
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface,
+#define GET_OP_LIST
+#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
+                            >();
 }
 
 LogicalResult LinalgDialect::verifyOperationAttribute(Operation *op,
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
index 47c236a267ca99..41082a85a485f2 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp
@@ -48,22 +48,12 @@ void mlir::memref::MemRefDialect::initialize() {
       >();
   addInterfaces<MemRefInlinerInterface>();
   declarePromisedInterface<MemRefDialect, ConvertToLLVMPatternInterface>();
-  declarePromisedInterface<AllocOp, bufferization::AllocationOpInterface>();
-  declarePromisedInterface<AllocaOp, bufferization::AllocationOpInterface>();
-  declarePromisedInterface<ReallocOp, bufferization::AllocationOpInterface>();
-  declarePromisedInterface<CastOp, RuntimeVerifiableOpInterface>();
-  declarePromisedInterface<ExpandShapeOp, RuntimeVerifiableOpInterface>();
-  declarePromisedInterface<LoadOp, RuntimeVerifiableOpInterface>();
-  declarePromisedInterface<ReinterpretCastOp, RuntimeVerifiableOpInterface>();
-  declarePromisedInterface<StoreOp, RuntimeVerifiableOpInterface>();
-  declarePromisedInterface<SubViewOp, RuntimeVerifiableOpInterface>();
-  declarePromisedInterface<AllocOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<AllocaOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<CastOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<DimOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<GetGlobalOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<RankOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<SubViewOp, ValueBoundsOpInterface>();
+  declarePromisedInterfaces<bufferization::AllocationOpInterface, AllocOp,
+                            AllocaOp, ReallocOp>();
+  declarePromisedInterfaces<RuntimeVerifiableOpInterface, CastOp, ExpandShapeOp,
+                            LoadOp, ReinterpretCastOp, StoreOp, SubViewOp>();
+  declarePromisedInterfaces<ValueBoundsOpInterface, AllocOp, AllocaOp, CastOp,
+                            DimOp, GetGlobalOp, RankOp, SubViewOp>();
   declarePromisedInterface<MemRefType, DestructurableTypeInterface>();
 }
 
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 399df4bc22cea4..7d036876bd508a 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -74,23 +74,11 @@ void SCFDialect::initialize() {
 #include "mlir/Dialect/SCF/IR/SCFOps.cpp.inc"
       >();
   addInterfaces<SCFInlinerInterface>();
-  declarePromisedInterface<InParallelOp,
-                           bufferization::BufferDeallocationOpInterface>();
-  declarePromisedInterface<ReduceReturnOp,
-                           bufferization::BufferDeallocationOpInterface>();
-  declarePromisedInterface<ConditionOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ExecuteRegionOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ForOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<IfOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<IndexSwitchOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ForallOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<InParallelOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<WhileOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<YieldOp, bufferization::BufferizableOpInterface>();
+  declarePromisedInterfaces<bufferization::BufferDeallocationOpInterface,
+                            InParallelOp, ReduceReturnOp>();
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface, ConditionOp,
+                           ExecuteRegionOp, ForOp, IfOp, IndexSwitchOp,
+                           ForallOp, InParallelOp, WhileOp, YieldOp>();
   declarePromisedInterface<ForOp, ValueBoundsOpInterface>();
 }
 
diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index 76e1e3fa86fe9d..f5a3717f815de5 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -144,10 +144,8 @@ void ShapeDialect::initialize() {
   // still evolving it makes it simple to start with an unregistered ops and
   // try different variants before actually defining the op.
   allowUnknownOperations();
-  declarePromisedInterface<AssumingOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<AssumingYieldOp,
-                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface, AssumingOp,
+                            AssumingYieldOp>();
 }
 
 Operation *ShapeDialect::materializeConstant(OpBuilder &builder,
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 0c0b8595ad825d..bc8992014f84e8 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1957,26 +1957,10 @@ void SparseTensorDialect::initialize() {
 #define GET_OP_LIST
 #include "mlir/Dialect/SparseTensor/IR/SparseTensorOps.cpp.inc"
       >();
-  declarePromisedInterface<ConcatenateOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ConvertOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<LoadOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<NewOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<InsertOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<NumberOfEntriesOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<AssembleOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<DisassembleOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ToCoordinatesBufferOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ToCoordinatesOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ToPositionsOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ToValuesOp,
-                           bufferization::BufferizableOpInterface>();
+  declarePromisedInterfaces<
+      bufferization::BufferizableOpInterface, ConcatenateOp, ConvertOp, LoadOp,
+      NewOp, InsertOp, NumberOfEntriesOp, AssembleOp, DisassembleOp,
+      ToCoordinatesBufferOp, ToCoordinatesOp, ToPositionsOp, ToValuesOp>();
 }
 
 #define GET_OP_CLASSES
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
index e8bb2ec96b4786..a8f2215455b02a 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
@@ -48,55 +48,22 @@ void TensorDialect::initialize() {
 #include "mlir/Dialect/Tensor/IR/TensorOps.cpp.inc"
       >();
   addInterfaces<TensorInlinerInterface>();
-  declarePromisedInterface<CastOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<CollapseShapeOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<DimOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<EmptyOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ExpandShapeOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ExtractSliceOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ExtractOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<FromElementsOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<GenerateOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<InsertOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<InsertSliceOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<PadOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ParallelInsertSliceOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<RankOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<ReshapeOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<SplatOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<CollapseShapeOp,
-                           transform::FindPayloadReplacementOpInterface>();
-  declarePromisedInterface<ExpandShapeOp,
-                           transform::FindPayloadReplacementOpInterface>();
-  declarePromisedInterface<ExtractSliceOp,
-                           transform::FindPayloadReplacementOpInterface>();
-  declarePromisedInterface<InsertSliceOp,
-                           transform::FindPayloadReplacementOpInterface>();
-  declarePromisedInterface<ReshapeOp,
-                           transform::FindPayloadReplacementOpInterface>();
-  declarePromisedInterface<ExpandShapeOp, ReifyRankedShapedTypeOpInterface>();
-  declarePromisedInterface<CollapseShapeOp, ReifyRankedShapedTypeOpInterface>();
-  declarePromisedInterface<PadOp, ReifyRankedShapedTypeOpInterface>();
-  declarePromisedInterface<ExtractSliceOp, SubsetOpInterface>();
+  declarePromisedInterfaces<
+      bufferization::BufferizableOpInterface, CastOp, CollapseShapeOp, DimOp,
+      EmptyOp, ExpandShapeOp, ExtractSliceOp, ExtractOp, FromElementsOp,
+      GenerateOp, InsertOp, InsertSliceOp, PadOp, ParallelInsertSliceOp, RankOp,
+      ReshapeOp, SplatOp>();
+  declarePromisedInterfaces<transform::FindPayloadReplacementOpInterface,
+                           CollapseShapeOp, ExpandShapeOp, ExtractSliceOp,
+                           InsertSliceOp, ReshapeOp>();
+  declarePromisedInterfaces<ReifyRankedShapedTypeOpInterface, ExpandShapeOp,
+                            CollapseShapeOp, PadOp>();
+  declarePromisedInterfaces<SubsetOpInterface, ExtractSliceOp, InsertSliceOp,
+                            ParallelInsertSliceOp>();
+  declarePromisedInterfaces<SubsetInsertionOpInterface, InsertSliceOp,
+                            ParallelInsertSliceOp>();
   declarePromisedInterface<ExtractSliceOp, SubsetExtractionOpInterface>();
-  declarePromisedInterface<InsertSliceOp, SubsetOpInterface>();
-  declarePromisedInterface<InsertSliceOp, SubsetInsertionOpInterface>();
-  declarePromisedInterface<ParallelInsertSliceOp, SubsetOpInterface>();
-  declarePromisedInterface<ParallelInsertSliceOp, SubsetInsertionOpInterface>();
-  declarePromisedInterface<PadOp, TilingInterface>();
-  declarePromisedInterface<PackOp, TilingInterface>();
-  declarePromisedInterface<UnPackOp, TilingInterface>();
-  declarePromisedInterface<CastOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<DimOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<EmptyOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<ExtractSliceOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<PadOp, ValueBoundsOpInterface>();
-  declarePromisedInterface<RankOp, ValueBoundsOpInterface>();
+  declarePromisedInterfaces<TilingInterface, PadOp, PackOp, UnPackOp>();
+  declarePromisedInterfaces<ValueBoundsOpInterface, CastOp, DimOp, EmptyOp,
+                           ExtractSliceOp, PadOp, RankOp>();
 }
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 50e39caf4b68c2..f461e7e1a555b8 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -127,17 +127,6 @@ SmallVector<Region *> tosa::WhileOp::getLoopRegions() { return {&getBody()}; }
 // Tosa dialect initialization.
 //===----------------------------------------------------------------------===//
 
-template <typename OpType>
-static void declareElemwiseOne(TosaDialect *dialect) {
-  dialect->declarePromisedInterface<OpType, mesh::ShardingInterface>();
-}
-
-/// Variadic helper function.
-template <typename... OpTypes>
-static void declareElemwiseAll(TosaDialect *dialect) {
-  (declareElemwiseOne<OpTypes>(dialect), ...);
-}
-
 void TosaDialect::initialize() {
   addOperations<
 #define GET_OP_LIST
@@ -148,15 +137,14 @@ void TosaDialect::initialize() {
 #include "mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
       >();
   addInterfaces<TosaDialectBytecodeInterface, TosaInlinerInterface>();
-  declareElemwiseAll<ClampOp, SigmoidOp, TanhOp, AddOp, ArithmeticRightShiftOp,
-                     BitwiseAndOp, BitwiseOrOp, BitwiseXorOp, DivOp,
-                     LogicalAndOp, LogicalLeftShiftOp, LogicalRightShiftOp,
-                     LogicalOrOp, LogicalXorOp, MaximumOp, MinimumOp, MulOp,
-                     PowOp, SubOp, AbsOp, BitwiseNotOp, CeilOp, ClzOp, ExpOp,
-                     FloorOp, LogOp, LogicalNotOp, NegateOp, ReciprocalOp,
-                     RsqrtOp, SelectOp, EqualOp, GreaterOp, GreaterEqualOp>(
-      this);
-  declarePromisedInterface<MatMulOp, mesh::ShardingInterface>();
+  declarePromisedInterfaces<
+      mesh::ShardingInterface, ClampOp, SigmoidOp, TanhOp, AddOp,
+      ArithmeticRightShiftOp, BitwiseAndOp, BitwiseOrOp, BitwiseXorOp, DivOp,
+      LogicalAndOp, LogicalLeftShiftOp, LogicalRightShiftOp, LogicalOrOp,
+      LogicalXorOp, MaximumOp, MinimumOp, MulOp, PowOp, SubOp, AbsOp,
+      BitwiseNotOp, CeilOp, ClzOp, ExpOp, FloorOp, LogOp, LogicalNotOp,
+      NegateOp, ReciprocalOp, RsqrtOp, SelectOp, EqualOp, GreaterOp,
+      GreaterEqualOp, MatMulOp>();
 }
 
 Operation *TosaDialect::materializeConstant(OpBuilder &builder, Attribute value,
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 44d51a7da72d27..1119d5051cc1ef 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -377,17 +377,12 @@ void VectorDialect::initialize() {
 
   addInterfaces<VectorInlinerInterface>();
 
-  declarePromisedInterface<TransferReadOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<TransferWriteOp,
-                           bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<GatherOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<MaskOp, bufferization::BufferizableOpInterface>();
-  declarePromisedInterface<YieldOp, bufferization::BufferizableOpInterface>();
-
-  declarePromisedInterface<TransferReadOp, SubsetOpInterface>();
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface,
+                           TransferReadOp, TransferWriteOp, GatherOp, MaskOp,
+                           YieldOp>();
+  declarePromisedInterfaces<SubsetOpInterface, TransferReadOp,
+                           TransferWriteOp>();
   declarePromisedInterface<TransferReadOp, SubsetExtractionOpInterface>();
-  declarePromisedInterface<TransferWriteOp, SubsetOpInterface>();
   declarePromisedInterface<TransferWriteOp, SubsetInsertionOpInterface>();
 }
 

>From 192edb41b5fa84479a7fe4835513568263240c98 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Sun, 11 Feb 2024 14:41:51 -0800
Subject: [PATCH 09/14] clang-format fixes

---
 mlir/lib/Dialect/SCF/IR/SCF.cpp              | 4 ++--
 mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp | 6 +++---
 mlir/lib/Dialect/Vector/IR/VectorOps.cpp     | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 7d036876bd508a..ddb9676eb4f628 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -77,8 +77,8 @@ void SCFDialect::initialize() {
   declarePromisedInterfaces<bufferization::BufferDeallocationOpInterface,
                             InParallelOp, ReduceReturnOp>();
   declarePromisedInterfaces<bufferization::BufferizableOpInterface, ConditionOp,
-                           ExecuteRegionOp, ForOp, IfOp, IndexSwitchOp,
-                           ForallOp, InParallelOp, WhileOp, YieldOp>();
+                            ExecuteRegionOp, ForOp, IfOp, IndexSwitchOp,
+                            ForallOp, InParallelOp, WhileOp, YieldOp>();
   declarePromisedInterface<ForOp, ValueBoundsOpInterface>();
 }
 
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
index a8f2215455b02a..b660a2de7b9d9a 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
@@ -54,8 +54,8 @@ void TensorDialect::initialize() {
       GenerateOp, InsertOp, InsertSliceOp, PadOp, ParallelInsertSliceOp, RankOp,
       ReshapeOp, SplatOp>();
   declarePromisedInterfaces<transform::FindPayloadReplacementOpInterface,
-                           CollapseShapeOp, ExpandShapeOp, ExtractSliceOp,
-                           InsertSliceOp, ReshapeOp>();
+                            CollapseShapeOp, ExpandShapeOp, ExtractSliceOp,
+                            InsertSliceOp, ReshapeOp>();
   declarePromisedInterfaces<ReifyRankedShapedTypeOpInterface, ExpandShapeOp,
                             CollapseShapeOp, PadOp>();
   declarePromisedInterfaces<SubsetOpInterface, ExtractSliceOp, InsertSliceOp,
@@ -65,5 +65,5 @@ void TensorDialect::initialize() {
   declarePromisedInterface<ExtractSliceOp, SubsetExtractionOpInterface>();
   declarePromisedInterfaces<TilingInterface, PadOp, PackOp, UnPackOp>();
   declarePromisedInterfaces<ValueBoundsOpInterface, CastOp, DimOp, EmptyOp,
-                           ExtractSliceOp, PadOp, RankOp>();
+                            ExtractSliceOp, PadOp, RankOp>();
 }
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 1119d5051cc1ef..023aec79a1c0f7 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -378,10 +378,10 @@ void VectorDialect::initialize() {
   addInterfaces<VectorInlinerInterface>();
 
   declarePromisedInterfaces<bufferization::BufferizableOpInterface,
-                           TransferReadOp, TransferWriteOp, GatherOp, MaskOp,
-                           YieldOp>();
+                            TransferReadOp, TransferWriteOp, GatherOp, MaskOp,
+                            YieldOp>();
   declarePromisedInterfaces<SubsetOpInterface, TransferReadOp,
-                           TransferWriteOp>();
+                            TransferWriteOp>();
   declarePromisedInterface<TransferReadOp, SubsetExtractionOpInterface>();
   declarePromisedInterface<TransferWriteOp, SubsetInsertionOpInterface>();
 }

>From 6dc11c8a2b8b0be1283236f4d0800646ca35b4a6 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Wed, 6 Mar 2024 21:57:19 -0800
Subject: [PATCH 10/14] Update include

---
 mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
index b660a2de7b9d9a..5ca9510408c301 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorDialect.cpp
@@ -11,7 +11,7 @@
 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Complex/IR/Complex.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
-#include "mlir/Dialect/Tensor/TransformOps/TensorTransformOps.h"
+#include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
 #include "mlir/Interfaces/SubsetOpInterface.h"
 #include "mlir/Transforms/InliningUtils.h"
 

>From 66b8d87e48af0ff330fd4293bb8fcc2c5d07cfe1 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Tue, 12 Mar 2024 21:04:41 -0700
Subject: [PATCH 11/14] Don't declare an promised interface for InsertOp

---
 mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index bc8992014f84e8..6da51bb6b9cacf 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1959,7 +1959,7 @@ void SparseTensorDialect::initialize() {
       >();
   declarePromisedInterfaces<
       bufferization::BufferizableOpInterface, ConcatenateOp, ConvertOp, LoadOp,
-      NewOp, InsertOp, NumberOfEntriesOp, AssembleOp, DisassembleOp,
+      NewOp, NumberOfEntriesOp, AssembleOp, DisassembleOp,
       ToCoordinatesBufferOp, ToCoordinatesOp, ToPositionsOp, ToValuesOp>();
 }
 

>From 1b74a03e6260dc86c6568d88bf51efe0a3329115 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Tue, 12 Mar 2024 21:30:28 -0700
Subject: [PATCH 12/14] Add `MLIRShardingInterfaceIncGen` dependency

---
 mlir/lib/Dialect/Tosa/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/lib/Dialect/Tosa/CMakeLists.txt b/mlir/lib/Dialect/Tosa/CMakeLists.txt
index ba5343dcd7ac6c..1911405c63cd58 100644
--- a/mlir/lib/Dialect/Tosa/CMakeLists.txt
+++ b/mlir/lib/Dialect/Tosa/CMakeLists.txt
@@ -12,6 +12,7 @@ add_mlir_dialect_library(MLIRTosaDialect
   MLIRTosaDialectBytecodeIncGen
   MLIRTosaOpsIncGen
   MLIRTosaInterfacesIncGen
+  MLIRShardingInterfaceIncGen
 
   LINK_LIBS PUBLIC
   MLIRIR

>From 8273ef4fe34d030c4ec9e1d5ea9426502e4451f1 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Thu, 14 Mar 2024 17:27:20 -0700
Subject: [PATCH 13/14] Move Func Op declared interfaces to the Func Dialect
 code.

---
 mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp | 3 ---
 mlir/lib/Dialect/Func/IR/FuncOps.cpp                       | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
index a03e43bc039eb6..e5a0c3c45b09e2 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationDialect.cpp
@@ -9,7 +9,6 @@
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/Dialect/Bufferization/IR/Bufferization.h"
-#include "mlir/Dialect/Func/IR/FuncOps.h"
 #include "mlir/Dialect/MemRef/IR/MemRef.h"
 #include "mlir/Dialect/Tensor/IR/Tensor.h"
 #include "mlir/Interfaces/FunctionInterfaces.h"
@@ -64,8 +63,6 @@ void mlir::bufferization::BufferizationDialect::initialize() {
 #include "mlir/Dialect/Bufferization/IR/BufferizationOps.cpp.inc"
       >();
   addInterfaces<BufferizationInlinerInterface>();
-  declarePromisedInterfaces<BufferizableOpInterface, func::CallOp, func::FuncOp,
-                            func::ReturnOp>();
 }
 
 LogicalResult BufferizationDialect::verifyRegionArgAttribute(
diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
index d18ec279e85c04..379338b1e65136 100644
--- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp
+++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
@@ -9,6 +9,7 @@
 #include "mlir/Dialect/Func/IR/FuncOps.h"
 
 #include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
+#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/IRMapping.h"
@@ -43,6 +44,8 @@ void FuncDialect::initialize() {
       >();
   declarePromisedInterface<FuncDialect, DialectInlinerInterface>();
   declarePromisedInterface<FuncDialect, ConvertToLLVMPatternInterface>();
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface, CallOp, 
+                            FuncOp, ReturnOp>();
 }
 
 /// Materialize a single constant operation from a given attribute value with

>From eedbbbc4d97e22216a02fa843706a0693988ccb8 Mon Sep 17 00:00:00 2001
From: justinfargnoli <justinfargnoli at gmail.com>
Date: Thu, 14 Mar 2024 17:49:02 -0700
Subject: [PATCH 14/14] Remove whitespace

---
 mlir/lib/Dialect/Func/IR/FuncOps.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
index 379338b1e65136..ed2ecfe9d0fb51 100644
--- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp
+++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
@@ -44,7 +44,7 @@ void FuncDialect::initialize() {
       >();
   declarePromisedInterface<FuncDialect, DialectInlinerInterface>();
   declarePromisedInterface<FuncDialect, ConvertToLLVMPatternInterface>();
-  declarePromisedInterfaces<bufferization::BufferizableOpInterface, CallOp, 
+  declarePromisedInterfaces<bufferization::BufferizableOpInterface, CallOp,
                             FuncOp, ReturnOp>();
 }
 



More information about the Mlir-commits mailing list