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

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 05:47:15 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Jay Foad (jayfoad)

<details>
<summary>Changes</summary>

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.


---
Full diff: https://github.com/llvm/llvm-project/pull/68703.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/LiveDebugVariables.cpp (+16) 
- (modified) llvm/lib/CodeGen/LiveDebugVariables.h (+1) 


``````````diff
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(

``````````

</details>


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


More information about the llvm-commits mailing list