github.com/ccccaoqing/test@v0.0.0-20220510085219-3985d23445c0/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	Node*	nodrat;
   147  EXTERN	Node*	nodret;
   148  EXTERN	Node*	nodsafe;
   149  EXTERN	int32	nrathole;
   150  EXTERN	int32	nstring;
   151  EXTERN	Prog*	p;
   152  EXTERN	int32	pc;
   153  EXTERN	Node	lregnode;
   154  EXTERN	Node	qregnode;
   155  EXTERN	char	string[NSNAME];
   156  EXTERN	Sym*	symrathole;
   157  EXTERN	Node	znode;
   158  EXTERN	Prog	zprog;
   159  EXTERN	int	reg[D_NONE];
   160  EXTERN	int32	exregoffset;
   161  EXTERN	int32	exfregoffset;
   162  EXTERN	uchar	typechlpv[NTYPE];
   163  
   164  #define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
   165  #define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
   166  #define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
   167  #define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
   168  
   169  #define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
   170  
   171  #define	CLOAD	5
   172  #define	CREF	5
   173  #define	CINF	1000
   174  #define	LOOP	3
   175  
   176  EXTERN	Rgn	region[NRGN];
   177  EXTERN	Rgn*	rgp;
   178  EXTERN	int	nregion;
   179  EXTERN	int	nvar;
   180  
   181  EXTERN	Bits	externs;
   182  EXTERN	Bits	params;
   183  EXTERN	Bits	consts;
   184  EXTERN	Bits	addrs;
   185  
   186  EXTERN	int32	regbits;
   187  EXTERN	int32	exregbits;
   188  
   189  EXTERN	int	change;
   190  EXTERN	int	suppress;
   191  
   192  EXTERN	Reg*	firstr;
   193  EXTERN	Reg*	lastr;
   194  EXTERN	Reg	zreg;
   195  EXTERN	Reg*	freer;
   196  EXTERN	int32*	idom;
   197  EXTERN	Reg**	rpo2r;
   198  EXTERN	int32	maxnr;
   199  
   200  extern	char*	anames[];
   201  
   202  /*
   203   * sgen.c
   204   */
   205  void	codgen(Node*, Node*);
   206  void	gen(Node*);
   207  void	noretval(int);
   208  void	usedset(Node*, int);
   209  void	xcom(Node*);
   210  void	indx(Node*);
   211  int	bcomplex(Node*, Node*);
   212  Prog*	gtext(Sym*, int32);
   213  vlong	argsize(int);
   214  
   215  /*
   216   * cgen.c
   217   */
   218  void	zeroregm(Node*);
   219  void	cgen(Node*, Node*);
   220  void	reglcgen(Node*, Node*, Node*);
   221  void	lcgen(Node*, Node*);
   222  void	bcgen(Node*, int);
   223  void	boolgen(Node*, int, Node*);
   224  void	sugen(Node*, Node*, int32);
   225  int	needreg(Node*, int);
   226  int	hardconst(Node*);
   227  int	immconst(Node*);
   228  
   229  /*
   230   * txt.c
   231   */
   232  void	ginit(void);
   233  void	gclean(void);
   234  void	nextpc(void);
   235  void	gargs(Node*, Node*, Node*);
   236  void	garg1(Node*, Node*, Node*, int, Node**);
   237  Node*	nodconst(int32);
   238  Node*	nodfconst(double);
   239  Node*	nodgconst(vlong, Type*);
   240  int	nodreg(Node*, Node*, int);
   241  int	isreg(Node*, int);
   242  void	regret(Node*, Node*, Type*, int);
   243  void	regalloc(Node*, Node*, Node*);
   244  void	regfree(Node*);
   245  void	regialloc(Node*, Node*, Node*);
   246  void	regsalloc(Node*, Node*);
   247  void	regaalloc1(Node*, Node*);
   248  void	regaalloc(Node*, Node*);
   249  void	regind(Node*, Node*);
   250  void	gprep(Node*, Node*);
   251  void	naddr(Node*, Addr*);
   252  void	gcmp(int, Node*, vlong);
   253  void	gmove(Node*, Node*);
   254  void	gins(int a, Node*, Node*);
   255  void	gopcode(int, Type*, Node*, Node*);
   256  int	samaddr(Node*, Node*);
   257  void	gbranch(int);
   258  void	patch(Prog*, int32);
   259  int	sconst(Node*);
   260  void	gpseudo(int, Sym*, Node*);
   261  void	gprefetch(Node*);
   262  void	gpcdata(int, int);
   263  
   264  /*
   265   * swt.c
   266   */
   267  int	swcmp(const void*, const void*);
   268  void	doswit(Node*);
   269  void	swit1(C1*, int, int32, Node*);
   270  void	swit2(C1*, int, int32, Node*);
   271  void	newcase(void);
   272  void	bitload(Node*, Node*, Node*, Node*, Node*);
   273  void	bitstore(Node*, Node*, Node*, Node*, Node*);
   274  int32	outstring(char*, int32);
   275  void	nullwarn(Node*, Node*);
   276  void	sextern(Sym*, Node*, int32, int32);
   277  void	gextern(Sym*, Node*, int32, int32);
   278  void	outcode(void);
   279  
   280  /*
   281   * list
   282   */
   283  void	listinit(void);
   284  
   285  /*
   286   * reg.c
   287   */
   288  Reg*	rega(void);
   289  int	rcmp(const void*, const void*);
   290  void	regopt(Prog*);
   291  void	addmove(Reg*, int, int, int);
   292  Bits	mkvar(Reg*, Addr*);
   293  void	prop(Reg*, Bits, Bits);
   294  void	loopit(Reg*, int32);
   295  void	synch(Reg*, Bits);
   296  uint32	allreg(uint32, Rgn*);
   297  void	paint1(Reg*, int);
   298  uint32	paint2(Reg*, int);
   299  void	paint3(Reg*, int, int32, int);
   300  void	addreg(Addr*, int);
   301  
   302  /*
   303   * peep.c
   304   */
   305  void	peep(void);
   306  void	excise(Reg*);
   307  Reg*	uniqp(Reg*);
   308  Reg*	uniqs(Reg*);
   309  int	regtyp(Addr*);
   310  int	anyvar(Addr*);
   311  int	subprop(Reg*);
   312  int	copyprop(Reg*);
   313  int	copy1(Addr*, Addr*, Reg*, int);
   314  int	copyu(Prog*, Addr*, Addr*);
   315  
   316  int	copyas(Addr*, Addr*);
   317  int	copyau(Addr*, Addr*);
   318  int	copysub(Addr*, Addr*, Addr*, int);
   319  int	copysub1(Prog*, Addr*, Addr*, int);
   320  
   321  int32	RtoB(int);
   322  int32	FtoB(int);
   323  int	BtoR(int32);
   324  int	BtoF(int32);
   325  
   326  #define	D_HI	D_NONE
   327  #define	D_LO	D_NONE
   328  
   329  /*
   330   * bound
   331   */
   332  void	comtarg(void);
   333  
   334  /*
   335   * com64
   336   */
   337  int	cond(int);
   338  int	com64(Node*);
   339  void	com64init(void);
   340  void	bool64(Node*);
   341  int32	lo64v(Node*);
   342  int32	hi64v(Node*);
   343  Node*	lo64(Node*);
   344  Node*	hi64(Node*);
   345  
   346  /*
   347   * div/mul
   348   */
   349  void	sdivgen(Node*, Node*, Node*, Node*);
   350  void	udivgen(Node*, Node*, Node*, Node*);
   351  void	sdiv2(int32, int, Node*, Node*);
   352  void	smod2(int32, int, Node*, Node*);
   353  void	mulgen(Type*, Node*, Node*);
   354  void	genmuladd(Node*, Node*, int, Node*);
   355  void	shiftit(Type*, Node*, Node*);
   356  
   357  #define	D_X7	(D_X0+7)
   358  
   359  void	fgopcode(int, Node*, Node*, int, int);