11 #include "llvm/Support/Debug.h"
16 #define DEBUG_TYPE "llvm-di-expression-simplifier"
23 std::unique_ptr<ExprRewritePattern> pattern) {
24 patterns.emplace_back(std::move(pattern));
29 std::optional<uint64_t> maxNumRewrites)
const {
38 std::deque<OperatorT> inputs(operators.begin(), operators.end());
41 uint64_t numRewrites = 0;
42 while (!inputs.empty() &&
43 (!maxNumRewrites || numRewrites < *maxNumRewrites)) {
44 bool foundMatch =
false;
45 for (
const std::unique_ptr<ExprRewritePattern> &pattern : patterns) {
47 if (matchEnd == inputs.begin())
52 pattern->replace(llvm::make_range(inputs.cbegin(), matchEnd));
53 inputs.erase(inputs.begin(), matchEnd);
54 inputs.insert(inputs.begin(), replacement.begin(), replacement.end());
61 result.push_back(inputs.front());
66 if (maxNumRewrites && numRewrites >= *maxNumRewrites) {
67 LLVM_DEBUG(llvm::dbgs()
68 <<
"LLVMDIExpressionSimplifier exceeded max num rewrites ("
69 << maxNumRewrites <<
")\n");
71 result.append(inputs.begin(), inputs.end());
std::deque< OperatorT >::const_iterator OpIterT
void addPattern(std::unique_ptr< ExprRewritePattern > pattern)
Register a rewrite pattern with the rewriter.
LLVM::DIExpressionAttr simplify(LLVM::DIExpressionAttr expr, std::optional< uint64_t > maxNumRewrites={}) const
Simplify a DIExpression according to all the patterns registered.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...