From 85fed148fd68c5e621353dfcf07351f66b290ce3 Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 15 Jun 2023 12:46:28 +0200 Subject: less memset --- c.c | 1 - ir.c | 12 +++++++++--- regalloc.c | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/c.c b/c.c index fed56c3..fb9ef7d 100644 --- a/c.c +++ b/c.c @@ -1,5 +1,4 @@ #include "parse.h" -#include "common.h" #include "ir.h" static struct arena *tlarena; diff --git a/ir.c b/ir.c index c2abe12..7ccb926 100644 --- a/ir.c +++ b/ir.c @@ -11,6 +11,9 @@ struct calltab calltab; struct phitab phitab; struct dattab dattab; struct addr addrht[1 << 12]; +static int naddrht; +struct xcon conht[1 << 12]; +static int nconht; void irinit(struct function *fn) @@ -24,7 +27,10 @@ irinit(struct function *fn) vinit(&calltab, callsbuf, arraylength(callsbuf)); vinit(&phitab, phisbuf, arraylength(phisbuf)); vinit(&dattab, datsbuf, arraylength(datsbuf)); - memset(addrht, 0, sizeof addrht); + if (naddrht >= arraylength(addrht)/2) + memset(addrht, naddrht = 0, sizeof addrht); + if (nconht >= arraylength(conht)/2) + memset(addrht, nconht = 0, sizeof addrht); if (!type2cls[TYINT]) { for (int i = TYBOOL; i <= TYUVLONG; ++i) { int siz = targ_primsizes[i]; @@ -52,6 +58,7 @@ addaddr(const struct addr *addr) i &= arraylength(addrht) - 1; if (!addrht[i].base.t && !addrht[i].index.t) { addrht[i] = *addr; + ++naddrht; return i; } else if (!memcmp(&addrht[i], addr, sizeof *addr)) { return i; @@ -60,8 +67,6 @@ addaddr(const struct addr *addr) } } -struct xcon conht[1 << 12]; - static int addcon(const struct xcon *con) { @@ -72,6 +77,7 @@ addcon(const struct xcon *con) i &= arraylength(conht) - 1; if (!conht[i].issym && !conht[i].cls) { conht[i] = *con; + ++nconht; return i; } else if (!memcmp(&conht[i], con, sizeof *con)) { return i; diff --git a/regalloc.c b/regalloc.c index 4801db9..a43425c 100644 --- a/regalloc.c +++ b/regalloc.c @@ -1,4 +1,3 @@ -#include "common.h" #include "ir.h" static struct bitset globusage[1]; -- cgit v1.2.3