@@ -47,6 +47,10 @@ static llvm::cl::opt<std::string>
47
47
OutputFilename (" o" , llvm::cl::desc(" Override output filename" ),
48
48
llvm::cl::value_desc(" filename" ));
49
49
50
+ static llvm::cl::opt<bool >
51
+ OmitDeadSymbol (" omit-dead-symbol" , llvm::cl::init(false ),
52
+ llvm::cl::desc(" Omit dead symbols" ));
53
+
50
54
static llvm::cl::opt<ActionType>
51
55
Action (llvm::cl::desc(" Mode:" ), llvm::cl::init(ActionType::None),
52
56
llvm::cl::cat(Category),
@@ -192,6 +196,7 @@ struct CallGraph {
192
196
struct Node {
193
197
FunctionSummary *FS;
194
198
SmallVector<Edge, 8 > Children;
199
+ Node (FunctionSummary *FS) : FS(FS), Children() {}
195
200
};
196
201
197
202
struct child_iterator
@@ -227,13 +232,12 @@ struct CallGraph {
227
232
};
228
233
229
234
CallGraph::CallGraph (ModuleSummaryIndex *Summary) {
230
- Nodes.resize (Summary->functions_size ());
231
235
llvm::DenseMap<GUID, Node *> NodeMap;
232
- int idx = 0 ;
233
236
for (auto FI = Summary->functions_begin (), FE = Summary->functions_end ();
234
237
FI != FE; ++FI) {
235
- Node &node = Nodes[idx++];
236
- node.FS = FI->second .get ();
238
+ if (options::OmitDeadSymbol && !FI->second ->isLive ()) continue ;
239
+ Nodes.emplace_back (FI->second .get ());
240
+ Node &node = Nodes.back ();
237
241
NodeMap[FI->first ] = &node;
238
242
}
239
243
@@ -307,31 +311,39 @@ namespace llvm {
307
311
return DCtx.demangleSymbolAsString (Node->FS ->getName ());
308
312
}
309
313
310
- static std::string getEdgeSourceLabel (const CallGraph::Node *Node,
311
- CallGraph::child_iterator I) {
314
+ static std::string getNodeAttributes (const CallGraph::Node *Node,
315
+ const CallGraph *Graph) {
316
+ std::string color = Node->FS ->isLive () ? " green" : " red" ;
317
+ std::string attrs = " color=\" " + color + " \" " ;
318
+ return attrs;
319
+ }
320
+
321
+ static std::string getEdgeAttributes (const CallGraph::Node *Node,
322
+ CallGraph::child_iterator I,
323
+ const CallGraph *Graph) {
312
324
std::string Label;
313
325
raw_string_ostream O (Label);
314
- FunctionSummary::Call call = I.baseIter ->Call ;
315
326
Demangle::Context DCtx;
316
- O << DCtx.demangleSymbolAsString (call.getName ());
317
- O << " (" ;
327
+ FunctionSummary::Call call = I.baseIter ->Call ;
328
+ std::string demangled = DCtx.demangleSymbolAsString (call.getName ());
329
+ O << " label=\" " ;
318
330
switch (call.getKind ()) {
319
331
case FunctionSummary::Call::Witness: {
320
- O << " W " ;
332
+ O << " (W) " << demangled ;
321
333
break ;
322
334
}
323
335
case FunctionSummary::Call::VTable: {
324
- O << " V " ;
336
+ O << " (V) " << demangled ;
325
337
break ;
326
338
}
327
339
case FunctionSummary::Call::Direct: {
328
- O << " D " ;
340
+ O << " (D) " ;
329
341
break ;
330
342
}
331
343
case FunctionSummary::Call::kindCount:
332
344
llvm_unreachable (" impossible" );
333
345
}
334
- O << " ) " ;
346
+ O << " \" " ;
335
347
return Label;
336
348
}
337
349
};
0 commit comments