[llvm] [LiveDebugVariables] Add basic verification (PR #68703)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 05:46:07 PDT 2023


https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/68703

Add a basic implementation of verifyAnalysis that just checks the
IntervalMap for consistency. This was useful for diagnosing some
SlotIndexes-related problems caused by #67038.


>From c759dabb71a55a956234947edbfa85d6957ddd88 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Mon, 9 Oct 2023 17:48:32 +0100
Subject: [PATCH] [LiveDebugVariables] Add basic verification

Add a basic implementation of verifyAnalysis that just checks the
IntervalMap for consistency. This was useful for diagnosing some
SlotIndexes-related problems caused by #67038.
---
 llvm/lib/CodeGen/LiveDebugVariables.cpp | 16 ++++++++++++++++
 llvm/lib/CodeGen/LiveDebugVariables.h   |  1 +
 2 files changed, 17 insertions(+)

diff --git a/llvm/lib/CodeGen/LiveDebugVariables.cpp b/llvm/lib/CodeGen/LiveDebugVariables.cpp
index 9603c1f01e08569..74546230b36a239 100644
--- a/llvm/lib/CodeGen/LiveDebugVariables.cpp
+++ b/llvm/lib/CodeGen/LiveDebugVariables.cpp
@@ -491,6 +491,12 @@ class UserValue {
   /// Return DebugLoc of this UserValue.
   const DebugLoc &getDebugLoc() { return dl; }
 
+  void verify() const {
+    // Verify consistency of the intervals in locInts.
+    for (auto I = locInts.begin(), E = locInts.end(); I != E; ++I)
+      assert(LocMap::KeyTraits::nonEmpty(I.start(), I.stop()));
+  }
+
   void print(raw_ostream &, const TargetRegisterInfo *);
 };
 
@@ -654,6 +660,11 @@ class LDVImpl {
     ModifiedMF = false;
   }
 
+  void verify() const {
+    for (auto [DV, UV] : userVarMap)
+      UV->verify();
+  }
+
   /// Map virtual register to an equivalence class.
   void mapVirtReg(Register VirtReg, UserValue *EC);
 
@@ -1319,6 +1330,11 @@ void LiveDebugVariables::releaseMemory() {
     static_cast<LDVImpl*>(pImpl)->clear();
 }
 
+void LiveDebugVariables::verifyAnalysis() const {
+  if (pImpl)
+    static_cast<LDVImpl*>(pImpl)->verify();
+}
+
 LiveDebugVariables::~LiveDebugVariables() {
   if (pImpl)
     delete static_cast<LDVImpl*>(pImpl);
diff --git a/llvm/lib/CodeGen/LiveDebugVariables.h b/llvm/lib/CodeGen/LiveDebugVariables.h
index 9998ce9e8dad861..c99f11c8565a819 100644
--- a/llvm/lib/CodeGen/LiveDebugVariables.h
+++ b/llvm/lib/CodeGen/LiveDebugVariables.h
@@ -56,6 +56,7 @@ class LLVM_LIBRARY_VISIBILITY LiveDebugVariables : public MachineFunctionPass {
   bool runOnMachineFunction(MachineFunction &) override;
   void releaseMemory() override;
   void getAnalysisUsage(AnalysisUsage &) const override;
+  void verifyAnalysis() const override;
 
   MachineFunctionProperties getSetProperties() const override {
     return MachineFunctionProperties().set(



More information about the llvm-commits mailing list