[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:48:40 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) {
----------------
adrian-prantl wrote:

Can the first argument be of type dwarf::LocationAtom for more clarity?

https://github.com/llvm/llvm-project/pull/71719


More information about the llvm-commits mailing list