shithub: mc

Download patch

ref: 4c863884833102c4d44d8d52104fd11e48200a55
parent: 7c0b1067c6f67044cc25d5d4d4e5f1c4e7e98968
parent: 8dba607d3b91df8ea8a70e67d589bbb40222a2ab
author: Ori Bernstein <[email protected]>
date: Mon Jul 9 09:08:54 EDT 2012

Merge branch 'master' of git+ssh://mimir.eigenstate.org/git/ori/mc2

--- a/8/ra.c
+++ b/8/ra.c
@@ -69,9 +69,9 @@
 static int isfixreg(Loc *l)
 {
     if (l->reg.colour == Resp)
-	return 1;
+        return 1;
     if (l->reg.colour == Rebp)
-	return 1;
+        return 1;
     return 0;
 }
 
@@ -86,33 +86,33 @@
      * in this list are fine, since they're being added to
      * a set anyways */
     for (i = 0; i < Maxarg; i++) {
-	if (!usetab[insn->op].l[i])
-	    break;
-	k = usetab[insn->op].l[i] - 1;
-	/* non-registers are handled later */
-	if (insn->args[k]->type == Locreg)
-	    if (!isfixreg(insn->args[k]))
-		u[j++] = insn->args[k]->reg.id;
+        if (!usetab[insn->op].l[i])
+            break;
+        k = usetab[insn->op].l[i] - 1;
+        /* non-registers are handled later */
+        if (insn->args[k]->type == Locreg)
+            if (!isfixreg(insn->args[k]))
+                u[j++] = insn->args[k]->reg.id;
     }
     /* some insns don't reflect their defs in the args.
      * These are explictly listed in the insn description */
     for (i = 0; i < Maxarg; i++) {
-	if (!usetab[insn->op].r[i])
-	    break;
-	/* not a leak; physical registers get memoized */
-	u[j++] = locphysreg(usetab[insn->op].r[i])->reg.id;
+        if (!usetab[insn->op].r[i])
+            break;
+        /* not a leak; physical registers get memoized */
+        u[j++] = locphysreg(usetab[insn->op].r[i])->reg.id;
     }
     /* If the registers are in an address calculation,
      * they're used no matter what. */
     for (i = 0; i < insn->nargs; i++) {
-	m = insn->args[i];
-	if (m->type != Locmem && m->type != Locmeml)
-	    continue;
-	if (!isfixreg(m->mem.base))
-	    u[j++] = m->mem.base->reg.id;
-	if (m->mem.idx)
-	    if (!isfixreg(m->mem.base))
-		u[j++] = m->mem.idx->reg.id;
+        m = insn->args[i];
+        if (m->type != Locmem && m->type != Locmeml)
+            continue;
+        if (!isfixreg(m->mem.base))
+            u[j++] = m->mem.base->reg.id;
+        if (m->mem.idx)
+            if (!isfixreg(m->mem.base))
+                u[j++] = m->mem.idx->reg.id;
     }
     return j;
 }
@@ -127,20 +127,20 @@
      * in this list are fine, since they're being added to
      * a set anyways */
     for (i = 0; i < Maxarg; i++) {
-	if (!deftab[insn->op].l[i])
-	    break;
-	k = deftab[insn->op].l[i] - 1;
-	if (insn->args[k]->type == Locreg)
-	    if (!isfixreg(insn->args[k]))
-		d[j++] = insn->args[k]->reg.id;
+        if (!deftab[insn->op].l[i])
+            break;
+        k = deftab[insn->op].l[i] - 1;
+        if (insn->args[k]->type == Locreg)
+            if (!isfixreg(insn->args[k]))
+                d[j++] = insn->args[k]->reg.id;
     }
     /* some insns don't reflect their defs in the args.
      * These are explictly listed in the insn description */
     for (i = 0; i < Maxarg; i++) {
-	if (!deftab[insn->op].r[i])
-	    break;
-	/* not a leak; physical registers get memoized */
-	d[j++] = locphysreg(deftab[insn->op].r[i])->reg.id;
+        if (!deftab[insn->op].r[i])
+            break;
+        /* not a leak; physical registers get memoized */
+        d[j++] = locphysreg(deftab[insn->op].r[i])->reg.id;
     }
     return j;
 }
