xref: /llvm-project/mlir/include/mlir/Transforms/SROA.h (revision db791b278a414fb6df1acc1799adcf11d8fb9169)
1 //===-- SROA.h - Scalar Replacement Of Aggregates ---------------*- 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_SROA_H
10 #define MLIR_TRANSFORMS_SROA_H
11 
12 #include "mlir/Interfaces/MemorySlotInterfaces.h"
13 #include "mlir/Support/LLVM.h"
14 #include "llvm/ADT/Statistic.h"
15 
16 namespace mlir {
17 
18 /// Statistics collected while applying SROA.
19 struct SROAStatistics {
20   /// Total amount of memory slots destructured.
21   llvm::Statistic *destructuredAmount = nullptr;
22   /// Total amount of memory slots in which the destructured size was smaller
23   /// than the total size after eliminating unused fields.
24   llvm::Statistic *slotsWithMemoryBenefit = nullptr;
25   /// Maximal number of sub-elements a successfully destructured slot initially
26   /// had.
27   llvm::Statistic *maxSubelementAmount = nullptr;
28 };
29 
30 /// Attempts to destructure the slots of destructurable allocators. Iteratively
31 /// retries the destructuring of all slots as destructuring one slot might
32 /// enable subsequent destructuring. Returns failure if no slot was
33 /// destructured.
34 LogicalResult tryToDestructureMemorySlots(
35     ArrayRef<DestructurableAllocationOpInterface> allocators,
36     OpBuilder &builder, const DataLayout &dataLayout,
37     SROAStatistics statistics = {});
38 
39 } // namespace mlir
40 
41 #endif // MLIR_TRANSFORMS_SROA_H
42