[llvm] Use DIExpression::foldConstantMath() at the result of an append() (PR #71719)
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Fri May 17 08:50:43 PDT 2024
================
@@ -0,0 +1,349 @@
+//===- DIExpressionOptimizer.cpp - Constant folding of DIExpressions ------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements functions to constant fold DIExpressions. Which were
+// declared in DIExpressionOptimizer.h
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+
+using namespace llvm;
+
+static std::optional<uint64_t> isConstantVal(DIExpression::ExprOperand Op) {
+ if (Op.getOp() == dwarf::DW_OP_constu)
+ return Op.getArg(0);
+ return std::nullopt;
+}
+
+static bool isNeutralElement(uint64_t Op, uint64_t Val) {
+ switch (Op) {
+ case dwarf::DW_OP_plus:
+ case dwarf::DW_OP_minus:
+ case dwarf::DW_OP_shl:
+ case dwarf::DW_OP_shr:
+ return Val == 0;
+ case dwarf::DW_OP_mul:
+ case dwarf::DW_OP_div:
+ return Val == 1;
+ default:
+ return false;
+ }
+}
+
+static std::optional<uint64_t> foldOperationIfPossible(
----------------
adrian-prantl wrote:
This function needs a few comments explaining at a high level what's happening. Especially the inout bool looks suspicious from a design perspective.
https://github.com/llvm/llvm-project/pull/71719
More information about the llvm-commits
mailing list