From 18b7c44086ca5ccd26bf29588841df302a3c0884 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 27 Sep 2022 10:25:58 +0200 Subject: [PATCH] [BasicAA] Use ScopeExit to clear Visited set (NFC) --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index bb5a23b..27c485d 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -687,16 +687,15 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal) { assert(Visited.empty() && "Visited must be cleared after use!"); + auto _ = make_scope_exit([&]{ Visited.clear(); }); unsigned MaxLookup = 8; SmallVector Worklist; Worklist.push_back(Loc.Ptr); do { const Value *V = getUnderlyingObject(Worklist.pop_back_val()); - if (!Visited.insert(V).second) { - Visited.clear(); + if (!Visited.insert(V).second) return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal); - } // An alloca instruction defines local memory. if (OrLocal && isa(V)) @@ -707,10 +706,8 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc, // Note: this doesn't require GV to be "ODR" because it isn't legal for a // global to be marked constant in some modules and non-constant in // others. GV may even be a declaration, not a definition. - if (!GV->isConstant()) { - Visited.clear(); + if (!GV->isConstant()) return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal); - } continue; } @@ -725,20 +722,16 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc, // the phi. if (const PHINode *PN = dyn_cast(V)) { // Don't bother inspecting phi nodes with many operands. - if (PN->getNumIncomingValues() > MaxLookup) { - Visited.clear(); + if (PN->getNumIncomingValues() > MaxLookup) return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal); - } append_range(Worklist, PN->incoming_values()); continue; } // Otherwise be conservative. - Visited.clear(); return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal); } while (!Worklist.empty() && --MaxLookup); - Visited.clear(); return Worklist.empty(); } -- 2.7.4