@@ -157,13 +157,13 @@
     bb->use = bsclear(bb->use);
     bb->def = bsclear(bb->def);
     for (i = 0; i < bb->ni; i++) {
-	nu = uses(bb->il[i], u);
-	nd = defs(bb->il[i], d);
-	for (j = 0; j < nu; j++)
-	    if (!bshas(bb->def, u[j]))
-		bsput(bb->use, u[j]);
-	for (j = 0; j < nd; j++)
-	    bsput(bb->def, d[j]);
+        nu = uses(bb->il[i], u);
+        nd = defs(bb->il[i], d);
+        for (j = 0; j < nu; j++)
+            if (!bshas(bb->def, u[j]))
+                bsput(bb->use, u[j]);
+        for (j = 0; j < nd; j++)
+            bsput(bb->def, d[j]);
     }
 }
 
@@ -178,27 +178,27 @@
     bb = s->bb;
     nbb = s->nbb;
     for (i = 0; i < nbb; i++) {
-	udcalc(s->bb[i]);
-	bb[i]->livein = bsclear(bb[i]->livein);
-	bb[i]->liveout = bsclear(bb[i]->liveout);
+        udcalc(s->bb[i]);
+        bb[i]->livein = bsclear(bb[i]->livein);
+        bb[i]->liveout = bsclear(bb[i]->liveout);
     }
 
     changed = 1;
     while (changed) {
-	changed = 0;
-	for (i = 0; i < nbb; i++) {
-	    old = bsdup(bb[i]->liveout);
-	    /* liveout[b] = U(s in succ) livein[s] */
-	    for (j = 0; bsiter(bb[i]->succ, &j); j++)
-		bsunion(bb[i]->liveout, bb[j]->livein);
-	    /* livein[b] = use[b] U (out[b] \ def[b]) */
-	    bb[i]->livein = bsclear(bb[i]->livein);
-	    bsunion(bb[i]->livein, bb[i]->liveout);
-	    bsdiff(bb[i]->livein, bb[i]->def);
-	    bsunion(bb[i]->livein, bb[i]->use);
-	    if (!changed)
-		changed = !bseq(old, bb[i]->liveout);
-	}
+        changed = 0;
+        for (i = 0; i < nbb; i++) {
+            old = bsdup(bb[i]->liveout);
+            /* liveout[b] = U(s in succ) livein[s] */
+            for (j = 0; bsiter(bb[i]->succ, &j); j++)
+                bsunion(bb[i]->liveout, bb[j]->livein);
+            /* livein[b] = use[b] U (out[b] \ def[b]) */
+            bb[i]->livein = bsclear(bb[i]->livein);
+            bsunion(bb[i]->livein, bb[i]->liveout);
+            bsdiff(bb[i]->livein, bb[i]->def);
+            bsunion(bb[i]->livein, bb[i]->use);
+            if (!changed)
+                changed = !bseq(old, bb[i]->liveout);
+        }
     }
 }
 
@@ -206,7 +206,7 @@
 static int ismove(Insn *i)
 {
     if (i->op != Imov)
-	return 0;
+        return 0;
     return i->args[0]->type == Locreg && i->args[1]->type == Locreg;
 }
 
@@ -231,16 +231,16 @@
 static void addedge(Isel *s, size_t u, size_t v)
 {
     if (u == v || gbhasedge(s, u, v))
-	return;
+        return;
     gbputedge(s, u, v);
     gbputedge(s, v, u);
     if (!bshas(s->prepainted, u)) {
-	bsput(s->gadj[u], v);
-	s->degree[u]++;
+        bsput(s->gadj[u], v);
+        s->degree[u]++;
     }
     if (!bshas(s->prepainted, v)) {
-	bsput(s->gadj[v], u);
-	s->degree[v]++;
+        bsput(s->gadj[v], u);
+        s->degree[v]++;
     }
 }
 
