1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
From 3415d1f4dc68092819faf1744bfab556e338649b Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Sun, 21 Apr 2019 13:37:32 -0700
Subject: [PATCH] Use dynamic array for phi arguments
---
all.h | 4 ++--
amd64/sysv.c | 8 ++++++--
arm64/abi.c | 8 ++++++--
load.c | 4 ++--
parse.c | 2 ++
ssa.c | 6 ++++--
6 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/all.h b/all.h
index 59eefe1..fba93b1 100644
--- a/all.h
+++ b/all.h
@@ -206,8 +206,8 @@ struct Ins {
struct Phi {
Ref to;
- Ref arg[NPred];
- Blk *blk[NPred];
+ Ref *arg;
+ Blk **blk;
uint narg;
int cls;
Phi *link;
diff --git a/amd64/sysv.c b/amd64/sysv.c
index ea9b2d2..286300a 100644
--- a/amd64/sysv.c
+++ b/amd64/sysv.c
@@ -590,9 +590,13 @@ selvaarg(Fn *fn, Blk *b, Ins *i)
*b0->phi = (Phi){
.cls = Kl, .to = loc,
.narg = 2,
- .blk = {bstk, breg},
- .arg = {lstk, lreg},
+ .blk = vnew(2, sizeof b0->phi->blk[0], Pfn),
+ .arg = vnew(2, sizeof b0->phi->arg[0], Pfn),
};
+ b0->phi->blk[0] = bstk;
+ b0->phi->blk[1] = breg;
+ b0->phi->arg[0] = lstk;
+ b0->phi->arg[1] = lreg;
r0 = newtmp("abi", Kl, fn);
r1 = newtmp("abi", Kw, fn);
b->jmp.type = Jjnz;
diff --git a/arm64/abi.c b/arm64/abi.c
index 8bc9c20..f5b605a 100644
--- a/arm64/abi.c
+++ b/arm64/abi.c
@@ -583,9 +583,13 @@ selvaarg(Fn *fn, Blk *b, Ins *i)
*b0->phi = (Phi){
.cls = Kl, .to = loc,
.narg = 2,
- .blk = {bstk, breg},
- .arg = {lstk, lreg},
+ .blk = vnew(2, sizeof b0->phi->blk[0], Pfn),
+ .arg = vnew(2, sizeof b0->phi->arg[0], Pfn),
};
+ b0->phi->blk[0] = bstk;
+ b0->phi->blk[1] = breg;
+ b0->phi->arg[0] = lstk;
+ b0->phi->arg[1] = lreg;
r0 = newtmp("abi", Kl, fn);
r1 = newtmp("abi", Kw, fn);
b->jmp.type = Jjnz;
diff --git a/load.c b/load.c
index 9894000..ae9cfcf 100644
--- a/load.c
+++ b/load.c
@@ -330,8 +330,8 @@ def(Slice sl, bits msk, Blk *b, Ins *i, Loc *il)
p->to = r;
p->cls = sl.cls;
p->narg = b->npred;
- if (b->npred >= NPred)
- die("def, too many phi args (%u)", b->npred);
+ p->arg = vnew(p->narg, sizeof p->arg[0], Pfn);
+ p->blk = vnew(p->narg, sizeof p->blk[0], Pfn);
for (np=0; np<b->npred; ++np) {
bp = b->pred[np];
if (!bp->s2
diff --git a/parse.c b/parse.c
index c4c1fe6..95bcf45 100644
--- a/parse.c
+++ b/parse.c
@@ -673,7 +673,9 @@ Ins:
phi = alloc(sizeof *phi);
phi->to = r;
phi->cls = k;
+ phi->arg = vnew(i, sizeof arg[0], Pfn);
memcpy(phi->arg, arg, i * sizeof arg[0]);
+ phi->blk = vnew(i, sizeof blk[0], Pfn);
memcpy(phi->blk, blk, i * sizeof blk[0]);
phi->narg = i;
*plink = phi;
diff --git a/ssa.c b/ssa.c
index c098438..2de02d1 100644
--- a/ssa.c
+++ b/ssa.c
@@ -181,6 +181,8 @@ phiins(Fn *fn)
p->cls = k;
p->to = TMP(t);
p->link = a->phi;
+ p->arg = vnew(0, sizeof p->arg[0], Pfn);
+ p->blk = vnew(0, sizeof p->blk[0], Pfn);
a->phi = p;
if (!bshas(defs, a->id))
if (!bshas(u, a->id)) {
@@ -294,8 +296,8 @@ renblk(Blk *b, Name **stk, Fn *fn)
t = p->to.val;
if ((t=fn->tmp[t].visit)) {
m = p->narg++;
- if (m == NPred)
- die("renblk, too many phi args");
+ vgrow(&p->arg, p->narg);
+ vgrow(&p->blk, p->narg);
p->arg[m] = getstk(t, b, stk);
p->blk[m] = b;
}
--
2.21.0
|