gc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "../cc/cc.h"
  10. #include "../8c/8.out.h"
  11. /*
  12. * 8c/386
  13. * Intel 386
  14. */
  15. #define SZ_CHAR 1
  16. #define SZ_SHORT 2
  17. #define SZ_INT 4
  18. #define SZ_LONG 4
  19. #define SZ_IND 4
  20. #define SZ_FLOAT 4
  21. #define SZ_VLONG 8
  22. #define SZ_DOUBLE 8
  23. #define FNX 100
  24. typedef struct Adr Adr;
  25. typedef struct Prog Prog;
  26. typedef struct Case Case;
  27. typedef struct C1 C1;
  28. typedef struct Var Var;
  29. typedef struct Reg Reg;
  30. typedef struct Rgn Rgn;
  31. typedef struct Renv Renv;
  32. EXTERN struct
  33. {
  34. Node* regtree;
  35. Node* basetree;
  36. short scale;
  37. short reg;
  38. short ptr;
  39. } idx;
  40. struct Adr
  41. {
  42. long offset;
  43. double dval;
  44. char sval[NSNAME];
  45. Sym* sym;
  46. uchar type;
  47. uchar index;
  48. uchar etype;
  49. uchar scale; /* doubles as width in DATA op */
  50. };
  51. #define A ((Adr*)0)
  52. #define INDEXED 9
  53. struct Prog
  54. {
  55. Adr from;
  56. Adr to;
  57. Prog* link;
  58. long lineno;
  59. short as;
  60. };
  61. #define P ((Prog*)0)
  62. struct Case
  63. {
  64. Case* link;
  65. vlong val;
  66. long label;
  67. char def;
  68. char isv;
  69. };
  70. #define C ((Case*)0)
  71. struct C1
  72. {
  73. vlong val;
  74. long label;
  75. };
  76. struct Var
  77. {
  78. long offset;
  79. Sym* sym;
  80. char name;
  81. char etype;
  82. };
  83. struct Reg
  84. {
  85. long pc;
  86. long rpo; /* reverse post ordering */
  87. Bits set;
  88. Bits use1;
  89. Bits use2;
  90. Bits refbehind;
  91. Bits refahead;
  92. Bits calbehind;
  93. Bits calahead;
  94. Bits regdiff;
  95. Bits act;
  96. long regu;
  97. long loop; /* could be shorter */
  98. Reg* log5;
  99. long active;
  100. Reg* p1;
  101. Reg* p2;
  102. Reg* p2link;
  103. Reg* s1;
  104. Reg* s2;
  105. Reg* link;
  106. Prog* prog;
  107. };
  108. #define R ((Reg*)0)
  109. struct Renv
  110. {
  111. int safe;
  112. Node base;
  113. Node* saved;
  114. Node* scope;
  115. };
  116. #define NRGN 600
  117. struct Rgn
  118. {
  119. Reg* enter;
  120. short cost;
  121. short varno;
  122. short regno;
  123. };
  124. EXTERN long breakpc;
  125. EXTERN long nbreak;
  126. EXTERN Case* cases;
  127. EXTERN Node constnode;
  128. EXTERN Node fconstnode;
  129. EXTERN long continpc;
  130. EXTERN long curarg;
  131. EXTERN long cursafe;
  132. EXTERN Prog* firstp;
  133. EXTERN Prog* lastp;
  134. EXTERN long maxargsafe;
  135. EXTERN int mnstring;
  136. EXTERN Node* nodrat;
  137. EXTERN Node* nodret;
  138. EXTERN Node* nodsafe;
  139. EXTERN long nrathole;
  140. EXTERN long nstring;
  141. EXTERN Prog* p;
  142. EXTERN long pc;
  143. EXTERN Node regnode;
  144. EXTERN Node fregnode0;
  145. EXTERN Node fregnode1;
  146. EXTERN char string[NSNAME];
  147. EXTERN Sym* symrathole;
  148. EXTERN Node znode;
  149. EXTERN Prog zprog;
  150. EXTERN int reg[D_NONE];
  151. EXTERN long exregoffset;
  152. EXTERN long exfregoffset;
  153. #define BLOAD(r) band(bnot(r->refbehind), r->refahead)
  154. #define BSTORE(r) band(bnot(r->calbehind), r->calahead)
  155. #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z])
  156. #define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z])
  157. #define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32))
  158. #define CLOAD 5
  159. #define CREF 5
  160. #define CINF 1000
  161. #define LOOP 3
  162. EXTERN Rgn region[NRGN];
  163. EXTERN Rgn* rgp;
  164. EXTERN int nregion;
  165. EXTERN int nvar;
  166. EXTERN Bits externs;
  167. EXTERN Bits params;
  168. EXTERN Bits consts;
  169. EXTERN Bits addrs;
  170. EXTERN long regbits;
  171. EXTERN long exregbits;
  172. EXTERN int change;
  173. EXTERN int suppress;
  174. EXTERN Reg* firstr;
  175. EXTERN Reg* lastr;
  176. EXTERN Reg zreg;
  177. EXTERN Reg* freer;
  178. EXTERN Var var[NVAR];
  179. EXTERN long* idom;
  180. EXTERN Reg** rpo2r;
  181. EXTERN long maxnr;
  182. extern char* anames[];
  183. /*
  184. * sgen.c
  185. */
  186. void codgen(Node*, Node*);
  187. void gen(Node*);
  188. void noretval(int);
  189. void usedset(Node*, int);
  190. void xcom(Node*);
  191. void indx(Node*);
  192. int bcomplex(Node*, Node*);
  193. /*
  194. * cgen.c
  195. */
  196. void zeroregm(Node*);
  197. void cgen(Node*, Node*);
  198. void reglcgen(Node*, Node*, Node*);
  199. void lcgen(Node*, Node*);
  200. void bcgen(Node*, int);
  201. void boolgen(Node*, int, Node*);
  202. void sugen(Node*, Node*, long);
  203. int needreg(Node*, int);
  204. /*
  205. * cgen64.c
  206. */
  207. int vaddr(Node*, int);
  208. void loadpair(Node*, Node*);
  209. int cgen64(Node*, Node*);
  210. void testv(Node*, int);
  211. /*
  212. * txt.c
  213. */
  214. void ginit(void);
  215. void gclean(void);
  216. void nextpc(void);
  217. void gargs(Node*, Node*, Node*);
  218. void garg1(Node*, Node*, Node*, int, Node**);
  219. Node* nodconst(long);
  220. int nareg(int);
  221. Node* nodfconst(double);
  222. int nodreg(Node*, Node*, int);
  223. int isreg(Node*, int);
  224. void regret(Node*, Node*);
  225. void regalloc(Node*, Node*, Node*);
  226. void regfree(Node*);
  227. void regialloc(Node*, Node*, Node*);
  228. void regsalloc(Node*, Node*);
  229. void regaalloc1(Node*, Node*);
  230. void regaalloc(Node*, Node*);
  231. void regind(Node*, Node*);
  232. void gprep(Node*, Node*);
  233. void naddr(Node*, Adr*);
  234. void gmove(Node*, Node*);
  235. void gins(int a, Node*, Node*);
  236. void fgopcode(int, Node*, Node*, int, int);
  237. void gopcode(int, Type*, Node*, Node*);
  238. int samaddr(Node*, Node*);
  239. void gbranch(int);
  240. void patch(Prog*, long);
  241. int sconst(Node*);
  242. void gpseudo(int, Sym*, Node*);
  243. /*
  244. * swt.c
  245. */
  246. int swcmp(const void*, const void*);
  247. void doswit(Node*);
  248. void swit1(C1*, int, long, Node*);
  249. void casf(void);
  250. void bitload(Node*, Node*, Node*, Node*, Node*);
  251. void bitstore(Node*, Node*, Node*, Node*, Node*);
  252. long outstring(char*, long);
  253. void nullwarn(Node*, Node*);
  254. void gextern(Sym*, Node*, long, long);
  255. void outcode(void);
  256. void ieeedtod(Ieee*, double);
  257. /*
  258. * list
  259. */
  260. void listinit(void);
  261. int Pconv(Fmt*);
  262. int Aconv(Fmt*);
  263. int Dconv(Fmt*);
  264. int Sconv(Fmt*);
  265. int Rconv(Fmt*);
  266. int Xconv(Fmt*);
  267. int Bconv(Fmt*);
  268. /*
  269. * reg.c
  270. */
  271. Reg* rega(void);
  272. int rcmp(const void*, const void*);
  273. void regopt(Prog*);
  274. void addmove(Reg*, int, int, int);
  275. Bits mkvar(Reg*, Adr*, int);
  276. void prop(Reg*, Bits, Bits);
  277. void loopit(Reg*, long);
  278. void synch(Reg*, Bits);
  279. uint32_t allreg(uint32_t, Rgn*);
  280. void paint1(Reg*, int);
  281. uint32_t paint2(Reg*, int);
  282. void paint3(Reg*, int, long, int);
  283. void addreg(Adr*, int);
  284. /*
  285. * peep.c
  286. */
  287. void peep(void);
  288. void excise(Reg*);
  289. Reg* uniqp(Reg*);
  290. Reg* uniqs(Reg*);
  291. int regtyp(Adr*);
  292. int anyvar(Adr*);
  293. int subprop(Reg*);
  294. int copyprop(Reg*);
  295. int copy1(Adr*, Adr*, Reg*, int);
  296. int copyu(Prog*, Adr*, Adr*);
  297. int copyas(Adr*, Adr*);
  298. int copyau(Adr*, Adr*);
  299. int copysub(Adr*, Adr*, Adr*, int);
  300. int copysub1(Prog*, Adr*, Adr*, int);
  301. long RtoB(int);
  302. long FtoB(int);
  303. int BtoR(long);
  304. int BtoF(long);
  305. #define D_HI D_NONE
  306. #define D_LO D_NONE
  307. /*
  308. * com64
  309. */
  310. int cond(int);
  311. int com64(Node*);
  312. void com64init(void);
  313. void bool64(Node*);
  314. long lo64v(Node*);
  315. long hi64v(Node*);
  316. Node* lo64(Node*);
  317. Node* hi64(Node*);
  318. /*
  319. * div/mul
  320. */
  321. void sdivgen(Node*, Node*, Node*, Node*);
  322. void udivgen(Node*, Node*, Node*, Node*);
  323. void sdiv2(long, int, Node*, Node*);
  324. void smod2(long, int, Node*, Node*);
  325. void mulgen(Type*, Node*, Node*);
  326. void genmuladd(Node*, Node*, int, Node*);
  327. void shiftit(Type*, Node*, Node*);
  328. #pragma varargck type "A" int
  329. #pragma varargck type "B" Bits
  330. #pragma varargck type "D" Adr*
  331. #pragma varargck type "P" Prog*
  332. #pragma varargck type "R" int
  333. #pragma varargck type "S" char*
  334. /* wrecklessly steal a field */
  335. #define rplink label