Skip to content

Commit 4e9ba8c

Browse files
[Prototype] Improve dot export stlyle
1 parent 3a7b5f5 commit 4e9ba8c

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

tools/swift-module-summary-test/swift-module-summary-test.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ static llvm::cl::opt<std::string>
4747
OutputFilename("o", llvm::cl::desc("Override output filename"),
4848
llvm::cl::value_desc("filename"));
4949

50+
static llvm::cl::opt<bool>
51+
OmitDeadSymbol("omit-dead-symbol", llvm::cl::init(false),
52+
llvm::cl::desc("Omit dead symbols"));
53+
5054
static llvm::cl::opt<ActionType>
5155
Action(llvm::cl::desc("Mode:"), llvm::cl::init(ActionType::None),
5256
llvm::cl::cat(Category),
@@ -192,6 +196,7 @@ struct CallGraph {
192196
struct Node {
193197
FunctionSummary *FS;
194198
SmallVector<Edge, 8> Children;
199+
Node(FunctionSummary *FS) : FS(FS), Children() {}
195200
};
196201

197202
struct child_iterator
@@ -227,13 +232,12 @@ struct CallGraph {
227232
};
228233

229234
CallGraph::CallGraph(ModuleSummaryIndex *Summary) {
230-
Nodes.resize(Summary->functions_size());
231235
llvm::DenseMap<GUID, Node *> NodeMap;
232-
int idx = 0;
233236
for (auto FI = Summary->functions_begin(), FE = Summary->functions_end();
234237
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();
237241
NodeMap[FI->first] = &node;
238242
}
239243

@@ -307,31 +311,39 @@ namespace llvm {
307311
return DCtx.demangleSymbolAsString(Node->FS->getName());
308312
}
309313

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) {
312324
std::string Label;
313325
raw_string_ostream O(Label);
314-
FunctionSummary::Call call = I.baseIter->Call;
315326
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=\"";
318330
switch (call.getKind()) {
319331
case FunctionSummary::Call::Witness: {
320-
O << "W";
332+
O << "(W) " << demangled;
321333
break;
322334
}
323335
case FunctionSummary::Call::VTable: {
324-
O << "V";
336+
O << "(V) " << demangled;
325337
break;
326338
}
327339
case FunctionSummary::Call::Direct: {
328-
O << "D";
340+
O << "(D)";
329341
break;
330342
}
331343
case FunctionSummary::Call::kindCount:
332344
llvm_unreachable("impossible");
333345
}
334-
O << ")";
346+
O << "\"";
335347
return Label;
336348
}
337349
};

0 commit comments

Comments
 (0)