summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Bebenita <mbebenita@gmail.com>2016-11-01 15:44:03 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-11-01 15:44:03 -0700
commit1bcbf5fd9b6cbedf302309eaae719115b2d83d4a (patch)
tree6b44de68015693e8bdf2d1e7fd56f1b77ffdb59d
parent119564e943fb47f081021d69a5456de8d051fe83 (diff)
downloadbinaryen-1bcbf5fd9b6cbedf302309eaae719115b2d83d4a.tar.gz
binaryen-1bcbf5fd9b6cbedf302309eaae719115b2d83d4a.tar.bz2
binaryen-1bcbf5fd9b6cbedf302309eaae719115b2d83d4a.zip
Work around dot quirks related to updating node styles. Remove indirect call edges as they greatly increase the size of the graph. (#818)
-rw-r--r--src/passes/PrintCallGraph.cpp47
-rw-r--r--test/passes/print-call-graph.txt185
2 files changed, 98 insertions, 134 deletions
diff --git a/src/passes/PrintCallGraph.cpp b/src/passes/PrintCallGraph.cpp
index 33fcb3457..233ae3a0c 100644
--- a/src/passes/PrintCallGraph.cpp
+++ b/src/passes/PrintCallGraph.cpp
@@ -33,20 +33,25 @@ struct PrintCallGraph : public Pass {
o << "digraph call {\n";
o << " rankdir = LR;\n";
o << " subgraph cluster_key {\n";
- o << " node [shape=box, style=rounded, fontname=courier, fontsize=10];\n";
+ o << " node [shape=box, fontname=courier, fontsize=10];\n";
o << " edge [fontname=courier, fontsize=10];\n";
o << " label = \"Key\";\n";
- o << " \"Import\" [style=\"filled, rounded\", fillcolor=\"turquoise\"];\n";
- o << " \"Export\" [style=\"filled, rounded\", fillcolor=\"gray\"];\n";
+ o << " \"Import\" [style=\"filled\", fillcolor=\"turquoise\"];\n";
+ o << " \"Export\" [style=\"filled\", fillcolor=\"gray\"];\n";
+ o << " \"Indirect Target\" [style=\"filled, rounded\", fillcolor=\"white\"];\n";
o << " \"A\" -> \"B\" [style=\"filled, rounded\", label = \"Direct Call\"];\n";
- o << " \"C\" -> \"D\" [style=\"filled, rounded, dashed\", label = \"Possible Indirect Call\"];\n";
o << " }\n\n";
- o << " node [shape=box,style=rounded, fontname=courier, fontsize=10];\n";
+ o << " node [shape=box, fontname=courier, fontsize=10];\n";
+
+ // All Functions
+ for (auto& func : module->functions) {
+ std::cout << " \"" << func.get()->name << "\" [style=\"filled\", fillcolor=\"white\"];\n";
+ }
// Imports Nodes
for (auto& curr : module->imports) {
if (curr->kind == ExternalKind::Function) {
- o << " \"" << curr->name << "\" [style=\"filled, rounded\", fillcolor=\"turquoise\"];\n";
+ o << " \"" << curr->name << "\" [style=\"filled\", fillcolor=\"turquoise\"];\n";
}
}
@@ -54,7 +59,7 @@ struct PrintCallGraph : public Pass {
for (auto& curr : module->exports) {
if (curr->kind == ExternalKind::Function) {
Function* func = module->getFunction(curr->value);
- o << " \"" << func->name << "\" [style=\"filled, rounded\", fillcolor=\"gray\"];\n";
+ o << " \"" << func->name << "\" [style=\"filled\", fillcolor=\"gray\"];\n";
}
}
@@ -64,16 +69,9 @@ struct PrintCallGraph : public Pass {
std::set<Name> visitedTargets; // Used to avoid printing duplicate edges.
std::vector<Function*> allIndirectTargets;
CallPrinter(Module *module) : module(module) {
- // Gather targets of indirect calls.
- for (auto& segment : module->table.segments) {
- for (auto& curr : segment.data) {
- allIndirectTargets.push_back(module->getFunction(curr));
- }
- }
// Walk function bodies.
for (auto& func : module->functions) {
currFunction = func.get();
- std::cout << " \"" << func->name << "\";\n";
visitedTargets.clear();
walk(func.get()->body);
}
@@ -90,20 +88,17 @@ struct PrintCallGraph : public Pass {
visitedTargets.insert(name);
std::cout << " \"" << currFunction->name << "\" -> \"" << name << "\"; // callImport\n";
}
- void visitCallIndirect(CallIndirect *curr) {
- // Find eligible indirect targets.
- auto* currType = module->getFunctionType(curr->fullType);
- for (auto& target : allIndirectTargets) {
- auto* targetType = module->getFunctionType(target->type);
- if (targetType->structuralComparison(*currType)) continue;
- auto name = target->name;
- if (visitedTargets.count(name) > 0) continue;
- visitedTargets.insert(name);
- std::cout << " \"" << currFunction->name << "\" -> \"" << name << "\" [style=\"dashed\"]; // callIndirect\n";
- }
- }
};
CallPrinter printer(module);
+
+ // Indirect Targets
+ for (auto& segment : module->table.segments) {
+ for (auto& curr : segment.data) {
+ auto* func = module->getFunction(curr);
+ o << " \"" << func->name << "\" [style=\"filled, rounded\"];\n";
+ }
+ }
+
o << "}\n";
}
};
diff --git a/test/passes/print-call-graph.txt b/test/passes/print-call-graph.txt
index 4558194ef..b12b95828 100644
--- a/test/passes/print-call-graph.txt
+++ b/test/passes/print-call-graph.txt
@@ -1,146 +1,115 @@
digraph call {
rankdir = LR;
subgraph cluster_key {
- node [shape=box, style=rounded, fontname=courier, fontsize=10];
+ node [shape=box, fontname=courier, fontsize=10];
edge [fontname=courier, fontsize=10];
label = "Key";
- "Import" [style="filled, rounded", fillcolor="turquoise"];
- "Export" [style="filled, rounded", fillcolor="gray"];
+ "Import" [style="filled", fillcolor="turquoise"];
+ "Export" [style="filled", fillcolor="gray"];
+ "Indirect Target" [style="filled, rounded", fillcolor="white"];
"A" -> "B" [style="filled, rounded", label = "Direct Call"];
- "C" -> "D" [style="filled, rounded, dashed", label = "Possible Indirect Call"];
}
- node [shape=box,style=rounded, fontname=courier, fontsize=10];
- "$abort" [style="filled, rounded", fillcolor="turquoise"];
- "$_pthread_cleanup_pop" [style="filled, rounded", fillcolor="turquoise"];
- "$___lock" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall6" [style="filled, rounded", fillcolor="turquoise"];
- "$_pthread_cleanup_push" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall140" [style="filled, rounded", fillcolor="turquoise"];
- "$_emscripten_memcpy_big" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall54" [style="filled, rounded", fillcolor="turquoise"];
- "$___unlock" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall146" [style="filled, rounded", fillcolor="turquoise"];
- "$_fflush" [style="filled, rounded", fillcolor="gray"];
- "$_main" [style="filled, rounded", fillcolor="gray"];
- "$_pthread_self" [style="filled, rounded", fillcolor="gray"];
- "$_memset" [style="filled, rounded", fillcolor="gray"];
- "$_malloc" [style="filled, rounded", fillcolor="gray"];
- "$_memcpy" [style="filled, rounded", fillcolor="gray"];
- "$_free" [style="filled, rounded", fillcolor="gray"];
- "$___errno_location" [style="filled, rounded", fillcolor="gray"];
- "$runPostSets" [style="filled, rounded", fillcolor="gray"];
- "$stackAlloc" [style="filled, rounded", fillcolor="gray"];
- "$stackSave" [style="filled, rounded", fillcolor="gray"];
- "$stackRestore" [style="filled, rounded", fillcolor="gray"];
- "$establishStackSpace" [style="filled, rounded", fillcolor="gray"];
- "$setThrew" [style="filled, rounded", fillcolor="gray"];
- "$setTempRet0" [style="filled, rounded", fillcolor="gray"];
- "$getTempRet0" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_ii" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_iiii" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_vi" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_v" [style="filled, rounded", fillcolor="gray"];
- "$stackAlloc";
- "$stackSave";
- "$stackRestore";
- "$establishStackSpace";
- "$setThrew";
- "$setTempRet0";
- "$getTempRet0";
- "$_malloc";
- "$_free";
- "$_main";
+ node [shape=box, fontname=courier, fontsize=10];
+ "$stackAlloc" [style="filled", fillcolor="white"];
+ "$stackSave" [style="filled", fillcolor="white"];
+ "$stackRestore" [style="filled", fillcolor="white"];
+ "$establishStackSpace" [style="filled", fillcolor="white"];
+ "$setThrew" [style="filled", fillcolor="white"];
+ "$setTempRet0" [style="filled", fillcolor="white"];
+ "$getTempRet0" [style="filled", fillcolor="white"];
+ "$_malloc" [style="filled", fillcolor="white"];
+ "$_free" [style="filled", fillcolor="white"];
+ "$_main" [style="filled", fillcolor="white"];
+ "$___stdio_close" [style="filled", fillcolor="white"];
+ "$___stdio_write" [style="filled", fillcolor="white"];
+ "$___stdio_seek" [style="filled", fillcolor="white"];
+ "$___syscall_ret" [style="filled", fillcolor="white"];
+ "$___errno_location" [style="filled", fillcolor="white"];
+ "$_cleanup_387" [style="filled", fillcolor="white"];
+ "$___stdout_write" [style="filled", fillcolor="white"];
+ "$_fflush" [style="filled", fillcolor="white"];
+ "$___fflush_unlocked" [style="filled", fillcolor="white"];
+ "$__Znwj" [style="filled", fillcolor="white"];
+ "$__ZSt15get_new_handlerv" [style="filled", fillcolor="white"];
+ "$runPostSets" [style="filled", fillcolor="white"];
+ "$_memset" [style="filled", fillcolor="white"];
+ "$_memcpy" [style="filled", fillcolor="white"];
+ "$_pthread_self" [style="filled", fillcolor="white"];
+ "$dynCall_ii" [style="filled", fillcolor="white"];
+ "$dynCall_iiii" [style="filled", fillcolor="white"];
+ "$dynCall_vi" [style="filled", fillcolor="white"];
+ "$dynCall_v" [style="filled", fillcolor="white"];
+ "$b0" [style="filled", fillcolor="white"];
+ "$b1" [style="filled", fillcolor="white"];
+ "$b2" [style="filled", fillcolor="white"];
+ "$b3" [style="filled", fillcolor="white"];
+ "$abort" [style="filled", fillcolor="turquoise"];
+ "$_pthread_cleanup_pop" [style="filled", fillcolor="turquoise"];
+ "$___lock" [style="filled", fillcolor="turquoise"];
+ "$___syscall6" [style="filled", fillcolor="turquoise"];
+ "$_pthread_cleanup_push" [style="filled", fillcolor="turquoise"];
+ "$___syscall140" [style="filled", fillcolor="turquoise"];
+ "$_emscripten_memcpy_big" [style="filled", fillcolor="turquoise"];
+ "$___syscall54" [style="filled", fillcolor="turquoise"];
+ "$___unlock" [style="filled", fillcolor="turquoise"];
+ "$___syscall146" [style="filled", fillcolor="turquoise"];
+ "$_fflush" [style="filled", fillcolor="gray"];
+ "$_main" [style="filled", fillcolor="gray"];
+ "$_pthread_self" [style="filled", fillcolor="gray"];
+ "$_memset" [style="filled", fillcolor="gray"];
+ "$_malloc" [style="filled", fillcolor="gray"];
+ "$_memcpy" [style="filled", fillcolor="gray"];
+ "$_free" [style="filled", fillcolor="gray"];
+ "$___errno_location" [style="filled", fillcolor="gray"];
+ "$runPostSets" [style="filled", fillcolor="gray"];
+ "$stackAlloc" [style="filled", fillcolor="gray"];
+ "$stackSave" [style="filled", fillcolor="gray"];
+ "$stackRestore" [style="filled", fillcolor="gray"];
+ "$establishStackSpace" [style="filled", fillcolor="gray"];
+ "$setThrew" [style="filled", fillcolor="gray"];
+ "$setTempRet0" [style="filled", fillcolor="gray"];
+ "$getTempRet0" [style="filled", fillcolor="gray"];
+ "$dynCall_ii" [style="filled", fillcolor="gray"];
+ "$dynCall_iiii" [style="filled", fillcolor="gray"];
+ "$dynCall_vi" [style="filled", fillcolor="gray"];
+ "$dynCall_v" [style="filled", fillcolor="gray"];
"$_main" -> "$__Znwj"; // call
- "$___stdio_close";
"$___stdio_close" -> "$___syscall6"; // callImport
"$___stdio_close" -> "$___syscall_ret"; // call
- "$___stdio_write";
"$___stdio_write" -> "$_pthread_cleanup_push"; // callImport
"$___stdio_write" -> "$___syscall146"; // callImport
"$___stdio_write" -> "$___syscall_ret"; // call
"$___stdio_write" -> "$_pthread_cleanup_pop"; // callImport
- "$___stdio_seek";
"$___stdio_seek" -> "$___syscall140"; // callImport
"$___stdio_seek" -> "$___syscall_ret"; // call
- "$___syscall_ret";
"$___syscall_ret" -> "$___errno_location"; // call
- "$___errno_location";
"$___errno_location" -> "$_pthread_self"; // call
- "$_cleanup_387";
"$_cleanup_387" -> "$_free"; // call
- "$___stdout_write";
"$___stdout_write" -> "$___syscall54"; // callImport
"$___stdout_write" -> "$___stdio_write"; // call
- "$_fflush";
"$_fflush" -> "$___fflush_unlocked"; // call
"$_fflush" -> "$_malloc"; // call
"$_fflush" -> "$_free"; // call
"$_fflush" -> "$_fflush"; // call
"$_fflush" -> "$___lock"; // callImport
"$_fflush" -> "$___unlock"; // callImport
- "$___fflush_unlocked";
- "$___fflush_unlocked" -> "$b0" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$b2" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$b3" [style="dashed"]; // callIndirect
- "$__Znwj";
"$__Znwj" -> "$_malloc"; // call
"$__Znwj" -> "$__ZSt15get_new_handlerv"; // call
- "$__Znwj" -> "$b0" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$b1" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$b2" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$__ZSt15get_new_handlerv";
- "$runPostSets";
- "$_memset";
- "$_memcpy";
"$_memcpy" -> "$_emscripten_memcpy_big"; // callImport
- "$_pthread_self";
- "$dynCall_ii";
- "$dynCall_ii" -> "$b1" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$b2" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$b3" [style="dashed"]; // callIndirect
- "$dynCall_iiii";
- "$dynCall_iiii" -> "$b0" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$b2" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$b3" [style="dashed"]; // callIndirect
- "$dynCall_vi";
- "$dynCall_vi" -> "$b0" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$b1" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$b3" [style="dashed"]; // callIndirect
- "$dynCall_v";
- "$dynCall_v" -> "$b0" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$b1" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$b2" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$b0";
"$b0" -> "$abort"; // callImport
- "$b1";
"$b1" -> "$abort"; // callImport
- "$b2";
"$b2" -> "$abort"; // callImport
- "$b3";
"$b3" -> "$abort"; // callImport
+ "$b0" [style="filled, rounded"];
+ "$___stdio_close" [style="filled, rounded"];
+ "$b1" [style="filled, rounded"];
+ "$___stdout_write" [style="filled, rounded"];
+ "$___stdio_seek" [style="filled, rounded"];
+ "$___stdio_write" [style="filled, rounded"];
+ "$b2" [style="filled, rounded"];
+ "$_cleanup_387" [style="filled, rounded"];
+ "$b3" [style="filled, rounded"];
}
(module
(type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32)))