8 #define MAKESURE(what, x) typedef char make_sure_##what[(x)?1:-1]
9 #define die(...) die_(__FILE__, __VA_ARGS__)
11 typedef unsigned char uchar
;
12 typedef unsigned int uint
;
13 typedef unsigned long ulong
;
14 typedef unsigned long long bits
;
16 typedef struct BSet BSet
;
17 typedef struct Ref Ref
;
19 typedef struct Ins Ins
;
20 typedef struct Phi Phi
;
21 typedef struct Blk Blk
;
22 typedef struct Use Use
;
23 typedef struct Alias Alias
;
24 typedef struct Tmp Tmp
;
25 typedef struct Con Con
;
26 typedef struct Addr Mem
;
28 typedef struct Typ Typ
;
29 typedef struct Field Field
;
30 typedef struct Dat Dat
;
31 typedef struct Target Target
;
38 NBit
= CHAR_BIT
* sizeof(bits
),
42 int gpr0
; /* first general purpose reg */
44 int fpr0
; /* first floating point reg */
46 bits rglob
; /* globally live regs (e.g., sp, fp) */
48 int *rsave
; /* caller-save */
50 bits (*retregs
)(Ref
, int[2]);
51 bits (*argregs
)(Ref
, int[2]);
55 void (*emitfn
)(Fn
*, FILE *);
58 #define BIT(n) ((bits)1 << (n))
62 Tmp0
= NBit
, /* first non-reg temporary */
85 #define TMP(x) (Ref){RTmp, x}
86 #define CON(x) (Ref){RCon, x}
87 #define CON_Z CON(0) /* reserved zero constant */
88 #define SLOT(x) (Ref){RSlot, (x)&0x1fffffff}
89 #define TYPE(x) (Ref){RType, x}
90 #define CALL(x) (Ref){RCall, x}
91 #define MEM(x) (Ref){RMem, x}
93 static inline int req(Ref a
, Ref b
)
95 return a
.type
== b
.type
&& a
.val
== b
.val
;
98 static inline int rtype(Ref r
)
129 NCmp
= NCmpI
+ NCmpF
,
134 #define O(op, x, y) O##op,
142 X(ret0) X(retw) X(retl) X(rets) \
143 X(retd) X(retc) X(jmp) X(jnz) \
144 X(jfieq) X(jfine) X(jfisge) X(jfisgt) \
145 X(jfisle) X(jfislt) X(jfiuge) X(jfiugt) \
146 X(jfiule) X(jfiult) X(jffeq) X(jffge) \
147 X(jffgt) X(jffle) X(jfflt) X(jffne) \
173 #define INRANGE(x, l, u) ((unsigned)(x) - l <= u - l) /* linear in x */
174 #define iscall(o) INRANGE(o, Ocall, Ovacall)
175 #define isstore(o) INRANGE(o, Ostoreb, Ostored)
176 #define isload(o) INRANGE(o, Oloadsb, Oload)
177 #define isext(o) INRANGE(o, Oextsb, Oextuw)
178 #define ispar(o) INRANGE(o, Opar, Opare)
179 #define isarg(o) INRANGE(o, Oarg, Oarge)
180 #define isret(j) INRANGE(j, Jret0, Jretc)
183 Kx
= -1, /* "top" class (see usecheck() and clsmerge()) */
190 #define KWIDE(k) ((k)&1)
191 #define KBASE(k) ((k)>>1)
237 BSet in
[1], out
[1], gen
[1];
266 ALoc
= 1, /* stack local */
268 AEsc
= 3, /* stack escaping */
271 #define astack(t) ((t) & 1)
283 uint bid
; /* id of a defining block */
285 int slot
; /* -1 for unset */
288 int r
; /* register or -1 */
290 bits m
; /* avoid these registers */
296 Wsb
, /* must match Oload/Oext order */
318 char flt
; /* 1 to print as s, 2 to print as d */
322 typedef struct Addr Addr
;
324 struct Addr
{ /* amd64 addressing */
340 int retty
; /* index in typ[], -1 if no aggregate return */
369 uint len
; /* or index in typ[] for FTyp */
370 } (*fields
)[NField
+1];
402 extern char debug
['Z'+1];
406 Pheap
, /* free() necessary */
407 Pfn
, /* discarded after processing the function */
411 extern Ins insb
[NIns
], *curi
;
412 uint32_t hash(char *);
413 void die_(char *, char *, ...) __attribute__((noreturn
));
414 void *emalloc(size_t);
417 void *vnew(ulong
, size_t, Pool
);
419 void vgrow(void *, ulong
);
420 uint32_t intern(char *);
422 int argcls(Ins
*, int);
424 int iscmp(int, int *, int *);
425 void emit(int, int, Ref
, Ref
, Ref
);
427 void idup(Ins
**, Ins
*, ulong
);
428 Ins
*icpy(Ins
*, Ins
*, ulong
);
431 int clsmerge(short *, short);
432 int phicls(int, Tmp
*);
433 Ref
newtmp(char *, int, Fn
*);
434 void chuse(Ref
, int, Fn
*);
435 Ref
getcon(int64_t, Fn
*);
436 int addcon(Con
*, Con
*);
437 void blit(Ref
, uint
, Ref
, uint
, Fn
*);
438 void dumpts(BSet
*, Tmp
*, FILE *);
440 void bsinit(BSet
*, uint
);
442 uint
bscount(BSet
*);
443 void bsset(BSet
*, uint
);
444 void bsclr(BSet
*, uint
);
445 void bscopy(BSet
*, BSet
*);
446 void bsunion(BSet
*, BSet
*);
447 void bsinter(BSet
*, BSet
*);
448 void bsdiff(BSet
*, BSet
*);
449 int bsequal(BSet
*, BSet
*);
450 int bsiter(BSet
*, int *);
453 bshas(BSet
*bs
, uint elt
)
455 assert(elt
< bs
->nt
* NBit
);
456 return (bs
->t
[elt
/NBit
] & BIT(elt
%NBit
)) != 0;
460 extern Op optab
[NOp
];
461 void parse(FILE *, char *, void (Dat
*), void (Fn
*));
462 void printfn(Fn
*, FILE *);
463 void printref(Ref
, Fn
*, FILE *);
464 void err(char *, ...) __attribute__((noreturn
));
468 void edgedel(Blk
*, Blk
**);
469 void fillpreds(Fn
*);
472 int sdom(Blk
*, Blk
*);
473 int dom(Blk
*, Blk
*);
475 void loopiter(Fn
*, void (*)(Blk
*, Blk
*));
483 void fillalias(Fn
*);
484 int alias(Ref
, int, Ref
, int, int *, Fn
*);
485 int escapes(Ref
, Fn
*);
494 void fillpreds(Fn
*);
506 void liveon(BSet
*, Blk
*, Blk
*);
519 void gasemitdat(Dat
*, FILE *);
520 int gasstash(void *, int);
521 void gasemitfin(FILE *);