@@ -256,11 +256,11 @@
     /* fresh adj list repr. try to avoid reallocating all the bitsets */
     gadj = zalloc(maxregid * sizeof(Bitset*));
     if (s->gadj)
-	for (i = 0; i < maxregid; i++)
-	    gadj[i] = bsclear(s->gadj[i]);
+        for (i = 0; i < maxregid; i++)
+            gadj[i] = bsclear(s->gadj[i]);
     else
-	for (i = 0; i < maxregid; i++)
-	    gadj[i] = mkbs();
+        for (i = 0; i < maxregid; i++)
+            gadj[i] = mkbs();
     free(s->gadj);
     s->gadj = gadj;
 
@@ -295,38 +295,38 @@
     nbb = s->nbb;
 
     for (i = 0; i < nbb; i++) {
-	live = bsdup(bb[i]->liveout);
-	for (j = bb[i]->ni - 1; j >= 0; j--) {
-	    insn = bb[i]->il[j];
-	    nu = uses(insn, u);
-	    nd = defs(insn, d);
+        live = bsdup(bb[i]->liveout);
+        for (j = bb[i]->ni - 1; j >= 0; j--) {
+            insn = bb[i]->il[j];
+            nu = uses(insn, u);
+            nd = defs(insn, d);
 
-	    /* moves get special treatment, since we don't want spurious
-	     * edges between the src and dest */
-	    if (ismove(insn)) {
-		/* live \= uses(i) */
-		for (k = 0; k < nu; k++)
-		    bsdel(live, u[k]);
+            /* moves get special treatment, since we don't want spurious
+             * edges between the src and dest */
+            if (ismove(insn)) {
+                /* live \= uses(i) */
+                for (k = 0; k < nu; k++)
+                    bsdel(live, u[k]);
 
-		for (k = 0; k < nu; k++)
-		    lappend(&s->rmoves[u[k]], &s->nrmoves[u[k]], insn);
-		for (k = 0; k < nd; k++)
-		    lappend(&s->rmoves[d[k]], &s->nrmoves[d[k]], insn);
-		lappend(&s->wlmove, &s->nwlmove, insn);
-	    }
-	    /* live = live U def(i) */
-	    for (k = 0; k < nd; k++)
-		bsput(live, d[k]);
+                for (k = 0; k < nu; k++)
+                    lappend(&s->rmoves[u[k]], &s->nrmoves[u[k]], insn);
+                for (k = 0; k < nd; k++)
+                    lappend(&s->rmoves[d[k]], &s->nrmoves[d[k]], insn);
+                lappend(&s->wlmove, &s->nwlmove, insn);
+            }
+            /* live = live U def(i) */
+            for (k = 0; k < nd; k++)
+                bsput(live, d[k]);
 
-	    for (k = 0; k < nd; k++)
-		for (l = 0; bsiter(live, &l); l++)
-		    addedge(s, d[k], l);
-	    /* live = use(i) U (live \ def(i)) */
-	    for (k = 0; k < nd; k++)
-		bsdel(live, d[k]);
-	    for (k = 0; k < nu; k++)
-		bsput(live, u[k]);
-	}
+            for (k = 0; k < nd; k++)
+                for (l = 0; bsiter(live, &l); l++)
+                    addedge(s, d[k], l);
+            /* live = use(i) U (live \ def(i)) */
+            for (k = 0; k < nd; k++)
+                bsdel(live, d[k]);
+            for (k = 0; k < nu; k++)
+                bsput(live, u[k]);
+        }
     }
 }
 
@@ -357,22 +357,22 @@
     /* FIXME: inefficient. Do I care? */
     count = 0;
     if (pil)
