1 //===- bolt/Core/CallGraphWalker.cpp ------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the CallGraphWalker class.
11 //===----------------------------------------------------------------------===//
13 #include "bolt/Core/CallGraphWalker.h"
14 #include "bolt/Core/BinaryFunctionCallGraph.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/Timer.h"
21 extern llvm::cl::opt
<bool> TimeOpts
;
27 void CallGraphWalker::traverseCG() {
28 NamedRegionTimer
T1("CG Traversal", "CG Traversal", "CG breakdown",
29 "CG breakdown", opts::TimeOpts
);
30 std::queue
<BinaryFunction
*> Queue
;
31 std::set
<BinaryFunction
*> InQueue
;
33 for (BinaryFunction
*Func
: TopologicalCGOrder
) {
38 while (!Queue
.empty()) {
39 BinaryFunction
*Func
= Queue
.front();
44 for (CallbackTy Visitor
: Visitors
) {
45 bool CurVisit
= Visitor(Func
);
46 Changed
= Changed
|| CurVisit
;
50 for (CallGraph::NodeId CallerID
: CG
.predecessors(CG
.getNodeId(Func
))) {
51 BinaryFunction
*CallerFunc
= CG
.nodeIdToFunc(CallerID
);
52 if (InQueue
.count(CallerFunc
))
54 Queue
.push(CallerFunc
);
55 InQueue
.insert(CallerFunc
);
61 void CallGraphWalker::walk() {
62 TopologicalCGOrder
= CG
.buildTraversalOrder();