[llvm] Add a pass to collect dropped variable statistics (PR #102233)

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 13:29:23 PDT 2024


================
@@ -0,0 +1,586 @@
+//===- unittests/IR/DroppedVariableStatsTest.cpp - TimePassesHandler tests
+//----------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/AsmParser/Parser.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/PassRegistry.h"
+#include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/Support/SourceMgr.h"
+#include "gtest/gtest.h"
+#include <gtest/gtest.h>
+#include <llvm/ADT/SmallString.h>
+#include <llvm/IR/LLVMContext.h>
+#include <llvm/IR/Module.h>
+#include <llvm/IR/PassInstrumentation.h>
+#include <llvm/IR/PassManager.h>
+#include <llvm/IR/PassTimingInfo.h>
+#include <llvm/Support/raw_ostream.h>
+
+using namespace llvm;
+namespace llvm {
+void initializePassTest1Pass(PassRegistry &);
+
+static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
+  SMDiagnostic Err;
+  std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C);
+  if (!Mod)
+    Err.print("AbstractCallSiteTests", errs());
+  return Mod;
+}
+} // namespace llvm
+
+namespace {
+
+// This test ensures that if a #dbg_value and an instruction that exists in the
+// same scope as that #dbg_value are both deleted as a result of an optimization
+// pass, debug information is considered not dropped.
+TEST(DroppedVariableStats, BothDeleted) {
+  PassInstrumentationCallbacks PIC;
+  PassInstrumentation PI(&PIC);
+
+  LLVMContext C;
+
+  const char *IR =
+      "; Function Attrs: mustprogress nounwind ssp uwtable(sync)\n"
+      "define noundef range(i32 -2147483647, -2147483648) i32 @_Z3fooi(i32 "
+      "noundef %x) local_unnamed_addr #0 !dbg !9 {\n"
+      "entry:\n"
+      "#dbg_value(i32 %x, !15, !DIExpression(), !16)\n"
+      "%add = add nsw i32 %x, 1, !dbg !17\n"
+      "ret i32 0\n"
+      "}\n"
+      "!llvm.dbg.cu = !{!0}\n"
+      "!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}\n"
+      "!llvm.ident = !{!8}\n"
+      "!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: "
+      "!1, producer: \"clang version 20.0.0git "
+      "(git at github.com:llvm/llvm-project.git "
+      "baff49d3a0ef8e0848a726656ebf6e7b310e5113)\", isOptimized: true, "
+      "runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, "
+      "nameTableKind: Apple, sysroot: \"/\")\n"
+      "!1 = !DIFile(filename: \"/tmp/code.cpp\", directory: "
+      "\"/Users/shubham/Development/llvm-project/build_ninja\", checksumkind: "
----------------
adrian-prantl wrote:

just use `/`

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


More information about the llvm-commits mailing list