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 Lnk Lnk
;
32 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 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, Oargv)
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 */
347 int retty
; /* index in typ[], -1 if no aggregate return */
376 uint len
; /* or index in typ[] for FTyp */
377 } (*fields
)[NField
+1];
408 extern char debug
['Z'+1];
412 Pheap
, /* free() necessary */
413 Pfn
, /* discarded after processing the function */
417 extern Ins insb
[NIns
], *curi
;
418 uint32_t hash(char *);
419 void die_(char *, char *, ...) __attribute__((noreturn
));
420 void *emalloc(size_t);
423 void *vnew(ulong
, size_t, Pool
);
425 void vgrow(void *, ulong
);
426 uint32_t intern(char *);
428 int argcls(Ins
*, int);
430 int iscmp(int, int *, int *);
431 void emit(int, int, Ref
, Ref
, Ref
);
433 void idup(Ins
**, Ins
*, ulong
);
434 Ins
*icpy(Ins
*, Ins
*, ulong
);
437 int clsmerge(short *, short);
438 int phicls(int, Tmp
*);
439 Ref
newtmp(char *, int, Fn
*);
440 void chuse(Ref
, int, Fn
*);
441 Ref
newcon(Con
*, Fn
*);
442 Ref
getcon(int64_t, Fn
*);
443 int addcon(Con
*, Con
*);
444 void blit(Ref
, uint
, Ref
, uint
, uint
, Fn
*);
445 void blit0(Ref
, Ref
, uint
, Fn
*);
446 void dumpts(BSet
*, Tmp
*, FILE *);
448 void bsinit(BSet
*, uint
);
450 uint
bscount(BSet
*);
451 void bsset(BSet
*, uint
);
452 void bsclr(BSet
*, uint
);
453 void bscopy(BSet
*, BSet
*);
454 void bsunion(BSet
*, BSet
*);
455 void bsinter(BSet
*, BSet
*);
456 void bsdiff(BSet
*, BSet
*);
457 int bsequal(BSet
*, BSet
*);
458 int bsiter(BSet
*, int *);
461 bshas(BSet
*bs
, uint elt
)
463 assert(elt
< bs
->nt
* NBit
);
464 return (bs
->t
[elt
/NBit
] & BIT(elt
%NBit
)) != 0;
468 extern Op optab
[NOp
];
469 void parse(FILE *, char *, void (Dat
*), void (Fn
*));
470 void printfn(Fn
*, FILE *);
471 void printref(Ref
, Fn
*, FILE *);
472 void err(char *, ...) __attribute__((noreturn
));
476 void edgedel(Blk
*, Blk
**);
477 void fillpreds(Fn
*);
480 int sdom(Blk
*, Blk
*);
481 int dom(Blk
*, Blk
*);
483 void loopiter(Fn
*, void (*)(Blk
*, Blk
*));
491 void fillalias(Fn
*);
492 int alias(Ref
, int, Ref
, int, int *, Fn
*);
493 int escapes(Ref
, Fn
*);
502 void fillpreds(Fn
*);
514 void liveon(BSet
*, Blk
*, Blk
*);
527 void gasemitlnk(char *, Lnk
*, char *, FILE *);
528 void gasemitdat(Dat
*, FILE *);
529 int gasstash(void *, int);
530 void gasemitfin(FILE *);