[llvm] Introduce DIExpressionOptimizer (PR #69769)
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 13:43:21 PDT 2023
================
@@ -1734,6 +1734,143 @@ const DIExpression *DIExpression::extractAddressClass(const DIExpression *Expr,
return Expr;
}
+SmallVector<uint64_t>
+DIExpressionOptimizer::getOperatorLocations(ArrayRef<uint64_t> Ops) {
+ SmallVector<uint64_t> OpLocs;
+ uint64_t Loc = 0;
+ DIExpressionCursor Cursor(Ops);
+
+ while (Cursor.peek()) {
+ OpLocs.push_back(Loc);
+ auto Size = Cursor.peek()->getSize();
+ Loc += Size;
+ Cursor.consume(1);
+ }
+
+ return OpLocs;
+}
+
+bool DIExpressionOptimizer::operatorIsCommutative(uint64_t Operator) {
+ return Operator == dwarf::DW_OP_mul || Operator == dwarf::DW_OP_plus;
+}
+
+bool DIExpressionOptimizer::operatorCanBeOptimized(uint64_t Operator) {
+ switch (Operator) {
+ case dwarf::DW_OP_plus:
+ case dwarf::DW_OP_plus_uconst:
+ case dwarf::DW_OP_minus:
+ case dwarf::DW_OP_mul:
+ case dwarf::DW_OP_div:
+ case dwarf::DW_OP_shl:
+ case dwarf::DW_OP_shr:
+ return true;
+ default:
+ return false;
+ }
+}
+
+void DIExpressionOptimizer::reset() {
+ NewMathOperator = 0;
+ CurrMathOperator = 0;
+ OperatorLeft = 0;
+ OperatorRight = 0;
+}
+
+void DIExpressionOptimizer::optimize(SmallVectorImpl<uint64_t> &NewOps,
+ ArrayRef<uint64_t> Ops) {
+
+ if (Ops.size() == 2 && Ops[0] == dwarf::DW_OP_plus_uconst) {
----------------
adrian-prantl wrote:
Why == 2 and not >= 2?
https://github.com/llvm/llvm-project/pull/69769
More information about the llvm-commits
mailing list