diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:32:43 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:32:43 +0000 | 
| commit | b7eb8e35e481a74962664b63dfb09483b200209a (patch) | |
| tree | 1937fb4a348458ce2d02ade03ac3bb0aa18d2fcd /lib/Analysis/CallGraphSCCPass.cpp | |
| parent | eb11fae6d08f479c0799db45860a98af528fa6e7 (diff) | |
Notes
Diffstat (limited to 'lib/Analysis/CallGraphSCCPass.cpp')
| -rw-r--r-- | lib/Analysis/CallGraphSCCPass.cpp | 98 | 
1 files changed, 49 insertions, 49 deletions
| diff --git a/lib/Analysis/CallGraphSCCPass.cpp b/lib/Analysis/CallGraphSCCPass.cpp index f2211edba216..4c33c420b65d 100644 --- a/lib/Analysis/CallGraphSCCPass.cpp +++ b/lib/Analysis/CallGraphSCCPass.cpp @@ -41,7 +41,7 @@ using namespace llvm;  #define DEBUG_TYPE "cgscc-passmgr" -static cl::opt<unsigned>  +static cl::opt<unsigned>  MaxIterations("max-cg-scc-iterations", cl::ReallyHidden, cl::init(4));  STATISTIC(MaxSCCIterations, "Maximum CGSCCPassMgr iterations on one SCC"); @@ -97,13 +97,13 @@ public:    }    PassManagerType getPassManagerType() const override { -    return PMT_CallGraphPassManager;  +    return PMT_CallGraphPassManager;    } -   +  private:    bool RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,                           bool &DevirtualizedCall); -   +    bool RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,                      CallGraph &CG, bool &CallGraphUpToDate,                      bool &DevirtualizedCall); @@ -142,21 +142,21 @@ bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,        if (EmitICRemark)          emitInstrCountChangedRemark(P, M, InstrCount);      } -     +      // After the CGSCCPass is done, when assertions are enabled, use      // RefreshCallGraph to verify that the callgraph was correctly updated.  #ifndef NDEBUG      if (Changed)        RefreshCallGraph(CurSCC, CG, true);  #endif -     +      return Changed;    } -   +    assert(PM->getPassManagerType() == PMT_FunctionPassManager &&           "Invalid CGPassManager member");    FPPassManager *FPP = (FPPassManager*)P; -   +    // Run pass P on all functions in the current SCC.    for (CallGraphNode *CGN : CurSCC) {      if (Function *F = CGN->getFunction()) { @@ -168,7 +168,7 @@ bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,        F->getContext().yield();      }    } -   +    // The function pass(es) modified the IR, they may have clobbered the    // callgraph.    if (Changed && CallGraphUpToDate) { @@ -199,7 +199,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,    bool MadeChange = false;    bool DevirtualizedCall = false; -   +    // Scan all functions in the SCC.    unsigned FunctionNo = 0;    for (CallGraphSCC::iterator SCCIdx = CurSCC.begin(), E = CurSCC.end(); @@ -207,14 +207,14 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,      CallGraphNode *CGN = *SCCIdx;      Function *F = CGN->getFunction();      if (!F || F->isDeclaration()) continue; -     +      // Walk the function body looking for call sites.  Sync up the call sites in      // CGN with those actually in the function.      // Keep track of the number of direct and indirect calls that were      // invalidated and removed.      unsigned NumDirectRemoved = 0, NumIndirectRemoved = 0; -     +      // Get the set of call sites currently in the function.      for (CallGraphNode::iterator I = CGN->begin(), E = CGN->end(); I != E; ) {        // If this call site is null, then the function pass deleted the call @@ -226,7 +226,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,            CallSites.count(I->first) ||            // If the call edge is not from a call or invoke, or it is a -          // instrinsic call, then the function pass RAUW'd a call with  +          // instrinsic call, then the function pass RAUW'd a call with            // another value. This can happen when constant folding happens            // of well known functions etc.            !CallSite(I->first) || @@ -236,18 +236,18 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,                 CallSite(I->first).getCalledFunction()->getIntrinsicID()))) {          assert(!CheckingMode &&                 "CallGraphSCCPass did not update the CallGraph correctly!"); -         +          // If this was an indirect call site, count it.          if (!I->second->getFunction())            ++NumIndirectRemoved; -        else  +        else            ++NumDirectRemoved; -         +          // Just remove the edge from the set of callees, keep track of whether          // I points to the last element of the vector.          bool WasLast = I + 1 == E;          CGN->removeCallEdge(I); -         +          // If I pointed to the last element of the vector, we have to bail out:          // iterator checking rejects comparisons of the resultant pointer with          // end. @@ -256,10 +256,10 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,          E = CGN->end();          continue;        } -       +        assert(!CallSites.count(I->first) &&               "Call site occurs in node multiple times"); -       +        CallSite CS(I->first);        if (CS) {          Function *Callee = CS.getCalledFunction(); @@ -269,7 +269,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,        }        ++I;      } -     +      // Loop over all of the instructions in the function, getting the callsites.      // Keep track of the number of direct/indirect calls added.      unsigned NumDirectAdded = 0, NumIndirectAdded = 0; @@ -280,7 +280,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,          if (!CS) continue;          Function *Callee = CS.getCalledFunction();          if (Callee && Callee->isIntrinsic()) continue; -         +          // If this call site already existed in the callgraph, just verify it          // matches up to expectations and remove it from CallSites.          DenseMap<Value*, CallGraphNode*>::iterator ExistingIt = @@ -290,11 +290,11 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,            // Remove from CallSites since we have now seen it.            CallSites.erase(ExistingIt); -           +            // Verify that the callee is right.            if (ExistingNode->getFunction() == CS.getCalledFunction())              continue; -           +            // If we are in checking mode, we are not allowed to actually mutate            // the callgraph.  If this is a case where we can infer that the            // callgraph is less precise than it could be (e.g. an indirect call @@ -303,10 +303,10 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,            if (CheckingMode && CS.getCalledFunction() &&                ExistingNode->getFunction() == nullptr)              continue; -           +            assert(!CheckingMode &&                   "CallGraphSCCPass did not update the CallGraph correctly!"); -           +            // If not, we either went from a direct call to indirect, indirect to            // direct, or direct to different direct.            CallGraphNode *CalleeNode; @@ -328,7 +328,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,            MadeChange = true;            continue;          } -         +          assert(!CheckingMode &&                 "CallGraphSCCPass did not update the CallGraph correctly!"); @@ -341,11 +341,11 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,            CalleeNode = CG.getCallsExternalNode();            ++NumIndirectAdded;          } -         +          CGN->addCalledFunction(CS, CalleeNode);          MadeChange = true;        } -     +      // We scanned the old callgraph node, removing invalidated call sites and      // then added back newly found call sites.  One thing that can happen is      // that an old indirect call site was deleted and replaced with a new direct @@ -359,13 +359,13 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,      if (NumIndirectRemoved > NumIndirectAdded &&          NumDirectRemoved < NumDirectAdded)        DevirtualizedCall = true; -     +      // After scanning this function, if we still have entries in callsites, then      // they are dangling pointers.  WeakTrackingVH should save us for this, so      // abort if      // this happens.      assert(CallSites.empty() && "Dangling pointers found in call sites map"); -     +      // Periodically do an explicit clear to remove tombstones when processing      // large scc's.      if ((FunctionNo & 15) == 15) @@ -392,7 +392,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,  bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,                                        bool &DevirtualizedCall) {    bool Changed = false; -   +    // Keep track of whether the callgraph is known to be up-to-date or not.    // The CGSSC pass manager runs two types of passes:    // CallGraphSCC Passes and other random function passes.  Because other @@ -406,7 +406,7 @@ bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,    for (unsigned PassNo = 0, e = getNumContainedPasses();         PassNo != e; ++PassNo) {      Pass *P = getContainedPass(PassNo); -     +      // If we're in -debug-pass=Executions mode, construct the SCC node list,      // otherwise avoid constructing this string as it is expensive.      if (isPassDebuggingExecutionsOrMore()) { @@ -423,23 +423,23 @@ bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,        dumpPassInfo(P, EXECUTION_MSG, ON_CG_MSG, Functions);      }      dumpRequiredSet(P); -     +      initializeAnalysisImpl(P); -     +      // Actually run this pass on the current SCC.      Changed |= RunPassOnSCC(P, CurSCC, CG,                              CallGraphUpToDate, DevirtualizedCall); -     +      if (Changed)        dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, "");      dumpPreservedSet(P); -     -    verifyPreservedAnalysis(P);       + +    verifyPreservedAnalysis(P);      removeNotPreservedAnalysis(P);      recordAvailableAnalysis(P);      removeDeadPasses(P, "", ON_CG_MSG);    } -   +    // If the callgraph was left out of date (because the last pass run was a    // functionpass), refresh it before we move on to the next SCC.    if (!CallGraphUpToDate) @@ -452,7 +452,7 @@ bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,  bool CGPassManager::runOnModule(Module &M) {    CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();    bool Changed = doInitialization(CG); -   +    // Walk the callgraph in bottom-up SCC order.    scc_iterator<CallGraph*> CGI = scc_begin(&CG); @@ -485,7 +485,7 @@ bool CGPassManager::runOnModule(Module &M) {        DevirtualizedCall = false;        Changed |= RunAllPassesOnSCC(CurSCC, CG, DevirtualizedCall);      } while (Iteration++ < MaxIterations && DevirtualizedCall); -     +      if (DevirtualizedCall)        LLVM_DEBUG(dbgs() << "  CGSCCPASSMGR: Stopped iteration after "                          << Iteration @@ -500,7 +500,7 @@ bool CGPassManager::runOnModule(Module &M) {  /// Initialize CG  bool CGPassManager::doInitialization(CallGraph &CG) {    bool Changed = false; -  for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {   +  for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {      if (PMDataManager *PM = getContainedPass(i)->getAsPMDataManager()) {        assert(PM->getPassManagerType() == PMT_FunctionPassManager &&               "Invalid CGPassManager member"); @@ -515,7 +515,7 @@ bool CGPassManager::doInitialization(CallGraph &CG) {  /// Finalize CG  bool CGPassManager::doFinalization(CallGraph &CG) {    bool Changed = false; -  for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {   +  for (unsigned i = 0, e = getNumContainedPasses(); i != e; ++i) {      if (PMDataManager *PM = getContainedPass(i)->getAsPMDataManager()) {        assert(PM->getPassManagerType() == PMT_FunctionPassManager &&               "Invalid CGPassManager member"); @@ -541,7 +541,7 @@ void CallGraphSCC::ReplaceNode(CallGraphNode *Old, CallGraphNode *New) {      Nodes[i] = New;      break;    } -   +    // Update the active scc_iterator so that it doesn't contain dangling    // pointers to the old CallGraphNode.    scc_iterator<CallGraph*> *CGI = (scc_iterator<CallGraph*>*)Context; @@ -555,18 +555,18 @@ void CallGraphSCC::ReplaceNode(CallGraphNode *Old, CallGraphNode *New) {  /// Assign pass manager to manage this pass.  void CallGraphSCCPass::assignPassManager(PMStack &PMS,                                           PassManagerType PreferredType) { -  // Find CGPassManager  +  // Find CGPassManager    while (!PMS.empty() &&           PMS.top()->getPassManagerType() > PMT_CallGraphPassManager)      PMS.pop();    assert(!PMS.empty() && "Unable to handle Call Graph Pass");    CGPassManager *CGP; -   +    if (PMS.top()->getPassManagerType() == PMT_CallGraphPassManager)      CGP = (CGPassManager*)PMS.top();    else { -    // Create new Call Graph SCC Pass Manager if it does not exist.  +    // Create new Call Graph SCC Pass Manager if it does not exist.      assert(!PMS.empty() && "Unable to create Call Graph Pass Manager");      PMDataManager *PMD = PMS.top(); @@ -608,7 +608,7 @@ namespace {    class PrintCallGraphPass : public CallGraphSCCPass {      std::string Banner;      raw_ostream &OS;       // raw_ostream to print on. -     +    public:      static char ID; @@ -640,10 +640,10 @@ namespace {        }        return false;      } -     +      StringRef getPassName() const override { return "Print CallGraph IR"; }    }; -   +  } // end anonymous namespace.  char PrintCallGraphPass::ID = 0; | 
