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