github.com/roboticscm/goman@v0.0.0-20210203095141-87c07b4a0a55/src/cmd/5c/gc.h (about)

     1  // Inferno utils/5c/gc.h
     2  // http://code.google.com/p/inferno-os/source/browse/utils/5c/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	"../5l/5.out.h"
    34  
    35  /*
    36   * 5c/arm
    37   * Arm 7500
    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		4
    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	Multab	Multab;
    52  typedef	struct	Hintab	Hintab;
    53  typedef	struct	Reg	Reg;
    54  typedef	struct	Rgn	Rgn;
    55  
    56  
    57  #define	R0ISZERO	0
    58  
    59  #define	A	((Addr*)0)
    60  
    61  #define	INDEXED	9
    62  #define	P	((Prog*)0)
    63  
    64  struct	Case
    65  {
    66  	Case*	link;
    67  	int32	val;
    68  	int32	label;
    69  	char	def;
    70  	char	isv;
    71  };
    72  #define	C	((Case*)0)
    73  
    74  struct	C1
    75  {
    76  	int32	val;
    77  	int32	label;
    78  };
    79  
    80  struct	Multab
    81  {
    82  	int32	val;
    83  	char	code[20];
    84  };
    85  
    86  struct	Hintab
    87  {
    88  	ushort	val;
    89  	char	hint[10];
    90  };
    91  
    92  struct	Reg
    93  {
    94  	int32	pc;
    95  	int32	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  	int32	regu;
   109  	int32	loop;		/* could be shorter */
   110  
   111  
   112  	Reg*	log5;
   113  	int32	active;
   114  
   115  	Reg*	p1;
   116  	Reg*	p2;
   117  	Reg*	p2link;
   118  	Reg*	s1;
   119  	Reg*	s2;
   120  	Reg*	link;
   121  	Prog*	prog;
   122  };
   123  #define	R	((Reg*)0)
   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	int32	continpc;
   140  EXTERN	int32	curarg;
   141  EXTERN	int32	cursafe;
   142  EXTERN	int32	isbigendian;
   143  EXTERN	Prog*	lastp;
   144  EXTERN	int32	maxargsafe;
   145  EXTERN	int	mnstring;
   146  EXTERN	Multab	multab[20];
   147  extern	int	hintabsize;
   148  EXTERN	Node*	nodrat;
   149  EXTERN	Node*	nodret;
   150  EXTERN	Node*	nodsafe;
   151  EXTERN	int32	nrathole;
   152  EXTERN	int32	nstring;
   153  EXTERN	Prog*	p;
   154  EXTERN	int32	pc;
   155  EXTERN	Node	regnode;
   156  EXTERN	char	string[NSNAME];
   157  EXTERN	Sym*	symrathole;
   158  EXTERN	Node	znode;
   159  EXTERN	Prog	zprog;
   160  EXTERN	char	reg[NREG+NFREG];
   161  EXTERN	int32	exregoffset;
   162  EXTERN	int32	exfregoffset;
   163  EXTERN	int	suppress;
   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	4
   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  
   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  extern	Hintab	hintab[];
   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  int	bcomplex(Node*, Node*);
   212  Prog*	gtext(Sym*, int32);
   213  vlong	argsize(int);
   214  
   215  /*
   216   * cgen.c
   217   */
   218  void	cgen(Node*, Node*);
   219  void	reglcgen(Node*, Node*, Node*);
   220  void	lcgen(Node*, Node*);
   221  void	bcgen(Node*, int);
   222  void	boolgen(Node*, int, Node*);
   223  void	sugen(Node*, Node*, int32);
   224  void	layout(Node*, Node*, int, int, Node*);
   225  void	cgenrel(Node*, Node*);
   226  
   227  /*
   228   * txt.c
   229   */
   230  void	ginit(void);
   231  void	gclean(void);
   232  void	nextpc(void);
   233  void	gargs(Node*, Node*, Node*);
   234  void	garg1(Node*, Node*, Node*, int, Node**);
   235  Node*	nodconst(int32);
   236  Node*	nod32const(vlong);
   237  Node*	nodfconst(double);
   238  void	nodreg(Node*, Node*, int);
   239  void	regret(Node*, Node*, Type*, int);
   240  int	tmpreg(void);
   241  void	regalloc(Node*, Node*, Node*);
   242  void	regfree(Node*);
   243  void	regialloc(Node*, Node*, Node*);
   244  void	regsalloc(Node*, Node*);
   245  void	regaalloc1(Node*, Node*);
   246  void	regaalloc(Node*, Node*);
   247  void	regind(Node*, Node*);
   248  void	gprep(Node*, Node*);
   249  void	raddr(Node*, Prog*);
   250  void	naddr(Node*, Addr*);
   251  void	gmovm(Node*, Node*, int);
   252  void	gmove(Node*, Node*);
   253  void	gmover(Node*, Node*);
   254  void	gins(int a, Node*, Node*);
   255  void	gopcode(int, Node*, Node*, Node*);
   256  int	samaddr(Node*, Node*);
   257  void	gbranch(int);
   258  void	patch(Prog*, int32);
   259  int	sconst(Node*);
   260  int	sval(int32);
   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  int	mulcon(Node*, Node*);
   276  Multab*	mulcon0(int32);
   277  void	nullwarn(Node*, Node*);
   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(Addr*, int);
   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	regzer(Addr*);
   311  int	anyvar(Addr*);
   312  int	subprop(Reg*);
   313  int	copyprop(Reg*);
   314  int	shiftprop(Reg*);
   315  void	constprop(Addr*, Addr*, Reg*);
   316  int	copy1(Addr*, Addr*, Reg*, int);
   317  int	copyu(Prog*, Addr*, Addr*);
   318  
   319  int	copyas(Addr*, Addr*);
   320  int	copyau(Addr*, Addr*);
   321  int	copyau1(Prog*, Addr*);
   322  int	copysub(Addr*, Addr*, Addr*, int);
   323  int	copysub1(Prog*, Addr*, Addr*, int);
   324  
   325  int32	RtoB(int);
   326  int32	FtoB(int);
   327  int	BtoR(int32);
   328  int	BtoF(int32);
   329  
   330  void	predicate(void);
   331  int	isbranch(Prog *);
   332  int	predicable(Prog *p);
   333  int	modifiescpsr(Prog *p);