-	*pil = NULL;
+        *pil = NULL;
     for (i = 0; i < s->nrmoves[n]; i++) {
-	for (j = 0; j < s->nmactive; j++) {
-	    if (s->mactive[j] == s->rmoves[n][i]) {
-		if (pil)
-		    lappend(pil, &count, s->rmoves[n][i]);
-		continue;
-	    }
-	}
-	for (j = 0; j < s->nwlmove; j++) {
-	    if (s->wlmove[j] == s->rmoves[n][i]) {
-		if (pil)
-		    lappend(pil, &count, s->rmoves[n][i]);
-		continue;
-	    }
-	}
+        for (j = 0; j < s->nmactive; j++) {
+            if (s->mactive[j] == s->rmoves[n][i]) {
+                if (pil)
+                    lappend(pil, &count, s->rmoves[n][i]);
+                continue;
+            }
+        }
+        for (j = 0; j < s->nwlmove; j++) {
+            if (s->wlmove[j] == s->rmoves[n][i]) {
+                if (pil)
+                    lappend(pil, &count, s->rmoves[n][i]);
+                continue;
+            }
+        }
     }
     return count;
 }
@@ -387,14 +387,14 @@
     size_t i;
 
     for (i = 0; i < maxregid; i++) {
-	if (bshas(s->prepainted, i))
-	    continue;
-	else if (s->degree[i] >= K)
-	    lappend(&s->wlspill, &s->nwlspill, locmap[i]);
-	else if (moverelated(s, i))
-	    lappend(&s->wlfreeze, &s->nwlfreeze, locmap[i]);
-	else
-	    lappend(&s->wlsimp, &s->nwlsimp, locmap[i]);
+        if (bshas(s->prepainted, i))
+            continue;
+        else if (s->degree[i] >= K)
+            lappend(&s->wlspill, &s->nwlspill, locmap[i]);
+        else if (moverelated(s, i))
+            lappend(&s->wlfreeze, &s->nwlfreeze, locmap[i]);
+        else
+            lappend(&s->wlsimp, &s->nwlsimp, locmap[i]);
     }
 }
 
@@ -406,12 +406,12 @@
 
     ni = nodemoves(s, n, &il);
     for (i = 0; i < ni; i++) {
-	for (j = 0; j < s->nmactive; j++) {
-	    if (il[i] == s->mactive[j]) {
-		ldel(&s->mactive, &s->nmactive, j);
-		lappend(&s->wlmove, &s->nwlmove, il[i]);
-	    }
-	}
+        for (j = 0; j < s->nmactive; j++) {
+            if (il[i] == s->mactive[j]) {
+                ldel(&s->mactive, &s->nmactive, j);
+                lappend(&s->wlmove, &s->nwlmove, il[i]);
+            }
+        }
     }
 }
 
@@ -425,9 +425,9 @@
     s->degree[n]--;
 
     if (d == K) {
-	enablemove(s, n);
-	for (m = 0; adjiter(s, n, &m); m++)
-	    enablemove(s, n);
+        enablemove(s, n);
+        for (m = 0; adjiter(s, n, &m); m++)
+            enablemove(s, n);
     }
 }
 
@@ -439,15 +439,15 @@
     l = lpop(&s->wlsimp, &s->nwlsimp);
     lappend(&s->selstk, &s->nselstk, l);
     for (m = 0; adjiter(s, l->reg.id, &m); m++)
-	decdegree(s, m);
+        decdegree(s, m);
 }
 
 static regid getalias(Isel *s, regid id)
 {
     while (1) {
-	if (!s->aliasmap[id])
-	    break;
-	id = s->aliasmap[id]->reg.id;
+        if (!s->aliasmap[id])
+            break;
+        id = s->aliasmap[id]->reg.id;
     };
     return id;
 }
@@ -457,14 +457,14 @@
     size_t i;
 
     if (bshas(s->prepainted, u))
-	return;
+        return;
     if (moverelated(s, u))
-	return;
+        return;
     if (s->degree[u] >= K)
-	return;
+        return;
     for (i = 0; i < s->nwlfreeze; i++)
