Skip to content

Commit

Permalink
[Analysis] Fix some Clang-tidy modernize-use-using and Include What Y…
Browse files Browse the repository at this point in the history
…ou Use warnings; other minor fixes. Also affected in files (NFC).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312289 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
EugeneZelenko committed Aug 31, 2017
1 parent bf95626 commit 046ca04
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 172 deletions.
70 changes: 46 additions & 24 deletions include/llvm/Analysis/CGSCCPassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,44 @@
#ifndef LLVM_ANALYSIS_CGSCCPASSMANAGER_H
#define LLVM_ANALYSIS_CGSCCPASSMANAGER_H

#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/PriorityWorklist.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <utility>

namespace llvm {

struct CGSCCUpdateResult;
class Module;

// Allow debug logging in this inline function.
#define DEBUG_TYPE "cgscc"

struct CGSCCUpdateResult;

/// Extern template declaration for the analysis set for this IR unit.
extern template class AllAnalysesOn<LazyCallGraph::SCC>;

extern template class AnalysisManager<LazyCallGraph::SCC, LazyCallGraph &>;

/// \brief The CGSCC analysis manager.
///
/// See the documentation for the AnalysisManager template for detail
/// documentation. This typedef serves as a convenient way to refer to this
/// documentation. This type serves as a convenient way to refer to this
/// construct in the adaptors and proxies used to integrate this into the larger
/// pass manager infrastructure.
typedef AnalysisManager<LazyCallGraph::SCC, LazyCallGraph &>
CGSCCAnalysisManager;
using CGSCCAnalysisManager =
AnalysisManager<LazyCallGraph::SCC, LazyCallGraph &>;

// Explicit specialization and instantiation declarations for the pass manager.
// See the comments on the definition of the specialization for details on how
Expand All @@ -132,10 +144,10 @@ extern template class PassManager<LazyCallGraph::SCC, CGSCCAnalysisManager,
///
/// See the documentation for the PassManager template for details. It runs
/// a sequence of SCC passes over each SCC that the manager is run over. This
/// typedef serves as a convenient way to refer to this construct.
typedef PassManager<LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &,
CGSCCUpdateResult &>
CGSCCPassManager;
/// type serves as a convenient way to refer to this construct.
using CGSCCPassManager =
PassManager<LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &,
CGSCCUpdateResult &>;

/// An explicit specialization of the require analysis template pass.
template <typename AnalysisT>
Expand All @@ -152,8 +164,8 @@ struct RequireAnalysisPass<AnalysisT, LazyCallGraph::SCC, CGSCCAnalysisManager,
};

/// A proxy from a \c CGSCCAnalysisManager to a \c Module.
typedef InnerAnalysisManagerProxy<CGSCCAnalysisManager, Module>
CGSCCAnalysisManagerModuleProxy;
using CGSCCAnalysisManagerModuleProxy =
InnerAnalysisManagerProxy<CGSCCAnalysisManager, Module>;

/// We need a specialized result for the \c CGSCCAnalysisManagerModuleProxy so
/// it can have access to the call graph in order to walk all the SCCs when
Expand Down Expand Up @@ -196,10 +208,11 @@ extern template class InnerAnalysisManagerProxy<CGSCCAnalysisManager, Module>;

extern template class OuterAnalysisManagerProxy<
ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph &>;

/// A proxy from a \c ModuleAnalysisManager to an \c SCC.
typedef OuterAnalysisManagerProxy<ModuleAnalysisManager, LazyCallGraph::SCC,
LazyCallGraph &>
ModuleAnalysisManagerCGSCCProxy;
using ModuleAnalysisManagerCGSCCProxy =
OuterAnalysisManagerProxy<ModuleAnalysisManager, LazyCallGraph::SCC,
LazyCallGraph &>;

/// Support structure for SCC passes to communicate updates the call graph back
/// to the CGSCC pass manager infrsatructure.
Expand Down Expand Up @@ -304,18 +317,21 @@ class ModuleToPostOrderCGSCCPassAdaptor
public:
explicit ModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass)
: Pass(std::move(Pass)) {}

// We have to explicitly define all the special member functions because MSVC
// refuses to generate them.
ModuleToPostOrderCGSCCPassAdaptor(
const ModuleToPostOrderCGSCCPassAdaptor &Arg)
: Pass(Arg.Pass) {}

ModuleToPostOrderCGSCCPassAdaptor(ModuleToPostOrderCGSCCPassAdaptor &&Arg)
: Pass(std::move(Arg.Pass)) {}

friend void swap(ModuleToPostOrderCGSCCPassAdaptor &LHS,
ModuleToPostOrderCGSCCPassAdaptor &RHS) {
using std::swap;
swap(LHS.Pass, RHS.Pass);
std::swap(LHS.Pass, RHS.Pass);
}

