diff mbox

[v1,10/18] idf: add test/debug/example

Message ID 20180320005256.53284-11-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck March 20, 2018, 12:52 a.m. UTC
This patch add a small silly function which dump the iterated
dominance frontier of each individual node in the CFG.

It's just there to show how to use the IDF API.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 dominate.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox

Patch

diff --git a/dominate.c b/dominate.c
index d7808119b..8085171d0 100644
--- a/dominate.c
+++ b/dominate.c
@@ -15,6 +15,7 @@ 
 #include "flow.h"
 #include <assert.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 
 struct piggy {
@@ -124,3 +125,29 @@  void idf_compute(struct entrypoint *ep, struct basic_block_list **idf, struct ba
 
 	bank_free(bank, levels);
 }
+
+void idf_dump(struct entrypoint *ep)
+{
+	struct basic_block *bb;
+
+	domtree_build(ep);
+
+	printf("%s's IDF:\n", show_ident(ep->name->ident));
+	FOR_EACH_PTR(ep->bbs, bb) {
+		struct basic_block_list *alpha = NULL;
+		struct basic_block_list *idf = NULL;
+		struct basic_block *df;
+
+		add_bb(&alpha, bb);
+		idf_compute(ep, &idf, alpha);
+
+		printf("\t%s\t<-", show_label(bb));
+		FOR_EACH_PTR(idf, df) {
+			printf(" %s", show_label(df));
+		} END_FOR_EACH_PTR(df);
+		printf("\n");
+
+		free_ptr_list(&idf);
+		free_ptr_list(&alpha);
+	} END_FOR_EACH_PTR(bb);
+}