MLIR: lib/Dialect/LLVMIR/Transforms/DIExpressionRewriter.cpp Source File (original) (raw)
Go to the documentation of this file.
1
2
3
4
5
6
7
8
10#include "llvm/Support/DebugLog.h"
11
12using namespace mlir;
13using namespace LLVM;
14
15#define DEBUG_TYPE "llvm-di-expression-simplifier"
16
17
18
19
20
22 std::unique_ptr pattern) {
23 patterns.emplace_back(std::move(pattern));
24}
25
26DIExpressionAttr
28 std::optional<uint64_t> maxNumRewrites) const {
30
31
32
33
34
35
36
37 std::deque inputs(operators.begin(), operators.end());
39
40 uint64_t numRewrites = 0;
41 while (!inputs.empty() &&
42 (!maxNumRewrites || numRewrites < *maxNumRewrites)) {
43 bool foundMatch = false;
44 for (const std::unique_ptr &pattern : patterns) {
46 if (matchEnd == inputs.begin())
47 continue;
48
49 foundMatch = true;
51 pattern->replace(llvm::make_range(inputs.cbegin(), matchEnd));
52 inputs.erase(inputs.begin(), matchEnd);
54 ++numRewrites;
55 break;
56 }
57
58 if (!foundMatch) {
59
60 result.push_back(inputs.front());
61 inputs.pop_front();
62 }
63 }
64
65 if (maxNumRewrites && numRewrites >= *maxNumRewrites) {
66 LDBG() << "LLVMDIExpressionSimplifier exceeded max num rewrites ("
67 << maxNumRewrites << ")";
68
69 result.append(inputs.begin(), inputs.end());
70 }
71
72 return LLVM::DIExpressionAttr::get(expr.getContext(), result);
73}
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be the output argument nBegin is set to its * replacement(set to `begin` if no invalidation happens). Since outgoing *copies could have been inserted at `end`
std::deque< OperatorT >::const_iterator OpIterT
void addPattern(std::unique_ptr< ExprRewritePattern > pattern)
Register a rewrite pattern with the rewriter.
Definition DIExpressionRewriter.cpp:21
LLVM::DIExpressionAttr simplify(LLVM::DIExpressionAttr expr, std::optional< uint64_t > maxNumRewrites={}) const
Simplify a DIExpression according to all the patterns registered.
Definition DIExpressionRewriter.cpp:27
Include the generated interface declarations.