ModuleToPostOrderCGSCCPassAdaptor &
operator=(ModuleToPostOrderCGSCCPassAdaptor RHS) {
swap(*this, RHS);
Expand Down Expand Up @@ -383,7 +399,7 @@ class ModuleToPostOrderCGSCCPassAdaptor

// Push the initial SCCs in reverse post-order as we'll pop off the the
// back and so see this in post-order.
for (LazyCallGraph::SCC &C : reverse(*RC))
for (LazyCallGraph::SCC &C : llvm::reverse(*RC))
CWorklist.insert(&C);

do {
Expand Down Expand Up @@ -505,13 +521,15 @@ class FunctionAnalysisManagerCGSCCProxy

private:
friend AnalysisInfoMixin<FunctionAnalysisManagerCGSCCProxy>;

static AnalysisKey Key;
};

extern template class OuterAnalysisManagerProxy<CGSCCAnalysisManager, Function>;

/// A proxy from a \c CGSCCAnalysisManager to a \c Function.
typedef OuterAnalysisManagerProxy<CGSCCAnalysisManager, Function>
CGSCCAnalysisManagerFunctionProxy;
using CGSCCAnalysisManagerFunctionProxy =
OuterAnalysisManagerProxy<CGSCCAnalysisManager, Function>;

/// Helper to update the call graph after running a function pass.
///
Expand All @@ -537,17 +555,20 @@ class CGSCCToFunctionPassAdaptor
public:
explicit CGSCCToFunctionPassAdaptor(FunctionPassT Pass)
: Pass(std::move(Pass)) {}

// We have to explicitly define all the special member functions because MSVC
// refuses to generate them.
CGSCCToFunctionPassAdaptor(const CGSCCToFunctionPassAdaptor &Arg)
: Pass(Arg.Pass) {}

CGSCCToFunctionPassAdaptor(CGSCCToFunctionPassAdaptor &&Arg)
: Pass(std::move(Arg.Pass)) {}

friend void swap(CGSCCToFunctionPassAdaptor &LHS,
CGSCCToFunctionPassAdaptor &RHS) {
using std::swap;
swap(LHS.Pass, RHS.Pass);
std::swap(LHS.Pass, RHS.Pass);
}

CGSCCToFunctionPassAdaptor &operator=(CGSCCToFunctionPassAdaptor RHS) {
swap(*this, RHS);
return *this;
Expand Down Expand Up @@ -733,7 +754,7 @@ class DevirtSCCRepeatedPass
// so iterate to process this devirtualization site.
return true;
};
bool Devirt = any_of(CallHandles, IsDevirtualizedHandle);
bool Devirt = llvm::any_of(CallHandles, IsDevirtualizedHandle);

// Rescan to build up a new set of handles and count how many direct
// calls remain. If we decide to iterate, this also sets up the input to
Expand Down Expand Up @@ -802,6 +823,7 @@ DevirtSCCRepeatedPass<PassT> createDevirtSCCRepeatedPass(PassT Pass,

// Clear out the debug logging macro.
#undef DEBUG_TYPE
}

#endif
} // end namespace llvm

#endif // LLVM_ANALYSIS_CGSCCPASSMANAGER_H
25 changes: 14 additions & 11 deletions include/llvm/Analysis/CallGraphSCCPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
#ifndef LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
#define LLVM_ANALYSIS_CALLGRAPHSCCPASS_H

#include "llvm/Analysis/CallGraph.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Pass.h"
#include "llvm/PassSupport.h"
#include <vector>

namespace llvm {

class CallGraphNode;
class CallGraph;
class PMStack;
class CallGraphNode;
class CallGraphSCC;
class PMStack;

class CallGraphSCCPass : public Pass {
public:
explicit CallGraphSCCPass(char &pid) : Pass(PT_CallGraphSCC, pid) {}

/// createPrinterPass - Get a pass that prints the Module
/// corresponding to a CallGraph.
Pass *createPrinterPass(raw_ostream &O,
Pass *createPrinterPass(raw_ostream &OS,
const std::string &Banner) const override;

using llvm::Pass::doInitialization;
Expand All @@ -57,7 +57,6 @@ class CallGraphSCCPass : public Pass {
///
/// SCC passes that add or delete functions to the SCC are required to update
/// the SCC list, otherwise stale pointers may be dereferenced.
///
virtual bool runOnSCC(CallGraphSCC &SCC) = 0;

/// doFinalization - This method is called after the SCC's of the program has
Expand Down Expand Up @@ -89,7 +88,7 @@ class CallGraphSCCPass : public Pass {
class CallGraphSCC {
const CallGraph &CG; // The call graph for this SCC.
void *Context; // The CGPassManager object that is vending this.
std::vector<CallGraphNode*> Nodes;
std::vector<CallGraphNode *> Nodes;

public:
CallGraphSCC(CallGraph &cg, void *context) : CG(cg), Context(context) {}
Expand All @@ -105,7 +104,8 @@ class CallGraphSCC {
/// Old node has been deleted, and New is to be used in its place.
void ReplaceNode(CallGraphNode *Old, CallGraphNode *New);

typedef std::vector<CallGraphNode *>::const_iterator iterator;
using iterator = std::vector<CallGraphNode *>::const_iterator;

iterator begin() const { return Nodes.begin(); }
iterator end() const { return Nodes.end(); }

Expand All @@ -119,16 +119,19 @@ void initializeDummyCGSCCPassPass(PassRegistry &);
class DummyCGSCCPass : public CallGraphSCCPass {
public:
static char ID;

DummyCGSCCPass() : CallGraphSCCPass(ID) {
PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializeDummyCGSCCPassPass(Registry);
};
}

bool runOnSCC(CallGraphSCC &SCC) override { return false; }

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
}
};

} // End llvm namespace
} // end namespace llvm

#endif
#endif // LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
47 changes: 31 additions & 16 deletions lib/Analysis/CGSCCPassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,25 @@
//===----------------------------------------------------------------------===//

#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <iterator>

#define DEBUG_TYPE "cgscc"

Expand Down Expand Up @@ -262,7 +279,7 @@ bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
return false;
}

} // End llvm namespace
} // end namespace llvm

