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 Sym Sym
;
24 typedef struct Num Num
;
25 typedef struct Alias Alias
;
26 typedef struct Tmp Tmp
;
27 typedef struct Con Con
;
28 typedef struct Addr Mem
;
30 typedef struct Typ Typ
;
31 typedef struct Field Field
;
32 typedef struct Dat Dat
;
33 typedef struct Lnk Lnk
;
34 typedef struct Target Target
;
41 NBit
= CHAR_BIT
* sizeof(bits
),
47 int gpr0
; /* first general purpose reg */
49 int fpr0
; /* first floating point reg */
51 bits rglob
; /* globally live regs (e.g., sp, fp) */
53 int *rsave
; /* caller-save */
55 bits (*retregs
)(Ref
, int[2]);
56 bits (*argregs
)(Ref
, int[2]);
61 void (*emitfn
)(Fn
*, FILE *);
62 void (*emitfin
)(FILE *);
67 #define BIT(n) ((bits)1 << (n))
71 Tmp0
= NBit
, /* first non-reg temporary */
88 RType
, /* last kind to come out of the parser */
94 #define R (Ref){RTmp, 0}
95 #define UNDEF (Ref){RCon, 0} /* represents uninitialized data */
96 #define CON_Z (Ref){RCon, 1}
97 #define TMP(x) (Ref){RTmp, x}
98 #define CON(x) (Ref){RCon, x}
99 #define SLOT(x) (Ref){RSlot, (x)&0x1fffffff}
100 #define TYPE(x) (Ref){RType, x}
101 #define CALL(x) (Ref){RCall, x}
102 #define MEM(x) (Ref){RMem, x}
103 #define INT(x) (Ref){RInt, (x)&0x1fffffff}
105 static inline int req(Ref a
, Ref b
)
107 return a
.type
== b
.type
&& a
.val
== b
.val
;
110 static inline int rtype(Ref r
)
117 static inline int rsval(Ref r
)
119 return ((int)r
.val
^ 0x10000000) - 0x10000000;
146 NCmp
= NCmpI
+ NCmpF
,
151 #define O(op, x, y) O##op,
159 X(retw) X(retl) X(rets) X(retd) \
160 X(retsb) X(retub) X(retsh) X(retuh) \
161 X(retc) X(ret0) X(jmp) X(jnz) \
162 X(jfieq) X(jfine) X(jfisge) X(jfisgt) \
163 X(jfisle) X(jfislt) X(jfiuge) X(jfiugt) \
164 X(jfiule) X(jfiult) X(jffeq) X(jffge) \
165 X(jffgt) X(jffle) X(jfflt) X(jffne) \
166 X(jffo) X(jffuo) X(hlt)
191 #define INRANGE(x, l, u) ((unsigned)(x) - l <= u - l) /* linear in x */
192 #define isstore(o) INRANGE(o, Ostoreb, Ostored)
193 #define isload(o) INRANGE(o, Oloadsb, Oload)
194 #define isext(o) INRANGE(o, Oextsb, Oextuw)
195 #define ispar(o) INRANGE(o, Opar, Opare)
196 #define isarg(o) INRANGE(o, Oarg, Oargv)
197 #define isret(j) INRANGE(j, Jretw, Jret0)
198 #define isparbh(o) INRANGE(o, Oparsb, Oparuh)
199 #define isargbh(o) INRANGE(o, Oargsb, Oarguh)
200 #define isretbh(j) INRANGE(j, Jretsb, Jretuh)
203 Kx
= -1, /* "top" class (see usecheck() and clsmerge()) */
210 #define KWIDE(k) ((k)&1)
211 #define KBASE(k) ((k)>>1)
257 BSet in
[1], out
[1], gen
[1];
300 ALoc
= 1, /* stack local */
302 AEsc
= 3, /* stack escaping */
305 #define astack(t) ((t) & 1)
312 int sz
; /* -1 if > NBit */
324 uint bid
; /* id of a defining block */
326 int slot
; /* -1 for unset */
329 int r
; /* register or -1 */
331 bits m
; /* avoid these registers */
337 Wsb
, /* must match Oload/Oext order */
359 char flt
; /* 1 to print as s, 2 to print as d */
362 typedef struct Addr Addr
;
364 struct Addr
{ /* amd64 addressing */
389 int retty
; /* index in typ[], -1 if no aggregate return */
419 uint len
; /* or index in typ[] for FTyp */
420 } (*fields
)[NField
+1];
451 extern char debug
['Z'+1];
455 PHeap
, /* free() necessary */
456 PFn
, /* discarded after processing the function */
460 extern Ins insb
[NIns
], *curi
;
461 uint32_t hash(char *);
462 void die_(char *, char *, ...) __attribute__((noreturn
));
463 void *emalloc(size_t);
466 void *vnew(ulong
, size_t, Pool
);
468 void vgrow(void *, ulong
);
469 void strf(char[NString
], char *, ...);
470 uint32_t intern(char *);
472 int argcls(Ins
*, int);
474 int iscmp(int, int *, int *);
475 void emit(int, int, Ref
, Ref
, Ref
);
477 void idup(Ins
**, Ins
*, ulong
);
478 Ins
*icpy(Ins
*, Ins
*, ulong
);
481 int clsmerge(short *, short);
482 int phicls(int, Tmp
*);
483 Ref
newtmp(char *, int, Fn
*);
484 void chuse(Ref
, int, Fn
*);
486 Ref
newcon(Con
*, Fn
*);
487 Ref
getcon(int64_t, Fn
*);
488 int addcon(Con
*, Con
*, int);
489 void salloc(Ref
, Ref
, Fn
*);
490 void dumpts(BSet
*, Tmp
*, FILE *);
491 void runmatch(uchar
*, Num
*, Ref
, Ref
*);
493 void bsinit(BSet
*, uint
);
495 uint
bscount(BSet
*);
496 void bsset(BSet
*, uint
);
497 void bsclr(BSet
*, uint
);
498 void bscopy(BSet
*, BSet
*);
499 void bsunion(BSet
*, BSet
*);
500 void bsinter(BSet
*, BSet
*);
501 void bsdiff(BSet
*, BSet
*);
502 int bsequal(BSet
*, BSet
*);
503 int bsiter(BSet
*, int *);
506 bshas(BSet
*bs
, uint elt
)
508 assert(elt
< bs
->nt
* NBit
);
509 return (bs
->t
[elt
/NBit
] & BIT(elt
%NBit
)) != 0;
513 extern Op optab
[NOp
];
514 void parse(FILE *, char *, void (char *), void (Dat
*), void (Fn
*));
515 void printfn(Fn
*, FILE *);
516 void printref(Ref
, Fn
*, FILE *);
517 void err(char *, ...) __attribute__((noreturn
));
524 void edgedel(Blk
*, Blk
**);
525 void fillpreds(Fn
*);
528 int sdom(Blk
*, Blk
*);
529 int dom(Blk
*, Blk
*);
531 void loopiter(Fn
*, void (*)(Blk
*, Blk
*));
540 void fillalias(Fn
*);
541 void getalias(Alias
*, Ref
, Fn
*);
542 int alias(Ref
, int, int, Ref
, int, int *, Fn
*);
543 int escapes(Ref
, Fn
*);
565 void liveon(BSet
*, Blk
*, Blk
*);
576 void emitfnlnk(char *, Lnk
*, FILE *);
577 void emitdat(Dat
*, FILE *);
578 void emitdbgfile(char *, FILE *);
579 void emitdbgloc(uint
, uint
, FILE *);
580 int stashbits(void *, int);
581 void elf_emitfnfin(char *, FILE *);
582 void elf_emitfin(FILE *);
583 void macho_emitfin(FILE *);