MLIR  16.0.0git
MemRefDialect.cpp
Go to the documentation of this file.
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
13 
14 using namespace mlir;
15 using namespace mlir::memref;
16 
17 #include "mlir/Dialect/MemRef/IR/MemRefOpsDialect.cpp.inc"
18 
19 //===----------------------------------------------------------------------===//
20 // MemRefDialect Dialect Interfaces
21 //===----------------------------------------------------------------------===//
22 
23 namespace {
24 struct MemRefInlinerInterface : public DialectInlinerInterface {
26  bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned,
27  BlockAndValueMapping &valueMapping) const final {
28  return true;
29  }
30  bool isLegalToInline(Operation *, Region *, bool wouldBeCloned,
31  BlockAndValueMapping &) const final {
32  return true;
33  }
34 };
35 } // namespace
36 
37 void mlir::memref::MemRefDialect::initialize() {
38  addOperations<
39 #define GET_OP_LIST
40 #include "mlir/Dialect/MemRef/IR/MemRefOps.cpp.inc"
41  >();
42  addInterfaces<MemRefInlinerInterface>();
43 }
44 
45 /// Finds the unique dealloc operation (if one exists) for `allocValue`.
47  Operation *dealloc = nullptr;
48  for (Operation *user : allocValue.getUsers()) {
49  if (!hasEffect<MemoryEffects::Free>(user, allocValue))
50  continue;
51  // If we found > 1 dealloc, return None.
52  if (dealloc)
53  return llvm::None;
54  dealloc = user;
55  }
56  return dealloc;
57 }
static bool isLegalToInline(InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, BlockAndValueMapping &valueMapping)
Utility to check that all of the operations within &#39;src&#39; can be inlined.
Include the generated interface declarations.
This class contains a list of basic blocks and a link to the parent operation it is attached to...
Definition: Region.h:26
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
user_range getUsers() const
Definition: Value.h:213
DialectInlinerInterface(Dialect *dialect)
Definition: InliningUtils.h:43
This is the interface that must be implemented by the dialects of operations to be inlined...
Definition: InliningUtils.h:40
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:85
Optional< Operation * > findDealloc(Value allocValue)
Finds a single dealloc operation for the given allocated value.