//===- PhiValues.cpp - Phi Value Analysis ---------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/Analysis/PhiValues.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/Instructions.h" #include "llvm/InitializePasses.h" usingnamespacellvm; void PhiValues::PhiValuesCallbackVH::deleted() { … } void PhiValues::PhiValuesCallbackVH::allUsesReplacedWith(Value *) { … } bool PhiValues::invalidate(Function &, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &) { … } // The goal here is to find all of the non-phi values reachable from this phi, // and to do the same for all of the phis reachable from this phi, as doing so // is necessary anyway in order to get the values for this phi. We do this using // Tarjan's algorithm with Nuutila's improvements to find the strongly connected // components of the phi graph rooted in this phi: // * All phis in a strongly connected component will have the same reachable // non-phi values. The SCC may not be the maximal subgraph for that set of // reachable values, but finding out that isn't really necessary (it would // only reduce the amount of memory needed to store the values). // * Tarjan's algorithm completes components in a bottom-up manner, i.e. it // never completes a component before the components reachable from it have // been completed. This means that when we complete a component we have // everything we need to collect the values reachable from that component. // * We collect both the non-phi values reachable from each SCC, as that's what // we're ultimately interested in, and all of the reachable values, i.e. // including phis, as that makes invalidateValue easier. void PhiValues::processPhi(const PHINode *Phi, SmallVectorImpl<const PHINode *> &Stack) { … } const PhiValues::ValueSet &PhiValues::getValuesForPhi(const PHINode *PN) { … } void PhiValues::invalidateValue(const Value *V) { … } void PhiValues::releaseMemory() { … } void PhiValues::print(raw_ostream &OS) const { … } AnalysisKey PhiValuesAnalysis::Key; PhiValues PhiValuesAnalysis::run(Function &F, FunctionAnalysisManager &) { … } PreservedAnalyses PhiValuesPrinterPass::run(Function &F, FunctionAnalysisManager &AM) { … } PhiValuesWrapperPass::PhiValuesWrapperPass() : … { … } bool PhiValuesWrapperPass::runOnFunction(Function &F) { … } void PhiValuesWrapperPass::releaseMemory() { … } void PhiValuesWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { … } char PhiValuesWrapperPass::ID = …; INITIALIZE_PASS(…)