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