gc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 "../kc/k.out.h"
  11. /*
  12. * kc/sparc
  13. * Sun sparc
  14. */
  15. #define SZ_CHAR 1
  16. #define SZ_SHORT 2
  17. #define SZ_INT 4
  18. #define SZ_LONG 4
  19. #define SZ_VLONG 8
  20. #define SZ_IND 4
  21. #define SZ_FLOAT 4
  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 Multab Multab;
  29. typedef struct Hintab Hintab;
  30. typedef struct Var Var;
  31. typedef struct Reg Reg;
  32. typedef struct Rgn Rgn;
  33. struct Adr
  34. {
  35. long offset;
  36. double dval;
  37. char sval[NSNAME];
  38. Sym* sym;
  39. char type;
  40. char reg;
  41. char name;
  42. char etype;
  43. };
  44. #define A ((Adr*)0)
  45. #define INDEXED 9
  46. struct Prog
  47. {
  48. Adr from;
  49. Adr to;
  50. Prog* link;
  51. long lineno;
  52. short as;
  53. char reg;
  54. };
  55. #define P ((Prog*)0)
  56. struct Case
  57. {
  58. Case* link;
  59. vlong val;
  60. long label;
  61. char def;
  62. char isv;
  63. };
  64. #define C ((Case*)0)
  65. struct C1
  66. {
  67. vlong val;
  68. long label;
  69. };
  70. struct Multab
  71. {
  72. long val;
  73. char code[20];
  74. };
  75. struct Hintab
  76. {
  77. ushort val;
  78. char hint[10];
  79. };
  80. struct Var
  81. {
  82. long offset;
  83. Sym* sym;
  84. char name;
  85. char etype;
  86. };
  87. struct Reg
  88. {
  89. long pc;
  90. long rpo; /* reverse post ordering */
  91. Bits set;
  92. Bits use1;
  93. Bits use2;
  94. Bits refbehind;
  95. Bits refahead;
  96. Bits calbehind;
  97. Bits calahead;
  98. Bits regdiff;
  99. Bits act;
  100. long regu;
  101. long loop; /* could be shorter */
  102. Reg* log5;
  103. long active;
  104. Reg* p1;
  105. Reg* p2;
  106. Reg* p2link;
  107. Reg* s1;
  108. Reg* s2;
  109. Reg* link;
  110. Prog* prog;
  111. };
  112. #define R ((Reg*)0)
  113. #define NRGN 600
  114. struct Rgn
  115. {
  116. Reg* enter;
  117. short cost;
  118. short varno;
  119. short regno;
  120. };
  121. EXTERN long breakpc;
  122. EXTERN long nbreak;
  123. EXTERN Case* cases;
  124. EXTERN Node constnode;
  125. EXTERN Node fconstnode;
  126. EXTERN long continpc;
  127. EXTERN long curarg;
  128. EXTERN long cursafe;
  129. EXTERN Prog* firstp;
  130. EXTERN Prog* lastp;
  131. EXTERN int hintabsize;
  132. EXTERN long maxargsafe;
  133. EXTERN Multab multab[20];
  134. EXTERN int mnstring;
  135. EXTERN Node* nodrat;
  136. EXTERN Node* nodret;
  137. EXTERN Node* nodsafe;
  138. EXTERN long nrathole;
  139. EXTERN long nstring;
  140. EXTERN Prog* p;
  141. EXTERN long pc;
  142. EXTERN Node regnode;
  143. EXTERN char string[NSNAME];
  144. EXTERN Sym* symrathole;
  145. EXTERN Node znode;
  146. EXTERN Prog zprog;
  147. EXTERN char reg[NREG+NREG];
  148. EXTERN long exregoffset;
  149. EXTERN long exfregoffset;
  150. #define BLOAD(r) band(bnot(r->refbehind), r->refahead)
  151. #define BSTORE(r) band(bnot(r->calbehind), r->calahead)
  152. #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z])
  153. #define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z])
  154. #define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32))
  155. #define CLOAD 5
  156. #define CREF 5
  157. #define CINF 1000
  158. #define LOOP 3
  159. EXTERN Rgn region[NRGN];
  160. EXTERN Rgn* rgp;
  161. EXTERN int nregion;
  162. EXTERN int nvar;
  163. EXTERN Bits externs;
  164. EXTERN Bits params;
  165. EXTERN Bits consts;
  166. EXTERN Bits addrs;
  167. EXTERN long regbits;
  168. EXTERN long exregbits;
  169. EXTERN int change;
  170. EXTERN int suppress;
  171. EXTERN Reg* firstr;
  172. EXTERN Reg* lastr;
  173. EXTERN Reg zreg;
  174. EXTERN Reg* freer;
  175. EXTERN Var var[NVAR];
  176. EXTERN long* idom;
  177. EXTERN Reg** rpo2r;
  178. EXTERN long maxnr;
  179. extern char* anames[];
  180. extern Hintab hintab[];
  181. /*
  182. * sgen.c
  183. */
  184. void codgen(Node*, Node*);
  185. void gen(Node*);
  186. void usedset(Node*, int);
  187. void noretval(int);
  188. void xcom(Node*);
  189. int bcomplex(Node*, Node*);
  190. /*
  191. * cgen.c
  192. */
  193. void cgen(Node*, Node*);
  194. void reglcgen(Node*, Node*, Node*);
  195. void lcgen(Node*, Node*);
  196. void bcgen(Node*, int);
  197. void boolgen(Node*, int, Node*);
  198. void sugen(Node*, Node*, long);
  199. void layout(Node*, Node*, int, int, Node*);
  200. /*
  201. * txt.c
  202. */
  203. void ginit(void);
  204. void gclean(void);
  205. void nextpc(void);
  206. void gargs(Node*, Node*, Node*);
  207. void garg1(Node*, Node*, Node*, int, Node**);
  208. Node* nodconst(long);
  209. Node* nod32const(vlong);
  210. Node* nodfconst(double);
  211. void nodreg(Node*, Node*, int);
  212. void regret(Node*, Node*);
  213. void regalloc(Node*, Node*, Node*);
  214. void regfree(Node*);
  215. void regialloc(Node*, Node*, Node*);
  216. void regsalloc(Node*, Node*);
  217. void regaalloc1(Node*, Node*);
  218. void regaalloc(Node*, Node*);
  219. void regind(Node*, Node*);
  220. void gprep(Node*, Node*);
  221. void raddr(Node*, Prog*);
  222. void naddr(Node*, Adr*);
  223. void gmove(Node*, Node*);
  224. void gins(int a, Node*, Node*);
  225. void gopcode(int, Node*, Node*, Node*);
  226. int samaddr(Node*, Node*);
  227. void gbranch(int);
  228. void patch(Prog*, long);
  229. int sconst(Node*);
  230. int sval(long);
  231. void gpseudo(int, Sym*, Node*);
  232. /*
  233. * swt.c
  234. */
  235. int swcmp(const void*, const void*);
  236. void doswit(Node*);
  237. void swit1(C1*, int, long, Node*);
  238. void swit2(C1*, int, long, Node*, Node*);
  239. void casf(void);
  240. void bitload(Node*, Node*, Node*, Node*, Node*);
  241. void bitstore(Node*, Node*, Node*, Node*, Node*);
  242. long outstring(char*, long);
  243. int mulcon(Node*, Node*);
  244. Multab* mulcon0(Node*, long);
  245. int mulcon1(Node*, long, Node*);
  246. void nullwarn(Node*, Node*);
  247. void gextern(Sym*, Node*, long, long);
  248. void outcode(void);
  249. void ieeedtod(Ieee*, double);
  250. /*
  251. * list
  252. */
  253. void listinit(void);
  254. int Pconv(Fmt*);
  255. int Aconv(Fmt*);
  256. int Dconv(Fmt*);
  257. int Sconv(Fmt*);
  258. int Nconv(Fmt*);
  259. int Bconv(Fmt*);
  260. /*
  261. * reg.c
  262. */
  263. Reg* rega(void);
  264. int rcmp(const void*, const void*);
  265. void regopt(Prog*);
  266. void addmove(Reg*, int, int, int);
  267. Bits mkvar(Adr*, int);
  268. void prop(Reg*, Bits, Bits);
  269. void loopit(Reg*, long);
  270. void synch(Reg*, Bits);
  271. uint32_t allreg(uint32_t, Rgn*);
  272. void paint1(Reg*, int);
  273. uint32_t paint2(Reg*, int);
  274. void paint3(Reg*, int, long, int);
  275. void addreg(Adr*, int);
  276. /*
  277. * peep.c
  278. */
  279. void peep(void);
  280. void excise(Reg*);
  281. Reg* uniqp(Reg*);
  282. Reg* uniqs(Reg*);
  283. int regtyp(Adr*);
  284. int regzer(Adr*);
  285. int anyvar(Adr*);
  286. int subprop(Reg*);
  287. int copyprop(Reg*);
  288. int copy1(Adr*, Adr*, Reg*, int);
  289. int copyu(Prog*, Adr*, Adr*);
  290. int copyas(Adr*, Adr*);
  291. int copyau(Adr*, Adr*);
  292. int copyau1(Prog*, Adr*);
  293. int copysub(Adr*, Adr*, Adr*, int);
  294. int copysub1(Prog*, Adr*, Adr*, int);
  295. long RtoB(int);
  296. long FtoB(int);
  297. int BtoR(long);
  298. int BtoF(long);
  299. /*
  300. * com64.c
  301. */
  302. int com64(Node*);
  303. void com64init(void);
  304. void bool64(Node*);
  305. #pragma varargck type "A" int
  306. #pragma varargck type "B" Bits
  307. #pragma varargck type "D" Adr*
  308. #pragma varargck type "N" Adr*
  309. #pragma varargck type "P" Prog*
  310. #pragma varargck type "S" char*