LLVM  3.7.0
CallGraphSCCPass.cpp
Go to the documentation of this file.
1 //===- CallGraphSCCPass.cpp - Pass that operates BU on call graph ---------===//
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 //
10 // This file implements the CallGraphSCCPass class, which is used for passes
11 // which are implemented as bottom-up traversals on the call graph. Because
12 // there may be cycles in the call graph, passes of this type operate on the
13 // call-graph in SCC order: that is, they process function bottom-up, except for
14 // recursive functions, which they process all at once.
15 //
16 //===----------------------------------------------------------------------===//
17 
19 #include "llvm/ADT/SCCIterator.h"
20 #include "llvm/ADT/Statistic.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/IR/IntrinsicInst.h"
24 #include "llvm/IR/LLVMContext.h"
27 #include "llvm/Support/Debug.h"
28 #include "llvm/Support/Timer.h"
30 using namespace llvm;
31 
32 #define DEBUG_TYPE "cgscc-passmgr"
33 
34 static cl::opt<unsigned>
35 MaxIterations("max-cg-scc-iterations", cl::ReallyHidden, cl::init(4));
36 
37 STATISTIC(MaxSCCIterations, "Maximum CGSCCPassMgr iterations on one SCC");
38 
39 //===----------------------------------------------------------------------===//
40 // CGPassManager
41 //
42 /// CGPassManager manages FPPassManagers and CallGraphSCCPasses.
43 
44 namespace {
45 
46 class CGPassManager : public ModulePass, public PMDataManager {
47 public:
48  static char ID;
49  explicit CGPassManager()
50  : ModulePass(ID), PMDataManager() { }
51 
52  /// Execute all of the passes scheduled for execution. Keep track of
53  /// whether any of the passes modifies the module, and if so, return true.
54  bool runOnModule(Module &M) override;
55 
58 
59  bool doInitialization(CallGraph &CG);
60  bool doFinalization(CallGraph &CG);
61 
62  /// Pass Manager itself does not invalidate any analysis info.
63  void getAnalysisUsage(AnalysisUsage &Info) const override {
64  // CGPassManager walks SCC and it needs CallGraph.
66  Info.setPreservesAll();
67  }
68 
69  const char *getPassName() const override {
70  return "CallGraph Pass Manager";
71  }
72 
73  PMDataManager *getAsPMDataManager() override { return this; }
74  Pass *getAsPass() override { return this; }
75 
76  // Print passes managed by this manager
77  void dumpPassStructure(unsigned Offset) override {
78  errs().indent(Offset*2) << "Call Graph SCC Pass Manager\n";
79  for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
80  Pass *P = getContainedPass(Index);
81  P->dumpPassStructure(Offset + 1);
82  dumpLastUses(P, Offset+1);
83  }
84  }
85 
86  Pass *getContainedPass(unsigned N) {
87  assert(N < PassVector.size() && "Pass number out of range!");
88  return static_cast<Pass *>(PassVector[N]);
89  }
90 
91  PassManagerType getPassManagerType() const override {
93  }
94 
95 private:
96  bool RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,
97  bool &DevirtualizedCall);
98 
99  bool RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
100  CallGraph &CG, bool &CallGraphUpToDate,
101  bool &DevirtualizedCall);
102  bool RefreshCallGraph(CallGraphSCC &CurSCC, CallGraph &CG,
103  bool IsCheckingMode);
104 };
105 
106 } // end anonymous namespace.
107 
108 char CGPassManager::ID = 0;
109 
110 
111 bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
112  CallGraph &CG, bool &CallGraphUpToDate,
113  bool &DevirtualizedCall) {
114  bool Changed = false;
116 
117  if (!PM) {
119  if (!CallGraphUpToDate) {
120  DevirtualizedCall |= RefreshCallGraph(CurSCC, CG, false);
121  CallGraphUpToDate = true;
122  }
123 
124  {
125  TimeRegion PassTimer(getPassTimer(CGSP));
126  Changed = CGSP->runOnSCC(CurSCC);
127  }
128 
129  // After the CGSCCPass is done, when assertions are enabled, use
130  // RefreshCallGraph to verify that the callgraph was correctly updated.
131 #ifndef NDEBUG
132  if (Changed)
133  RefreshCallGraph(CurSCC, CG, true);
134 #endif
135 
136  return Changed;
137  }
138 
139 
141  "Invalid CGPassManager member");
142  FPPassManager *FPP = (FPPassManager*)P;
143 
144  // Run pass P on all functions in the current SCC.
145  for (CallGraphNode *CGN : CurSCC) {
146  if (Function *F = CGN->getFunction()) {
147  dumpPassInfo(P, EXECUTION_MSG, ON_FUNCTION_MSG, F->getName());
148  {
149  TimeRegion PassTimer(getPassTimer(FPP));
150  Changed |= FPP->runOnFunction(*F);
151  }
152  F->getContext().yield();
153  }
154  }
155 
156  // The function pass(es) modified the IR, they may have clobbered the
157  // callgraph.
158  if (Changed && CallGraphUpToDate) {
159  DEBUG(dbgs() << "CGSCCPASSMGR: Pass Dirtied SCC: "
160  << P->getPassName() << '\n');
161  CallGraphUpToDate = false;
162  }
163  return Changed;
164 }
165 
166 
167 /// Scan the functions in the specified CFG and resync the
168 /// callgraph with the call sites found in it. This is used after
169 /// FunctionPasses have potentially munged the callgraph, and can be used after
170 /// CallGraphSCC passes to verify that they correctly updated the callgraph.
171 ///
172 /// This function returns true if it devirtualized an existing function call,
173 /// meaning it turned an indirect call into a direct call. This happens when
174 /// a function pass like GVN optimizes away stuff feeding the indirect call.
175 /// This never happens in checking mode.
176 ///
177 bool CGPassManager::RefreshCallGraph(CallGraphSCC &CurSCC,
178  CallGraph &CG, bool CheckingMode) {
180 
181  DEBUG(dbgs() << "CGSCCPASSMGR: Refreshing SCC with " << CurSCC.size()
182  << " nodes:\n";
183  for (CallGraphNode *CGN : CurSCC)
184  CGN->dump();
185  );
186 
187  bool MadeChange = false;
188  bool DevirtualizedCall = false;
189 
190  // Scan all functions in the SCC.
191  unsigned FunctionNo = 0;
192  for (CallGraphSCC::iterator SCCIdx = CurSCC.begin(), E = CurSCC.end();
193  SCCIdx != E; ++SCCIdx, ++FunctionNo) {
194  CallGraphNode *CGN = *SCCIdx;
195  Function *F = CGN->getFunction();
196  if (!F || F->isDeclaration()) continue;
197 
198  // Walk the function body looking for call sites. Sync up the call sites in
199  // CGN with those actually in the function.
200 
201  // Keep track of the number of direct and indirect calls that were
202  // invalidated and removed.
203  unsigned NumDirectRemoved = 0, NumIndirectRemoved = 0;
204 
205  // Get the set of call sites currently in the function.
206  for (CallGraphNode::iterator I = CGN->begin(), E = CGN->end(); I != E; ) {
207  // If this call site is null, then the function pass deleted the call
208  // entirely and the WeakVH nulled it out.
209  if (!I->first ||
210  // If we've already seen this call site, then the FunctionPass RAUW'd
211  // one call with another, which resulted in two "uses" in the edge
212  // list of the same call.
213  CallSites.count(I->first) ||
214 
215  // If the call edge is not from a call or invoke, or it is a
216  // instrinsic call, then the function pass RAUW'd a call with
217  // another value. This can happen when constant folding happens
218  // of well known functions etc.
219  !CallSite(I->first) ||
220  (CallSite(I->first).getCalledFunction() &&
221  CallSite(I->first).getCalledFunction()->isIntrinsic() &&
223  CallSite(I->first).getCalledFunction()->getIntrinsicID()))) {
224  assert(!CheckingMode &&
225  "CallGraphSCCPass did not update the CallGraph correctly!");
226 
227  // If this was an indirect call site, count it.
228  if (!I->second->getFunction())
229  ++NumIndirectRemoved;
230  else
231  ++NumDirectRemoved;
232 
233  // Just remove the edge from the set of callees, keep track of whether
234  // I points to the last element of the vector.
235  bool WasLast = I + 1 == E;
236  CGN->removeCallEdge(I);
237 
238  // If I pointed to the last element of the vector, we have to bail out:
239  // iterator checking rejects comparisons of the resultant pointer with
240  // end.
241  if (WasLast)
242  break;
243  E = CGN->end();
244  continue;
245  }
246 
247  assert(!CallSites.count(I->first) &&
248  "Call site occurs in node multiple times");
249 
250  CallSite CS(I->first);
251  if (CS) {
252  Function *Callee = CS.getCalledFunction();
253  // Ignore intrinsics because they're not really function calls.
254  if (!Callee || !(Callee->isIntrinsic()))
255  CallSites.insert(std::make_pair(I->first, I->second));
256  }
257  ++I;
258  }
259 
260  // Loop over all of the instructions in the function, getting the callsites.
261  // Keep track of the number of direct/indirect calls added.
262  unsigned NumDirectAdded = 0, NumIndirectAdded = 0;
263 
264  for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
265  for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
266  CallSite CS(cast<Value>(I));
267  if (!CS) continue;
268  Function *Callee = CS.getCalledFunction();
269  if (Callee && Callee->isIntrinsic()) continue;
270 
271  // If this call site already existed in the callgraph, just verify it
272  // matches up to expectations and remove it from CallSites.
274  CallSites.find(CS.getInstruction());
275  if (ExistingIt != CallSites.end()) {
276  CallGraphNode *ExistingNode = ExistingIt->second;
277 
278  // Remove from CallSites since we have now seen it.
279  CallSites.erase(ExistingIt);
280 
281  // Verify that the callee is right.
282  if (ExistingNode->getFunction() == CS.getCalledFunction())
283  continue;
284 
285  // If we are in checking mode, we are not allowed to actually mutate
286  // the callgraph. If this is a case where we can infer that the
287  // callgraph is less precise than it could be (e.g. an indirect call
288  // site could be turned direct), don't reject it in checking mode, and
289  // don't tweak it to be more precise.
290  if (CheckingMode && CS.getCalledFunction() &&
291  ExistingNode->getFunction() == nullptr)
292  continue;
293 
294  assert(!CheckingMode &&
295  "CallGraphSCCPass did not update the CallGraph correctly!");
296 
297  // If not, we either went from a direct call to indirect, indirect to
298  // direct, or direct to different direct.
299  CallGraphNode *CalleeNode;
300  if (Function *Callee = CS.getCalledFunction()) {
301  CalleeNode = CG.getOrInsertFunction(Callee);
302  // Keep track of whether we turned an indirect call into a direct
303  // one.
304  if (!ExistingNode->getFunction()) {
305  DevirtualizedCall = true;
306  DEBUG(dbgs() << " CGSCCPASSMGR: Devirtualized call to '"
307  << Callee->getName() << "'\n");
308  }
309  } else {
310  CalleeNode = CG.getCallsExternalNode();
311  }
312 
313  // Update the edge target in CGN.
314  CGN->replaceCallEdge(CS, CS, CalleeNode);
315  MadeChange = true;
316  continue;
317  }
318 
319  assert(!CheckingMode &&
320  "CallGraphSCCPass did not update the CallGraph correctly!");
321 
322  // If the call site didn't exist in the CGN yet, add it.
323  CallGraphNode *CalleeNode;
324  if (Function *Callee = CS.getCalledFunction()) {
325  CalleeNode = CG.getOrInsertFunction(Callee);
326  ++NumDirectAdded;
327  } else {
328  CalleeNode = CG.getCallsExternalNode();
329  ++NumIndirectAdded;
330  }
331 
332  CGN->addCalledFunction(CS, CalleeNode);
333  MadeChange = true;
334  }
335 
336  // We scanned the old callgraph node, removing invalidated call sites and
337  // then added back newly found call sites. One thing that can happen is
338  // that an old indirect call site was deleted and replaced with a new direct
339  // call. In this case, we have devirtualized a call, and CGSCCPM would like
340  // to iteratively optimize the new code. Unfortunately, we don't really
341  // have a great way to detect when this happens. As an approximation, we
342  // just look at whether the number of indirect calls is reduced and the
343  // number of direct calls is increased. There are tons of ways to fool this
344  // (e.g. DCE'ing an indirect call and duplicating an unrelated block with a
345  // direct call) but this is close enough.
346  if (NumIndirectRemoved > NumIndirectAdded &&
347  NumDirectRemoved < NumDirectAdded)
348  DevirtualizedCall = true;
349 
350  // After scanning this function, if we still have entries in callsites, then
351  // they are dangling pointers. WeakVH should save us for this, so abort if
352  // this happens.
353  assert(CallSites.empty() && "Dangling pointers found in call sites map");
354 
355  // Periodically do an explicit clear to remove tombstones when processing
356  // large scc's.
357  if ((FunctionNo & 15) == 15)
358  CallSites.clear();
359  }
360 
361  DEBUG(if (MadeChange) {
362  dbgs() << "CGSCCPASSMGR: Refreshed SCC is now:\n";
363  for (CallGraphNode *CGN : CurSCC)
364  CGN->dump();
365  if (DevirtualizedCall)
366  dbgs() << "CGSCCPASSMGR: Refresh devirtualized a call!\n";
367 
368  } else {
369  dbgs() << "CGSCCPASSMGR: SCC Refresh didn't change call graph.\n";
370  }
371  );
372  (void)MadeChange;
373 
374  return DevirtualizedCall;
375 }
376 
377 /// Execute the body of the entire pass manager on the specified SCC.
378 /// This keeps track of whether a function pass devirtualizes
379 /// any calls and returns it in DevirtualizedCall.
380 bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,
381  bool &DevirtualizedCall) {
382  bool Changed = false;
383 
384  // Keep track of whether the callgraph is known to be up-to-date or not.
385  // The CGSSC pass manager runs two types of passes:
386  // CallGraphSCC Passes and other random function passes. Because other
387  // random function passes are not CallGraph aware, they may clobber the
388  // call graph by introducing new calls or deleting other ones. This flag
389  // is set to false when we run a function pass so that we know to clean up
390  // the callgraph when we need to run a CGSCCPass again.
391  bool CallGraphUpToDate = true;
392 
393  // Run all passes on current SCC.
394  for (unsigned PassNo = 0, e = getNumContainedPasses();
395  PassNo != e; ++PassNo) {
396  Pass *P = getContainedPass(PassNo);
397 
398  // If we're in -debug-pass=Executions mode, construct the SCC node list,
399  // otherwise avoid constructing this string as it is expensive.
400  if (isPassDebuggingExecutionsOrMore()) {
401  std::string Functions;
402  #ifndef NDEBUG
403  raw_string_ostream OS(Functions);
404  for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
405  I != E; ++I) {
406  if (I != CurSCC.begin()) OS << ", ";
407  (*I)->print(OS);
408  }
409  OS.flush();
410  #endif
411  dumpPassInfo(P, EXECUTION_MSG, ON_CG_MSG, Functions);
412  }
413  dumpRequiredSet(P);
414 
415  initializeAnalysisImpl(P);
416 
417  // Actually run this pass on the current SCC.
418  Changed |= RunPassOnSCC(P, CurSCC, CG,
419  CallGraphUpToDate, DevirtualizedCall);
420 
421  if (Changed)
422  dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, "");
423  dumpPreservedSet(P);
424 
425  verifyPreservedAnalysis(P);
426  removeNotPreservedAnalysis(P);
427  recordAvailableAnalysis(P);
428  removeDeadPasses(P, "", ON_CG_MSG);
429  }
430 
431  // If the callgraph was left out of date (because the last pass run was a
432  // functionpass), refresh it before we move on to the next SCC.
433  if (!CallGraphUpToDate)
434  DevirtualizedCall |= RefreshCallGraph(CurSCC, CG, false);
435  return Changed;
436 }
437 
438 /// Execute all of the passes scheduled for execution. Keep track of
439 /// whether any of the passes modifies the module, and if so, return true.
440 bool CGPassManager::runOnModule(Module &M) {
441  CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
442  bool Changed = doInitialization(CG);
443 
444  // Walk the callgraph in bottom-up SCC order.
446 
447  CallGraphSCC CurSCC(&CGI);
448  while (!CGI.isAtEnd()) {
449  // Copy the current SCC and increment past it so that the pass can hack
450  // on the SCC if it wants to without invalidating our iterator.
451  const std::vector<CallGraphNode *> &NodeVec = *CGI;
452  CurSCC.initialize(NodeVec.data(), NodeVec.data() + NodeVec.size());
453  ++CGI;
454 
455  // At the top level, we run all the passes in this pass manager on the
456  // functions in this SCC. However, we support iterative compilation in the
457  // case where a function pass devirtualizes a call to a function. For
458  // example, it is very common for a function pass (often GVN or instcombine)
459  // to eliminate the addressing that feeds into a call. With that improved
460  // information, we would like the call to be an inline candidate, infer
461  // mod-ref information etc.
462  //
463  // Because of this, we allow iteration up to a specified iteration count.
464  // This only happens in the case of a devirtualized call, so we only burn
465  // compile time in the case that we're making progress. We also have a hard
466  // iteration count limit in case there is crazy code.
467  unsigned Iteration = 0;
468  bool DevirtualizedCall = false;
469  do {
470  DEBUG(if (Iteration)
471  dbgs() << " SCCPASSMGR: Re-visiting SCC, iteration #"
472  << Iteration << '\n');
473  DevirtualizedCall = false;
474  Changed |= RunAllPassesOnSCC(CurSCC, CG, DevirtualizedCall);
475  } while (Iteration++ < MaxIterations && DevirtualizedCall);
476 
477  if (DevirtualizedCall)
478  DEBUG(dbgs() << " CGSCCPASSMGR: Stopped iteration after " << Iteration
479  << " times, due to -max-cg-scc-iterations\n");
480 
481  if (Iteration > MaxSCCIterations)
482  MaxSCCIterations = Iteration;
483 
484  }
485  Changed |= doFinalization(CG);
486  return Changed;
487 }
488 
489 
490 /// Initialize CG
491 bool CGPassManager::doInitialization(CallGraph &CG) {
492  bool Changed = false;
493  for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {
494  if (PMDataManager *PM = getContainedPass(i)->getAsPMDataManager()) {
496  "Invalid CGPassManager member");
497  Changed |= ((FPPassManager*)PM)->doInitialization(CG.getModule());
498  } else {
499  Changed |= ((CallGraphSCCPass*)getContainedPass(i))->doInitialization(CG);
500  }
501  }
502  return Changed;
503 }
504 
505 /// Finalize CG
506 bool CGPassManager::doFinalization(CallGraph &CG) {
507  bool Changed = false;
508  for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {
509  if (PMDataManager *PM = getContainedPass(i)->getAsPMDataManager()) {
511  "Invalid CGPassManager member");
512  Changed |= ((FPPassManager*)PM)->doFinalization(CG.getModule());
513  } else {
514  Changed |= ((CallGraphSCCPass*)getContainedPass(i))->doFinalization(CG);
515  }
516  }
517  return Changed;
518 }
519 
520 //===----------------------------------------------------------------------===//
521 // CallGraphSCC Implementation
522 //===----------------------------------------------------------------------===//
523 
524 /// This informs the SCC and the pass manager that the specified
525 /// Old node has been deleted, and New is to be used in its place.
527  assert(Old != New && "Should not replace node with self");
528  for (unsigned i = 0; ; ++i) {
529  assert(i != Nodes.size() && "Node not in SCC");
530  if (Nodes[i] != Old) continue;
531  Nodes[i] = New;
532  break;
533  }
534 
535  // Update the active scc_iterator so that it doesn't contain dangling
536  // pointers to the old CallGraphNode.
538  CGI->ReplaceNode(Old, New);
539 }
540 
541 
542 //===----------------------------------------------------------------------===//
543 // CallGraphSCCPass Implementation
544 //===----------------------------------------------------------------------===//
545 
546 /// Assign pass manager to manage this pass.
548  PassManagerType PreferredType) {
549  // Find CGPassManager
550  while (!PMS.empty() &&
552  PMS.pop();
553 
554  assert(!PMS.empty() && "Unable to handle Call Graph Pass");
555  CGPassManager *CGP;
556 
558  CGP = (CGPassManager*)PMS.top();
559  else {
560  // Create new Call Graph SCC Pass Manager if it does not exist.
561  assert(!PMS.empty() && "Unable to create Call Graph Pass Manager");
562  PMDataManager *PMD = PMS.top();
563 
564  // [1] Create new Call Graph Pass Manager
565  CGP = new CGPassManager();
566 
567  // [2] Set up new manager's top level manager
568  PMTopLevelManager *TPM = PMD->getTopLevelManager();
569  TPM->addIndirectPassManager(CGP);
570 
571  // [3] Assign manager to manage this new manager. This may create
572  // and push new managers into PMS
573  Pass *P = CGP;
574  TPM->schedulePass(P);
575 
576  // [4] Push new manager into PMS
577  PMS.push(CGP);
578  }
579 
580  CGP->add(this);
581 }
582 
583 /// For this class, we declare that we require and preserve the call graph.
584 /// If the derived class implements this method, it should
585 /// always explicitly call the implementation here.
589 }
590 
591 
592 //===----------------------------------------------------------------------===//
593 // PrintCallGraphPass Implementation
594 //===----------------------------------------------------------------------===//
595 
596 namespace {
597  /// PrintCallGraphPass - Print a Module corresponding to a call graph.
598  ///
599  class PrintCallGraphPass : public CallGraphSCCPass {
600  std::string Banner;
601  raw_ostream &Out; // raw_ostream to print on.
602 
603  public:
604  static char ID;
605  PrintCallGraphPass(const std::string &B, raw_ostream &o)
606  : CallGraphSCCPass(ID), Banner(B), Out(o) {}
607 
608  void getAnalysisUsage(AnalysisUsage &AU) const override {
609  AU.setPreservesAll();
610  }
611 
612  bool runOnSCC(CallGraphSCC &SCC) override {
613  Out << Banner;
614  for (CallGraphNode *CGN : SCC) {
615  if (CGN->getFunction())
616  CGN->getFunction()->print(Out);
617  else
618  Out << "\nPrinting <null> Function\n";
619  }
620  return false;
621  }
622  };
623 
624 } // end anonymous namespace.
625 
626 char PrintCallGraphPass::ID = 0;
627 
629  const std::string &Banner) const {
630  return new PrintCallGraphPass(Banner, O);
631 }
632 
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:82
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:55
CGPassManager.
Definition: Pass.h:58
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
STATISTIC(NumFunctions,"Total number of functions")
virtual PMDataManager * getAsPMDataManager()
Definition: Pass.cpp:98
virtual void dumpPassStructure(unsigned Offset=0)
Definition: Pass.cpp:53
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
std::vector< CallGraphNode * >::const_iterator iterator
iterator end()
Definition: Function.h:459
unsigned size() const
bool isIntrinsic() const
Definition: Function.h:160
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
virtual const char * getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:61
bool isAtEnd() const
Direct loop termination test which is more efficient than comparison with end().
Definition: SCCIterator.h:107
F(f)
A node in the call graph for a module.
Definition: CallGraph.h:166
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
void dump() const
Print out this call graph node.
Definition: CallGraph.cpp:194
virtual PassManagerType getPassManagerType() const
Module & getModule() const
Returns the module the call graph corresponds to.
Definition: CallGraph.h:117
PMTopLevelManager manages LastUser info and collects common APIs used by top level pass managers...
Timer * getPassTimer(Pass *)
If TimingInfo is enabled then start pass timer.
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
Function * getFunction() const
Returns the function that this call graph node represents.
Definition: CallGraph.h:186
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
Definition: Timer.h:126
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:169
void addCalledFunction(CallSite CS, CallGraphNode *M)
Adds a function to the list of functions called by this one.
Definition: CallGraph.h:231
std::vector< CallRecord >::iterator iterator
Definition: CallGraph.h:182
void schedulePass(Pass *P)
Schedule pass P for execution.
AnalysisUsage & addRequired()
iterator end() const
iterator end()
Definition: CallGraph.h:189
void replaceCallEdge(CallSite CS, CallSite NewCS, CallGraphNode *NewNode)
Replaces the edge in the node for the specified call site with a new one.
Definition: CallGraph.cpp:243
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:116
FPPassManager manages BBPassManagers and FunctionPasses.
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
Definition: SCCIterator.h:224
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
iterator begin()
Definition: Function.h:457
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:111
static cl::opt< unsigned > MaxIterations("max-cg-scc-iterations", cl::ReallyHidden, cl::init(4))
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition: CallGraph.h:316
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
Definition: Function.cpp:849
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
Definition: CallSite.h:99
void addIndirectPassManager(PMDataManager *Manager)
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a pass that prints the Module corresponding to a CallGraph.
Represent the analysis usage information of a pass.
void ReplaceNode(NodeType *Old, NodeType *New)
This informs the scc_iterator that the specified Old node has been deleted, and New is to be used in ...
Definition: SCCIterator.h:134
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manager this pass.
bool empty() const
FPPassManager.
Definition: Pass.h:59
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:159
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:123
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:119
PMDataManager * top() const
iterator begin() const
void setPreservesAll()
Set by analyses that do not transform their input at all.
void removeCallEdge(iterator I)
Definition: CallGraph.h:239
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr) const
Print the function to an output stream with an optional AssemblyAnnotationWriter. ...
Definition: AsmWriter.cpp:3139
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:75
void ReplaceNode(CallGraphNode *Old, CallGraphNode *New)
ReplaceNode - This informs the SCC and the pass manager that the specified Old node has been deleted...
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:128
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:236
void push(PMDataManager *PM)
PMDataManager provides the common place to manage the analysis data used by pass managers.
virtual bool runOnSCC(CallGraphSCC &SCC)=0
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:465
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
CallGraphNode * getOrInsertFunction(const Function *F)
Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist...
Definition: CallGraph.cpp:162
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
#define DEBUG(X)
Definition: Debug.h:92
iterator begin()
Definition: CallGraph.h:188
void initialize(CallGraphNode *const *I, CallGraphNode *const *E)
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
Definition: SCCIterator.h:40
CallGraphNode * getCallsExternalNode() const
Definition: CallGraph.h:142