mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 04:24:00 +00:00
[LCG] Switch the Callee sets to be DenseMaps pointing to the index into
the Callee list. This is going to be quite important to prevent removal from going quadratic. No functionality changed at this point, this is one of the refactoring patches I've broken out of my initial work toward mutation updates of the call graph. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206938 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -187,10 +187,10 @@ public:
|
|||||||
int LowLink;
|
int LowLink;
|
||||||
|
|
||||||
mutable NodeVectorT Callees;
|
mutable NodeVectorT Callees;
|
||||||
SmallPtrSet<Function *, 4> CalleeSet;
|
DenseMap<Function *, size_t> CalleeIndexMap;
|
||||||
|
|
||||||
/// \brief Basic constructor implements the scanning of F into Callees and
|
/// \brief Basic constructor implements the scanning of F into Callees and
|
||||||
/// CalleeSet.
|
/// CalleeIndexMap.
|
||||||
Node(LazyCallGraph &G, Function &F);
|
Node(LazyCallGraph &G, Function &F);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -333,8 +333,9 @@ private:
|
|||||||
/// escape at the module scope.
|
/// escape at the module scope.
|
||||||
NodeVectorT EntryNodes;
|
NodeVectorT EntryNodes;
|
||||||
|
|
||||||
/// \brief Set of the entry nodes to the graph.
|
/// \brief Map of the entry nodes in the graph to their indices in
|
||||||
SmallPtrSet<Function *, 4> EntryNodeSet;
|
/// \c EntryNodes.
|
||||||
|
DenseMap<Function *, size_t> EntryIndexMap;
|
||||||
|
|
||||||
/// \brief Allocator that holds all the call graph SCCs.
|
/// \brief Allocator that holds all the call graph SCCs.
|
||||||
SpecificBumpPtrAllocator<SCC> SCCBPA;
|
SpecificBumpPtrAllocator<SCC> SCCBPA;
|
||||||
|
@ -23,7 +23,7 @@ using namespace llvm;
|
|||||||
static void findCallees(
|
static void findCallees(
|
||||||
SmallVectorImpl<Constant *> &Worklist, SmallPtrSetImpl<Constant *> &Visited,
|
SmallVectorImpl<Constant *> &Worklist, SmallPtrSetImpl<Constant *> &Visited,
|
||||||
SmallVectorImpl<PointerUnion<Function *, LazyCallGraph::Node *>> &Callees,
|
SmallVectorImpl<PointerUnion<Function *, LazyCallGraph::Node *>> &Callees,
|
||||||
SmallPtrSetImpl<Function *> &CalleeSet) {
|
DenseMap<Function *, size_t> &CalleeIndexMap) {
|
||||||
while (!Worklist.empty()) {
|
while (!Worklist.empty()) {
|
||||||
Constant *C = Worklist.pop_back_val();
|
Constant *C = Worklist.pop_back_val();
|
||||||
|
|
||||||
@ -38,7 +38,8 @@ static void findCallees(
|
|||||||
// alias. Then a test of the address of the weak function against the new
|
// alias. Then a test of the address of the weak function against the new
|
||||||
// strong definition's address would be an effective way to determine the
|
// strong definition's address would be an effective way to determine the
|
||||||
// safety of optimizing a direct call edge.
|
// safety of optimizing a direct call edge.
|
||||||
if (!F->isDeclaration() && CalleeSet.insert(F)) {
|
if (!F->isDeclaration() &&
|
||||||
|
CalleeIndexMap.insert(std::make_pair(F, Callees.size())).second) {
|
||||||
DEBUG(dbgs() << " Added callable function: " << F->getName()
|
DEBUG(dbgs() << " Added callable function: " << F->getName()
|
||||||
<< "\n");
|
<< "\n");
|
||||||
Callees.push_back(F);
|
Callees.push_back(F);
|
||||||
@ -71,7 +72,7 @@ LazyCallGraph::Node::Node(LazyCallGraph &G, Function &F)
|
|||||||
// We've collected all the constant (and thus potentially function or
|
// We've collected all the constant (and thus potentially function or
|
||||||
// function containing) operands to all of the instructions in the function.
|
// function containing) operands to all of the instructions in the function.
|
||||||
// Process them (recursively) collecting every function found.
|
// Process them (recursively) collecting every function found.
|
||||||
findCallees(Worklist, Visited, Callees, CalleeSet);
|
findCallees(Worklist, Visited, Callees, CalleeIndexMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyCallGraph::LazyCallGraph(Module &M) : NextDFSNumber(0) {
|
LazyCallGraph::LazyCallGraph(Module &M) : NextDFSNumber(0) {
|
||||||
@ -79,7 +80,7 @@ LazyCallGraph::LazyCallGraph(Module &M) : NextDFSNumber(0) {
|
|||||||
<< "\n");
|
<< "\n");
|
||||||
for (Function &F : M)
|
for (Function &F : M)
|
||||||
if (!F.isDeclaration() && !F.hasLocalLinkage())
|
if (!F.isDeclaration() && !F.hasLocalLinkage())
|
||||||
if (EntryNodeSet.insert(&F)) {
|
if (EntryIndexMap.insert(std::make_pair(&F, EntryNodes.size())).second) {
|
||||||
DEBUG(dbgs() << " Adding '" << F.getName()
|
DEBUG(dbgs() << " Adding '" << F.getName()
|
||||||
<< "' to entry set of the graph.\n");
|
<< "' to entry set of the graph.\n");
|
||||||
EntryNodes.push_back(&F);
|
EntryNodes.push_back(&F);
|
||||||
@ -95,7 +96,7 @@ LazyCallGraph::LazyCallGraph(Module &M) : NextDFSNumber(0) {
|
|||||||
|
|
||||||
DEBUG(dbgs() << " Adding functions referenced by global initializers to the "
|
DEBUG(dbgs() << " Adding functions referenced by global initializers to the "
|
||||||
"entry set.\n");
|
"entry set.\n");
|
||||||
findCallees(Worklist, Visited, EntryNodes, EntryNodeSet);
|
findCallees(Worklist, Visited, EntryNodes, EntryIndexMap);
|
||||||
|
|
||||||
for (auto &Entry : EntryNodes)
|
for (auto &Entry : EntryNodes)
|
||||||
if (Function *F = Entry.dyn_cast<Function *>())
|
if (Function *F = Entry.dyn_cast<Function *>())
|
||||||
@ -107,7 +108,7 @@ LazyCallGraph::LazyCallGraph(Module &M) : NextDFSNumber(0) {
|
|||||||
LazyCallGraph::LazyCallGraph(LazyCallGraph &&G)
|
LazyCallGraph::LazyCallGraph(LazyCallGraph &&G)
|
||||||
: BPA(std::move(G.BPA)), NodeMap(std::move(G.NodeMap)),
|
: BPA(std::move(G.BPA)), NodeMap(std::move(G.NodeMap)),
|
||||||
EntryNodes(std::move(G.EntryNodes)),
|
EntryNodes(std::move(G.EntryNodes)),
|
||||||
EntryNodeSet(std::move(G.EntryNodeSet)), SCCBPA(std::move(G.SCCBPA)),
|
EntryIndexMap(std::move(G.EntryIndexMap)), SCCBPA(std::move(G.SCCBPA)),
|
||||||
SCCMap(std::move(G.SCCMap)), LeafSCCs(std::move(G.LeafSCCs)),
|
SCCMap(std::move(G.SCCMap)), LeafSCCs(std::move(G.LeafSCCs)),
|
||||||
DFSStack(std::move(G.DFSStack)),
|
DFSStack(std::move(G.DFSStack)),
|
||||||
SCCEntryNodes(std::move(G.SCCEntryNodes)),
|
SCCEntryNodes(std::move(G.SCCEntryNodes)),
|
||||||
@ -119,7 +120,7 @@ LazyCallGraph &LazyCallGraph::operator=(LazyCallGraph &&G) {
|
|||||||
BPA = std::move(G.BPA);
|
BPA = std::move(G.BPA);
|
||||||
NodeMap = std::move(G.NodeMap);
|
NodeMap = std::move(G.NodeMap);
|
||||||
EntryNodes = std::move(G.EntryNodes);
|
EntryNodes = std::move(G.EntryNodes);
|
||||||
EntryNodeSet = std::move(G.EntryNodeSet);
|
EntryIndexMap = std::move(G.EntryIndexMap);
|
||||||
SCCBPA = std::move(G.SCCBPA);
|
SCCBPA = std::move(G.SCCBPA);
|
||||||
SCCMap = std::move(G.SCCMap);
|
SCCMap = std::move(G.SCCMap);
|
||||||
LeafSCCs = std::move(G.LeafSCCs);
|
LeafSCCs = std::move(G.LeafSCCs);
|
||||||
|
Reference in New Issue
Block a user