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