/// When a new SCC is created for the graph and there might be function
/// analysis results cached for the functions now in that SCC two forms of
Expand Down Expand Up @@ -309,7 +326,6 @@ static void updateNewSCCFunctionAnalyses(LazyCallGraph::SCC &C,
}
}

namespace {
/// Helper function to update both the \c CGSCCAnalysisManager \p AM and the \c
/// CGSCCPassManager's \c CGSCCUpdateResult \p UR based on a range of newly
/// added SCCs.
Expand All @@ -321,11 +337,11 @@ namespace {
/// This function returns the SCC containing \p N. This will be either \p C if
/// no new SCCs have been split out, or it will be the new SCC containing \p N.
template <typename SCCRangeT>
LazyCallGraph::SCC *
static LazyCallGraph::SCC *
incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
LazyCallGraph::Node &N, LazyCallGraph::SCC *C,
CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
typedef LazyCallGraph::SCC SCC;
using SCC = LazyCallGraph::SCC;

if (NewSCCRange.begin() == NewSCCRange.end())
return C;
Expand Down Expand Up @@ -363,8 +379,8 @@ incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
if (NeedFAMProxy)
updateNewSCCFunctionAnalyses(*C, G, AM);

for (SCC &NewC :
reverse(make_range(std::next(NewSCCRange.begin()), NewSCCRange.end()))) {
for (SCC &NewC : llvm::reverse(make_range(std::next(NewSCCRange.begin()),
NewSCCRange.end()))) {
assert(C != &NewC && "No need to re-visit the current SCC!");
assert(OldC != &NewC && "Already handled the original SCC!");
UR.CWorklist.insert(&NewC);
Expand All @@ -380,15 +396,14 @@ incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
}
return C;
}
}

LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
LazyCallGraph &G, LazyCallGraph::SCC &InitialC, LazyCallGraph::Node &N,
CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
typedef LazyCallGraph::Node Node;
typedef LazyCallGraph::Edge Edge;
typedef LazyCallGraph::SCC SCC;
typedef LazyCallGraph::RefSCC RefSCC;
using Node = LazyCallGraph::Node;
using Edge = LazyCallGraph::Edge;
using SCC = LazyCallGraph::SCC;
using RefSCC = LazyCallGraph::RefSCC;

RefSCC &InitialRC = InitialC.getOuterRefSCC();
SCC *C = &InitialC;
Expand Down Expand Up @@ -430,7 +445,7 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
// Now walk all references.
for (Instruction &I : instructions(F))
for (Value *Op : I.operand_values())
if (Constant *C = dyn_cast<Constant>(Op))
if (auto *C = dyn_cast<Constant>(Op))
if (Visited.insert(C).second)
Worklist.push_back(C);

Expand Down Expand Up @@ -521,8 +536,8 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
// "bottom" we will continue processing in the bottom-up walk.
assert(NewRefSCCs.front() == RC &&
"New current RefSCC not first in the returned list!");
for (RefSCC *NewRC :
reverse(make_range(std::next(NewRefSCCs.begin()), NewRefSCCs.end()))) {
for (RefSCC *NewRC : llvm::reverse(make_range(std::next(NewRefSCCs.begin()),
NewRefSCCs.end()))) {
assert(NewRC != RC && "Should not encounter the current RefSCC further "
"in the postorder list of new RefSCCs.");
UR.RCWorklist.insert(NewRC);
Expand Down Expand Up @@ -644,8 +659,8 @@ LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist: " << *C
<< "\n");
// Enqueue in reverse order as we pop off the back of the worklist.
for (SCC &MovedC : reverse(make_range(RC->begin() + InitialSCCIndex,
RC->begin() + NewSCCIndex))) {
for (SCC &MovedC : llvm::reverse(make_range(RC->begin() + InitialSCCIndex,
RC->begin() + NewSCCIndex))) {
UR.CWorklist.insert(&MovedC);
DEBUG(dbgs() << "Enqueuing a newly earlier in post-order SCC: "
<< MovedC << "\n");
Expand Down
Loading

0 comments on commit 046ca04

Please sign in to comment.