shithub: mc

Download patch

ref: 10a3edcf0264c6e2b878a230f4a77f8954b67d0d
parent: ec1385e4eeb73318684695de73cb61f276deb887
parent: f635856c50c2a640c3765af746ee23a8d4282373
author: Ori Bernstein <[email protected]>
date: Wed Feb 6 12:25:08 EST 2013

Merge branch 'callee-save' of git+ssh://mimir.eigenstate.org/git/ori/mc into callee-save

--- a/6/asm.h
+++ b/6/asm.h
@@ -49,17 +49,22 @@
     Nmode,
 } Mode;
 
+/* a register, label, or memory location */
 struct Loc {
-    Loctype type;
-    Mode mode;
+    Loctype type; /* the type of loc */
+    Mode mode;    /* the mode of this location */
     union {
-        char *lbl;
-        struct {
+        char *lbl;  /* for Loclbl, Loclitl */
+        struct {    /* for Locreg */
             regid id;
             Reg   colour;
         } reg;
-        long  lit;
-        /* disp(base + index) */
+        long  lit;  /* for Loclit */
+        /*
+         * for Locmem, Locmeml.
+         * address format is
+         *    disp(base + index)
+         */
         struct {
             /* only one of lbldisp and constdisp may be used */
             char *lbldisp;
@@ -78,28 +83,28 @@
 };
 
 struct Func {
-    char *name;
-    int   isexport;
-    size_t stksz;
-    Type *type;
-    Htab *locs;
-    Node *ret;
-    Cfg  *cfg;
+    char *name;   /* function name */
+    int   isexport; /* is this exported from the asm? */
+    size_t stksz; /* stack size */
+    Type *type;   /* type of function */
+    Htab *stkoff; /* Loc* -> int stackoff map */
+    Node *ret;    /* return value */
+    Cfg  *cfg;    /* flow graph */
 };
 
 struct Asmbb {
-    int id;
-    char **lbls;
-    size_t nlbls;
-    Insn **il;
-    size_t ni;
+    int id;       /* unique identifier */
+    char **lbls;  /* list of BB labels */
+    size_t nlbls; /* number of labels */
+    Insn **il;    /* instructions */
+    size_t ni;    /* number of instructions */
 
-    Bitset *pred;
-    Bitset *succ;
-    Bitset *use;
-    Bitset *def;
-    Bitset *livein;
-    Bitset *liveout;
+    Bitset *pred; /* set of predecessor BB ids */
+    Bitset *succ; /* set of successor BB ids */
+    Bitset *use;  /* registers used by this BB */
+    Bitset *def;  /* registers defined by this BB */
+    Bitset *livein; /* variables live on entrance to BB */
+    Bitset *liveout;  /* variables live on exit from BB */
 };
 
 
@@ -112,10 +117,10 @@
     Asmbb *curbb;
 
     Node *ret;          /* we store the return into here */
-    Htab *locs;         /* decl id => int stkoff */
     Htab *spillslots;   /* reg id  => int stkoff */
     Htab *reglocs;      /* decl id => Loc *reg */
-    Htab *globls;       /* decl id => char *globlname */
+    Htab *stkoff;       /* decl id => int stkoff */
+    Htab *_globls;       /* decl id => char *globlname */
 
     /* increased when we spill */
     Loc *stksz;
--- a/6/isel.c
+++ b/6/isel.c
@@ -78,21 +78,21 @@
 
 static Loc *loc(Isel *s, Node *n)
 {
-    size_t stkoff;
+    ssize_t stkoff;
     Loc *l, *rip;
     Node *v;
 
     switch (exprop(n)) {
         case Ovar:
-            if (hthas(s->locs, n)) {
-                stkoff = (size_t)htget(s->locs, n);
+            if (hthas(s->stkoff, n)) {
+                stkoff = (ssize_t)htget(s->stkoff, n);
                 l = locmem(-stkoff, locphysreg(Rrbp), NULL, mode(n));
-            } else if (hthas(s->globls, n)) {
+            } else if (hthas(s->_globls, n)) {
                 if (tybase(exprtype(n))->type == Tyfunc)
                     rip = NULL;
                 else
                     rip = locphysreg(Rrip);
-                l = locmeml(htget(s->globls, n), rip, NULL, mode(n));
+                l = locmeml(htget(s->_globls, n), rip, NULL, mode(n));
             } else {
                 if (!hthas(s->reglocs, n))
                     htput(s->reglocs, n, locreg(mode(n)));
@@ -931,7 +931,7 @@
     char buf[128];
 
     is.reglocs = mkht(dclhash, dcleq);
-    is.locs = fn->locs;
+    is.stkoff = fn->stkoff;
     is.globls = globls;
     is.ret = fn->ret;
     is.cfg = fn->cfg;