From a2d0a907d6165c28d96baadbfb53b44311df47cb Mon Sep 17 00:00:00 2001 From: Vasileios Porpodas 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 00b53b42e2e57..b2d7c9b8aa8bb 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 52891c3f7535c..25432e1396c73 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