10 #include "llvm/Support/DebugLog.h"
15 #define DEBUG_TYPE "llvm-di-expression-simplifier"
22 std::unique_ptr<ExprRewritePattern> pattern) {
23 patterns.emplace_back(std::move(pattern));
28 std::optional<uint64_t> maxNumRewrites)
const {
37 std::deque<OperatorT> inputs(operators.begin(), operators.end());
40 uint64_t numRewrites = 0;
41 while (!inputs.empty() &&
42 (!maxNumRewrites || numRewrites < *maxNumRewrites)) {
43 bool foundMatch =
false;
44 for (
const std::unique_ptr<ExprRewritePattern> &pattern : patterns) {
46 if (matchEnd == inputs.begin())
51 pattern->replace(llvm::make_range(inputs.cbegin(), matchEnd));
52 inputs.erase(inputs.begin(), matchEnd);
53 inputs.insert(inputs.begin(), replacement.begin(), replacement.end());
60 result.push_back(inputs.front());
65 if (maxNumRewrites && numRewrites >= *maxNumRewrites) {
66 LDBG() <<
"LLVMDIExpressionSimplifier exceeded max num rewrites ("
67 << maxNumRewrites <<
")";
69 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...