xref: /llvm-project/mlir/include/mlir/Dialect/LLVMIR/Transforms/DIExpressionLegalization.h (revision 422b84a77167c43259e18cc3eff88b4b2530defc)
1 //===- DIExpressionLegalization.h - DIExpression Legalization Patterns ----===//
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 // Declarations for known legalization patterns for DIExpressions that should
10 // be performed before translation into llvm.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_DIALECT_LLVMIR_TRANSFORMS_DIEXPRESSIONLEGALIZATION_H
15 #define MLIR_DIALECT_LLVMIR_TRANSFORMS_DIEXPRESSIONLEGALIZATION_H
16 
17 #include "mlir/Dialect/LLVMIR/Transforms/DIExpressionRewriter.h"
18 
19 namespace mlir {
20 namespace LLVM {
21 
22 //===----------------------------------------------------------------------===//
23 // Rewrite Patterns
24 //===----------------------------------------------------------------------===//
25 
26 /// Adjacent DW_OP_LLVM_fragment should be merged into one.
27 ///
28 /// E.g.
29 ///   #llvm.di_expression<[
30 ///     DW_OP_LLVM_fragment(32, 32), DW_OP_LLVM_fragment(32, 64)
31 ///   ]>
32 /// =>
33 ///   #llvm.di_expression<[DW_OP_LLVM_fragment(64, 32)]>
34 class MergeFragments : public DIExpressionRewriter::ExprRewritePattern {
35 public:
36   OpIterT match(OpIterRange operators) const override;
37   SmallVector<OperatorT> replace(OpIterRange operators) const override;
38 };
39 
40 //===----------------------------------------------------------------------===//
41 // Runner
42 //===----------------------------------------------------------------------===//
43 
44 /// Register all known legalization patterns declared here and apply them to
45 /// all ops in `op`.
46 void legalizeDIExpressionsRecursively(Operation *op);
47 
48 } // namespace LLVM
49 } // namespace mlir
50 
51 #endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_DIEXPRESSIONLEGALIZATION_H
52