xref: /llvm-project/mlir/include/mlir/Transforms/Mem2Reg.h (revision eeafc9daa15d2d022bcdd456d4b8bafd23f5f121)
1 //===-- Mem2Reg.h - Mem2Reg definitions -------------------------*- C++ -*-===//
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 
9 #ifndef MLIR_TRANSFORMS_MEM2REG_H
10 #define MLIR_TRANSFORMS_MEM2REG_H
11 
12 #include "mlir/Interfaces/MemorySlotInterfaces.h"
13 #include "llvm/ADT/Statistic.h"
14 
15 namespace mlir {
16 
17 /// Statistics collected while applying mem2reg.
18 struct Mem2RegStatistics {
19   /// Total amount of memory slots promoted.
20   llvm::Statistic *promotedAmount = nullptr;
21   /// Total amount of new block arguments inserted in blocks.
22   llvm::Statistic *newBlockArgumentAmount = nullptr;
23 };
24 
25 /// Attempts to promote the memory slots of the provided allocators. Iteratively
26 /// retries the promotion of all slots as promoting one slot might enable
27 /// subsequent promotions. Succeeds if at least one memory slot was promoted.
28 LogicalResult
29 tryToPromoteMemorySlots(ArrayRef<PromotableAllocationOpInterface> allocators,
30                         OpBuilder &builder, const DataLayout &dataLayout,
31                         DominanceInfo &dominance,
32                         Mem2RegStatistics statistics = {});
33 
34 } // namespace mlir
35 
36 #endif // MLIR_TRANSFORMS_MEM2REG_H
37