From b353bb302faaf3d2e6ed5cae2241d5512b75178d Mon Sep 17 00:00:00 2001 From: Aidan Hall Date: Fri, 31 Oct 2025 13:47:22 +0000 Subject: [PATCH] DebugUtils: Remove eraseFromParentWithDebugInsts There is another near-identical function in DebugOptUtils.h that can be used everywhere this function is used, and offers more flexibility in its callback interface. --- include/swift/SIL/DebugUtils.h | 39 --------------------- lib/SILOptimizer/Transforms/CSE.cpp | 2 +- lib/SILOptimizer/Transforms/SimplifyCFG.cpp | 2 +- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/include/swift/SIL/DebugUtils.h b/include/swift/SIL/DebugUtils.h index 0b8c6aa46a678..afe74d4fd333e 100644 --- a/include/swift/SIL/DebugUtils.h +++ b/include/swift/SIL/DebugUtils.h @@ -204,45 +204,6 @@ inline Operand *getAnyDebugUse(SILValue value) { return *ii; } -/// Erases the instruction \p I from it's parent block and deletes it, including -/// all debug instructions which use \p I. -/// Precondition: The instruction may only have debug instructions as uses. -/// If the iterator \p InstIter references any deleted instruction, it is -/// incremented. -/// -/// \p callBack will be invoked before each instruction is deleted. \p callBack -/// is not responsible for deleting the instruction because this utility -/// unconditionally deletes the \p I and its debug users. -/// -/// Returns an iterator to the next non-deleted instruction after \p I. -inline SILBasicBlock::iterator eraseFromParentWithDebugInsts( - SILInstruction *I, llvm::function_ref callBack = - [](SILInstruction *) {}) { - - auto nextII = std::next(I->getIterator()); - - auto results = I->getResults(); - - bool foundAny; - do { - foundAny = false; - for (auto result : results) { - while (!result->use_empty()) { - foundAny = true; - auto *User = result->use_begin()->getUser(); - assert(User->isDebugInstruction()); - if (nextII == User->getIterator()) - nextII++; - callBack(User); - User->eraseFromParent(); - } - } - } while (foundAny); - - I->eraseFromParent(); - return nextII; -} - /// Return true if the def-use graph rooted at \p V contains any non-debug, /// non-trivial users. bool hasNonTrivialNonDebugTransitiveUsers( diff --git a/lib/SILOptimizer/Transforms/CSE.cpp b/lib/SILOptimizer/Transforms/CSE.cpp index 2139509343826..b4205971e8c54 100644 --- a/lib/SILOptimizer/Transforms/CSE.cpp +++ b/lib/SILOptimizer/Transforms/CSE.cpp @@ -17,7 +17,6 @@ #define DEBUG_TYPE "sil-cse" #include "swift/Basic/Assertions.h" -#include "swift/SIL/DebugUtils.h" #include "swift/SIL/Dominance.h" #include "swift/SIL/InstructionUtils.h" #include "swift/SIL/NodeBits.h" @@ -34,6 +33,7 @@ #include "swift/SILOptimizer/PassManager/Passes.h" #include "swift/SILOptimizer/PassManager/Transforms.h" #include "swift/SILOptimizer/Utils/BasicBlockOptUtils.h" +#include "swift/SILOptimizer/Utils/DebugOptUtils.h" #include "swift/SILOptimizer/Utils/InstOptUtils.h" #include "swift/SILOptimizer/Utils/OwnershipOptUtils.h" #include "swift/SILOptimizer/Utils/SILInliner.h" diff --git a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp index 98b5c0d87849b..accd78ee75fb8 100644 --- a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp +++ b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp @@ -34,7 +34,6 @@ #include "swift/AST/Module.h" #include "swift/Basic/Assertions.h" #include "swift/SIL/BasicBlockDatastructures.h" -#include "swift/SIL/DebugUtils.h" #include "swift/SIL/Dominance.h" #include "swift/SIL/InstructionUtils.h" #include "swift/SIL/Projection.h" @@ -52,6 +51,7 @@ #include "swift/SILOptimizer/Utils/BasicBlockOptUtils.h" #include "swift/SILOptimizer/Utils/CFGOptUtils.h" #include "swift/SILOptimizer/Utils/CastOptimizer.h" +#include "swift/SILOptimizer/Utils/DebugOptUtils.h" #include "swift/SILOptimizer/Utils/InstOptUtils.h" #include "swift/SILOptimizer/Utils/OwnershipOptUtils.h" #include "swift/SILOptimizer/Utils/SILInliner.h"