-	if (s->wlfreeze[i]->reg.id == u)
-	    ldel(&s->wlfreeze, &s->nwlfreeze, i);
+        if (s->wlfreeze[i]->reg.id == u)
+            ldel(&s->wlfreeze, &s->nwlfreeze, i);
     lappend(&s->wlsimp, &s->nwlsimp, locmap[u]);
 }
 
@@ -476,11 +476,11 @@
 
     k = 0;
     for (i = 0; adjiter(s, u, &n); i++)
-	if (s->degree[n] >= K)
-	    k++;
+        if (s->degree[n] >= K)
+            k++;
     for (i = 0; adjiter(s, v, &n); i++)
-	if (s->degree[n] >= K)
-	    k++;
+        if (s->degree[n] >= K)
+            k++;
     return k < K;
 }
 
@@ -488,11 +488,11 @@
 static int ok(Isel *s, regid t, regid r)
 {
     if (s->degree[t] >= K)
-	return 0;
+        return 0;
     if (!bshas(s->prepainted, t))
-	return 0;
+        return 0;
     if (!gbhasedge(s, t, r))
-	return 0;
+        return 0;
     return 1;
 }
 
@@ -502,12 +502,12 @@
 
     /* if u isn't prepainted, can we conservatively coalesce? */
     if (!bshas(s->prepainted, u) && conservative(s, u, v))
-	return 1;
+        return 1;
 
     /* if it is, are the adjacent nodes ok to combine with this? */
     for (t = 0; adjiter(s, u, &t); t++)
-	if (!ok(s, t, u))
-	    return 0;
+        if (!ok(s, t, u))
+            return 0;
     return 1;
 }
 
@@ -516,10 +516,10 @@
     size_t i;
 
     for (i = 0; i < nwl; i++) {
-	if (wl[i]->reg.id == v) { 
-	    *idx = i;
-	    return 1;
-	}
+        if (wl[i]->reg.id == v) { 
+            *idx = i;
+            return 1;
+        }
     }
     return 0;
 }
@@ -526,7 +526,6 @@
 
 static void combine(Isel *s, regid u, regid v)
 {
-    Bitset *adj;
     regid t;
     size_t idx;
     size_t i, j;
@@ -533,42 +532,39 @@
     int has;
 
     if (debugopt['r']) {
-	printf("Combine ");
-	locprint(stdout, locmap[u]);
-	printf(" ==> ");
-	locprint(stdout, locmap[v]);
-	printf("\n");
+        printf("Combine ");
+        locprint(stdout, locmap[u]);
+        printf(" ==> ");
+        locprint(stdout, locmap[v]);
+        printf("\n");
     }
     if (wlhas(s->wlfreeze, s->nwlfreeze, v, &idx))
-	ldel(&s->wlfreeze, &s->nwlfreeze, idx);
+        ldel(&s->wlfreeze, &s->nwlfreeze, idx);
     else if (wlhas(s->wlspill, s->nwlspill, v, &idx))
-	ldel(&s->wlspill, &s->nwlspill, idx);
+        ldel(&s->wlspill, &s->nwlspill, idx);
     bsput(s->coalesced, v);
     s->aliasmap[v] = locmap[u];
 
     /* nodemoves[u] = nodemoves[u] U nodemoves[v] */
     for (i = 0; i < s->nrmoves[v]; i++) {
-	has = 0;
-	for (j = 0; j < s->nrmoves[u]; j++) {
-	    if (s->rmoves[v][i] == s->rmoves[u][j]) {
-		has = 1;
-		break;
-	    }
-	}
-	if (!has)
-	    lappend(&s->rmoves[u], &s->nrmoves[u], s->rmoves[v][i]);
+        has = 0;
+        for (j = 0; j < s->nrmoves[u]; j++) {
+            if (s->rmoves[v][i] == s->rmoves[u][j]) {
+                has = 1;
+                break;
+            }
+        }
+        if (!has)
+            lappend(&s->rmoves[u], &s->nrmoves[u], s->rmoves[v][i]);
     }
-    
-    size_t x;
+
     for (t = 0; adjiter(s, v, &t); t++) {
-        bsiter(adj, &x);
-        assert(t == x);
-	gbputedge(s, t, u);
-	decdegree(s, t);
+        gbputedge(s, t, u);
+        decdegree(s, t);
     }
     if (s->degree[u] >= K && wlhas(s->wlfreeze, s->nwlfreeze, u, &idx)) {
-	ldel(&s->wlfreeze, &s->nwlfreeze, idx);
-	lappend(&s->wlspill, &s->nwlspill, locmap[u]);
+        ldel(&s->wlfreeze, &s->nwlfreeze, idx);
+        lappend(&s->wlspill, &s->nwlspill, locmap[u]);
     }
 }
 
