[llvm] Introduce DIExpressionOptimizer (PR #69769)
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 13:43:20 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() {
----------------
adrian-prantl wrote:
Is this needed for performance reasons? If not, it is easier to reason about the code if a fresh DIExpressionOptimizer is created for each use.
https://github.com/llvm/llvm-project/pull/69769
More information about the llvm-commits
mailing list