Skip to content

Commit

Permalink
Revert "[mlir] Move AllocationOpInterface to Bufferize/IR/AllocationO…
Browse files Browse the repository at this point in the history
…pInterface.td."

This reverts commit 3028bca.
For some reason using FallbackModel works with CMake and does not work
with bazel. Using `ExternalModel` works. I will check what's going on
and resubmit tomorrow.
  • Loading branch information
pifon2a committed Nov 22, 2021
1 parent ad50105 commit de18b7d
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 171 deletions.
1 change: 0 additions & 1 deletion mlir/include/mlir/Dialect/Bufferization/CMakeLists.txt

This file was deleted.

21 changes: 0 additions & 21 deletions mlir/include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion mlir/include/mlir/Dialect/Bufferization/IR/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion mlir/include/mlir/Dialect/CMakeLists.txt
Expand Up @@ -4,7 +4,6 @@ add_subdirectory(Async)
add_subdirectory(ArmNeon)
add_subdirectory(ArmSVE)
add_subdirectory(AMX)
add_subdirectory(Bufferization)
add_subdirectory(Complex)
add_subdirectory(DLTI)
add_subdirectory(EmitC)
Expand Down
7 changes: 6 additions & 1 deletion mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
Expand Up @@ -120,7 +120,10 @@ def AssumeAlignmentOp : MemRef_Op<"assume_alignment"> {
// AllocOp
//===----------------------------------------------------------------------===//

def MemRef_AllocOp : AllocLikeOp<"alloc", DefaultResource, []> {
def MemRef_AllocOp : AllocLikeOp<"alloc", DefaultResource, [
DeclareOpInterfaceMethods<AllocationOpInterface,
["buildDealloc", "buildClone"]>]
> {
let summary = "memory allocation operation";
let description = [{
The `alloc` operation allocates a region of memory, as specified by its
Expand Down Expand Up @@ -415,6 +418,8 @@ def MemRef_CastOp : MemRef_Op<"cast", [
def CloneOp : MemRef_Op<"clone", [
CopyOpInterface,
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
DeclareOpInterfaceMethods<AllocationOpInterface,
["buildDealloc", "buildClone"]>
]> {
let builders = [
OpBuilder<(ins "Value":$value), [{
Expand Down
39 changes: 39 additions & 0 deletions mlir/include/mlir/Interfaces/SideEffectInterfaces.td
Expand Up @@ -16,6 +16,45 @@

include "mlir/Interfaces/SideEffectInterfaceBase.td"

//===----------------------------------------------------------------------===//
// AllocationOpInterface
//===----------------------------------------------------------------------===//

def AllocationOpInterface : OpInterface<"AllocationOpInterface"> {
let description = [{
This interface provides general allocation-related methods that are
designed for allocation operations. For example, it offers the ability to
construct associated deallocation and clone operations that are compatible
with the current allocation operation.
}];
let cppNamespace = "::mlir";

let methods = [
StaticInterfaceMethod<[{
Builds a deallocation operation using the provided builder and the
current allocation value (which refers to the current Op implementing
this interface). The allocation value is a result of the current
operation implementing this interface. If there is no compatible
deallocation operation, this method can return ::llvm::None.
}],
"::mlir::Optional<::mlir::Operation*>", "buildDealloc",
(ins "::mlir::OpBuilder&":$opBuilder, "::mlir::Value":$alloc), [{}],
/*defaultImplementation=*/[{ return llvm::None; }]
>,
StaticInterfaceMethod<[{
Builds a clone operation using the provided builder and the current
allocation value (which refers to the current Op implementing this
interface). The allocation value is a result of the current operation
implementing this interface. If there is no compatible clone operation,
this method can return ::llvm::None.
}],
"::mlir::Optional<::mlir::Value>", "buildClone",
(ins "::mlir::OpBuilder&":$opBuilder, "::mlir::Value":$alloc), [{}],
/*defaultImplementation=*/[{ return llvm::None; }]
>
];
}

//===----------------------------------------------------------------------===//
// MemoryEffects
//===----------------------------------------------------------------------===//
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Bufferization/CMakeLists.txt

This file was deleted.

10 changes: 0 additions & 10 deletions mlir/lib/Dialect/Bufferization/IR/AllocationOpInterface.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions mlir/lib/Dialect/Bufferization/IR/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion mlir/lib/Dialect/CMakeLists.txt
Expand Up @@ -4,7 +4,6 @@ add_subdirectory(ArmNeon)
add_subdirectory(ArmSVE)
add_subdirectory(Async)
add_subdirectory(AMX)
add_subdirectory(Bufferization)
add_subdirectory(Complex)
add_subdirectory(DLTI)
add_subdirectory(EmitC)
Expand Down
18 changes: 18 additions & 0 deletions mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
Expand Up @@ -196,6 +196,15 @@ struct SimplifyDeadAlloc : public OpRewritePattern<T> {
};
} // end anonymous namespace.

Optional<Operation *> AllocOp::buildDealloc(OpBuilder &builder, Value alloc) {
return builder.create<memref::DeallocOp>(alloc.getLoc(), alloc)
.getOperation();
}

Optional<Value> AllocOp::buildClone(OpBuilder &builder, Value alloc) {
return builder.create<memref::CloneOp>(alloc.getLoc(), alloc).getResult();
}

void AllocOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
results.add<SimplifyAllocConst<AllocOp>, SimplifyDeadAlloc<AllocOp>>(context);
Expand Down Expand Up @@ -644,6 +653,15 @@ OpFoldResult CloneOp::fold(ArrayRef<Attribute> operands) {
return succeeded(foldMemRefCast(*this)) ? getResult() : Value();
}

Optional<Operation *> CloneOp::buildDealloc(OpBuilder &builder, Value alloc) {
return builder.create<memref::DeallocOp>(alloc.getLoc(), alloc)
.getOperation();
}

Optional<Value> CloneOp::buildClone(OpBuilder &builder, Value alloc) {
return builder.create<memref::CloneOp>(alloc.getLoc(), alloc).getResult();
}

//===----------------------------------------------------------------------===//
// DeallocOp
//===----------------------------------------------------------------------===//
Expand Down
24 changes: 2 additions & 22 deletions mlir/lib/Transforms/BufferDeallocation.cpp
Expand Up @@ -51,8 +51,6 @@
//===----------------------------------------------------------------------===//

#include "PassDetail.h"

#include "mlir/Dialect/Bufferization/IR/AllocationOpInterface.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Operation.h"
Expand Down Expand Up @@ -195,8 +193,7 @@ class Backedges {
/// introduce clones that in turn leads to additional deallocations.
class BufferDeallocation : public BufferPlacementTransformationBase {
public:
using AliasAllocationMapT =
llvm::DenseMap<Value, bufferization::AllocationOpInterface>;
using AliasAllocationMapT = llvm::DenseMap<Value, AllocationOpInterface>;

BufferDeallocation(Operation *op)
: BufferPlacementTransformationBase(op), dominators(op),
Expand All @@ -211,8 +208,7 @@ class BufferDeallocation : public BufferPlacementTransformationBase {
for (const BufferPlacementAllocs::AllocEntry &entry : allocs) {
// Get the defining allocation operation.
Value alloc = std::get<0>(entry);
auto allocationInterface =
alloc.getDefiningOp<bufferization::AllocationOpInterface>();
auto allocationInterface = alloc.getDefiningOp<AllocationOpInterface>();
// If there is no existing deallocation operation and no implementation of
// the AllocationOpInterface, we cannot apply the BufferDeallocation pass.
if (!std::get<1>(entry) && !allocationInterface) {
Expand Down Expand Up @@ -618,26 +614,10 @@ class BufferDeallocation : public BufferPlacementTransformationBase {
// BufferDeallocationPass
//===----------------------------------------------------------------------===//

template <typename T>
struct DefaultAllocationInterface
: public bufferization::AllocationOpInterface::FallbackModel<T> {
static Optional<Operation *> buildDealloc(OpBuilder &builder, Value alloc) {
return builder.create<memref::DeallocOp>(alloc.getLoc(), alloc)
.getOperation();
}
};

/// The actual buffer deallocation pass that inserts and moves dealloc nodes
/// into the right positions. Furthermore, it inserts additional clones if
/// necessary. It uses the algorithm described at the top of the file.
struct BufferDeallocationPass : BufferDeallocationBase<BufferDeallocationPass> {
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<memref::MemRefDialect>();
registry.addOpInterface<memref::AllocOp,
DefaultAllocationInterface<memref::AllocOp>>();
registry.addOpInterface<memref::CloneOp,
DefaultAllocationInterface<memref::CloneOp>>();
}

void runOnFunction() override {
// Ensure that there are supported loops only.
Expand Down
1 change: 0 additions & 1 deletion mlir/lib/Transforms/CMakeLists.txt
Expand Up @@ -32,7 +32,6 @@ add_mlir_library(MLIRTransforms
LINK_LIBS PUBLIC
MLIRAffine
MLIRAnalysis
MLIRAllocationOpInterface
MLIRCopyOpInterface
MLIRLoopLikeInterface
MLIRMemRef
Expand Down
38 changes: 0 additions & 38 deletions utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Expand Up @@ -4432,7 +4432,6 @@ cc_library(
includes = ["include"],
deps = [
":Affine",
":AllocationOpInterface",
":Analysis",
":ArithmeticDialect",
":ControlFlowInterfaces",
Expand Down Expand Up @@ -7489,43 +7488,6 @@ cc_library(
],
)

td_library(
name = "AllocationOpInterfaceTdFiles",
srcs = ["include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.td"],
includes = ["include"],
deps = [":OpBaseTdFiles"],
)

gentbl_cc_library(
name = "AllocationOpInterfaceIncGen",
strip_include_prefix = "include",
tbl_outs = [
(
["-gen-op-interface-decls"],
"include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h.inc",
),
(
["-gen-op-interface-defs"],
"include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.cpp.inc",
),
],
tblgen = ":mlir-tblgen",
td_file = "include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.td",
deps = [":AllocationOpInterfaceTdFiles"],
)

cc_library(
name = "AllocationOpInterface",
srcs = ["lib/Dialect/Bufferization/IR/AllocationOpInterface.cpp"],
hdrs = ["include/mlir/Dialect/Bufferization/IR/AllocationOpInterface.h"],
includes = ["include"],
deps = [
":AllocationOpInterfaceIncGen",
":IR",
":MemRefDialect",
],
)

td_library(
name = "DLTIDialectTdFiles",
srcs = [
Expand Down

0 comments on commit de18b7d

Please sign in to comment.