@@ -583,25 +579,25 @@
     v = getalias(s, m->args[1]->reg.id);
 
     if (bshas(s->prepainted, v)) {
-	tmp = u;
-	u = v;
-	v = tmp;
+        tmp = u;
+        u = v;
+        v = tmp;
     }
 
     if (u == v) {
-	lappend(&s->mcoalesced, &s->nmcoalesced, m);
-	wladd(s, u);
-	wladd(s, v);
+        lappend(&s->mcoalesced, &s->nmcoalesced, m);
+        wladd(s, u);
+        wladd(s, v);
     } else if (bshas(s->prepainted, v) || gbhasedge(s, u, v)) {
-	lappend(&s->mconstrained, &s->nmconstrained, m);
-	wladd(s, u);
-	wladd(s, v);
+        lappend(&s->mconstrained, &s->nmconstrained, m);
+        wladd(s, u);
+        wladd(s, v);
     } else if (combinable(s, u, v)) {
-	lappend(&s->mcoalesced, &s->nmcoalesced, m);
-	combine(s, u, v);
-	wladd(s, u);
+        lappend(&s->mcoalesced, &s->nmcoalesced, m);
+        combine(s, u, v);
+        wladd(s, u);
     } else {
-	lappend(&s->mactive, &s->nmactive, m);
+        lappend(&s->mactive, &s->nmactive, m);
     }
 }
 
@@ -609,10 +605,10 @@
 {
     size_t i;
     for (i = 0; i < *nml; i++) {
-	if (m == (*ml)[i]) {
-	    ldel(ml, nml, i);
-	    return 1;
-	}
+        if (m == (*ml)[i]) {
+            ldel(ml, nml, i);
+            return 1;
+        }
     }
     return 0;
 }
@@ -628,23 +624,23 @@
     
     nml = nodemoves(s, u->reg.id, &ml);
     for (i = 0; i < nml; i++) {
-	m = ml[i];
-	if (m->args[0] == u)
-	    v = m->args[1];
-	else if (m->args[1] == u)
-	    v = m->args[0];
-	else
-	    continue;
+        m = ml[i];
+        if (m->args[0] == u)
+            v = m->args[1];
+        else if (m->args[1] == u)
+            v = m->args[0];
+        else
+            continue;
 
-	if (!mldel(&s->mactive, &s->nmactive, m))
-	    mldel(&s->wlmove, &s->nwlmove, m);
-	lappend(&s->mfrozen, &s->nmfrozen, m);
-	if (!nodemoves(s, v->reg.id, NULL) && s->degree[v->reg.id] < K) {
-	    if (!wlhas(s->wlfreeze, s->nwlfreeze, v->reg.id, &idx))
-		die("Reg %zd not in freeze wl\n", v->reg.id);
-	    ldel(&s->wlfreeze, &s->nwlfreeze, idx);
-	    lappend(&s->wlsimp, &s->nwlsimp, v);
-	}
+        if (!mldel(&s->mactive, &s->nmactive, m))
+            mldel(&s->wlmove, &s->nwlmove, m);
+        lappend(&s->mfrozen, &s->nmfrozen, m);
+        if (!nodemoves(s, v->reg.id, NULL) && s->degree[v->reg.id] < K) {
+            if (!wlhas(s->wlfreeze, s->nwlfreeze, v->reg.id, &idx))
+                die("Reg %zd not in freeze wl\n", v->reg.id);
+            ldel(&s->wlfreeze, &s->nwlfreeze, idx);
+            lappend(&s->wlsimp, &s->nwlsimp, v);
+        }
 
     }
     lfree(&ml, &nml);
