[llvm] [SandboxVec][Scheduler] Fix clear() to clear all state (PR #124214)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 16:35:08 PST 2025


https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/124214

This patch fixes the scheduler's clear() function to also clear the ReadyList. Not doing so is a bug and results in crashes when the ReadyList contains stale instructions, because it was never clered.

>From a2d0a907d6165c28d96baadbfb53b44311df47cb Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Mon, 13 Jan 2025 09:20:48 -0800
Subject: [PATCH] [SandboxVec][Scheduler] Fix clear() to clear all state

This patch fixes the scheduler's clear() function to also clear
the ReadyList. Not doing so is a bug and results in crashes when the
ReadyList contains stale instructions, because it was never clered.
---
 .../Vectorize/SandboxVectorizer/DependencyGraph.h          | 7 +++++++
 .../Transforms/Vectorize/SandboxVectorizer/Scheduler.h     | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
index 00b53b42e2e572..b2d7c9b8aa8bbc 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
@@ -417,6 +417,13 @@ class DependencyGraph {
     DAGInterval = {};
   }
 #ifndef NDEBUG
+  /// \Returns true if the DAG's state is clear. Used in assertions.
+  bool empty() const {
+    bool IsEmpty = InstrToNodeMap.empty();
+    assert(IsEmpty == DAGInterval.empty() &&
+           "Interval and InstrToNodeMap out of sync!");
+    return IsEmpty;
+  }
   void print(raw_ostream &OS) const;
   LLVM_DUMP_METHOD void dump() const;
 #endif // NDEBUG
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Scheduler.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Scheduler.h
index 52891c3f7535c9..25432e1396c73f 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Scheduler.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Scheduler.h
@@ -164,7 +164,10 @@ class Scheduler {
     Bndls.clear();
     // TODO: clear view once it lands.
     DAG.clear();
+    ReadyList.clear();
     ScheduleTopItOpt = std::nullopt;
+    assert(Bndls.empty() && DAG.empty() && ReadyList.empty() &&
+           !ScheduleTopItOpt && "Expected empty state!");
   }
 
 #ifndef NDEBUG



More information about the llvm-commits mailing list