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
;
39 NBit
= CHAR_BIT
* sizeof(bits
),
43 int gpr0
; /* first general purpose reg */
45 int fpr0
; /* first floating point reg */
47 bits rglob
; /* globally live regs (e.g., sp, fp) */
49 int *rsave
; /* caller-save */
51 bits (*retregs
)(Ref
, int[2]);
52 bits (*argregs
)(Ref
, int[2]);
56 void (*emitfn
)(Fn
*, FILE *);
59 #define BIT(n) ((bits)1 << (n))
63 Tmp0
= NBit
, /* first non-reg temporary */
86 #define TMP(x) (Ref){RTmp, x}
87 #define CON(x) (Ref){RCon, x}
88 #define CON_Z CON(0) /* reserved zero constant */
89 #define SLOT(x) (Ref){RSlot, (x)&0x1fffffff}
90 #define TYPE(x) (Ref){RType, x}
91 #define CALL(x) (Ref){RCall, x}
92 #define MEM(x) (Ref){RMem, x}
94 static inline int req(Ref a
, Ref b
)
96 return a
.type
== b
.type
&& a
.val
== b
.val
;
99 static inline int rtype(Ref r
)
130 NCmp
= NCmpI
+ NCmpF
,
135 #define O(op, x, y) O##op,
143 X(ret0) X(retw) X(retl) X(rets) \
144 X(retd) X(retc) X(jmp) X(jnz) \
145 X(jfieq) X(jfine) X(jfisge) X(jfisgt) \
146 X(jfisle) X(jfislt) X(jfiuge) X(jfiugt) \
147 X(jfiule) X(jfiult) X(jffeq) X(jffge) \
148 X(jffgt) X(jffle) X(jfflt) X(jffne) \
174 #define INRANGE(x, l, u) ((unsigned)(x) - l <= u - l) /* linear in x */
175 #define iscall(o) INRANGE(o, Ocall, Ovacall)
176 #define isstore(o) INRANGE(o, Ostoreb, Ostored)
177 #define isload(o) INRANGE(o, Oloadsb, Oload)
178 #define isext(o) INRANGE(o, Oextsb, Oextuw)
179 #define ispar(o) INRANGE(o, Opar, Opare)
180 #define isarg(o) INRANGE(o, Oarg, Oarge)
181 #define isret(j) INRANGE(j, Jret0, Jretc)
184 Kx
= -1, /* "top" class (see usecheck() and clsmerge()) */
191 #define KWIDE(k) ((k)&1)
192 #define KBASE(k) ((k)>>1)
238 BSet in
[1], out
[1], gen
[1];
267 ALoc
= 1, /* stack local */
269 AEsc
= 3, /* stack escaping */
272 #define astack(t) ((t) & 1)
284 uint bid
; /* id of a defining block */
286 int slot
; /* -1 for unset */
289 int r
; /* register or -1 */
291 bits m
; /* avoid these registers */
297 Wsb
, /* must match Oload/Oext order */
319 char flt
; /* 1 to print as s, 2 to print as d */
323 typedef struct Addr Addr
;
325 struct Addr
{ /* amd64 addressing */
341 int retty
; /* index in typ[], -1 if no aggregate return */
370 uint len
; /* or index in typ[] for FTyp */
371 } (*fields
)[NField
+1];
403 extern char debug
['Z'+1];
407 Pheap
, /* free() necessary */
408 Pfn
, /* discarded after processing the function */
412 extern Ins insb
[NIns
], *curi
;
413 uint32_t hash(char *);
414 void die_(char *, char *, ...) __attribute__((noreturn
));
415 void *emalloc(size_t);
418 void *vnew(ulong
, size_t, Pool
);
420 void vgrow(void *, ulong
);
421 uint32_t intern(char *);
423 int argcls(Ins
*, int);
425 int iscmp(int, int *, int *);
426 void emit(int, int, Ref
, Ref
, Ref
);
428 void idup(Ins
**, Ins
*, ulong
);
429 Ins
*icpy(Ins
*, Ins
*, ulong
);
432 int clsmerge(short *, short);
433 int phicls(int, Tmp
*);
434 Ref
newtmp(char *, int, Fn
*);
435 void chuse(Ref
, int, Fn
*);
436 Ref
getcon(int64_t, Fn
*);
437 void addcon(Con
*, Con
*);
438 void blit(Ref
, uint
, Ref
, uint
, Fn
*);
439 void dumpts(BSet
*, Tmp
*, FILE *);
441 void bsinit(BSet
*, uint
);
443 uint
bscount(BSet
*);
444 void bsset(BSet
*, uint
);
445 void bsclr(BSet
*, uint
);
446 void bscopy(BSet
*, BSet
*);
447 void bsunion(BSet
*, BSet
*);
448 void bsinter(BSet
*, BSet
*);
449 void bsdiff(BSet
*, BSet
*);
450 int bsequal(BSet
*, BSet
*);
451 int bsiter(BSet
*, int *);
454 bshas(BSet
*bs
, uint elt
)
456 assert(elt
< bs
->nt
* NBit
);
457 return (bs
->t
[elt
/NBit
] & BIT(elt
%NBit
)) != 0;
461 extern Op optab
[NOp
];
462 void parse(FILE *, char *, void (Dat
*), void (Fn
*));
463 void printfn(Fn
*, FILE *);
464 void printref(Ref
, Fn
*, FILE *);
465 void err(char *, ...) __attribute__((noreturn
));
469 void edgedel(Blk
*, Blk
**);
470 void fillpreds(Fn
*);
473 int sdom(Blk
*, Blk
*);
474 int dom(Blk
*, Blk
*);
476 void loopiter(Fn
*, void (*)(Blk
*, Blk
*));
484 void fillalias(Fn
*);
485 int alias(Ref
, int, Ref
, int, int *, Fn
*);
486 int escapes(Ref
, Fn
*);
495 void fillpreds(Fn
*);
510 void liveon(BSet
*, Blk
*, Blk
*);
523 void gasemitdat(Dat
*, FILE *);
524 int gasstash(void *, int);
525 void gasemitfin(FILE *);