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)
218 uint idval
:1; /* identity value 0/1 */
259 BSet in
[1], out
[1], gen
[1];
302 ALoc
= 1, /* stack local */
304 AEsc
= 3, /* stack escaping */
307 #define astack(t) ((t) & 1)
314 int sz
; /* -1 if > NBit */
326 uint bid
; /* id of a defining block */
328 int slot
; /* -1 for unset */
331 int r
; /* register or -1 */
333 bits m
; /* avoid these registers */
339 Wsb
, /* must match Oload/Oext order */
361 char flt
; /* 1 to print as s, 2 to print as d */
364 typedef struct Addr Addr
;
366 struct Addr
{ /* amd64 addressing */
391 int retty
; /* index in typ[], -1 if no aggregate return */
421 uint len
; /* or index in typ[] for FTyp */
422 } (*fields
)[NField
+1];
453 extern char debug
['Z'+1];
457 PHeap
, /* free() necessary */
458 PFn
, /* discarded after processing the function */
462 extern Ins insb
[NIns
], *curi
;
463 uint32_t hash(char *);
464 void die_(char *, char *, ...) __attribute__((noreturn
));
465 void *emalloc(size_t);
468 void *vnew(ulong
, size_t, Pool
);
470 void vgrow(void *, ulong
);
471 void strf(char[NString
], char *, ...);
472 uint32_t intern(char *);
474 int argcls(Ins
*, int);
476 int iscmp(int, int *, int *);
477 void emit(int, int, Ref
, Ref
, Ref
);
479 void idup(Ins
**, Ins
*, ulong
);
480 Ins
*icpy(Ins
*, Ins
*, ulong
);
483 int clsmerge(short *, short);
484 int phicls(int, Tmp
*);
485 Ref
newtmp(char *, int, Fn
*);
486 void chuse(Ref
, int, Fn
*);
488 Ref
newcon(Con
*, Fn
*);
489 Ref
getcon(int64_t, Fn
*);
490 int addcon(Con
*, Con
*, int);
491 void salloc(Ref
, Ref
, Fn
*);
492 void dumpts(BSet
*, Tmp
*, FILE *);
493 void runmatch(uchar
*, Num
*, Ref
, Ref
*);
495 void bsinit(BSet
*, uint
);
497 uint
bscount(BSet
*);
498 void bsset(BSet
*, uint
);
499 void bsclr(BSet
*, uint
);
500 void bscopy(BSet
*, BSet
*);
501 void bsunion(BSet
*, BSet
*);
502 void bsinter(BSet
*, BSet
*);
503 void bsdiff(BSet
*, BSet
*);
504 int bsequal(BSet
*, BSet
*);
505 int bsiter(BSet
*, int *);
508 bshas(BSet
*bs
, uint elt
)
510 assert(elt
< bs
->nt
* NBit
);
511 return (bs
->t
[elt
/NBit
] & BIT(elt
%NBit
)) != 0;
515 extern Op optab
[NOp
];
516 void parse(FILE *, char *, void (char *), void (Dat
*), void (Fn
*));
517 void printfn(Fn
*, FILE *);
518 void printref(Ref
, Fn
*, FILE *);
519 void err(char *, ...) __attribute__((noreturn
));
526 void edgedel(Blk
*, Blk
**);
527 void fillpreds(Fn
*);
530 int sdom(Blk
*, Blk
*);
531 int dom(Blk
*, Blk
*);
533 void loopiter(Fn
*, void (*)(Blk
*, Blk
*));
542 void fillalias(Fn
*);
543 void getalias(Alias
*, Ref
, Fn
*);
544 int alias(Ref
, int, int, Ref
, int, int *, Fn
*);
545 int escapes(Ref
, Fn
*);
567 void liveon(BSet
*, Blk
*, Blk
*);
578 void emitfnlnk(char *, Lnk
*, FILE *);
579 void emitdat(Dat
*, FILE *);
580 void emitdbgfile(char *, FILE *);
581 void emitdbgloc(uint
, uint
, FILE *);
582 int stashbits(void *, int);
583 void elf_emitfnfin(char *, FILE *);
584 void elf_emitfin(FILE *);
585 void macho_emitfin(FILE *);