mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[callgraph] Use one bump ptr alloctor for all memory allocated in the callgraph.
I also did some small llvm style fixes. Swift SVN r25515
This commit is contained in:
@@ -220,16 +220,14 @@ class CallGraph {
|
|||||||
llvm::DenseMap<SILFunction *, CallGraphNode *> FunctionToNodeMap;
|
llvm::DenseMap<SILFunction *, CallGraphNode *> FunctionToNodeMap;
|
||||||
llvm::SmallVector<CallGraphSCC *, 16> BottomUpSCCOrder;
|
llvm::SmallVector<CallGraphSCC *, 16> BottomUpSCCOrder;
|
||||||
std::vector<SILFunction *> BottomUpFunctionOrder;
|
std::vector<SILFunction *> BottomUpFunctionOrder;
|
||||||
llvm::BumpPtrAllocator NodeAllocator;
|
|
||||||
llvm::SpecificBumpPtrAllocator<CallGraphEdge> EdgeAllocator;
|
/// An allocator used by the callgraph.
|
||||||
|
llvm::BumpPtrAllocator Allocator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CallGraph(SILModule *M, bool completeModule);
|
CallGraph(SILModule *M, bool completeModule);
|
||||||
|
|
||||||
~CallGraph() {
|
~CallGraph() {}
|
||||||
for (auto *SCC : BottomUpSCCOrder)
|
|
||||||
delete SCC;
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::SmallVectorImpl<CallGraphNode *> &getCallGraphRoots() {
|
llvm::SmallVectorImpl<CallGraphNode *> &getCallGraphRoots() {
|
||||||
return CallGraphRoots;
|
return CallGraphRoots;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ void CallGraph::addCallGraphNode(SILFunction *F, unsigned NodeOrdinal) {
|
|||||||
// TODO: Compute this from the call graph itself after stripping
|
// TODO: Compute this from the call graph itself after stripping
|
||||||
// unreachable nodes from graph.
|
// unreachable nodes from graph.
|
||||||
++NumCallGraphNodes;
|
++NumCallGraphNodes;
|
||||||
auto *Node = new (NodeAllocator) CallGraphNode(F, NodeOrdinal);
|
auto *Node = new (Allocator) CallGraphNode(F, NodeOrdinal);
|
||||||
|
|
||||||
assert(!FunctionToNodeMap.count(F) &&
|
assert(!FunctionToNodeMap.count(F) &&
|
||||||
"Added function already has a call graph node!");
|
"Added function already has a call graph node!");
|
||||||
@@ -135,8 +135,7 @@ void CallGraph::addEdgesForApply(ApplyInst *AI, CallGraphNode *CallerNode) {
|
|||||||
bool Complete = false;
|
bool Complete = false;
|
||||||
|
|
||||||
if (tryGetCalleeSet(AI->getCallee(), CalleeSet, Complete)) {
|
if (tryGetCalleeSet(AI->getCallee(), CalleeSet, Complete)) {
|
||||||
auto *Edge = new (EdgeAllocator.Allocate()) CallGraphEdge(AI, CalleeSet,
|
auto *Edge = new (Allocator) CallGraphEdge(AI, CalleeSet, Complete);
|
||||||
Complete);
|
|
||||||
CallerNode->addCalleeEdge(Edge);
|
CallerNode->addCalleeEdge(Edge);
|
||||||
|
|
||||||
for (auto *CalleeNode : CalleeSet)
|
for (auto *CalleeNode : CalleeSet)
|
||||||
@@ -197,9 +196,19 @@ static void orderCallees(const CallGraphEdge::CalleeSetType &Callees,
|
|||||||
/// point to multiple call graph nodes in the case where we can call
|
/// point to multiple call graph nodes in the case where we can call
|
||||||
/// one of several different functions.
|
/// one of several different functions.
|
||||||
class CallGraphSCCFinder {
|
class CallGraphSCCFinder {
|
||||||
|
unsigned NextDFSNum;
|
||||||
|
llvm::SmallVectorImpl<CallGraphSCC *> &TheSCCs;
|
||||||
|
|
||||||
|
llvm::DenseMap<CallGraphNode *, unsigned> DFSNum;
|
||||||
|
llvm::DenseMap<CallGraphNode *, unsigned> MinDFSNum;
|
||||||
|
llvm::SetVector<CallGraphNode *> DFSStack;
|
||||||
|
|
||||||
|
llvm::BumpPtrAllocator &BPA;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CallGraphSCCFinder(llvm::SmallVectorImpl<CallGraphSCC *> &TheSCCs)
|
CallGraphSCCFinder(llvm::SmallVectorImpl<CallGraphSCC *> &TheSCCs,
|
||||||
: NextDFSNum(0), TheSCCs(TheSCCs) {}
|
llvm::BumpPtrAllocator &BPA)
|
||||||
|
: NextDFSNum(0), TheSCCs(TheSCCs), BPA(BPA) {}
|
||||||
|
|
||||||
void DFS(CallGraphNode *Node) {
|
void DFS(CallGraphNode *Node) {
|
||||||
// Set the DFSNum for this node if we haven't already, and if we
|
// Set the DFSNum for this node if we haven't already, and if we
|
||||||
@@ -232,7 +241,7 @@ public:
|
|||||||
// If this node is the root of an SCC (including SCCs with a
|
// If this node is the root of an SCC (including SCCs with a
|
||||||
// single node), pop the SCC and push it on our SCC stack.
|
// single node), pop the SCC and push it on our SCC stack.
|
||||||
if (DFSNum[Node] == MinDFSNum[Node]) {
|
if (DFSNum[Node] == MinDFSNum[Node]) {
|
||||||
auto *SCC = new CallGraphSCC();
|
auto *SCC = new (BPA) CallGraphSCC();
|
||||||
|
|
||||||
CallGraphNode *Popped;
|
CallGraphNode *Popped;
|
||||||
do {
|
do {
|
||||||
@@ -243,14 +252,6 @@ public:
|
|||||||
TheSCCs.push_back(SCC);
|
TheSCCs.push_back(SCC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned NextDFSNum;
|
|
||||||
llvm::SmallVectorImpl<CallGraphSCC *> &TheSCCs;
|
|
||||||
|
|
||||||
llvm::DenseMap<CallGraphNode *, unsigned> DFSNum;
|
|
||||||
llvm::DenseMap<CallGraphNode *, unsigned> MinDFSNum;
|
|
||||||
llvm::SetVector<CallGraphNode *> DFSStack;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void CallGraph::computeBottomUpSCCOrder() {
|
void CallGraph::computeBottomUpSCCOrder() {
|
||||||
@@ -261,7 +262,7 @@ void CallGraph::computeBottomUpSCCOrder() {
|
|||||||
BottomUpSCCOrder.clear();
|
BottomUpSCCOrder.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CallGraphSCCFinder SCCFinder(BottomUpSCCOrder);
|
CallGraphSCCFinder SCCFinder(BottomUpSCCOrder, Allocator);
|
||||||
for (auto *Node : getCallGraphRoots())
|
for (auto *Node : getCallGraphRoots())
|
||||||
SCCFinder.DFS(Node);
|
SCCFinder.DFS(Node);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user