@@ -666,11 +662,11 @@
 
     /* FIXME: pick a better heuristic for spilling */
     for (i = 0; i < s->nwlspill; i++) {
-	if (!bshas(s->spilled, s->wlspill[i]->reg.id)) {
-	    m = s->wlspill[i];
-	    ldel(&s->wlspill, &s->nwlspill, i);
-	    break;
-	}
+        if (!bshas(s->spilled, s->wlspill[i]->reg.id)) {
+            m = s->wlspill[i];
+            ldel(&s->wlspill, &s->nwlspill, i);
+            break;
+        }
     }
     assert(m != NULL);
     lappend(&s->wlsimp, &s->nwlsimp, m);
@@ -688,35 +684,35 @@
 
     spilled = 0;
     while (s->nselstk) {
-	bzero(taken, K*sizeof(int));
-	n = lpop(&s->selstk, &s->nselstk);
+        bzero(taken, K*sizeof(int));
+        n = lpop(&s->selstk, &s->nselstk);
 
-	for (l = 0; adjiter(s, n->reg.id, &l); l++) {
-	    w = locmap[getalias(s, l)];
-	    if (w->reg.colour)
-		taken[colourmap[w->reg.colour]] = 1;
-	}
+        for (l = 0; adjiter(s, n->reg.id, &l); l++) {
+            w = locmap[getalias(s, l)];
+            if (w->reg.colour)
+                taken[colourmap[w->reg.colour]] = 1;
+        }
 
-	found = 0;
-	for (i = 0; i < K; i++) {
-	    if (!taken[i]) {
-		if (debugopt['r']) {
-		    locprint(stdout, n);
-		    printf(" ==> %s\n", regnames[regmap[i][n->mode]]);
-		}
-		n->reg.colour = regmap[i][n->mode];
-		found = 1;
-		break;
-	    }
-	}
-	if (!found) {
-	    spilled = 1;
-	    bsput(s->spilled, n->reg.id);
-	}
+        found = 0;
+        for (i = 0; i < K; i++) {
+            if (!taken[i]) {
+                if (debugopt['r']) {
+                    locprint(stdout, n);
+                    printf(" ==> %s\n", regnames[regmap[i][n->mode]]);
+                }
+                n->reg.colour = regmap[i][n->mode];
+                found = 1;
+                break;
+            }
+        }
+        if (!found) {
+            spilled = 1;
+            bsput(s->spilled, n->reg.id);
+        }
     }
     for (l = 0; bsiter(s->coalesced, &l); l++) {
-	n = locmap[getalias(s, l)];
-	locmap[l]->reg.colour = n->reg.colour;
+        n = locmap[getalias(s, l)];
+        locmap[l]->reg.colour = n->reg.colour;
     }
     return spilled;
 }
@@ -733,28 +729,28 @@
 
     s->prepainted = mkbs();
     for (i = 0; i < maxregid; i++)
-	if (locmap[i]->reg.colour)
-	    bsput(s->prepainted, i);
+        if (locmap[i]->reg.colour)
+            bsput(s->prepainted, i);
     do {
-	setup(s);
-	liveness(s);
-	build(s);
-	mkworklist(s);
-	if (debugopt['r'])
-	    dumpasm(s, stdout);
-	do {
-	    if (s->nwlsimp)
-		simp(s);
-	    else if (s->nwlmove)
-		coalesce(s);
-	    else if (s->nwlfreeze)
-		freeze(s);
-	    else if (s->nwlspill)
-		selspill(s);
-	} while (s->nwlsimp || s->nwlmove || s->nwlfreeze || s->nwlspill);
-	spilled = paint(s);
-	if (spilled)
-	    rewrite(s);
+        setup(s);
+        liveness(s);
+        build(s);
+        mkworklist(s);
+        if (debugopt['r'])
+            dumpasm(s, stdout);
+        do {
+            if (s->nwlsimp)
+                simp(s);
+            else if (s->nwlmove)
+                coalesce(s);
+            else if (s->nwlfreeze)
+                freeze(s);
+            else if (s->nwlspill)
+                selspill(s);
+        } while (s->nwlsimp || s->nwlmove || s->nwlfreeze || s->nwlspill);
+        spilled = paint(s);
+        if (spilled)
+            rewrite(s);
     } while (spilled);
 
 }
