gc.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 "../5c/5.out.h"
  11. /*
  12. * 5c/arm
  13. * Arm
  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. #define BTRUE 0x1000
  25. typedef struct Adr Adr;
  26. typedef struct Prog Prog;
  27. typedef struct Case Case;
  28. typedef struct C1 C1;
  29. typedef struct Multab Multab;
  30. typedef struct Hintab Hintab;
  31. typedef struct Var Var;
  32. typedef struct Reg Reg;
  33. typedef struct Rgn Rgn;
  34. #define R0ISZERO 0
  35. struct Adr
  36. {
  37. long offset;
  38. double dval;
  39. char sval[NSNAME];
  40. Ieee ieee;
  41. Sym* sym;
  42. char type;
  43. char reg;
  44. char name;
  45. char etype;
  46. };
  47. #define A ((Adr*)0)
  48. #define INDEXED 9
  49. struct Prog
  50. {
  51. Adr from;
  52. Adr to;
  53. Prog* link;
  54. long lineno;
  55. char as;
  56. char reg;
  57. uchar scond;
  58. };
  59. #define P ((Prog*)0)
  60. struct Case
  61. {
  62. Case* link;
  63. vlong val;
  64. long label;
  65. char def;
  66. char isv;
  67. };
  68. #define C ((Case*)0)
  69. struct C1
  70. {
  71. vlong val;
  72. long label;
  73. };
  74. struct Multab
  75. {
  76. long val;
  77. char code[20];
  78. };
  79. struct Hintab
  80. {
  81. ushort val;
  82. char hint[10];
  83. };
  84. struct Var
  85. {
  86. long offset;
  87. Sym* sym;
  88. char name;
  89. char etype;
  90. };
  91. struct Reg
  92. {
  93. long pc;
  94. long rpo; /* reverse post ordering */
  95. Bits set;
  96. Bits use1;
  97. Bits use2;
  98. Bits refbehind;
  99. Bits refahead;
  100. Bits calbehind;
  101. Bits calahead;
  102. Bits regdiff;
  103. Bits act;
  104. long regu;
  105. long loop; /* could be shorter */
  106. Reg* log5;
  107. long active;
  108. Reg* p1;
  109. Reg* p2;
  110. Reg* p2link;
  111. Reg* s1;
  112. Reg* s2;
  113. Reg* link;
  114. Prog* prog;
  115. };
  116. #define R ((Reg*)0)
  117. #define NRGN 1000 /* was 600; raised for paranoia.c */
  118. struct Rgn
  119. {
  120. Reg* enter;
  121. short cost;
  122. short varno;
  123. short regno;
  124. };
  125. EXTERN long breakpc;
  126. EXTERN long nbreak;
  127. EXTERN Case* cases;
  128. EXTERN Node constnode;
  129. EXTERN Node fconstnode;
  130. EXTERN long continpc;
  131. EXTERN long curarg;
  132. EXTERN long cursafe;
  133. EXTERN Prog* firstp;
  134. EXTERN Prog* lastp;
  135. EXTERN long maxargsafe;
  136. EXTERN int mnstring;
  137. EXTERN Multab multab[20];
  138. EXTERN int hintabsize;
  139. EXTERN Node* nodrat;
  140. EXTERN Node* nodret;
  141. EXTERN Node* nodsafe;
  142. EXTERN long nrathole;
  143. EXTERN long nstring;
  144. EXTERN Prog* p;
  145. EXTERN long pc;
  146. EXTERN Node regnode;
  147. EXTERN char string[NSNAME];
  148. EXTERN Sym* symrathole;
  149. EXTERN Node znode;
  150. EXTERN Prog zprog;
  151. EXTERN char reg[NREG+NFREG];
  152. EXTERN long exregoffset;
  153. EXTERN long exfregoffset;
  154. EXTERN int suppress;
  155. #define BLOAD(r) band(bnot(r->refbehind), r->refahead)
  156. #define BSTORE(r) band(bnot(r->calbehind), r->calahead)
  157. #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z])
  158. #define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z])
  159. #define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32))
  160. #define CLOAD 4
  161. #define CREF 5
  162. #define CINF 1000
  163. #define LOOP 3
  164. EXTERN Rgn region[NRGN];
  165. EXTERN Rgn* rgp;
  166. EXTERN int nregion;
  167. EXTERN int nvar;
  168. EXTERN Bits externs;
  169. EXTERN Bits params;
  170. EXTERN Bits consts;
  171. EXTERN Bits addrs;
  172. EXTERN long regbits;
  173. EXTERN long exregbits;
  174. EXTERN int change;
  175. EXTERN Reg* firstr;
  176. EXTERN Reg* lastr;
  177. EXTERN Reg zreg;
  178. EXTERN Reg* freer;
  179. EXTERN Var var[NVAR];
  180. EXTERN long* idom;
  181. EXTERN Reg** rpo2r;
  182. EXTERN long maxnr;
  183. extern char* anames[];
  184. extern Hintab hintab[];
  185. /*
  186. * sgen.c
  187. */
  188. void codgen(Node*, Node*);
  189. void gen(Node*);
  190. void noretval(int);
  191. void usedset(Node*, int);
  192. void xcom(Node*);
  193. int bcomplex(Node*, Node*);
  194. /*
  195. * cgen.c
  196. */
  197. void cgen(Node*, Node*);
  198. void cgenrel(Node*, Node*, int);
  199. void reglcgen(Node*, Node*, Node*);
  200. void lcgen(Node*, Node*);
  201. void bcgen(Node*, int);
  202. void boolgen(Node*, int, Node*);
  203. void sugen(Node*, Node*, long);
  204. void layout(Node*, Node*, int, int, Node*);
  205. /*
  206. * txt.c
  207. */
  208. void ginit(void);
  209. void gclean(void);
  210. void nextpc(void);
  211. void gargs(Node*, Node*, Node*);
  212. void garg1(Node*, Node*, Node*, int, Node**);
  213. Node* nodconst(long);
  214. Node* nod32const(vlong);
  215. Node* nodfconst(double);
  216. void nodreg(Node*, Node*, int);
  217. void regret(Node*, Node*);
  218. int tmpreg(void);
  219. void regalloc(Node*, Node*, Node*);
  220. void regfree(Node*);
  221. void regialloc(Node*, Node*, Node*);
  222. void regsalloc(Node*, Node*);
  223. void regaalloc1(Node*, Node*);
  224. void regaalloc(Node*, Node*);
  225. void regind(Node*, Node*);
  226. void gprep(Node*, Node*);
  227. void raddr(Node*, Prog*);
  228. void naddr(Node*, Adr*);
  229. void gmovm(Node*, Node*, int);
  230. void gmove(Node*, Node*);
  231. void gmover(Node*, Node*);
  232. void gins(int a, Node*, Node*);
  233. void gopcode(int, Node*, Node*, Node*);
  234. int samaddr(Node*, Node*);
  235. void gbranch(int);
  236. void patch(Prog*, long);
  237. int sconst(Node*);
  238. int sval(long);
  239. void gpseudo(int, Sym*, Node*);
  240. /*
  241. * swt.c
  242. */
  243. int swcmp(const void*, const void*);
  244. void doswit(Node*);
  245. void swit1(C1*, int, long, Node*);
  246. void swit2(C1*, int, long, Node*, Node*);
  247. void casf(void);
  248. void bitload(Node*, Node*, Node*, Node*, Node*);
  249. void bitstore(Node*, Node*, Node*, Node*, Node*);
  250. long outstring(char*, long);
  251. int mulcon(Node*, Node*);
  252. Multab* mulcon0(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 Nconv(Fmt*);
  266. int Bconv(Fmt*);
  267. int Rconv(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(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 regzer(Adr*);
  293. int anyvar(Adr*);
  294. int subprop(Reg*);
  295. int copyprop(Reg*);
  296. int shiftprop(Reg*);
  297. void constprop(Adr*, Adr*, Reg*);
  298. int copy1(Adr*, Adr*, Reg*, int);
  299. int copyu(Prog*, Adr*, Adr*);
  300. int copyas(Adr*, Adr*);
  301. int copyau(Adr*, Adr*);
  302. int copyau1(Prog*, Adr*);
  303. int copysub(Adr*, Adr*, Adr*, int);
  304. int copysub1(Prog*, Adr*, Adr*, int);
  305. long RtoB(int);
  306. long FtoB(int);
  307. int BtoR(long);
  308. int BtoF(long);
  309. void predicate(void);
  310. int isbranch(Prog *);
  311. int predicable(Prog *p);
  312. int modifiescpsr(Prog *p);
  313. #pragma varargck type "A" int
  314. #pragma varargck type "B" Bits
  315. #pragma varargck type "D" Adr*
  316. #pragma varargck type "N" Adr*
  317. #pragma varargck type "R" Adr*
  318. #pragma varargck type "P" Prog*
  319. #pragma varargck type "S" char*