github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/cmd/6c/gc.h (about) 1 // Inferno utils/6c/gc.h 2 // http://code.google.com/p/inferno-os/source/browse/utils/6c/gc.h 3 // 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 6 // Portions Copyright © 1997-1999 Vita Nuova Limited 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) 8 // Portions Copyright © 2004,2006 Bruce Ellis 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others 11 // Portions Copyright © 2009 The Go Authors. All rights reserved. 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a copy 14 // of this software and associated documentation files (the "Software"), to deal 15 // in the Software without restriction, including without limitation the rights 16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 // copies of the Software, and to permit persons to whom the Software is 18 // furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included in 21 // all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 // THE SOFTWARE. 30 31 #include <u.h> 32 #include "../cc/cc.h" 33 #include "../6l/6.out.h" 34 35 /* 36 * 6c/amd64 37 * Intel 386 with AMD64 extensions 38 */ 39 #define SZ_CHAR 1 40 #define SZ_SHORT 2 41 #define SZ_INT 4 42 #define SZ_LONG 4 43 #define SZ_IND 8 44 #define SZ_FLOAT 4 45 #define SZ_VLONG 8 46 #define SZ_DOUBLE 8 47 #define FNX 100 48 49 typedef struct Case Case; 50 typedef struct C1 C1; 51 typedef struct Reg Reg; 52 typedef struct Rgn Rgn; 53 typedef struct Renv Renv; 54 55 EXTERN struct 56 { 57 Node* regtree; 58 Node* basetree; 59 short scale; 60 short reg; 61 short ptr; 62 } idx; 63 64 #define INDEXED 9 65 66 #define A ((Addr*)0) 67 #define P ((Prog*)0) 68 69 struct Case 70 { 71 Case* link; 72 vlong val; 73 int32 label; 74 char def; 75 char isv; 76 }; 77 #define C ((Case*)0) 78 79 struct C1 80 { 81 vlong val; 82 int32 label; 83 }; 84 85 struct Reg 86 { 87 int32 pc; 88 int32 rpo; /* reverse post ordering */ 89 90 Bits set; 91 Bits use1; 92 Bits use2; 93 94 Bits refbehind; 95 Bits refahead; 96 Bits calbehind; 97 Bits calahead; 98 Bits regdiff; 99 Bits act; 100 101 int32 regu; 102 int32 loop; /* could be shorter */ 103 104 Reg* log5; 105 int32 active; 106 107 Reg* p1; 108 Reg* p2; 109 Reg* p2link; 110 Reg* s1; 111 Reg* s2; 112 Reg* link; 113 Prog* prog; 114 }; 115 #define R ((Reg*)0) 116 117 struct Renv 118 { 119 int safe; 120 Node base; 121 Node* saved; 122 Node* scope; 123 }; 124 125 #define NRGN 600 126 struct Rgn 127 { 128 Reg* enter; 129 short cost; 130 short varno; 131 short regno; 132 }; 133 134 EXTERN int32 breakpc; 135 EXTERN int32 nbreak; 136 EXTERN Case* cases; 137 EXTERN Node constnode; 138 EXTERN Node fconstnode; 139 EXTERN Node vconstnode; 140 EXTERN int32 continpc; 141 EXTERN int32 curarg; 142 EXTERN int32 cursafe; 143 EXTERN Prog* lastp; 144 EXTERN int32 maxargsafe; 145 EXTERN int mnstring; 146 EXTERN int retok; 147 EXTERN Node* nodrat; 148 EXTERN Node* nodret; 149 EXTERN Node* nodsafe; 150 EXTERN int32 nrathole; 151 EXTERN int32 nstring; 152 EXTERN Prog* p; 153 EXTERN int32 pc; 154 EXTERN Node lregnode; 155 EXTERN Node qregnode; 156 EXTERN char string[NSNAME]; 157 EXTERN Sym* symrathole; 158 EXTERN Node znode; 159 EXTERN Prog zprog; 160 EXTERN int reg[D_NONE]; 161 EXTERN int32 exregoffset; 162 EXTERN int32 exfregoffset; 163 EXTERN uchar typechlpv[NTYPE]; 164 165 #define BLOAD(r) band(bnot(r->refbehind), r->refahead) 166 #define BSTORE(r) band(bnot(r->calbehind), r->calahead) 167 #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z]) 168 #define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z]) 169 170 #define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32)) 171 172 #define CLOAD 5 173 #define CREF 5 174 #define CINF 1000 175 #define LOOP 3 176 177 EXTERN Rgn region[NRGN]; 178 EXTERN Rgn* rgp; 179 EXTERN int nregion; 180 EXTERN int nvar; 181 182 EXTERN Bits externs; 183 EXTERN Bits params; 184 EXTERN Bits consts; 185 EXTERN Bits addrs; 186 187 EXTERN int32 regbits; 188 EXTERN int32 exregbits; 189 190 EXTERN int change; 191 EXTERN int suppress; 192 193 EXTERN Reg* firstr; 194 EXTERN Reg* lastr; 195 EXTERN Reg zreg; 196 EXTERN Reg* freer; 197 EXTERN int32* idom; 198 EXTERN Reg** rpo2r; 199 EXTERN int32 maxnr; 200 201 extern char* anames[]; 202 203 /* 204 * sgen.c 205 */ 206 void codgen(Node*, Node*); 207 void gen(Node*); 208 void noretval(int); 209 void usedset(Node*, int); 210 void xcom(Node*); 211 void indx(Node*); 212 int bcomplex(Node*, Node*); 213 Prog* gtext(Sym*, int32); 214 vlong argsize(void); 215 216 /* 217 * cgen.c 218 */ 219 void zeroregm(Node*); 220 void cgen(Node*, Node*); 221 void reglcgen(Node*, Node*, Node*); 222 void lcgen(Node*, Node*); 223 void bcgen(Node*, int); 224 void boolgen(Node*, int, Node*); 225 void sugen(Node*, Node*, int32); 226 int needreg(Node*, int); 227 int hardconst(Node*); 228 int immconst(Node*); 229 230 /* 231 * txt.c 232 */ 233 void ginit(void); 234 void gclean(void); 235 void nextpc(void); 236 void gargs(Node*, Node*, Node*); 237 void garg1(Node*, Node*, Node*, int, Node**); 238 Node* nodconst(int32); 239 Node* nodfconst(double); 240 Node* nodgconst(vlong, Type*); 241 int nodreg(Node*, Node*, int); 242 int isreg(Node*, int); 243 void regret(Node*, Node*); 244 void regalloc(Node*, Node*, Node*); 245 void regfree(Node*); 246 void regialloc(Node*, Node*, Node*); 247 void regsalloc(Node*, Node*); 248 void regaalloc1(Node*, Node*); 249 void regaalloc(Node*, Node*); 250 void regind(Node*, Node*); 251 void gprep(Node*, Node*); 252 void naddr(Node*, Addr*); 253 void gcmp(int, Node*, vlong); 254 void gmove(Node*, Node*); 255 void gins(int a, Node*, Node*); 256 void gopcode(int, Type*, Node*, Node*); 257 int samaddr(Node*, Node*); 258 void gbranch(int); 259 void patch(Prog*, int32); 260 int sconst(Node*); 261 void gpseudo(int, Sym*, Node*); 262 void gprefetch(Node*); 263 void gpcdata(int, int); 264 265 /* 266 * swt.c 267 */ 268 int swcmp(const void*, const void*); 269 void doswit(Node*); 270 void swit1(C1*, int, int32, Node*); 271 void swit2(C1*, int, int32, Node*); 272 void newcase(void); 273 void bitload(Node*, Node*, Node*, Node*, Node*); 274 void bitstore(Node*, Node*, Node*, Node*, Node*); 275 int32 outstring(char*, int32); 276 void nullwarn(Node*, Node*); 277 void sextern(Sym*, Node*, int32, int32); 278 void gextern(Sym*, Node*, int32, int32); 279 void outcode(void); 280 281 /* 282 * list 283 */ 284 void listinit(void); 285 286 /* 287 * reg.c 288 */ 289 Reg* rega(void); 290 int rcmp(const void*, const void*); 291 void regopt(Prog*); 292 void addmove(Reg*, int, int, int); 293 Bits mkvar(Reg*, Addr*); 294 void prop(Reg*, Bits, Bits); 295 void loopit(Reg*, int32); 296 void synch(Reg*, Bits); 297 uint32 allreg(uint32, Rgn*); 298 void paint1(Reg*, int); 299 uint32 paint2(Reg*, int); 300 void paint3(Reg*, int, int32, int); 301 void addreg(Addr*, int); 302 303 /* 304 * peep.c 305 */ 306 void peep(void); 307 void excise(Reg*); 308 Reg* uniqp(Reg*); 309 Reg* uniqs(Reg*); 310 int regtyp(Addr*); 311 int anyvar(Addr*); 312 int subprop(Reg*); 313 int copyprop(Reg*); 314 int copy1(Addr*, Addr*, Reg*, int); 315 int copyu(Prog*, Addr*, Addr*); 316 317 int copyas(Addr*, Addr*); 318 int copyau(Addr*, Addr*); 319 int copysub(Addr*, Addr*, Addr*, int); 320 int copysub1(Prog*, Addr*, Addr*, int); 321 322 int32 RtoB(int); 323 int32 FtoB(int); 324 int BtoR(int32); 325 int BtoF(int32); 326 327 #define D_HI D_NONE 328 #define D_LO D_NONE 329 330 /* 331 * bound 332 */ 333 void comtarg(void); 334 335 /* 336 * com64 337 */ 338 int cond(int); 339 int com64(Node*); 340 void com64init(void); 341 void bool64(Node*); 342 int32 lo64v(Node*); 343 int32 hi64v(Node*); 344 Node* lo64(Node*); 345 Node* hi64(Node*); 346 347 /* 348 * div/mul 349 */ 350 void sdivgen(Node*, Node*, Node*, Node*); 351 void udivgen(Node*, Node*, Node*, Node*); 352 void sdiv2(int32, int, Node*, Node*); 353 void smod2(int32, int, Node*, Node*); 354 void mulgen(Type*, Node*, Node*); 355 void genmuladd(Node*, Node*, int, Node*); 356 void shiftit(Type*, Node*, Node*); 357 358 #define D_X7 (D_X0+7) 359 360 void fgopcode(int, Node*, Node*, int, int);