@@ -766,10 +762,10 @@
 
     sep = "";
     for (i = 0; i < bsmax(s); i++) {
-	if (bshas(s, i)) {
-	    fprintf(fd, "%s%zd", sep, i);
-	    sep = ",";
-	}
+        if (bshas(s, i)) {
+            fprintf(fd, "%s%zd", sep, i);
+            sep = ",";
+        }
     }
     fprintf(fd, "\n");
 }
@@ -781,11 +777,11 @@
 
     sep = "";
     for (i = 0; i < bsmax(s); i++) {
-	if (bshas(s, i)) {
-	    fprintf(fd, "%s", sep);
-	    locprint(fd, locmap[i]);
-	    sep = ",";
-	}
+        if (bshas(s, i)) {
+            fprintf(fd, "%s", sep);
+            locprint(fd, locmap[i]);
+            sep = ",";
+        }
     }
     fprintf(fd, "\n");
 }
@@ -798,14 +794,14 @@
 
     fprintf(fd, "IGRAPH ----- \n");
     for (i = 0; i < maxregid; i++) {
-	for (j = i; j < maxregid; j++) {
-	    if (gbhasedge(s, i, j)) {
-		locprint(fd, locmap[i]);
-		fprintf(fd, " -- ");
-		locprint(fd, locmap[j]);
-		fprintf(fd, "\n");
-	    }
-	}
+        for (j = i; j < maxregid; j++) {
+            if (gbhasedge(s, i, j)) {
+                locprint(fd, locmap[i]);
+                fprintf(fd, " -- ");
+                locprint(fd, locmap[j]);
+                fprintf(fd, "\n");
+            }
+        }
     }
     fprintf(fd, "ASM -------- \n");
     for (j = 0; j < s->nbb; j++) {
@@ -820,21 +816,20 @@
         fprintf(fd, ")\n");
 
         fprintf(fd, "Pred: ");
-	setprint(fd, bb->pred);
+        setprint(fd, bb->pred);
         fprintf(fd, "Succ: ");
-	setprint(fd, bb->succ);
+        setprint(fd, bb->succ);
 
         fprintf(fd, "Use: ");
-	locsetprint(fd, bb->use);
+        locsetprint(fd, bb->use);
         fprintf(fd, "Def: ");
-	locsetprint(fd, bb->def);
+        locsetprint(fd, bb->def);
         fprintf(fd, "Livein:  ");
-	locsetprint(fd, bb->livein);
+        locsetprint(fd, bb->livein);
         fprintf(fd, "Liveout: ");
-	locsetprint(fd, bb->liveout);
+        locsetprint(fd, bb->liveout);
         for (i = 0; i < bb->ni; i++)
             iprintf(fd, bb->il[i]);
     }
     fprintf(fd, "ENDASM -------- \n");
 }
-
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -529,9 +529,9 @@
              {lappend(&$$.nl, &$$.nn, $3);}
         ;
 
-seqelt  : Tdot Tident Tasn expr 
+seqelt  : Tdot Tident Tasn expr
             {die("Unimplemented struct member init");}
-        | Thash atomicexpr Tasn expr 
+        | Thash atomicexpr Tasn expr
             {die("Unimplmented array member init");}
         | expr {$$ = $1;}
         | Tendln seqelt {$$ = $2;}