summaryrefslogtreecommitdiff
path: root/opt
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2012-06-11 14:29:09 -0400
committerOri Bernstein <orib@google.com>2012-06-11 14:29:09 -0400
commitd4652ead0e6be99b889228f76caa4bb1c3ba62d8 (patch)
tree3b77a069204d4db9e4873ca11d5fbe18020cd30c /opt
parentcb4e2d4b69b663b99271bd4b29efceb873603f53 (diff)
downloadmc-d4652ead0e6be99b889228f76caa4bb1c3ba62d8.tar.gz
Make the CFG correct.
Explitly insert out jumps where we expect fallthroughs.
Diffstat (limited to 'opt')
-rw-r--r--opt/df.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/opt/df.c b/opt/df.c
index 4f77934..be3d2a1 100644
--- a/opt/df.c
+++ b/opt/df.c
@@ -63,6 +63,12 @@ Cfg *mkcfg(Node **nl, int nn)
for (i = 0; i < nn; i++) {
switch (nl[i]->type) {
case Nlbl:
+ /* if the current block assumes fall-through, insert an explicit
+ * jump */
+ if (i > 0 && nl[i - 1]->type == Nexpr) {
+ if (exprop(nl[i - 1]) != Ocjmp && exprop(nl[i - 1]) != Ojmp)
+ addnode(cfg, bb, mkexpr(-1, Ojmp, mklbl(-1, nl[i]->lbl.name), NULL));
+ }
if (bb->nnl)
bb = mkbb(cfg);
label(cfg, nl[i], bb);
@@ -130,9 +136,10 @@ void dumpcfg(Cfg *cfg, FILE *fd)
fprintf(fd, "In: ");
sep = "";
for (i = 0; i < bsmax(bb->in); i++) {
- if (bshas(bb->in, i))
- fprintf(fd, "%d%s", i, sep);
- sep = ",";
+ if (bshas(bb->in, i)) {
+ fprintf(fd, "%s%d", sep, i);
+ sep = ",";
+ }
}
fprintf(fd, "\n");
@@ -141,7 +148,7 @@ void dumpcfg(Cfg *cfg, FILE *fd)
sep = "";
for (i = 0; i < bsmax(bb->out); i++) {
if (bshas(bb->out, i)) {
- fprintf(fd, "%d%s", i, sep);
+ fprintf(fd, "%s%d", sep, i);
sep = ",";
}
}