From 4c8d48ca5202c680b97fcf442c2f356371c9eafd Mon Sep 17 00:00:00 2001
From: "thomas.dilasser" <thomas.dilasser@ensiie.fr>
Date: Tue, 23 Oct 2018 00:19:43 +0200
Subject: [PATCH] basic pdf

---
 functions/frontier.c | 64 ++++++--------------------------------------
 functions/frontier.h |  1 -
 2 files changed, 8 insertions(+), 57 deletions(-)

diff --git a/functions/frontier.c b/functions/frontier.c
index c2b0318..bbdd464 100644
--- a/functions/frontier.c
+++ b/functions/frontier.c
@@ -6,6 +6,7 @@ void bitmap_pdf(function * fun)
 	printf("\n---PDF---\n");
 	printf("---------\n");
 
+        calculate_dominance_info(CDI_POST_DOMINATORS);
 	bitmap_head *pfrontiers;
 	basic_block bb;
 	pfrontiers = XNEWVEC (bitmap_head, last_basic_block_for_fn (fun));
@@ -15,46 +16,16 @@ void bitmap_pdf(function * fun)
 		bitmap_initialize (&pfrontiers[bb->index], &bitmap_default_obstack);
 	}
 
-	td5_q1_bitmap_post_dominance_frontiers (pfrontiers, fun);	
+	bitmap_post_dominance_frontiers (pfrontiers, fun);	
 
-	//FOR_ALL_BB_FN (bb, cfun)
-	//{
-	//	printf( "PDF Node %d: ", bb->index ) ;
-	//	bitmap_print( stdout, &pfrontiers[bb->index], "", "\n" ) ;
-	//}
-}	
-void bitmap_post_dominance_frontiers (bitmap_head *frontiers, function * fun)
-{
-	edge p;
-	edge_iterator ei;
-	basic_block b;
-
-	FOR_EACH_BB_FN (b, fun)
+	FOR_ALL_BB_FN (bb, cfun)
 	{
-
-		if (EDGE_COUNT (b->succs) >= 2)
-		{
-			FOR_EACH_EDGE (p, ei, b->succs)
-			{
-				basic_block runner = p->dest;
-				basic_block pdomsb; 
-
-				if (runner == EXIT_BLOCK_PTR_FOR_FN (fun))
-					continue;
-
-				pdomsb = get_immediate_dominator (CDI_POST_DOMINATORS, b);
-				while (runner != pdomsb)
-				{
-					if (!bitmap_set_bit (&frontiers[runner->index], b->index))
-						break;
-					runner = get_immediate_dominator (CDI_POST_DOMINATORS, runner);
-				}
-			}
-		}
+		printf( "PDF Node %d: ", bb->index ) ;
+		bitmap_print( stdout, &pfrontiers[bb->index], "", "\n" ) ;
 	}
-}
-void                                                                      
-td5_q1_bitmap_post_dominance_frontiers (bitmap_head *frontiers, function * fun)
+        free_dominance_info(fun, CDI_POST_DOMINATORS);
+}	
+void bitmap_post_dominance_frontiers (bitmap_head *frontiers, function * fun)
 {
 	edge p;
 	edge_iterator ei;
@@ -64,40 +35,21 @@ td5_q1_bitmap_post_dominance_frontiers (bitmap_head *frontiers, function * fun)
 	{
 
 		if (EDGE_COUNT (b->succs) >= 2)
-//		if (EDGE_COUNT (b->preds) >= 2)
 		{
 			FOR_EACH_EDGE (p, ei, b->succs)
-//			FOR_EACH_EDGE (p, ei, b->preds)
 			{
 				basic_block runner = p->dest;
-//				basic_block runner = p->src;
 				basic_block pdomsb; 
 
 				if (runner == EXIT_BLOCK_PTR_FOR_FN (fun))
-//				if (runner == ENTRY_BLOCK_PTR_FOR_FN (fun))
 					continue;
 
 				pdomsb = get_immediate_dominator (CDI_POST_DOMINATORS, b);
-//				pdomsb = get_immediate_dominator (CDI_DOMINATORS, b);
 				while (runner != pdomsb)
 				{
 					if (!bitmap_set_bit (&frontiers[runner->index], b->index))
 						break;
-/*
-					if (1 == bitmap_bit_p(&frontiers[runner->index], b->index))
-					{
-						break;
-					}	
-					else
-					{
-						bitmap_set_bit (&frontiers[runner->index], b->index);	
-						cpt++;
-						printf("%d\n", cpt);
-	
-					}
-*/
 					runner = get_immediate_dominator (CDI_POST_DOMINATORS, runner);
-//					runner = get_immediate_dominator (CDI_DOMINATORS, runner);
 				}
 			}
 		}
diff --git a/functions/frontier.h b/functions/frontier.h
index f3e73bf..b3847c3 100644
--- a/functions/frontier.h
+++ b/functions/frontier.h
@@ -2,5 +2,4 @@
 #define __PDFDD__H
 void bitmap_pdf(function * fun);
 void bitmap_post_dominance_frontiers (bitmap_head *frontiers, function * fun);
-void td5_q1_bitmap_post_dominance_frontiers (bitmap_head *frontiers, function * fun);
 #endif
-- 
GitLab