[hackers] [scc] [cc2] Add general tree optimizations for jumps and labels || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 27 Apr 2016 20:46:34 +0200 (CEST)

commit 9be8dcd2584b09ed00978daadb5ec6b597349b0d
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Tue Apr 26 19:59:28 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Tue Apr 26 20:02:09 2016 +0200

    [cc2] Add general tree optimizations for jumps and labels
    
    These commit adds:
            - Remove consecutive labels
            - Jump to jump
            - Jump to next instruction

diff --git a/cc2/optm.c b/cc2/optm.c
index 12cecb1..1690bb2 100644
--- a/cc2/optm.c
+++ b/cc2/optm.c
_AT_@ -1,18 +1,44 @@
 
+#include <stddef.h>
+
 #include "arch.h"
 #include "cc2.h"
 
 Node *
 optm(Node *np)
 {
- Node *dst;
+ Node *p, *dst, *next = np->next;
+ Symbol *sym, *osym;
 
         switch (np->op) {
+ case ONOP:
+ if (next && next->op == ONOP) {
+ sym = np->u.sym;
+ osym = next->u.sym;
+ osym->id = sym->id;
+ osym->numid = sym->id;
+ osym->u.stmt = sym->u.stmt;
+ return NULL;
+ }
+ break;
         case OJMP:
         case OBRANCH:
- dst = np->u.sym->u.stmt;
- if (dst->op == OJMP)
+ for (;;) {
+ dst = np->u.sym->u.stmt;
+ if (dst->op != OJMP)
+ break;
                         np->u.sym = dst->u.sym;
+ }
+ for (p = np->next; p; p = p->next) {
+ if (p == dst)
+ return NULL;
+ if (p->op == ONOP ||
+ p->op == OBLOOP ||
+ p->op == OELOOP) {
+ continue;
+ }
+ break;
+ }
                 break;
         }
         return np;
Received on Wed Apr 27 2016 - 20:46:34 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 27 2016 - 20:48:31 CEST