CGSCCPassManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. //===- CGSCCPassManager.cpp - Managing & running CGSCC passes -------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "llvm/Analysis/CGSCCPassManager.h"
  10. #include "llvm/IR/CallSite.h"
  11. #include "llvm/IR/InstIterator.h"
  12. using namespace llvm;
  13. // Explicit template instantiations and specialization defininitions for core
  14. // template typedefs.
  15. namespace llvm {
  16. // Explicit instantiations for the core proxy templates.
  17. template class AllAnalysesOn<LazyCallGraph::SCC>;
  18. template class AnalysisManager<LazyCallGraph::SCC, LazyCallGraph &>;
  19. template class PassManager<LazyCallGraph::SCC, CGSCCAnalysisManager,
  20. LazyCallGraph &, CGSCCUpdateResult &>;
  21. template class InnerAnalysisManagerProxy<CGSCCAnalysisManager, Module>;
  22. template class OuterAnalysisManagerProxy<ModuleAnalysisManager,
  23. LazyCallGraph::SCC, LazyCallGraph &>;
  24. template class OuterAnalysisManagerProxy<CGSCCAnalysisManager, Function>;
  25. /// Explicitly specialize the pass manager run method to handle call graph
  26. /// updates.
  27. template <>
  28. PreservedAnalyses
  29. PassManager<LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &,
  30. CGSCCUpdateResult &>::run(LazyCallGraph::SCC &InitialC,
  31. CGSCCAnalysisManager &AM,
  32. LazyCallGraph &G, CGSCCUpdateResult &UR) {
  33. PreservedAnalyses PA = PreservedAnalyses::all();
  34. if (DebugLogging)
  35. dbgs() << "Starting CGSCC pass manager run.\n";
  36. // The SCC may be refined while we are running passes over it, so set up
  37. // a pointer that we can update.
  38. LazyCallGraph::SCC *C = &InitialC;
  39. for (auto &Pass : Passes) {
  40. if (DebugLogging)
  41. dbgs() << "Running pass: " << Pass->name() << " on " << *C << "\n";
  42. PreservedAnalyses PassPA = Pass->run(*C, AM, G, UR);
  43. // Update the SCC if necessary.
  44. C = UR.UpdatedC ? UR.UpdatedC : C;
  45. // Check that we didn't miss any update scenario.
  46. assert(!UR.InvalidatedSCCs.count(C) && "Processing an invalid SCC!");
  47. assert(C->begin() != C->end() && "Cannot have an empty SCC!");
  48. // Update the analysis manager as each pass runs and potentially
  49. // invalidates analyses.
  50. AM.invalidate(*C, PassPA);
  51. // Finally, we intersect the final preserved analyses to compute the
  52. // aggregate preserved set for this pass manager.
  53. PA.intersect(std::move(PassPA));
  54. // FIXME: Historically, the pass managers all called the LLVM context's
  55. // yield function here. We don't have a generic way to acquire the
  56. // context and it isn't yet clear what the right pattern is for yielding
  57. // in the new pass manager so it is currently omitted.
  58. // ...getContext().yield();
  59. }
  60. // Invaliadtion was handled after each pass in the above loop for the current
  61. // SCC. Therefore, the remaining analysis results in the AnalysisManager are
  62. // preserved. We mark this with a set so that we don't need to inspect each
  63. // one individually.
  64. PA.preserveSet<AllAnalysesOn<LazyCallGraph::SCC>>();
  65. if (DebugLogging)
  66. dbgs() << "Finished CGSCC pass manager run.\n";
  67. return PA;
  68. }
  69. bool CGSCCAnalysisManagerModuleProxy::Result::invalidate(
  70. Module &M, const PreservedAnalyses &PA,
  71. ModuleAnalysisManager::Invalidator &Inv) {
  72. // If literally everything is preserved, we're done.
  73. if (PA.areAllPreserved())
  74. return false; // This is still a valid proxy.
  75. // If this proxy or the call graph is going to be invalidated, we also need
  76. // to clear all the keys coming from that analysis.
  77. //
  78. // We also directly invalidate the FAM's module proxy if necessary, and if
  79. // that proxy isn't preserved we can't preserve this proxy either. We rely on
  80. // it to handle module -> function analysis invalidation in the face of
  81. // structural changes and so if it's unavailable we conservatively clear the
  82. // entire SCC layer as well rather than trying to do invalidation ourselves.
  83. auto PAC = PA.getChecker<CGSCCAnalysisManagerModuleProxy>();
  84. if (!(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Module>>()) ||
  85. Inv.invalidate<LazyCallGraphAnalysis>(M, PA) ||
  86. Inv.invalidate<FunctionAnalysisManagerModuleProxy>(M, PA)) {
  87. InnerAM->clear();
  88. // And the proxy itself should be marked as invalid so that we can observe
  89. // the new call graph. This isn't strictly necessary because we cheat
  90. // above, but is still useful.
  91. return true;
  92. }
  93. // Directly check if the relevant set is preserved so we can short circuit
  94. // invalidating SCCs below.
  95. bool AreSCCAnalysesPreserved =
  96. PA.allAnalysesInSetPreserved<AllAnalysesOn<LazyCallGraph::SCC>>();
  97. // Ok, we have a graph, so we can propagate the invalidation down into it.
  98. for (auto &RC : G->postorder_ref_sccs())
  99. for (auto &C : RC) {
  100. Optional<PreservedAnalyses> InnerPA;
  101. // Check to see whether the preserved set needs to be adjusted based on
  102. // module-level analysis invalidation triggering deferred invalidation
  103. // for this SCC.
  104. if (auto *OuterProxy =
  105. InnerAM->getCachedResult<ModuleAnalysisManagerCGSCCProxy>(C))
  106. for (const auto &OuterInvalidationPair :
  107. OuterProxy->getOuterInvalidations()) {
  108. AnalysisKey *OuterAnalysisID = OuterInvalidationPair.first;
  109. const auto &InnerAnalysisIDs = OuterInvalidationPair.second;
  110. if (Inv.invalidate(OuterAnalysisID, M, PA)) {
  111. if (!InnerPA)
  112. InnerPA = PA;
  113. for (AnalysisKey *InnerAnalysisID : InnerAnalysisIDs)
  114. InnerPA->abandon(InnerAnalysisID);
  115. }
  116. }
  117. // Check if we needed a custom PA set. If so we'll need to run the inner
  118. // invalidation.
  119. if (InnerPA) {
  120. InnerAM->invalidate(C, *InnerPA);
  121. continue;
  122. }
  123. // Otherwise we only need to do invalidation if the original PA set didn't
  124. // preserve all SCC analyses.
  125. if (!AreSCCAnalysesPreserved)
  126. InnerAM->invalidate(C, PA);
  127. }
  128. // Return false to indicate that this result is still a valid proxy.
  129. return false;
  130. }
  131. template <>
  132. CGSCCAnalysisManagerModuleProxy::Result
  133. CGSCCAnalysisManagerModuleProxy::run(Module &M, ModuleAnalysisManager &AM) {
  134. // Force the Function analysis manager to also be available so that it can
  135. // be accessed in an SCC analysis and proxied onward to function passes.
  136. // FIXME: It is pretty awkward to just drop the result here and assert that
  137. // we can find it again later.
  138. (void)AM.getResult<FunctionAnalysisManagerModuleProxy>(M);
  139. return Result(*InnerAM, AM.getResult<LazyCallGraphAnalysis>(M));
  140. }
  141. AnalysisKey FunctionAnalysisManagerCGSCCProxy::Key;
  142. FunctionAnalysisManagerCGSCCProxy::Result
  143. FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC &C,
  144. CGSCCAnalysisManager &AM,
  145. LazyCallGraph &CG) {
  146. // Collect the FunctionAnalysisManager from the Module layer and use that to
  147. // build the proxy result.
  148. //
  149. // This allows us to rely on the FunctionAnalysisMangaerModuleProxy to
  150. // invalidate the function analyses.
  151. auto &MAM = AM.getResult<ModuleAnalysisManagerCGSCCProxy>(C, CG).getManager();
  152. Module &M = *C.begin()->getFunction().getParent();
  153. auto *FAMProxy = MAM.getCachedResult<FunctionAnalysisManagerModuleProxy>(M);
  154. assert(FAMProxy && "The CGSCC pass manager requires that the FAM module "
  155. "proxy is run on the module prior to entering the CGSCC "
  156. "walk.");
  157. // Note that we special-case invalidation handling of this proxy in the CGSCC
  158. // analysis manager's Module proxy. This avoids the need to do anything
  159. // special here to recompute all of this if ever the FAM's module proxy goes
  160. // away.
  161. return Result(FAMProxy->getManager());
  162. }
  163. bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
  164. LazyCallGraph::SCC &C, const PreservedAnalyses &PA,
  165. CGSCCAnalysisManager::Invalidator &Inv) {
  166. for (LazyCallGraph::Node &N : C)
  167. FAM->invalidate(N.getFunction(), PA);
  168. // This proxy doesn't need to handle invalidation itself. Instead, the
  169. // module-level CGSCC proxy handles it above by ensuring that if the
  170. // module-level FAM proxy becomes invalid the entire SCC layer, which
  171. // includes this proxy, is cleared.
  172. return false;
  173. }
  174. } // End llvm namespace
  175. namespace {
  176. /// Helper function to update both the \c CGSCCAnalysisManager \p AM and the \c
  177. /// CGSCCPassManager's \c CGSCCUpdateResult \p UR based on a range of newly
  178. /// added SCCs.
  179. ///
  180. /// The range of new SCCs must be in postorder already. The SCC they were split
  181. /// out of must be provided as \p C. The current node being mutated and
  182. /// triggering updates must be passed as \p N.
  183. ///
  184. /// This function returns the SCC containing \p N. This will be either \p C if
  185. /// no new SCCs have been split out, or it will be the new SCC containing \p N.
  186. template <typename SCCRangeT>
  187. LazyCallGraph::SCC *
  188. incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
  189. LazyCallGraph::Node &N, LazyCallGraph::SCC *C,
  190. CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR,
  191. bool DebugLogging = false) {
  192. typedef LazyCallGraph::SCC SCC;
  193. if (NewSCCRange.begin() == NewSCCRange.end())
  194. return C;
  195. // Add the current SCC to the worklist as its shape has changed.
  196. UR.CWorklist.insert(C);
  197. if (DebugLogging)
  198. dbgs() << "Enqueuing the existing SCC in the worklist:" << *C << "\n";
  199. SCC *OldC = C;
  200. (void)OldC;
  201. // Update the current SCC. Note that if we have new SCCs, this must actually
  202. // change the SCC.
  203. assert(C != &*NewSCCRange.begin() &&
  204. "Cannot insert new SCCs without changing current SCC!");
  205. C = &*NewSCCRange.begin();
  206. assert(G.lookupSCC(N) == C && "Failed to update current SCC!");
  207. for (SCC &NewC :
  208. reverse(make_range(std::next(NewSCCRange.begin()), NewSCCRange.end()))) {
  209. assert(C != &NewC && "No need to re-visit the current SCC!");
  210. assert(OldC != &NewC && "Already handled the original SCC!");
  211. UR.CWorklist.insert(&NewC);
  212. if (DebugLogging)
  213. dbgs() << "Enqueuing a newly formed SCC:" << NewC << "\n";
  214. }
  215. return C;
  216. }
  217. }
  218. LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
  219. LazyCallGraph &G, LazyCallGraph::SCC &InitialC, LazyCallGraph::Node &N,
  220. CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, bool DebugLogging) {
  221. typedef LazyCallGraph::Node Node;
  222. typedef LazyCallGraph::Edge Edge;
  223. typedef LazyCallGraph::SCC SCC;
  224. typedef LazyCallGraph::RefSCC RefSCC;
  225. RefSCC &InitialRC = InitialC.getOuterRefSCC();
  226. SCC *C = &InitialC;
  227. RefSCC *RC = &InitialRC;
  228. Function &F = N.getFunction();
  229. // Walk the function body and build up the set of retained, promoted, and
  230. // demoted edges.
  231. SmallVector<Constant *, 16> Worklist;
  232. SmallPtrSet<Constant *, 16> Visited;
  233. SmallPtrSet<Function *, 16> RetainedEdges;
  234. SmallSetVector<Function *, 4> PromotedRefTargets;
  235. SmallSetVector<Function *, 4> DemotedCallTargets;
  236. // First walk the function and handle all called functions. We do this first
  237. // because if there is a single call edge, whether there are ref edges is
  238. // irrelevant.
  239. for (Instruction &I : instructions(F))
  240. if (auto CS = CallSite(&I))
  241. if (Function *Callee = CS.getCalledFunction())
  242. if (Visited.insert(Callee).second && !Callee->isDeclaration()) {
  243. const Edge *E = N.lookup(*Callee);
  244. // FIXME: We should really handle adding new calls. While it will
  245. // make downstream usage more complex, there is no fundamental
  246. // limitation and it will allow passes within the CGSCC to be a bit
  247. // more flexible in what transforms they can do. Until then, we
  248. // verify that new calls haven't been introduced.
  249. assert(E && "No function transformations should introduce *new* "
  250. "call edges! Any new calls should be modeled as "
  251. "promoted existing ref edges!");
  252. RetainedEdges.insert(Callee);
  253. if (!E->isCall())
  254. PromotedRefTargets.insert(Callee);
  255. }
  256. // Now walk all references.
  257. for (Instruction &I : instructions(F))
  258. for (Value *Op : I.operand_values())
  259. if (Constant *C = dyn_cast<Constant>(Op))
  260. if (Visited.insert(C).second)
  261. Worklist.push_back(C);
  262. LazyCallGraph::visitReferences(Worklist, Visited, [&](Function &Referee) {
  263. const Edge *E = N.lookup(Referee);
  264. // FIXME: Similarly to new calls, we also currently preclude
  265. // introducing new references. See above for details.
  266. assert(E && "No function transformations should introduce *new* ref "
  267. "edges! Any new ref edges would require IPO which "
  268. "function passes aren't allowed to do!");
  269. RetainedEdges.insert(&Referee);
  270. if (E->isCall())
  271. DemotedCallTargets.insert(&Referee);
  272. });
  273. // First remove all of the edges that are no longer present in this function.
  274. // We have to build a list of dead targets first and then remove them as the
  275. // data structures will all be invalidated by removing them.
  276. SmallVector<PointerIntPair<Node *, 1, Edge::Kind>, 4> DeadTargets;
  277. for (Edge &E : N)
  278. if (!RetainedEdges.count(&E.getFunction()))
  279. DeadTargets.push_back({E.getNode(), E.getKind()});
  280. for (auto DeadTarget : DeadTargets) {
  281. Node &TargetN = *DeadTarget.getPointer();
  282. bool IsCall = DeadTarget.getInt() == Edge::Call;
  283. SCC &TargetC = *G.lookupSCC(TargetN);
  284. RefSCC &TargetRC = TargetC.getOuterRefSCC();
  285. if (&TargetRC != RC) {
  286. RC->removeOutgoingEdge(N, TargetN);
  287. if (DebugLogging)
  288. dbgs() << "Deleting outgoing edge from '" << N << "' to '" << TargetN
  289. << "'\n";
  290. continue;
  291. }
  292. if (DebugLogging)
  293. dbgs() << "Deleting internal " << (IsCall ? "call" : "ref")
  294. << " edge from '" << N << "' to '" << TargetN << "'\n";
  295. if (IsCall) {
  296. if (C != &TargetC) {
  297. // For separate SCCs this is trivial.
  298. RC->switchTrivialInternalEdgeToRef(N, TargetN);
  299. } else {
  300. // Otherwise we may end up re-structuring the call graph. First,
  301. // invalidate any SCC analyses. We have to do this before we split
  302. // functions into new SCCs and lose track of where their analyses are
  303. // cached.
  304. // FIXME: We should accept a more precise preserved set here. For
  305. // example, it might be possible to preserve some function analyses
  306. // even as the SCC structure is changed.
  307. AM.invalidate(*C, PreservedAnalyses::none());
  308. // Now update the call graph.
  309. C = incorporateNewSCCRange(RC->switchInternalEdgeToRef(N, TargetN), G,
  310. N, C, AM, UR, DebugLogging);
  311. }
  312. }
  313. auto NewRefSCCs = RC->removeInternalRefEdge(N, TargetN);
  314. if (!NewRefSCCs.empty()) {
  315. // Note that we don't bother to invalidate analyses as ref-edge
  316. // connectivity is not really observable in any way and is intended
  317. // exclusively to be used for ordering of transforms rather than for
  318. // analysis conclusions.
  319. // The RC worklist is in reverse postorder, so we first enqueue the
  320. // current RefSCC as it will remain the parent of all split RefSCCs, then
  321. // we enqueue the new ones in RPO except for the one which contains the
  322. // source node as that is the "bottom" we will continue processing in the
  323. // bottom-up walk.
  324. UR.RCWorklist.insert(RC);
  325. if (DebugLogging)
  326. dbgs() << "Enqueuing the existing RefSCC in the update worklist: "
  327. << *RC << "\n";
  328. // Update the RC to the "bottom".
  329. assert(G.lookupSCC(N) == C && "Changed the SCC when splitting RefSCCs!");
  330. RC = &C->getOuterRefSCC();
  331. assert(G.lookupRefSCC(N) == RC && "Failed to update current RefSCC!");
  332. assert(NewRefSCCs.front() == RC &&
  333. "New current RefSCC not first in the returned list!");
  334. for (RefSCC *NewRC : reverse(
  335. make_range(std::next(NewRefSCCs.begin()), NewRefSCCs.end()))) {
  336. assert(NewRC != RC && "Should not encounter the current RefSCC further "
  337. "in the postorder list of new RefSCCs.");
  338. UR.RCWorklist.insert(NewRC);
  339. if (DebugLogging)
  340. dbgs() << "Enqueuing a new RefSCC in the update worklist: " << *NewRC
  341. << "\n";
  342. }
  343. }
  344. }
  345. // Next demote all the call edges that are now ref edges. This helps make
  346. // the SCCs small which should minimize the work below as we don't want to
  347. // form cycles that this would break.
  348. for (Function *RefTarget : DemotedCallTargets) {
  349. Node &TargetN = *G.lookup(*RefTarget);
  350. SCC &TargetC = *G.lookupSCC(TargetN);
  351. RefSCC &TargetRC = TargetC.getOuterRefSCC();
  352. // The easy case is when the target RefSCC is not this RefSCC. This is
  353. // only supported when the target RefSCC is a child of this RefSCC.
  354. if (&TargetRC != RC) {
  355. assert(RC->isAncestorOf(TargetRC) &&
  356. "Cannot potentially form RefSCC cycles here!");
  357. RC->switchOutgoingEdgeToRef(N, TargetN);
  358. if (DebugLogging)
  359. dbgs() << "Switch outgoing call edge to a ref edge from '" << N
  360. << "' to '" << TargetN << "'\n";
  361. continue;
  362. }
  363. // We are switching an internal call edge to a ref edge. This may split up
  364. // some SCCs.
  365. if (C != &TargetC) {
  366. // For separate SCCs this is trivial.
  367. RC->switchTrivialInternalEdgeToRef(N, TargetN);
  368. continue;
  369. }
  370. // Otherwise we may end up re-structuring the call graph. First, invalidate
  371. // any SCC analyses. We have to do this before we split functions into new
  372. // SCCs and lose track of where their analyses are cached.
  373. // FIXME: We should accept a more precise preserved set here. For example,
  374. // it might be possible to preserve some function analyses even as the SCC
  375. // structure is changed.
  376. AM.invalidate(*C, PreservedAnalyses::none());
  377. // Now update the call graph.
  378. C = incorporateNewSCCRange(RC->switchInternalEdgeToRef(N, TargetN), G,
  379. N, C, AM, UR, DebugLogging);
  380. }
  381. // Now promote ref edges into call edges.
  382. for (Function *CallTarget : PromotedRefTargets) {
  383. Node &TargetN = *G.lookup(*CallTarget);
  384. SCC &TargetC = *G.lookupSCC(TargetN);
  385. RefSCC &TargetRC = TargetC.getOuterRefSCC();
  386. // The easy case is when the target RefSCC is not this RefSCC. This is
  387. // only supported when the target RefSCC is a child of this RefSCC.
  388. if (&TargetRC != RC) {
  389. assert(RC->isAncestorOf(TargetRC) &&
  390. "Cannot potentially form RefSCC cycles here!");
  391. RC->switchOutgoingEdgeToCall(N, TargetN);
  392. if (DebugLogging)
  393. dbgs() << "Switch outgoing ref edge to a call edge from '" << N
  394. << "' to '" << TargetN << "'\n";
  395. continue;
  396. }
  397. if (DebugLogging)
  398. dbgs() << "Switch an internal ref edge to a call edge from '" << N
  399. << "' to '" << TargetN << "'\n";
  400. // Otherwise we are switching an internal ref edge to a call edge. This
  401. // may merge away some SCCs, and we add those to the UpdateResult. We also
  402. // need to make sure to update the worklist in the event SCCs have moved
  403. // before the current one in the post-order sequence.
  404. auto InitialSCCIndex = RC->find(*C) - RC->begin();
  405. auto InvalidatedSCCs = RC->switchInternalEdgeToCall(N, TargetN);
  406. if (!InvalidatedSCCs.empty()) {
  407. C = &TargetC;
  408. assert(G.lookupSCC(N) == C && "Failed to update current SCC!");
  409. // Any analyses cached for this SCC are no longer precise as the shape
  410. // has changed by introducing this cycle.
  411. AM.invalidate(*C, PreservedAnalyses::none());
  412. for (SCC *InvalidatedC : InvalidatedSCCs) {
  413. assert(InvalidatedC != C && "Cannot invalidate the current SCC!");
  414. UR.InvalidatedSCCs.insert(InvalidatedC);
  415. // Also clear any cached analyses for the SCCs that are dead. This
  416. // isn't really necessary for correctness but can release memory.
  417. AM.clear(*InvalidatedC);
  418. }
  419. }
  420. auto NewSCCIndex = RC->find(*C) - RC->begin();
  421. if (InitialSCCIndex < NewSCCIndex) {
  422. // Put our current SCC back onto the worklist as we'll visit other SCCs
  423. // that are now definitively ordered prior to the current one in the
  424. // post-order sequence, and may end up observing more precise context to
  425. // optimize the current SCC.
  426. UR.CWorklist.insert(C);
  427. if (DebugLogging)
  428. dbgs() << "Enqueuing the existing SCC in the worklist: " << *C << "\n";
  429. // Enqueue in reverse order as we pop off the back of the worklist.
  430. for (SCC &MovedC : reverse(make_range(RC->begin() + InitialSCCIndex,
  431. RC->begin() + NewSCCIndex))) {
  432. UR.CWorklist.insert(&MovedC);
  433. if (DebugLogging)
  434. dbgs() << "Enqueuing a newly earlier in post-order SCC: " << MovedC
  435. << "\n";
  436. }
  437. }
  438. }
  439. assert(!UR.InvalidatedSCCs.count(C) && "Invalidated the current SCC!");
  440. assert(!UR.InvalidatedRefSCCs.count(RC) && "Invalidated the current RefSCC!");
  441. assert(&C->getOuterRefSCC() == RC && "Current SCC not in current RefSCC!");
  442. // Record the current RefSCC and SCC for higher layers of the CGSCC pass
  443. // manager now that all the updates have been applied.
  444. if (RC != &InitialRC)
  445. UR.UpdatedRC = RC;
  446. if (C != &InitialC)
  447. UR.UpdatedC = C;
  448. return *C;
  449. }