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
),
44 int gpr0
; /* first general purpose reg */
46 int fpr0
; /* first floating point reg */
48 bits rglob
; /* globally live regs (e.g., sp, fp) */
50 int *rsave
; /* caller-save */
52 bits (*retregs
)(Ref
, int[2]);
53 bits (*argregs
)(Ref
, int[2]);
57 void (*emitfn
)(Fn
*, FILE *);
60 #define BIT(n) ((bits)1 << (n))
64 Tmp0
= NBit
, /* first non-reg temporary */
87 #define TMP(x) (Ref){RTmp, x}
88 #define CON(x) (Ref){RCon, x}
89 #define CON_Z CON(0) /* reserved zero constant */
90 #define SLOT(x) (Ref){RSlot, (x)&0x1fffffff}
91 #define TYPE(x) (Ref){RType, x}
92 #define CALL(x) (Ref){RCall, x}
93 #define MEM(x) (Ref){RMem, x}
95 static inline int req(Ref a
, Ref b
)
97 return a
.type
== b
.type
&& a
.val
== b
.val
;
100 static inline int rtype(Ref r
)
131 NCmp
= NCmpI
+ NCmpF
,
136 #define O(op, x, y) O##op,
144 X(ret0) X(retw) X(retl) X(rets) \
145 X(retd) X(retc) X(jmp) X(jnz) \
146 X(jfieq) X(jfine) X(jfisge) X(jfisgt) \
147 X(jfisle) X(jfislt) X(jfiuge) X(jfiugt) \
148 X(jfiule) X(jfiult) X(jffeq) X(jffge) \
149 X(jffgt) X(jffle) X(jfflt) X(jffne) \
175 #define INRANGE(x, l, u) ((unsigned)(x) - l <= u - l) /* linear in x */
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, Oargv)
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 */
348 int retty
; /* index in typ[], -1 if no aggregate return */
378 uint len
; /* or index in typ[] for FTyp */
379 } (*fields
)[NField
+1];
410 extern char debug
['Z'+1];
414 Pheap
, /* free() necessary */
415 Pfn
, /* discarded after processing the function */
419 extern Ins insb
[NIns
], *curi
;
420 uint32_t hash(char *);
421 void die_(char *, char *, ...) __attribute__((noreturn
));
422 void *emalloc(size_t);
425 void *vnew(ulong
, size_t, Pool
);
427 void vgrow(void *, ulong
);
428 uint32_t intern(char *);
430 int argcls(Ins
*, int);
432 int iscmp(int, int *, int *);
433 void emit(int, int, Ref
, Ref
, Ref
);
435 void idup(Ins
**, Ins
*, ulong
);
436 Ins
*icpy(Ins
*, Ins
*, ulong
);
439 int clsmerge(short *, short);
440 int phicls(int, Tmp
*);
441 Ref
newtmp(char *, int, Fn
*);
442 void chuse(Ref
, int, Fn
*);
443 Ref
newcon(Con
*, Fn
*);
444 Ref
getcon(int64_t, Fn
*);
445 int addcon(Con
*, Con
*);
446 void blit(Ref
, uint
, Ref
, uint
, uint
, Fn
*);
447 void blit0(Ref
, Ref
, uint
, Fn
*);
448 void salloc(Ref
, Ref
, Fn
*);
449 void dumpts(BSet
*, Tmp
*, FILE *);
451 void bsinit(BSet
*, uint
);
453 uint
bscount(BSet
*);
454 void bsset(BSet
*, uint
);
455 void bsclr(BSet
*, uint
);
456 void bscopy(BSet
*, BSet
*);
457 void bsunion(BSet
*, BSet
*);
458 void bsinter(BSet
*, BSet
*);
459 void bsdiff(BSet
*, BSet
*);
460 int bsequal(BSet
*, BSet
*);
461 int bsiter(BSet
*, int *);
464 bshas(BSet
*bs
, uint elt
)
466 assert(elt
< bs
->nt
* NBit
);
467 return (bs
->t
[elt
/NBit
] & BIT(elt
%NBit
)) != 0;
471 extern Op optab
[NOp
];
472 void parse(FILE *, char *, void (Dat
*), void (Fn
*));
473 void printfn(Fn
*, FILE *);
474 void printref(Ref
, Fn
*, FILE *);
475 void err(char *, ...) __attribute__((noreturn
));
479 void edgedel(Blk
*, Blk
**);
480 void fillpreds(Fn
*);
483 int sdom(Blk
*, Blk
*);
484 int dom(Blk
*, Blk
*);
486 void loopiter(Fn
*, void (*)(Blk
*, Blk
*));
494 void fillalias(Fn
*);
495 int alias(Ref
, int, Ref
, int, int *, Fn
*);
496 int escapes(Ref
, Fn
*);
505 void fillpreds(Fn
*);
517 void liveon(BSet
*, Blk
*, Blk
*);
534 void gasinit(enum Asm
);
535 void gasemitlnk(char *, Lnk
*, char *, FILE *);
536 void gasemitfntail(char *, FILE *);
537 void gasemitdat(Dat
*, FILE *);
538 int gasstash(void *, int);
539 void gasemitfin(FILE *);