MLIR  18.0.0git
Mem2Reg.h
Go to the documentation of this file.
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/IR/Dominance.h"
13 #include "mlir/IR/OpDefinition.h"
14 #include "mlir/IR/PatternMatch.h"
16 #include "llvm/ADT/Statistic.h"
17 
18 namespace mlir {
19 
20 /// Statistics collected while applying mem2reg.
22  /// Total amount of memory slots promoted.
23  llvm::Statistic *promotedAmount = nullptr;
24  /// Total amount of new block arguments inserted in blocks.
25  llvm::Statistic *newBlockArgumentAmount = nullptr;
26 };
27 
28 /// Pattern applying mem2reg to the regions of the operations on which it
29 /// matches.
31  : public OpInterfaceRewritePattern<PromotableAllocationOpInterface> {
32 public:
34 
35  Mem2RegPattern(MLIRContext *context, Mem2RegStatistics statistics = {},
36  PatternBenefit benefit = 1)
37  : OpInterfaceRewritePattern(context, benefit), statistics(statistics) {}
38 
39  LogicalResult matchAndRewrite(PromotableAllocationOpInterface allocator,
40  PatternRewriter &rewriter) const override;
41 
42 private:
43  Mem2RegStatistics statistics;
44 };
45 
46 /// Attempts to promote the memory slots of the provided allocators. Succeeds if
47 /// at least one memory slot was promoted.
48 LogicalResult
49 tryToPromoteMemorySlots(ArrayRef<PromotableAllocationOpInterface> allocators,
50  RewriterBase &rewriter,
51  Mem2RegStatistics statistics = {});
52 
53 } // namespace mlir
54 
55 #endif // MLIR_TRANSFORMS_MEM2REG_H
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Pattern applying mem2reg to the regions of the operations on which it matches.
Definition: Mem2Reg.h:31
LogicalResult matchAndRewrite(PromotableAllocationOpInterface allocator, PatternRewriter &rewriter) const override
Definition: Mem2Reg.cpp:639
Mem2RegPattern(MLIRContext *context, Mem2RegStatistics statistics={}, PatternBenefit benefit=1)
Definition: Mem2Reg.h:35
OpInterfaceRewritePattern(MLIRContext *context, PatternBenefit benefit=1)
Definition: PatternMatch.h:373
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
Definition: PatternMatch.h:33
Include the generated interface declarations.
LogicalResult tryToPromoteMemorySlots(ArrayRef< PromotableAllocationOpInterface > allocators, RewriterBase &rewriter, Mem2RegStatistics statistics={})
Attempts to promote the memory slots of the provided allocators.
Definition: Mem2Reg.cpp:613
Statistics collected while applying mem2reg.
Definition: Mem2Reg.h:21
llvm::Statistic * promotedAmount
Total amount of memory slots promoted.
Definition: Mem2Reg.h:23
llvm::Statistic * newBlockArgumentAmount
Total amount of new block arguments inserted in blocks.
Definition: Mem2Reg.h:25
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