github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/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	Adr	Adr;
    50  typedef	struct	Prog	Prog;
    51  typedef	struct	Case	Case;
    52  typedef	struct	C1	C1;
    53  typedef	struct	Multab	Multab;
    54  typedef	struct	Hintab	Hintab;
    55  typedef	struct	Var	Var;
    56  typedef	struct	Reg	Reg;
    57  typedef	struct	Rgn	Rgn;
    58  
    59  
    60  #define	R0ISZERO	0
    61  
    62  struct	Adr
    63  {
    64  	int32	offset;
    65  	int32	offset2;
    66  	double	dval;
    67  	char	sval[NSNAME];
    68  	Ieee	ieee;
    69  
    70  	Sym*	sym;
    71  	char	type;
    72  	uchar	reg;
    73  	char	name;
    74  	char	etype;
    75  };
    76  #define	A	((Adr*)0)
    77  
    78  #define	INDEXED	9
    79  struct	Prog
    80  {
    81  	Adr	from;
    82  	Adr	to;
    83  	Prog*	link;
    84  	int32	lineno;
    85  	char	as;
    86  	uchar	reg;
    87  	uchar	scond;
    88  };
    89  #define	P	((Prog*)0)
    90  
    91  struct	Case
    92  {
    93  	Case*	link;
    94  	int32	val;
    95  	int32	label;
    96  	char	def;
    97  	char	isv;
    98  };
    99  #define	C	((Case*)0)
   100  
   101  struct	C1
   102  {
   103  	int32	val;
   104  	int32	label;
   105  };
   106  
   107  struct	Multab
   108  {
   109  	int32	val;
   110  	char	code[20];
   111  };
   112  
   113  struct	Hintab
   114  {
   115  	ushort	val;
   116  	char	hint[10];
   117  };
   118  
   119  struct	Var
   120  {
   121  	int32	offset;
   122  	Sym*	sym;
   123  	char	name;
   124  	char	etype;
   125  };
   126  
   127  struct	Reg
   128  {
   129  	int32	pc;
   130  	int32	rpo;		/* reverse post ordering */
   131  
   132  	Bits	set;
   133  	Bits	use1;
   134  	Bits	use2;
   135  
   136  	Bits	refbehind;
   137  	Bits	refahead;
   138  	Bits	calbehind;
   139  	Bits	calahead;
   140  	Bits	regdiff;
   141  	Bits	act;
   142  
   143  	int32	regu;
   144  	int32	loop;		/* could be shorter */
   145  
   146  
   147  	Reg*	log5;
   148  	int32	active;
   149  
   150  	Reg*	p1;
   151  	Reg*	p2;
   152  	Reg*	p2link;
   153  	Reg*	s1;
   154  	Reg*	s2;
   155  	Reg*	link;
   156  	Prog*	prog;
   157  };
   158  #define	R	((Reg*)0)
   159  
   160  #define	NRGN	600
   161  struct	Rgn
   162  {
   163  	Reg*	enter;
   164  	short	cost;
   165  	short	varno;
   166  	short	regno;
   167  };
   168  
   169  EXTERN	int32	breakpc;
   170  EXTERN	int32	nbreak;
   171  EXTERN	Case*	cases;
   172  EXTERN	Node	constnode;
   173  EXTERN	Node	fconstnode;
   174  EXTERN	int32	continpc;
   175  EXTERN	int32	curarg;
   176  EXTERN	int32	cursafe;
   177  EXTERN	Prog*	firstp;
   178  EXTERN	int32	isbigendian;
   179  EXTERN	Prog*	lastp;
   180  EXTERN	int32	maxargsafe;
   181  EXTERN	int	mnstring;
   182  EXTERN	Multab	multab[20];
   183  EXTERN	int	retok;
   184  extern	int	hintabsize;
   185  EXTERN	Node*	nodrat;
   186  EXTERN	Node*	nodret;
   187  EXTERN	Node*	nodsafe;
   188  EXTERN	int32	nrathole;
   189  EXTERN	int32	nstring;
   190  EXTERN	Prog*	p;
   191  EXTERN	int32	pc;
   192  EXTERN	Node	regnode;
   193  EXTERN	char	string[NSNAME];
   194  EXTERN	Sym*	symrathole;
   195  EXTERN	Node	znode;
   196  EXTERN	Prog	zprog;
   197  EXTERN	char	reg[NREG+NFREG];
   198  EXTERN	int32	exregoffset;
   199  EXTERN	int32	exfregoffset;
   200  EXTERN	int	suppress;
   201  
   202  #define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
   203  #define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
   204  #define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
   205  #define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
   206  
   207  #define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
   208  
   209  #define	CLOAD	4
   210  #define	CREF	5
   211  #define	CINF	1000
   212  #define	LOOP	3
   213  
   214  EXTERN	Rgn	region[NRGN];
   215  EXTERN	Rgn*	rgp;
   216  EXTERN	int	nregion;
   217  EXTERN	int	nvar;
   218  
   219  EXTERN	Bits	externs;
   220  EXTERN	Bits	params;
   221  EXTERN	Bits	consts;
   222  EXTERN	Bits	addrs;
   223  
   224  EXTERN	int32	regbits;
   225  EXTERN	int32	exregbits;
   226  
   227  EXTERN	int	change;
   228  
   229  EXTERN	Reg*	firstr;
   230  EXTERN	Reg*	lastr;
   231  EXTERN	Reg	zreg;
   232  EXTERN	Reg*	freer;
   233  EXTERN	Var	var[NVAR];
   234  EXTERN	int32*	idom;
   235  EXTERN	Reg**	rpo2r;
   236  EXTERN	int32	maxnr;
   237  
   238  extern	char*	anames[];
   239  extern	Hintab	hintab[];
   240  
   241  /*
   242   * sgen.c
   243   */
   244  void	codgen(Node*, Node*);
   245  void	gen(Node*);
   246  void	noretval(int);
   247  void	usedset(Node*, int);
   248  void	xcom(Node*);
   249  int	bcomplex(Node*, Node*);
   250  Prog*	gtext(Sym*, int32);
   251  vlong	argsize(void);
   252  
   253  /*
   254   * cgen.c
   255   */
   256  void	cgen(Node*, Node*);
   257  void	reglcgen(Node*, Node*, Node*);
   258  void	lcgen(Node*, Node*);
   259  void	bcgen(Node*, int);
   260  void	boolgen(Node*, int, Node*);
   261  void	sugen(Node*, Node*, int32);
   262  void	layout(Node*, Node*, int, int, Node*);
   263  void	cgenrel(Node*, Node*);
   264  
   265  /*
   266   * txt.c
   267   */
   268  void	ginit(void);
   269  void	gclean(void);
   270  void	nextpc(void);
   271  void	gargs(Node*, Node*, Node*);
   272  void	garg1(Node*, Node*, Node*, int, Node**);
   273  Node*	nodconst(int32);
   274  Node*	nod32const(vlong);
   275  Node*	nodfconst(double);
   276  void	nodreg(Node*, Node*, int);
   277  void	regret(Node*, Node*);
   278  int	tmpreg(void);
   279  void	regalloc(Node*, Node*, Node*);
   280  void	regfree(Node*);
   281  void	regialloc(Node*, Node*, Node*);
   282  void	regsalloc(Node*, Node*);
   283  void	regaalloc1(Node*, Node*);
   284  void	regaalloc(Node*, Node*);
   285  void	regind(Node*, Node*);
   286  void	gprep(Node*, Node*);
   287  void	raddr(Node*, Prog*);
   288  void	naddr(Node*, Adr*);
   289  void	gmovm(Node*, Node*, int);
   290  void	gmove(Node*, Node*);
   291  void	gmover(Node*, Node*);
   292  void	gins(int a, Node*, Node*);
   293  void	gopcode(int, Node*, Node*, Node*);
   294  int	samaddr(Node*, Node*);
   295  void	gbranch(int);
   296  void	patch(Prog*, int32);
   297  int	sconst(Node*);
   298  int	sval(int32);
   299  void	gpseudo(int, Sym*, Node*);
   300  void	gprefetch(Node*);
   301  
   302  /*
   303   * swt.c
   304   */
   305  int	swcmp(const void*, const void*);
   306  void	doswit(Node*);
   307  void	swit1(C1*, int, int32, Node*);
   308  void	swit2(C1*, int, int32, Node*);
   309  void	newcase(void);
   310  void	bitload(Node*, Node*, Node*, Node*, Node*);
   311  void	bitstore(Node*, Node*, Node*, Node*, Node*);
   312  int	mulcon(Node*, Node*);
   313  Multab*	mulcon0(int32);
   314  void	nullwarn(Node*, Node*);
   315  void	outcode(void);
   316  void	ieeedtod(Ieee*, double);
   317  
   318  /*
   319   * list
   320   */
   321  void	listinit(void);
   322  int	Pconv(Fmt*);
   323  int	Aconv(Fmt*);
   324  int	Dconv(Fmt*);
   325  int	Sconv(Fmt*);
   326  int	Nconv(Fmt*);
   327  int	Bconv(Fmt*);
   328  int	Rconv(Fmt*);
   329  
   330  /*
   331   * reg.c
   332   */
   333  Reg*	rega(void);
   334  int	rcmp(const void*, const void*);
   335  void	regopt(Prog*);
   336  void	addmove(Reg*, int, int, int);
   337  Bits	mkvar(Adr*, int);
   338  void	prop(Reg*, Bits, Bits);
   339  void	loopit(Reg*, int32);
   340  void	synch(Reg*, Bits);
   341  uint32	allreg(uint32, Rgn*);
   342  void	paint1(Reg*, int);
   343  uint32	paint2(Reg*, int);
   344  void	paint3(Reg*, int, int32, int);
   345  void	addreg(Adr*, int);
   346  
   347  /*
   348   * peep.c
   349   */
   350  void	peep(void);
   351  void	excise(Reg*);
   352  Reg*	uniqp(Reg*);
   353  Reg*	uniqs(Reg*);
   354  int	regtyp(Adr*);
   355  int	regzer(Adr*);
   356  int	anyvar(Adr*);
   357  int	subprop(Reg*);
   358  int	copyprop(Reg*);
   359  int	shiftprop(Reg*);
   360  void	constprop(Adr*, Adr*, Reg*);
   361  int	copy1(Adr*, Adr*, Reg*, int);
   362  int	copyu(Prog*, Adr*, Adr*);
   363  
   364  int	copyas(Adr*, Adr*);
   365  int	copyau(Adr*, Adr*);
   366  int	copyau1(Prog*, Adr*);
   367  int	copysub(Adr*, Adr*, Adr*, int);
   368  int	copysub1(Prog*, Adr*, Adr*, int);
   369  
   370  int32	RtoB(int);
   371  int32	FtoB(int);
   372  int	BtoR(int32);
   373  int	BtoF(int32);
   374  
   375  void	predicate(void);
   376  int	isbranch(Prog *);
   377  int	predicable(Prog *p);
   378  int	modifiescpsr(Prog *p);
   379  
   380  #pragma	varargck	type	"A"	int
   381  #pragma	varargck	type	"B"	Bits
   382  #pragma	varargck	type	"D"	Adr*
   383  #pragma	varargck	type	"N"	Adr*
   384  #pragma	varargck	type	"R"	Adr*
   385  #pragma	varargck	type	"P"	Prog*
   386  #pragma	varargck	type	"S"	char*