From 477ccd4e50edcf297765c7bbb6464abd3533f150 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Thu, 1 Nov 2018 10:16:06 +0000 Subject: [PATCH] [NFC] Specialize public API of ICFLoopSafetyInfo for insertions and removals git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345822 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/MustExecute.h | 18 ++++++++++++------ lib/Analysis/MustExecute.cpp | 8 +++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/llvm/Analysis/MustExecute.h b/include/llvm/Analysis/MustExecute.h index 62d9b056e88..c4005a9af95 100644 --- a/include/llvm/Analysis/MustExecute.h +++ b/include/llvm/Analysis/MustExecute.h @@ -125,8 +125,9 @@ public: /// This implementation of LoopSafetyInfo use ImplicitControlFlowTracking to /// give precise answers on "may throw" queries. This implementation uses cache -/// that should be invalidated by calling the method dropCachedInfo whenever we -/// modify a basic block's contents by adding or removing instructions. +/// that should be invalidated by calling the methods insertInstructionTo and +/// removeInstruction whenever we modify a basic block's contents by adding or +/// removing instructions. class ICFLoopSafetyInfo: public LoopSafetyInfo { bool MayThrow = false; // The current loop contains an instruction which // may throw. @@ -144,10 +145,15 @@ public: const DominatorTree *DT, const Loop *CurLoop) const; - /// Drops cached information regarding the implicit control flow in block - /// \p BB. It should be called for every block in which we add or remove any - /// instructions to a block before we make queries to it. - void dropCachedInfo(const BasicBlock *BB); + /// Inform the safety info that we are planning to insert a new instruction + /// into the basic block \p BB. It will make all cache updates to keep it + /// correct after this insertion. + void insertInstructionTo(const BasicBlock *BB); + + /// Inform safety info that we are planning to remove the instruction \p Inst + /// from its block. It will make all cache updates to keep it correct after + /// this removal. + void removeInstruction(const Instruction *Inst); ICFLoopSafetyInfo(DominatorTree *DT) : LoopSafetyInfo(), ICF(DT) {}; diff --git a/lib/Analysis/MustExecute.cpp b/lib/Analysis/MustExecute.cpp index 64ee2a7e5b0..7507aebb527 100644 --- a/lib/Analysis/MustExecute.cpp +++ b/lib/Analysis/MustExecute.cpp @@ -82,10 +82,16 @@ void ICFLoopSafetyInfo::computeLoopSafetyInfo(const Loop *CurLoop) { computeBlockColors(CurLoop); } -void ICFLoopSafetyInfo::dropCachedInfo(const BasicBlock *BB) { +void ICFLoopSafetyInfo::insertInstructionTo(const BasicBlock *BB) { ICF.invalidateBlock(BB); } +void ICFLoopSafetyInfo::removeInstruction(const Instruction *Inst) { + // TODO: So far we just conservatively drop cache, but maybe we can not do it + // when Inst is not an ICF instruction. Follow-up on that. + ICF.invalidateBlock(Inst->getParent()); +} + void LoopSafetyInfo::computeBlockColors(const Loop *CurLoop) { // Compute funclet colors if we might sink/hoist in a function with a funclet // personality routine.