shithub: mc

Download patch

ref: 51567134bf91de89705a64670abae17514ecc55a
parent: 822da329297079d473f20a6fe14c7c2d712cdc83
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Dec 6 15:04:39 EST 2016

Reduce memory usage.

--- a/6/ra.c
+++ b/6/ra.c
@@ -662,6 +662,7 @@
 			}
 		}
 	}
+	free(il);
 }
 
 static void decdegree(Isel *s, regid m)
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -94,6 +94,7 @@
 		bsfree(reach);
 		bsfree(kill);
 	}
+	reachingfree(r);
 }
 
 static void checkpredret(Cfg *cfg, Bb *bb)
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -33,10 +33,13 @@
 	Bitset **out;
 	size_t **defs;
 	size_t *ndefs;
+	size_t nbb;
 };
 
 /* dataflow analysis */
 Reaching *reaching(Cfg *cfg);
+void reachingfree(Reaching *r);
+
 Node *assignee(Node *n);
 
 /* Takes a reduced block, and returns a flow graph. */
--- a/mi/reaching.c
+++ b/mi/reaching.c
@@ -139,15 +139,44 @@
 				bsfree(out[i]);
 				in[i] = bbin;
 				out[i] = bbout;
+			} else {
+				bsfree(bbin);
+				bsfree(bbout);
 			}
 		}
 	} while (changed);
 
 
+	for (i = 0; i < cfg->nbb; i++) {
+		bsfree(gen[i]);
+		bsfree(kill[i]);
+	}
+	free(gen);
+	free(kill);
+
 	reaching = xalloc(sizeof(Reaching));
 	reaching->in = in;
 	reaching->out = out;
 	reaching->defs = defs;
 	reaching->ndefs = ndefs;
+	reaching->nbb = cfg->nbb;
 	return reaching;
 }
+
+void reachingfree(Reaching *r)
+{
+	size_t i;
+
+	for (i = 0; i < r->nbb; i++) {
+		bsfree(r->in[i]);
+		bsfree(r->out[i]);
+	}
+	for (i = 0; i < ndecls; i++)
+		free(r->defs[i]);
+	free(r->in);
+	free(r->out);
+	free(r->defs);
+	free(r->ndefs);
+	free(r);
+}
+