MLIR  19.0.0git
SROA.h
Go to the documentation of this file.
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/IR/PatternMatch.h"
15 #include "llvm/ADT/Statistic.h"
16 #include <variant>
17 
18 namespace mlir {
19 
20 /// Statistics collected while applying SROA.
22  /// Total amount of memory slots destructured.
23  llvm::Statistic *destructuredAmount = nullptr;
24  /// Total amount of memory slots in which the destructured size was smaller
25  /// than the total size after eliminating unused fields.
26  llvm::Statistic *slotsWithMemoryBenefit = nullptr;
27  /// Maximal number of sub-elements a successfully destructured slot initially
28  /// had.
29  llvm::Statistic *maxSubelementAmount = nullptr;
30 };
31 
32 /// Pattern applying SROA to the regions of the operations on which it
33 /// matches.
35  : public OpInterfaceRewritePattern<DestructurableAllocationOpInterface> {
36 public:
38 
39  SROAPattern(MLIRContext *context, SROAStatistics statistics = {},
40  PatternBenefit benefit = 1)
41  : OpInterfaceRewritePattern(context, benefit), statistics(statistics) {}
42 
43  LogicalResult matchAndRewrite(DestructurableAllocationOpInterface allocator,
44  PatternRewriter &rewriter) const override;
45 
46 private:
47  SROAStatistics statistics;
48 };
49 
50 /// Attempts to destructure the slots of destructurable allocators. Returns
51 /// failure if no slot was destructured.
52 LogicalResult tryToDestructureMemorySlots(
53  ArrayRef<DestructurableAllocationOpInterface> allocators,
54  RewriterBase &rewriter, SROAStatistics statistics = {});
55 
56 } // namespace mlir
57 
58 #endif // MLIR_TRANSFORMS_SROA_H
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
Definition: PatternMatch.h:33
Pattern applying SROA to the regions of the operations on which it matches.
Definition: SROA.h:35
LogicalResult matchAndRewrite(DestructurableAllocationOpInterface allocator, PatternRewriter &rewriter) const override
Definition: SROA.cpp:209
OpInterfaceRewritePattern(MLIRContext *context, PatternBenefit benefit=1)
Definition: PatternMatch.h:373
SROAPattern(MLIRContext *context, SROAStatistics statistics={}, PatternBenefit benefit=1)
Definition: SROA.h:39
Include the generated interface declarations.
LogicalResult tryToDestructureMemorySlots(ArrayRef< DestructurableAllocationOpInterface > allocators, RewriterBase &rewriter, SROAStatistics statistics={})
Attempts to destructure the slots of destructurable allocators.
Definition: SROA.cpp:188
OpInterfaceRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting a...
Definition: PatternMatch.h:372
OpInterfaceRewritePattern(MLIRContext *context, PatternBenefit benefit=1)
Definition: PatternMatch.h:373
Statistics collected while applying SROA.
Definition: SROA.h:21
llvm::Statistic * maxSubelementAmount
Maximal number of sub-elements a successfully destructured slot initially had.
Definition: SROA.h:29
llvm::Statistic * slotsWithMemoryBenefit
Total amount of memory slots in which the destructured size was smaller than the total size after eli...
Definition: SROA.h:26
llvm::Statistic * destructuredAmount
Total amount of memory slots destructured.
Definition: SROA.h:23