[PATCH 5/6] move inner optimization loop into optimize.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The code for the inner optimization loop was in the same file
than the one for CSE. Now that the CSE have a well defined
interface, we can move this inner loop together with
the main optimization loop in optimize.c

This move make the code better structured and make it easier
to understand the optimization logic and make any experiment
or needed changes to it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 cse.c      | 41 +++--------------------------------------
 cse.h      | 11 +++++++++++
 flow.h     |  1 -
 optimize.c | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 51 insertions(+), 39 deletions(-)
 create mode 100644 cse.h

diff --git a/cse.c b/cse.c
index 6469359f1..4a2675e75 100644
--- a/cse.c
+++ b/cse.c
@@ -16,12 +16,11 @@
 #include "expression.h"
 #include "linearize.h"
 #include "flow.h"
+#include "cse.h"
 
 #define INSN_HASH_SIZE 256
 static struct instruction_list *insn_hash_table[INSN_HASH_SIZE];
 
-int repeat_phase;
-
 static int phi_compare(pseudo_t phi1, pseudo_t phi2)
 {
 	const struct instruction *def1 = phi1->def;
@@ -35,7 +34,7 @@ static int phi_compare(pseudo_t phi1, pseudo_t phi2)
 }
 
 
-static void cse_collect(struct instruction *insn)
+void cse_collect(struct instruction *insn)
 {
 	unsigned long hash;
 
@@ -131,22 +130,6 @@ static void cse_collect(struct instruction *insn)
 	add_instruction(insn_hash_table + hash, insn);
 }
 
-static void clean_up_insns(struct entrypoint *ep)
-{
-	struct basic_block *bb;
-
-	FOR_EACH_PTR(ep->bbs, bb) {
-		struct instruction *insn;
-		FOR_EACH_PTR(bb->insns, insn) {
-			repeat_phase |= simplify_instruction(insn);
-			if (!insn->bb)
-				continue;
-			assert(insn->bb == bb);
-			cse_collect(insn);
-		} END_FOR_EACH_PTR(insn);
-	} END_FOR_EACH_PTR(bb);
-}
-
 /* Compare two (sorted) phi-lists */
 static int phi_list_compare(struct pseudo_list *l1, struct pseudo_list *l2)
 {
@@ -381,7 +364,7 @@ static struct instruction * try_to_cse(struct entrypoint *ep, struct instruction
 	return i1;
 }
 
-static void cse_eliminate(struct entrypoint *ep)
+void cse_eliminate(struct entrypoint *ep)
 {
 	int i;
 
@@ -408,21 +391,3 @@ static void cse_eliminate(struct entrypoint *ep)
 		}
 	}
 }
-
-void cleanup_and_cse(struct entrypoint *ep)
-{
-	simplify_memops(ep);
-repeat:
-	repeat_phase = 0;
-	clean_up_insns(ep);
-	if (repeat_phase & REPEAT_CFG_CLEANUP)
-		kill_unreachable_bbs(ep);
-
-	cse_eliminate(ep);
-
-	if (repeat_phase & REPEAT_SYMBOL_CLEANUP)
-		simplify_memops(ep);
-
-	if (repeat_phase & REPEAT_CSE)
-		goto repeat;
-}
diff --git a/cse.h b/cse.h
new file mode 100644
index 000000000..29c97ea9d
--- /dev/null
+++ b/cse.h
@@ -0,0 +1,11 @@
+#ifndef CSE_H
+#define CSE_H
+
+struct instruction;
+struct entrypoint;
+
+/* cse.c */
+void cse_collect(struct instruction *insn);
+void cse_eliminate(struct entrypoint *ep);
+
+#endif
diff --git a/flow.h b/flow.h
index 8e96f62fb..611aed7af 100644
--- a/flow.h
+++ b/flow.h
@@ -19,7 +19,6 @@ extern void simplify_memops(struct entrypoint *ep);
 extern void pack_basic_blocks(struct entrypoint *ep);
 
 extern void convert_instruction_target(struct instruction *insn, pseudo_t src);
-extern void cleanup_and_cse(struct entrypoint *ep);
 extern int simplify_instruction(struct instruction *);
 
 extern void kill_bb(struct basic_block *);
diff --git a/optimize.c b/optimize.c
index 8cf243517..6435d0c87 100644
--- a/optimize.c
+++ b/optimize.c
@@ -8,7 +8,9 @@
 #include "optimize.h"
 #include "linearize.h"
 #include "flow.h"
+#include "cse.h"
 
+int repeat_phase;
 
 static void clear_symbol_pseudos(struct entrypoint *ep)
 {
@@ -19,6 +21,41 @@ static void clear_symbol_pseudos(struct entrypoint *ep)
 	} END_FOR_EACH_PTR(pseudo);
 }
 
+
+static void clean_up_insns(struct entrypoint *ep)
+{
+	struct basic_block *bb;
+
+	FOR_EACH_PTR(ep->bbs, bb) {
+		struct instruction *insn;
+		FOR_EACH_PTR(bb->insns, insn) {
+			repeat_phase |= simplify_instruction(insn);
+			if (!insn->bb)
+				continue;
+			assert(insn->bb == bb);
+			cse_collect(insn);
+		} END_FOR_EACH_PTR(insn);
+	} END_FOR_EACH_PTR(bb);
+}
+
+static void cleanup_and_cse(struct entrypoint *ep)
+{
+	simplify_memops(ep);
+repeat:
+	repeat_phase = 0;
+	clean_up_insns(ep);
+	if (repeat_phase & REPEAT_CFG_CLEANUP)
+		kill_unreachable_bbs(ep);
+
+	cse_eliminate(ep);
+
+	if (repeat_phase & REPEAT_SYMBOL_CLEANUP)
+		simplify_memops(ep);
+
+	if (repeat_phase & REPEAT_CSE)
+		goto repeat;
+}
+
 void optimize(struct entrypoint *ep)
 {
 	if (fdump_ir & PASS_LINEARIZE)
-- 
2.16.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux