aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LazyCallGraph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/LazyCallGraph.cpp')
-rw-r--r--llvm/lib/Analysis/LazyCallGraph.cpp57
1 files changed, 50 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/LazyCallGraph.cpp b/llvm/lib/Analysis/LazyCallGraph.cpp
index ef31c1e0ba8c..efded17cef4e 100644
--- a/llvm/lib/Analysis/LazyCallGraph.cpp
+++ b/llvm/lib/Analysis/LazyCallGraph.cpp
@@ -15,8 +15,8 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Analysis/VectorUtils.h"
#include "llvm/Config/llvm-config.h"
-#include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
@@ -99,8 +99,8 @@ LazyCallGraph::EdgeSequence &LazyCallGraph::Node::populateSlow() {
// safety of optimizing a direct call edge.
for (BasicBlock &BB : *F)
for (Instruction &I : BB) {
- if (auto CS = CallSite(&I))
- if (Function *Callee = CS.getCalledFunction())
+ if (auto *CB = dyn_cast<CallBase>(&I))
+ if (Function *Callee = CB->getCalledFunction())
if (!Callee->isDeclaration())
if (Callees.insert(Callee).second) {
Visited.insert(Callee);
@@ -146,8 +146,11 @@ LLVM_DUMP_METHOD void LazyCallGraph::Node::dump() const {
static bool isKnownLibFunction(Function &F, TargetLibraryInfo &TLI) {
LibFunc LF;
- // Either this is a normal library function or a "vectorizable" function.
- return TLI.getLibFunc(F, LF) || TLI.isFunctionVectorizable(F.getName());
+ // Either this is a normal library function or a "vectorizable"
+ // function. Not using the VFDatabase here because this query
+ // is related only to libraries handled via the TLI.
+ return TLI.getLibFunc(F, LF) ||
+ TLI.isKnownVectorFunctionInLibrary(F.getName());
}
LazyCallGraph::LazyCallGraph(
@@ -211,6 +214,15 @@ LazyCallGraph::LazyCallGraph(LazyCallGraph &&G)
updateGraphPtrs();
}
+bool LazyCallGraph::invalidate(Module &, const PreservedAnalyses &PA,
+ ModuleAnalysisManager::Invalidator &) {
+ // Check whether the analysis, all analyses on functions, or the function's
+ // CFG have been preserved.
+ auto PAC = PA.getChecker<llvm::LazyCallGraphAnalysis>();
+ return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Module>>() ||
+ PAC.preservedSet<CFGAnalyses>());
+}
+
LazyCallGraph &LazyCallGraph::operator=(LazyCallGraph &&G) {
BPA = std::move(G.BPA);
NodeMap = std::move(G.NodeMap);
@@ -1553,6 +1565,21 @@ void LazyCallGraph::removeDeadFunction(Function &F) {
// allocators.
}
+void LazyCallGraph::addNewFunctionIntoSCC(Function &NewF, SCC &C) {
+ addNodeToSCC(C, createNode(NewF));
+}
+
+void LazyCallGraph::addNewFunctionIntoRefSCC(Function &NewF, RefSCC &RC) {
+ Node &N = createNode(NewF);
+
+ auto *C = createSCC(RC, SmallVector<Node *, 1>());
+ addNodeToSCC(*C, N);
+
+ auto Index = RC.SCCIndices.size();
+ RC.SCCIndices[C] = Index;
+ RC.SCCs.push_back(C);
+}
+
LazyCallGraph::Node &LazyCallGraph::insertInto(Function &F, Node *&MappedN) {
return *new (MappedN = BPA.Allocate()) Node(*this, F);
}
@@ -1567,6 +1594,21 @@ void LazyCallGraph::updateGraphPtrs() {
RC->G = this;
}
+LazyCallGraph::Node &LazyCallGraph::createNode(Function &F) {
+ assert(!lookup(F) && "node already exists");
+
+ Node &N = get(F);
+ NodeMap[&F] = &N;
+ N.DFSNumber = N.LowLink = -1;
+ N.populate();
+ return N;
+}
+
+void LazyCallGraph::addNodeToSCC(LazyCallGraph::SCC &C, Node &N) {
+ C.Nodes.push_back(&N);
+ SCCMap[&N] = &C;
+}
+
template <typename RootsT, typename GetBeginT, typename GetEndT,
typename GetNodeT, typename FormSCCCallbackT>
void LazyCallGraph::buildGenericSCCs(RootsT &&Roots, GetBeginT &&GetBegin,
@@ -1788,11 +1830,12 @@ LazyCallGraphDOTPrinterPass::LazyCallGraphDOTPrinterPass(raw_ostream &OS)
: OS(OS) {}
static void printNodeDOT(raw_ostream &OS, LazyCallGraph::Node &N) {
- std::string Name = "\"" + DOT::EscapeString(N.getFunction().getName()) + "\"";
+ std::string Name =
+ "\"" + DOT::EscapeString(std::string(N.getFunction().getName())) + "\"";
for (LazyCallGraph::Edge &E : N.populate()) {
OS << " " << Name << " -> \""
- << DOT::EscapeString(E.getFunction().getName()) << "\"";
+ << DOT::EscapeString(std::string(E.getFunction().getName())) << "\"";
if (!E.isCall()) // It is a ref edge.
OS << " [style=dashed,label=\"ref\"]";
OS << ";\n";