77// ===----------------------------------------------------------------------===//
88#include " clang/Analysis/Analyses/LifetimeSafety/LoanPropagation.h"
99#include " Dataflow.h"
10+ #include " clang/Analysis/CFG.h"
1011#include " llvm/ADT/BitVector.h"
1112#include " llvm/Support/TimeProfiler.h"
1213#include < memory>
@@ -18,19 +19,20 @@ namespace clang::lifetimes::internal {
1819static llvm::BitVector computePersistentOrigins (FactManager &FactMgr,
1920 const CFG &C) {
2021 llvm::TimeTraceScope (" ComputePersistentOrigins" );
21- llvm::BitVector PersistentOrigins ( FactMgr.getOriginMgr ().getOrigins ().size () +
22- 1 );
22+ unsigned NumOrigins = FactMgr.getOriginMgr ().getOrigins ().size ();
23+ llvm::BitVector PersistentOrigins (NumOrigins + 1 );
2324
24- llvm::DenseMap<OriginID, const CFGBlock *> OriginToBlock;
25+ llvm::SmallVector<const CFGBlock *> OriginToFirstSeenBlock (NumOrigins + 1 ,
26+ nullptr );
2527 for (const CFGBlock *B : C) {
2628 for (const Fact *F : FactMgr.getFacts (B)) {
2729 auto CheckOrigin = [&](OriginID OID) {
2830 if (PersistentOrigins.test (OID.Value ))
2931 return ;
30- auto It = OriginToBlock. find ( OID) ;
31- if (It == OriginToBlock. end () )
32- OriginToBlock[OID] = B;
33- else if (It-> second != B) {
32+ auto &FirstSeenBlock = OriginToFirstSeenBlock[ OID. Value ] ;
33+ if (FirstSeenBlock == nullptr )
34+ FirstSeenBlock = B;
35+ if (FirstSeenBlock != B) {
3436 // We saw this origin in more than one block.
3537 PersistentOrigins.set (OID.Value );
3638 }
@@ -195,9 +197,9 @@ class AnalysisImpl
195197
196198 OriginLoanMap::Factory &OriginLoanMapFactory;
197199 LoanSet::Factory &LoanSetFactory;
198- // / Origins that appear in multiple basic blocks and must participate in join
199- // / operations. Origins not in this set are block-local and can be discarded
200- // / at block boundaries.
200+ // / Boolean vector indexed by origin ID. If true, the origin appears in
201+ // / multiple basic blocks and must participate in join operations. If false,
202+ // / the origin is block-local and can be discarded at block boundaries.
201203 llvm::BitVector PersistentOrigins;
202204};
203205} // namespace
0 commit comments