aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/optimize.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-02-18 12:17:59 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-02-24 10:49:15 +0100
commit1cd676703c37472ee533aaa28090e19bbb83bec0 (patch)
treec5eee41a8df8ca87429009cd2f384fb8a2cd7607 /optimize.c
parente22588735b2ed54a08d1b3fb593cc3a26afb320b (diff)
downloadsparse-dev-1cd676703c37472ee533aaa28090e19bbb83bec0.tar.gz
move inner optimization loop into optimize.c
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@gmail.com>
Diffstat (limited to 'optimize.c')
-rw-r--r--optimize.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/optimize.c b/optimize.c
index 317d7d4d..76cb0afc 100644
--- a/optimize.c
+++ b/optimize.c
@@ -5,11 +5,14 @@
// Copyright (C) 2004 Linus Torvalds
// Copyright (C) 2004 Christopher Li
+#include <assert.h>
#include "optimize.h"
#include "linearize.h"
#include "liveness.h"
#include "flow.h"
+#include "cse.h"
+int repeat_phase;
static void clear_symbol_pseudos(struct entrypoint *ep)
{
@@ -20,6 +23,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)