]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/5c/gc.h
fix ref822 again: remove uniqarray(), fix case with many entries in 'n'.
[plan9front.git] / sys / src / cmd / 5c / gc.h
1 #include        "../cc/cc.h"
2 #include        "../5c/5.out.h"
3
4 /*
5  * 5c/arm
6  * Arm
7  */
8 #define SZ_CHAR         1
9 #define SZ_SHORT        2
10 #define SZ_INT          4
11 #define SZ_LONG         4
12 #define SZ_IND          4
13 #define SZ_FLOAT        4
14 #define SZ_VLONG        8
15 #define SZ_DOUBLE       8
16 #define FNX             100
17 #define BTRUE           0x1000
18
19 typedef struct  Adr     Adr;
20 typedef struct  Prog    Prog;
21 typedef struct  Case    Case;
22 typedef struct  C1      C1;
23 typedef struct  Multab  Multab;
24 typedef struct  Hintab  Hintab;
25 typedef struct  Var     Var;
26 typedef struct  Reg     Reg;
27 typedef struct  Rgn     Rgn;
28
29
30 #define R0ISZERO        0
31
32 struct  Adr
33 {
34         long    offset;
35         double  dval;
36         char    sval[NSNAME];
37         Ieee    ieee;
38
39         Sym*    sym;
40         char    type;
41         char    reg;
42         char    name;
43         char    etype;
44 };
45 #define A       ((Adr*)0)
46
47 #define INDEXED 9
48 struct  Prog
49 {
50         Adr     from;
51         Adr     to;
52         Prog*   link;
53         long    lineno;
54         char    as;
55         char    reg;
56         uchar   scond;
57 };
58 #define P       ((Prog*)0)
59
60 struct  Case
61 {
62         Case*   link;
63         vlong   val;
64         long    label;
65         char    def;
66         char isv;
67 };
68 #define C       ((Case*)0)
69
70 struct  C1
71 {
72         vlong   val;
73         long    label;
74 };
75
76 struct  Multab
77 {
78         long    val;
79         char    code[20];
80 };
81
82 struct  Hintab
83 {
84         ushort  val;
85         char    hint[10];
86 };
87
88 struct  Var
89 {
90         long    offset;
91         Sym*    sym;
92         char    name;
93         char    etype;
94 };
95
96 struct  Reg
97 {
98         long    pc;
99         long    rpo;            /* reverse post ordering */
100
101         Bits    set;
102         Bits    use1;
103         Bits    use2;
104
105         Bits    refbehind;
106         Bits    refahead;
107         Bits    calbehind;
108         Bits    calahead;
109         Bits    regdiff;
110         Bits    act;
111
112         long    regu;
113         long    loop;           /* could be shorter */
114
115         
116         Reg*    log5;
117         long    active;
118
119         Reg*    p1;
120         Reg*    p2;
121         Reg*    p2link;
122         Reg*    s1;
123         Reg*    s2;
124         Reg*    link;
125         Prog*   prog;
126 };
127 #define R       ((Reg*)0)
128
129 #define NRGN    600
130 struct  Rgn
131 {
132         Reg*    enter;
133         short   cost;
134         short   varno;
135         short   regno;
136 };
137
138 EXTERN  long    breakpc;
139 EXTERN  long    nbreak;
140 EXTERN  Case*   cases;
141 EXTERN  Node    constnode;
142 EXTERN  Node    fconstnode;
143 EXTERN  long    continpc;
144 EXTERN  long    curarg;
145 EXTERN  long    cursafe;
146 EXTERN  Prog*   firstp;
147 EXTERN  Prog*   lastp;
148 EXTERN  long    maxargsafe;
149 EXTERN  int     mnstring;
150 EXTERN  Multab  multab[20];
151 EXTERN  int     hintabsize;
152 EXTERN  Node*   nodrat;
153 EXTERN  Node*   nodret;
154 EXTERN  Node*   nodsafe;
155 EXTERN  long    nrathole;
156 EXTERN  long    nstring;
157 EXTERN  Prog*   p;
158 EXTERN  long    pc;
159 EXTERN  Node    regnode;
160 EXTERN  char    string[NSNAME];
161 EXTERN  Sym*    symrathole;
162 EXTERN  Node    znode;
163 EXTERN  Prog    zprog;
164 EXTERN  char    reg[NREG+NFREG];
165 EXTERN  long    exregoffset;
166 EXTERN  long    exfregoffset;
167 EXTERN  int     suppress;
168
169 #define BLOAD(r)        band(bnot(r->refbehind), r->refahead)
170 #define BSTORE(r)       band(bnot(r->calbehind), r->calahead)
171 #define LOAD(r)         (~r->refbehind.b[z] & r->refahead.b[z])
172 #define STORE(r)        (~r->calbehind.b[z] & r->calahead.b[z])
173
174 #define bset(a,n)       ((a).b[(n)/32]&(1L<<(n)%32))
175
176 #define CLOAD   4
177 #define CREF    5
178 #define CINF    1000
179 #define LOOP    3
180
181 EXTERN  Rgn     region[NRGN];
182 EXTERN  Rgn*    rgp;
183 EXTERN  int     nregion;
184 EXTERN  int     nvar;
185
186 EXTERN  Bits    externs;
187 EXTERN  Bits    params;
188 EXTERN  Bits    consts;
189 EXTERN  Bits    addrs;
190
191 EXTERN  long    regbits;
192 EXTERN  long    exregbits;
193
194 EXTERN  int     change;
195
196 EXTERN  Reg*    firstr;
197 EXTERN  Reg*    lastr;
198 EXTERN  Reg     zreg;
199 EXTERN  Reg*    freer;
200 EXTERN  Var     var[NVAR];
201 EXTERN  long*   idom;
202 EXTERN  Reg**   rpo2r;
203 EXTERN  long    maxnr;
204
205 extern  char*   anames[];
206 extern  Hintab  hintab[];
207
208 /*
209  * sgen.c
210  */
211 void    codgen(Node*, Node*);
212 void    gen(Node*);
213 void    noretval(int);
214 void    usedset(Node*, int);
215 void    xcom(Node*);
216 int     bcomplex(Node*, Node*);
217
218 /*
219  * cgen.c
220  */
221 void    cgen(Node*, Node*);
222 void    cgenrel(Node*, Node*, int);
223 void    reglcgen(Node*, Node*, Node*);
224 void    lcgen(Node*, Node*);
225 void    bcgen(Node*, int);
226 void    boolgen(Node*, int, Node*);
227 void    sugen(Node*, Node*, long);
228 void    layout(Node*, Node*, int, int, Node*);
229 int     cgen64(Node*, Node*);
230
231 /*
232  * txt.c
233  */
234 void    ginit(void);
235 void    gclean(void);
236 void    nextpc(void);
237 void    gargs(Node*, Node*, Node*);
238 void    garg1(Node*, Node*, Node*, int, Node**);
239 Node*   nodconst(long);
240 Node*   nod32const(vlong);
241 Node*   nodfconst(double);
242 void    nodreg(Node*, Node*, int);
243 void    regret(Node*, Node*);
244 int     tmpreg(void);
245 void    regalloc(Node*, Node*, Node*);
246 void    regfree(Node*);
247 void    regialloc(Node*, Node*, Node*);
248 void    regsalloc(Node*, Node*);
249 void    regaalloc1(Node*, Node*);
250 void    regaalloc(Node*, Node*);
251 void    regind(Node*, Node*);
252 void    gprep(Node*, Node*);
253 void    raddr(Node*, Prog*);
254 void    naddr(Node*, Adr*);
255 void    gmovm(Node*, Node*, int);
256 void    gmove(Node*, Node*);
257 void    gmover(Node*, Node*);
258 void    gins(int a, Node*, Node*);
259 void    gopcode(int, Node*, Node*, Node*);
260 int     samaddr(Node*, Node*);
261 void    gbranch(int);
262 void    patch(Prog*, long);
263 int     sconst(Node*);
264 int     sval(long);
265 void    gpseudo(int, Sym*, Node*);
266
267 /*
268  * swt.c
269  */
270 int     swcmp(const void*, const void*);
271 void    doswit(Node*);
272 void    swit1(C1*, int, long, Node*);
273 void    swit2(C1*, int, long, Node*, Node*);
274 void    casf(void);
275 void    bitload(Node*, Node*, Node*, Node*, Node*);
276 void    bitstore(Node*, Node*, Node*, Node*, Node*);
277 long    outstring(char*, long);
278 int     mulcon(Node*, Node*);
279 Multab* mulcon0(long);
280 void    nullwarn(Node*, Node*);
281 void    sextern(Sym*, Node*, long, long);
282 void    gextern(Sym*, Node*, long, long);
283 void    outcode(void);
284 void    ieeedtod(Ieee*, double);
285
286 /*
287  * list
288  */
289 void    listinit(void);
290 int     Pconv(Fmt*);
291 int     Aconv(Fmt*);
292 int     Dconv(Fmt*);
293 int     Sconv(Fmt*);
294 int     Nconv(Fmt*);
295 int     Bconv(Fmt*);
296 int     Rconv(Fmt*);
297
298 /*
299  * reg.c
300  */
301 Reg*    rega(void);
302 int     rcmp(const void*, const void*);
303 void    regopt(Prog*);
304 void    addmove(Reg*, int, int, int);
305 Bits    mkvar(Adr*, int);
306 void    prop(Reg*, Bits, Bits);
307 void    loopit(Reg*, long);
308 void    synch(Reg*, Bits);
309 ulong   allreg(ulong, Rgn*);
310 void    paint1(Reg*, int);
311 ulong   paint2(Reg*, int);
312 void    paint3(Reg*, int, long, int);
313 void    addreg(Adr*, int);
314
315 /*
316  * peep.c
317  */
318 void    peep(void);
319 void    excise(Reg*);
320 Reg*    uniqp(Reg*);
321 Reg*    uniqs(Reg*);
322 int     regtyp(Adr*);
323 int     regzer(Adr*);
324 int     anyvar(Adr*);
325 int     subprop(Reg*);
326 int     copyprop(Reg*);
327 int     shiftprop(Reg*);
328 void    constprop(Adr*, Adr*, Reg*);
329 int     copy1(Adr*, Adr*, Reg*, int);
330 int     copyu(Prog*, Adr*, Adr*);
331
332 int     copyas(Adr*, Adr*);
333 int     copyau(Adr*, Adr*);
334 int     copyau1(Prog*, Adr*);
335 int     copysub(Adr*, Adr*, Adr*, int);
336 int     copysub1(Prog*, Adr*, Adr*, int);
337
338 long    RtoB(int);
339 long    FtoB(int);
340 int     BtoR(long);
341 int     BtoF(long);
342
343 void    predicate(void); 
344 int     isbranch(Prog *); 
345 int     predicable(Prog *p); 
346 int     modifiescpsr(Prog *p); 
347
348 #pragma varargck        type    "A"     int
349 #pragma varargck        type    "B"     Bits
350 #pragma varargck        type    "D"     Adr*
351 #pragma varargck        type    "N"     Adr*
352 #pragma varargck        type    "R"     Adr*
353 #pragma varargck        type    "P"     Prog*
354 #pragma varargck        type    "S"     char*