github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/8g/opt.h (about)

     1  // Derived from 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  #define	Z	N
    32  #define	Adr	Addr
    33  
    34  #define	D_HI	D_NONE
    35  #define	D_LO	D_NONE
    36  
    37  #define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
    38  #define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
    39  #define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
    40  #define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
    41  
    42  #define	CLOAD	5
    43  #define	CREF	5
    44  #define	CINF	1000
    45  #define	LOOP	3
    46  
    47  typedef	struct	Reg	Reg;
    48  typedef	struct	Rgn	Rgn;
    49  
    50  // A Reg is a wrapper around a single Prog (one instruction) that holds
    51  // register optimization information while the optimizer runs.
    52  // r->prog is the instruction.
    53  // r->prog->regp points back to r.
    54  struct	Reg
    55  {
    56  
    57  	Bits	set;  		// variables written by this instruction.
    58  	Bits	use1; 		// variables read by prog->from.
    59  	Bits	use2; 		// variables read by prog->to.
    60  
    61  	Bits	refbehind;
    62  	Bits	refahead;
    63  	Bits	calbehind;
    64  	Bits	calahead;
    65  	Bits	regdiff;
    66  	Bits	act;
    67  
    68  	int32	regu;		// register used bitmap
    69  	int32	rpo;		// reverse post ordering
    70  	int32	active;
    71  
    72  	uint16	loop;		// x5 for every loop
    73  	uchar	refset;		// diagnostic generated
    74  
    75  	Reg*	p1;     	// predecessors of this instruction: p1,
    76  	Reg*	p2;     	// and then p2 linked though p2link.
    77  	Reg*	p2link;
    78  	Reg*	s1;     	// successors of this instruction (at most two: s1 and s2).
    79  	Reg*	s2;
    80  	Reg*	link;   	// next instruction in function code
    81  	Prog*	prog;   	// actual instruction
    82  };
    83  #define	R	((Reg*)0)
    84  
    85  #define	NRGN	600
    86  struct	Rgn
    87  {
    88  	Reg*	enter;
    89  	short	cost;
    90  	short	varno;
    91  	short	regno;
    92  };
    93  
    94  EXTERN	int32	exregoffset;		// not set
    95  EXTERN	int32	exfregoffset;		// not set
    96  EXTERN	Reg*	firstr;
    97  EXTERN	Reg*	lastr;
    98  EXTERN	Reg	zreg;
    99  EXTERN	Reg*	freer;
   100  EXTERN	Reg**	rpo2r;
   101  EXTERN	Rgn	region[NRGN];
   102  EXTERN	Rgn*	rgp;
   103  EXTERN	int	nregion;
   104  EXTERN	int	nvar;
   105  EXTERN	int32	regbits;
   106  EXTERN	int32	exregbits;
   107  EXTERN	Bits	externs;
   108  EXTERN	Bits	params;
   109  EXTERN	Bits	consts;
   110  EXTERN	Bits	addrs;
   111  EXTERN	Bits	ovar;
   112  EXTERN	int	change;
   113  EXTERN	int32	maxnr;
   114  EXTERN	int32*	idom;
   115  
   116  EXTERN	struct
   117  {
   118  	int32	ncvtreg;
   119  	int32	nspill;
   120  	int32	nreload;
   121  	int32	ndelmov;
   122  	int32	nvar;
   123  	int32	naddr;
   124  } ostats;
   125  
   126  /*
   127   * reg.c
   128   */
   129  Reg*	rega(void);
   130  int	rcmp(const void*, const void*);
   131  void	regopt(Prog*);
   132  void	addmove(Reg*, int, int, int);
   133  Bits	mkvar(Reg*, Adr*);
   134  void	prop(Reg*, Bits, Bits);
   135  void	loopit(Reg*, int32);
   136  void	synch(Reg*, Bits);
   137  uint32	allreg(uint32, Rgn*);
   138  void	paint1(Reg*, int);
   139  uint32	paint2(Reg*, int);
   140  void	paint3(Reg*, int, int32, int);
   141  void	addreg(Adr*, int);
   142  void	dumpone(Reg*);
   143  void	dumpit(char*, Reg*);
   144  int	noreturn(Prog *p);
   145  
   146  /*
   147   * peep.c
   148   */
   149  void	peep(void);
   150  void	excise(Reg*);
   151  Reg*	uniqp(Reg*);
   152  Reg*	uniqs(Reg*);
   153  int	regtyp(Adr*);
   154  int	anyvar(Adr*);
   155  int	subprop(Reg*);
   156  int	copyprop(Reg*);
   157  int	copy1(Adr*, Adr*, Reg*, int);
   158  int	copyu(Prog*, Adr*, Adr*);
   159  
   160  int	copyas(Adr*, Adr*);
   161  int	copyau(Adr*, Adr*);
   162  int	copysub(Adr*, Adr*, Adr*, int);
   163  int	copysub1(Prog*, Adr*, Adr*, int);
   164  
   165  int32	RtoB(int);
   166  int32	FtoB(int);
   167  int	BtoR(int32);
   168  int	BtoF(int32);
   169  
   170  #pragma	varargck	type	"D"	Adr*