Skip to content

Commit dab0627

Browse files
committed
more cfg graphviz dump helpers
1 parent 5dfa26b commit dab0627

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/shady/analysis/looptree.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,10 @@ void dump_loop_trees(FILE* output, Module* mod) {
295295
destroy_list(scopes);
296296
fprintf(output, "}\n");
297297
}
298+
299+
300+
void dump_loop_trees_auto(Module* mod) {
301+
FILE* f = fopen("loop_trees.dot", "wb");
302+
dump_loop_trees(f, mod);
303+
fclose(f);
304+
}

src/shady/analysis/scope_dump.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,43 @@ void dump_cfg_auto(Module* mod) {
162162
dump_cfg(f, mod);
163163
fclose(f);
164164
}
165+
166+
static void dump_domtree_cfnode(Printer* p, CFNode* idom) {
167+
String name = get_abstraction_name_unsafe(idom->node);
168+
if (name)
169+
print(p, "bb_%zu [label=\"%s\", shape=box];\n", (size_t) idom, name);
170+
else
171+
print(p, "bb_%zu [label=\"%%%d\", shape=box];\n", (size_t) idom, idom->node->id);
172+
173+
for (size_t i = 0; i < entries_count_list(idom->dominates); i++) {
174+
CFNode* child = read_list(CFNode*, idom->dominates)[i];
175+
dump_domtree_cfnode(p, child);
176+
print(p, "bb_%zu -> bb_%zu;\n", (size_t) (idom), (size_t) (child));
177+
}
178+
}
179+
180+
void dump_domtree_scope(Printer* p, Scope* s) {
181+
print(p, "subgraph cluster_%s {\n", get_abstraction_name(s->entry->node));
182+
dump_domtree_cfnode(p, s->entry);
183+
print(p, "}\n");
184+
}
185+
186+
void dump_domtree_module(Printer* p, Module* mod) {
187+
print(p, "digraph G {\n");
188+
struct List* scopes = build_scopes(mod);
189+
for (size_t i = 0; i < entries_count_list(scopes); i++) {
190+
Scope* scope = read_list(Scope*, scopes)[i];
191+
dump_domtree_scope(p, scope);
192+
destroy_scope(scope);
193+
}
194+
destroy_list(scopes);
195+
print(p, "}\n");
196+
}
197+
198+
void dump_domtree_auto(Module* mod) {
199+
FILE* f = fopen("domtree.dot", "wb");
200+
Printer* p = open_file_as_printer(f);
201+
dump_domtree_module(p, mod);
202+
destroy_printer(p);
203+
fclose(f);
204+
}

0 commit comments

Comments
 (0)