gc

package
v0.0.0-...-e040fd4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2015 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WORDSIZE  = 4
	WORDBITS  = 32
	WORDMASK  = WORDBITS - 1
	WORDSHIFT = 5
)
View Source
const (
	EscFuncUnknown = 0 + iota
	EscFuncPlanned
	EscFuncStarted
	EscFuncTagged
)
View Source
const (
	FErr = iota
	FDbg
	FExp
	FTypeId
)

Format conversions

	%L int		Line numbers

	%E int		etype values (aka 'Kind')

	%O int		Node Opcodes
		Flags: "%#O": print go syntax. (automatic unless fmtmode == FDbg)

	%J Node*	Node details
		Flags: "%hJ" suppresses things not relevant until walk.

	%V Val*		Constant values

	%S Sym*		Symbols
		Flags: +,- #: mode (see below)
			"%hS"	unqualified identifier in any mode
			"%hhS"  in export mode: unqualified identifier if exported, qualified if not

	%T Type*	Types
		Flags: +,- #: mode (see below)
			'l' definition instead of name.
			'h' omit "func" and receiver in function types
			'u' (only in -/Sym mode) print type identifiers wit package name instead of prefix.

	%N Node*	Nodes
		Flags: +,- #: mode (see below)
			'h' (only in +/debug mode) suppress recursion
			'l' (only in Error mode) print "foo (type Bar)"

	%H NodeList*	NodeLists
		Flags: those of %N
			','  separate items with ',' instead of ';'

  In mparith1.c:
     %B Mpint*	Big integers
	%F Mpflt*	Big floats

  %S, %T and %N obey use the following flags to set the format mode:
View Source
const (
	NHUNK           = 50000
	BUFSIZ          = 8192
	NSYMB           = 500
	NHASH           = 1024
	MAXALIGN        = 7
	UINF            = 100
	PRIME1          = 3
	BADWIDTH        = -1000000000
	MaxStackVarSize = 10 * 1024 * 1024
)

The parser's maximum stack size. We have to use a #define macro here since yacc or bison will check for its definition and use a potentially smaller value if it is undefined.

View Source
const (
	// These values are known by runtime.
	// The MEMx and NOEQx values must run in parallel.  See algtype.
	AMEM = iota
	AMEM0
	AMEM8
	AMEM16
	AMEM32
	AMEM64
	AMEM128
	ANOEQ
	ANOEQ0
	ANOEQ8
	ANOEQ16
	ANOEQ32
	ANOEQ64
	ANOEQ128
	ASTRING
	AINTER
	ANILINTER
	ASLICE
	AFLOAT32
	AFLOAT64
	ACPLX64
	ACPLX128
	AUNK = 100
)
View Source
const (
	// Maximum size in bits for Mpints before signalling
	// overflow and also mantissa precision for Mpflts.
	Mpprec = 512
	// Turn on for constant arithmetic debugging output.
	Mpdebug = false
)
View Source
const (
	EscUnknown = iota
	EscHeap
	EscScope
	EscNone
	EscReturn
	EscNever
	EscBits           = 3
	EscMask           = (1 << EscBits) - 1
	EscContentEscapes = 1 << EscBits // value obtained by indirect of parameter escapes to some returned result
	EscReturnBits     = EscBits + 1
)
View Source
const (
	SymExport   = 1 << 0 // to be exported
	SymPackage  = 1 << 1
	SymExported = 1 << 2 // already written out by export
	SymUniq     = 1 << 3
	SymSiggen   = 1 << 4
	SymAsm      = 1 << 5
	SymAlgGen   = 1 << 6
)
View Source
const (
	Txxx = iota

	TINT8
	TUINT8
	TINT16
	TUINT16
	TINT32
	TUINT32
	TINT64
	TUINT64
	TINT
	TUINT
	TUINTPTR

	TCOMPLEX64
	TCOMPLEX128

	TFLOAT32
	TFLOAT64

	TBOOL

	TPTR32
	TPTR64

	TFUNC
	TARRAY
	T_old_DARRAY
	TSTRUCT
	TCHAN
	TMAP
	TINTER
	TFORW
	TFIELD
	TANY
	TSTRING
	TUNSAFEPTR

	// pseudo-types for literals
	TIDEAL
	TNIL
	TBLANK

	// pseudo-type for frame layout
	TFUNCARGS
	TCHANARGS
	TINTERMETH

	NTYPE
)
View Source
const (
	CTxxx = iota

	CTINT
	CTRUNE
	CTFLT
	CTCPLX
	CTSTR
	CTBOOL
	CTNIL
)
View Source
const (
	/* types of channel */
	/* must match ../../pkg/nreflect/type.go:/Chandir */
	Cxxx  = 0
	Crecv = 1 << 0
	Csend = 1 << 1
	Cboth = Crecv | Csend
)
View Source
const (
	Pxxx      = uint8(iota)
	PEXTERN   // global variable
	PAUTO     // local variables
	PPARAM    // input arguments
	PPARAMOUT // output results
	PPARAMREF // closure variable reference
	PFUNC     // global function

	PDISCARD // discard during parse of duplicate import

	PHEAP = uint8(1 << 7) // an extra bit to identify an escaped variable
)

declaration context

View Source
const (
	Etop      = 1 << 1 // evaluated at statement level
	Erv       = 1 << 2 // evaluated in value context
	Etype     = 1 << 3
	Ecall     = 1 << 4  // call-only expressions are ok
	Efnstruct = 1 << 5  // multivalue function returns are ok
	Eiota     = 1 << 6  // iota is ok
	Easgn     = 1 << 7  // assigning to expression
	Eindir    = 1 << 8  // indirecting through expression
	Eaddr     = 1 << 9  // taking address of expression
	Eproc     = 1 << 10 // inside a go statement
	Ecomplit  = 1 << 11 // type in composite literal
)
View Source
const (
	// Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA.
	Pseudo = 1 << 1

	// There's nothing to say about the instruction,
	// but it's still okay to see.
	OK = 1 << 2

	// Size of right-side write, or right-side read if no write.
	SizeB = 1 << 3
	SizeW = 1 << 4
	SizeL = 1 << 5
	SizeQ = 1 << 6
	SizeF = 1 << 7
	SizeD = 1 << 8

	// Left side (Prog.from): address taken, read, write.
	LeftAddr  = 1 << 9
	LeftRead  = 1 << 10
	LeftWrite = 1 << 11

	// Register in middle (Prog.reg); only ever read. (arm, ppc64)
	RegRead    = 1 << 12
	CanRegRead = 1 << 13

	// Right side (Prog.to): address taken, read, write.
	RightAddr  = 1 << 14
	RightRead  = 1 << 15
	RightWrite = 1 << 16

	// Instruction kinds
	Move  = 1 << 17 // straight move
	Conv  = 1 << 18 // size conversion
	Cjmp  = 1 << 19 // conditional jump
	Break = 1 << 20 // breaks control flow (no fallthrough)
	Call  = 1 << 21 // function call
	Jump  = 1 << 22 // jump
	Skip  = 1 << 23 // data instruction

	// Set, use, or kill of carry bit.
	// Kill means we never look at the carry bit after this kind of instruction.
	SetCarry  = 1 << 24
	UseCarry  = 1 << 25
	KillCarry = 1 << 26

	// Special cases for register use. (amd64, 386)
	ShiftCX  = 1 << 27 // possible shift by CX
	ImulAXDX = 1 << 28 // possible multiply into DX:AX

	// Instruction updates whichever of from/to is type D_OREG. (ppc64)
	PostInc = 1 << 29
)
View Source
const (
	UNVISITED = 0
	VISITED   = 1
)
View Source
const (
	H0 = 2166136261
	Hp = 16777619
)

FNV-1 hash function constants.

View Source
const (
	BUCKETSIZE = 8
	MAXKEYSIZE = 128
	MAXVALSIZE = 128
)

Builds a type respresenting a Bucket structure for the given map type. This type is not visible to users - we include only enough information to generate a correct GC program for it. Make sure this stays in sync with ../../runtime/hashmap.go!

View Source
const (
	BITS = 3
	NVAR = BITS * 64
)
View Source
const (
	CLOAD = 5 // cost of load
	CREF  = 5 // cost of reference if not registerized
	LOOP  = 3 // loop execution count (applied in popt.go)
)

Cost parameters

View Source
const (
	InitNotStarted = 0
	InitDone       = 1
	InitPending    = 2
)

* static initialization

View Source
const (
	MODEDYNAM = 1
	MODECONST = 2
)
View Source
const (
	OXXX = iota

	// names
	ONAME    // var, const or func name
	ONONAME  // unnamed arg or return value: f(int, string) (int, error) { etc }
	OTYPE    // type name
	OPACK    // import
	OLITERAL // literal

	// expressions
	OADD             // x + y
	OSUB             // x - y
	OOR              // x | y
	OXOR             // x ^ y
	OADDSTR          // s + "foo"
	OADDR            // &x
	OANDAND          // b0 && b1
	OAPPEND          // append
	OARRAYBYTESTR    // string(bytes)
	OARRAYBYTESTRTMP // string(bytes) ephemeral
	OARRAYRUNESTR    // string(runes)
	OSTRARRAYBYTE    // []byte(s)
	OSTRARRAYBYTETMP // []byte(s) ephemeral
	OSTRARRAYRUNE    // []rune(s)
	OAS              // x = y or x := y
	OAS2             // x, y, z = xx, yy, zz
	OAS2FUNC         // x, y = f()
	OAS2RECV         // x, ok = <-c
	OAS2MAPR         // x, ok = m["foo"]
	OAS2DOTTYPE      // x, ok = I.(int)
	OASOP            // x += y
	OCALL            // function call, method call or type conversion, possibly preceded by defer or go.
	OCALLFUNC        // f()
	OCALLMETH        // t.Method()
	OCALLINTER       // err.Error()
	OCALLPART        // t.Method (without ())
	OCAP             // cap
	OCLOSE           // close
	OCLOSURE         // f = func() { etc }
	OCMPIFACE        // err1 == err2
	OCMPSTR          // s1 == s2
	OCOMPLIT         // composite literal, typechecking may convert to a more specific OXXXLIT.
	OMAPLIT          // M{"foo":3, "bar":4}
	OSTRUCTLIT       // T{x:3, y:4}
	OARRAYLIT        // [2]int{3, 4}
	OPTRLIT          // &T{x:3, y:4}
	OCONV            // var i int; var u uint; i = int(u)
	OCONVIFACE       // I(t)
	OCONVNOP         // type Int int; var i int; var j Int; i = int(j)
	OCOPY            // copy
	ODCL             // var x int
	ODCLFUNC         // func f() or func (r) f()
	ODCLFIELD        // struct field, interface field, or func/method argument/return value.
	ODCLCONST        // const pi = 3.14
	ODCLTYPE         // type Int int
	ODELETE          // delete
	ODOT             // t.x
	ODOTPTR          // p.x that is implicitly (*p).x
	ODOTMETH         // t.Method
	ODOTINTER        // err.Error
	OXDOT            // t.x, typechecking may convert to a more specific ODOTXXX.
	ODOTTYPE         // e = err.(MyErr)
	ODOTTYPE2        // e, ok = err.(MyErr)
	OEQ              // x == y
	ONE              // x != y
	OLT              // x < y
	OLE              // x <= y
	OGE              // x >= y
	OGT              // x > y
	OIND             // *p
	OINDEX           // a[i]
	OINDEXMAP        // m[s]
	OKEY             // The x:3 in t{x:3, y:4}, the 1:2 in a[1:2], the 2:20 in [3]int{2:20}, etc.
	OPARAM           // The on-stack copy of a parameter or return value that escapes.
	OLEN             // len
	OMAKE            // make, typechecking may convert to a more specific OMAKEXXX.
	OMAKECHAN        // make(chan int)
	OMAKEMAP         // make(map[string]int)
	OMAKESLICE       // make([]int, 0)
	OMUL             // *
	ODIV             // x / y
	OMOD             // x % y
	OLSH             // x << u
	ORSH             // x >> u
	OAND             // x & y
	OANDNOT          // x &^ y
	ONEW             // new
	ONOT             // !b
	OCOM             // ^x
	OPLUS            // +x
	OMINUS           // -y
	OOROR            // b1 || b2
	OPANIC           // panic
	OPRINT           // print
	OPRINTN          // println
	OPAREN           // (x)
	OSEND            // c <- x
	OSLICE           // v[1:2], typechecking may convert to a more specific OSLICEXXX.
	OSLICEARR        // a[1:2]
	OSLICESTR        // s[1:2]
	OSLICE3          // v[1:2:3], typechecking may convert to OSLICE3ARR.
	OSLICE3ARR       // a[1:2:3]
	ORECOVER         // recover
	ORECV            // <-c
	ORUNESTR         // string(i)
	OSELRECV         // case x = <-c:
	OSELRECV2        // case x, ok = <-c:
	OIOTA            // iota
	OREAL            // real
	OIMAG            // imag
	OCOMPLEX         // complex

	// statements
	OBLOCK    // block of code
	OBREAK    // break
	OCASE     // case, after being verified by swt.c's casebody.
	OXCASE    // case, before verification.
	OCONTINUE // continue
	ODEFER    // defer
	OEMPTY    // no-op
	OFALL     // fallthrough, after being verified by swt.c's casebody.
	OXFALL    // fallthrough, before verification.
	OFOR      // for
	OGOTO     // goto
	OIF       // if
	OLABEL    // label:
	OPROC     // go
	ORANGE    // range
	ORETURN   // return
	OSELECT   // select
	OSWITCH   // switch x
	OTYPESW   // switch err.(type)

	// types
	OTCHAN   // chan int
	OTMAP    // map[string]int
	OTSTRUCT // struct{}
	OTINTER  // interface{}
	OTFUNC   // func()
	OTARRAY  // []int, [8]int, [N]int or [...]int

	// misc
	ODDD        // func f(args ...int) or f(l...) or var a = [...]int{0, 1, 2}.
	ODDDARG     // func f(args ...int), introduced by escape analysis.
	OINLCALL    // intermediary representation of an inlined call.
	OEFACE      // itable and data words of an empty-interface value.
	OITAB       // itable word of an interface value.
	OSPTR       // base pointer of a slice or string.
	OCLOSUREVAR // variable reference at beginning of closure function
	OCFUNC      // reference to c function pointer (not go func value)
	OCHECKNIL   // emit code to ensure pointer/interface not nil
	OVARKILL    // variable is dead

	// thearch-specific registers
	OREGISTER // a register, such as AX.
	OINDREG   // offset plus indirect of a register, such as 8(SP).

	// arch-specific opcodes
	OCMP    // compare: ACMP.
	ODEC    // decrement: ADEC.
	OINC    // increment: AINC.
	OEXTEND // extend: ACWD/ACDQ/ACQO.
	OHMUL   // high mul: AMUL/AIMUL for unsigned/signed (OMUL uses AIMUL for both).
	OLROT   // left rotate: AROL.
	ORROTC  // right rotate-carry: ARCR.
	ORETJMP // return to other function
	OPS     // compare parity set (for x86 NaN check)
	OSQRT   // sqrt(float64), on systems that have hw support
	OGETG   // runtime.getg() (read g pointer)

	OEND
)

Node ops.

View Source
const (
	ArhdrSize = 60
)

* architecture-independent object file output

View Source
const (
	EOF = -1
)
View Source
const LANDAND = 57376
View Source
const LANDNOT = 57377
View Source
const LASOP = 57347
View Source
const LBODY = 57378
View Source
const LBREAK = 57349
View Source
const LCASE = 57350
View Source
const LCHAN = 57351
View Source
const LCOLAS = 57348
View Source
const LCOMM = 57379
View Source
const LCONST = 57352
View Source
const LCONTINUE = 57353
View Source
const LDDD = 57354
View Source
const LDEC = 57380
View Source
const LDEFAULT = 57355
View Source
const LDEFER = 57356
View Source
const LELSE = 57357
View Source
const LEQ = 57381
View Source
const LFALL = 57358
View Source
const LFOR = 57359
View Source
const LFUNC = 57360
View Source
const LGE = 57382
View Source
const LGO = 57361
View Source
const LGOTO = 57362
View Source
const LGT = 57383
View Source
const LIF = 57363
View Source
const LIGNORE = 57384
View Source
const LIMPORT = 57364
View Source
const LINC = 57385
View Source
const LINTERFACE = 57365
View Source
const LLE = 57386
View Source
const LLITERAL = 57346
View Source
const LLSH = 57387
View Source
const LLT = 57388
View Source
const LMAP = 57366
View Source
const LNAME = 57367
View Source
const LNE = 57389
View Source
const LOROR = 57390
View Source
const LPACKAGE = 57368
View Source
const LRANGE = 57369
View Source
const LRETURN = 57370
View Source
const LRSH = 57391
View Source
const LSELECT = 57371
View Source
const LSTRUCT = 57372
View Source
const LSWITCH = 57373
View Source
const LTYPE = 57374
View Source
const LVAR = 57375
View Source
const MaxFlowProg = 50000

MaxFlowProg is the maximum size program (counted in instructions) for which the flow code will build a graph. Functions larger than this limit will not have flow graphs and consequently will not be optimized.

View Source
const MaxRgn = 6000

The Plan 9 C compilers used a limit of 600 regions, but the yacc-generated parser in y.go has 3100 regions. We set MaxRgn large enough to handle that. There's not a huge cost to having too many regions: the main processing traces the live area for each variable, which is limited by the number of variables times the area, not the raw region count. If there are many regions, they are almost certainly small and easy to trace. The only operation that scales with region count is the sorting by cost, which uses sort.Sort and is therefore guaranteed n log n.

View Source
const (
	MinLevel = -2
)

There appear to be some loops in the escape graph, causing arbitrary recursion into deeper and deeper levels. Cut this off safely by making minLevel sticky: once you get that deep, you cannot go down any further but you also cannot go up any further. This is a conservative fix. Making minLevel smaller (more negative) would handle more complex chains of indirections followed by address-of operations, at the cost of repeating the traversal once for each additional allowed level when a loop is encountered. Using -2 suffices to pass all the tests we have written so far, which we assume matches the level of complexity we want the escape analysis code to handle.

View Source
const NotPackage = 57392
View Source
const NotParen = 57393
View Source
const PreferToRightParen = 57394

Variables

View Source
var (
	Isptr [NTYPE]bool

	Isint     [NTYPE]bool
	Isfloat   [NTYPE]bool
	Iscomplex [NTYPE]bool
	Issigned  [NTYPE]bool
)
View Source
var Array_array int // runtime offsetof(Array,array) - same for String

* note this is the runtime representation * of the compilers arrays. * * typedef struct * { // must not move anything * uchar array[8]; // pointer to data * uchar nel[4]; // number of elements * uchar cap[4]; // allocated number of elements * } Array;

View Source
var Array_cap int // runtime offsetof(Array,cap)
View Source
var Array_nel int // runtime offsetof(Array,nel) - same for String
View Source
var Ctxt *obj.Link
View Source
var Debug [256]int
View Source
var Debug_checknil int
View Source
var Debug_typeassert int
View Source
var Disable_checknil int
View Source
var Funcdepth int32
View Source
var Hasdefer int // flag that curfn has defer statetment
View Source
var Maxarg int64
View Source
var Maxintval [NTYPE]*Mpint
View Source
var Minintval [NTYPE]*Mpint
View Source
var Nacl bool
View Source
var Pc *obj.Prog
View Source
var Simtype [NTYPE]uint8
View Source
var Stksize int64 // stack size for current frame
View Source
var Tptr int // either TPTR32 or TPTR64
View Source
var Types [NTYPE]*Type
View Source
var Widthint int
View Source
var Widthptr int
View Source
var Widthreg int

Functions

func Afunclit

func Afunclit(a *obj.Addr, n *Node)

func Agen

func Agen(n *Node, res *Node)

* generate: * res = &n; * The generated code checks that the result is not nil.

func Agenr

func Agenr(n *Node, a *Node, res *Node)

* allocate a register (reusing res if possible) and generate * a = &n * The caller must call Regfree(a). * The generated code checks that the result is not nil.

func Anyregalloc

func Anyregalloc() bool

func Argsize

func Argsize(t *Type) int

* compute total size of f's in/out arguments.

func AtExit

func AtExit(f func())

func Bconv

func Bconv(xval *Mpint, flag int) string

func Bgen

func Bgen(n *Node, true_ bool, likely int, to *obj.Prog)

* generate: * if(n == true) goto to;

func Bitno

func Bitno(b uint64) int

Bitno reports the lowest index of a 1 bit in b. It calls Fatal if there is no 1 bit.

func Bputname

func Bputname(b *obj.Biobuf, s *obj.LSym)

func Brcom

func Brcom(a int) int

* return !(op) * eg == <=> !=

func Brrev

func Brrev(a int) int

* return reverse(op) * eg a op b <=> b r(op) a

func CASE

func CASE(a int, b int) int

func Cgen

func Cgen(n *Node, res *Node)

* generate: * res = n; * simplifies and calls Thearch.Gmove.

func Cgen_As2dottype

func Cgen_As2dottype(n, res, resok *Node)

* generate: * res, resok = x.(T) * n.Left is x * n.Type is T

func Cgen_as

func Cgen_as(nl *Node, nr *Node)

func Cgen_checknil

func Cgen_checknil(n *Node)

func Cgen_eface

func Cgen_eface(n *Node, res *Node)

* generate: * res = iface{typ, data} * n->left is typ * n->right is data

func Cgen_slice

func Cgen_slice(n *Node, res *Node)

* generate: * res = s[lo, hi]; * n->left is s * n->list is (cap(s)-lo(TUINT), hi-lo(TUINT)[, lo*width(TUINTPTR)]) * caller (cgen) guarantees res is an addable ONAME. * * called for OSLICE, OSLICE3, OSLICEARR, OSLICE3ARR, OSLICESTR.

func Cgenr

func Cgenr(n *Node, a *Node, res *Node)

* allocate a register (reusing res if possible) and generate * a = n * The caller must call Regfree(a).

func Clearp

func Clearp(p *obj.Prog)

func Clearslim

func Clearslim(n *Node)

* clearslim generates code to zero a slim node.

func Complexbool

func Complexbool(op int, nl *Node, nr *Node, true_ bool, likely int, to *obj.Prog)

func Complexgen

func Complexgen(n *Node, res *Node)

func Complexmove

func Complexmove(f *Node, t *Node)

func Complexop

func Complexop(n *Node, res *Node) bool

func Componentgen

func Componentgen(nr *Node, nl *Node) bool

Componentgen copies a composite value by moving its individual components. Slices, strings and interfaces are supported. Small structs or arrays with elements of basic type are also supported. nr is nil when assigning a zero value.

func Convconst

func Convconst(con *Node, t *Type, val *Val)

* convert constant val to type t; leave in con. * for back end.

func Convlit

func Convlit(np **Node, t *Type)

* convert n, if literal, to type t. * implicit conversion.

func Datastring

func Datastring(s string, a *obj.Addr)

func Dotoffset

func Dotoffset(n *Node, oary []int64, nn **Node) int

* gather series of offsets * >=0 is direct addressed field * <0 is pointer to next field (+1)

func Dump

func Dump(s string, n *Node)

func Dumpit

func Dumpit(str string, r0 *Flow, isreg int)

func Econv

func Econv(et int, flag int) string

Fmt "%E": etype

func Eqtype

func Eqtype(t1 *Type, t2 *Type) bool

Return 1 if t1 and t2 are identical, following the spec rules.

Any cyclic type must go through a named type, and if one is named, it is only identical to the other if they are the same pointer (t1 == t2), so there's no chance of chasing cycles ad infinitum, so no need for a depth counter.

func Exit

func Exit(code int)

func Fatal

func Fatal(fmt_ string, args ...interface{})

func Fconv

func Fconv(fvp *Mpflt, flag int) string

func Fixlargeoffset

func Fixlargeoffset(n *Node)

func Flowend

func Flowend(graph *Graph)

func Flusherrors

func Flusherrors()

func Gbranch

func Gbranch(as int, t *Type, likely int) *obj.Prog

func Genlist

func Genlist(l *NodeList)

* compile statements

func Ginscall

func Ginscall(f *Node, proc int)

* generate: * call f * proc=-1 normal call but no return * proc=0 normal call * proc=1 goroutine run in new proc * proc=2 defer call save away stack

  • proc=3 normal call to C pointer (not Go func value)

func Gvardef

func Gvardef(n *Node)

func HasLinkRegister

func HasLinkRegister() bool

func Hconv

func Hconv(l *NodeList, flag int) string

Fmt '%H': NodeList. Flags: all those of %N plus ',': separate with comma's instead of semicolons.

func Igen

func Igen(n *Node, a *Node, res *Node)

Igen computes the address &n, stores it in a register r, and rewrites a to refer to *r. The chosen r may be the stack pointer, it may be borrowed from res, or it may be a newly allocated register. The caller must call Regfree(a) to free r when the address is no longer needed. The generated code ensures that &n is not nil.

func Is64

func Is64(t *Type) bool

* Is this a 64-bit type?

func Isconst

func Isconst(n *Node, ct int) bool

func Isfat

func Isfat(t *Type) bool

func Isfixedarray

func Isfixedarray(t *Type) bool

func Isinter

func Isinter(t *Type) bool

func Ismem

func Ismem(n *Node) bool

* Is this node a memory operand?

func Isslice

func Isslice(t *Type) bool

func Istype

func Istype(t *Type, et int) bool

func Jconv

func Jconv(n *Node, flag int) string

Fmt "%J": Node details.

func LOAD

func LOAD(r *Reg, z int) uint64

func Linksym

func Linksym(s *Sym) *obj.LSym

func Main

func Main()

func Mfree

func Mfree(n *Node)

func Mgen

func Mgen(n *Node, n1 *Node, rg *Node)

func Mpcmpfixfix

func Mpcmpfixfix(a, b *Mpint) int

func Mpgetfix

func Mpgetfix(a *Mpint) int64

func Mpmovecfix

func Mpmovecfix(a *Mpint, c int64)

func Mpmovecflt

func Mpmovecflt(a *Mpflt, c float64)

func Mpmovefixflt

func Mpmovefixflt(a *Mpflt, b *Mpint)

func Mpshiftfix

func Mpshiftfix(a *Mpint, s int)

shift left by s (or right by -s)

func Naddr

func Naddr(a *obj.Addr, n *Node)

Naddr rewrites a to refer to n. It assumes that a is zeroed on entry.

func Nconv

func Nconv(n *Node, flag int) string

Fmt '%N': Nodes. Flags: 'l' suffix with "(type %T)" where possible

'+h' in debug mode, don't recurse, no multiline output

func Noconv

func Noconv(t1 *Type, t2 *Type) bool

* Is a conversion between t1 and t2 a no-op?

func Nodconst

func Nodconst(n *Node, t *Type, v int64)

func Nodindreg

func Nodindreg(n *Node, t *Type, r int)

func Nodreg

func Nodreg(n *Node, t *Type, r int)

func Noreturn

func Noreturn(p *obj.Prog) bool

p is a call instruction. Does the call fail to return?

func Oconv

func Oconv(o int, flag int) string

Fmt "%O": Node opcodes

func Patch

func Patch(p *obj.Prog, to *obj.Prog)

func Prog

func Prog(as int) *obj.Prog

func Regalloc

func Regalloc(n *Node, t *Type, o *Node)

* allocate register of type t, leave in n. * if o != N, o may be reusable register. * caller must Regfree(n).

func Regdump

func Regdump()

func Regfree

func Regfree(n *Node)

func Reginuse

func Reginuse(r int) bool

Reginuse reports whether r is in use.

func Regrealloc

func Regrealloc(n *Node)

Regrealloc(n) undoes the effect of Regfree(n), so that a register can be given up but then reclaimed.

func Rnd

func Rnd(o int64, r int64) int64

func STORE

func STORE(r *Reg, z int) uint64

func Samereg

func Samereg(a *Node, b *Node) bool

func Sconv

func Sconv(s *Sym, flag int) string

Fmt "%S": syms Flags: "%hS" suppresses qualifying with package

func Setmaxarg

func Setmaxarg(t *Type, extra int32)

func Simsimtype

func Simsimtype(t *Type) int

* even simpler simtype; get rid of ptr, bool. * assuming that the front end has rejected * all the invalid conversions (like ptr -> bool)

func Smagic

func Smagic(m *Magic)

* magic number for signed division * see hacker's delight chapter 10

func Smallintconst

func Smallintconst(n *Node) bool

func Tconv

func Tconv(t *Type, flag int) string

Fmt "%T": types. Flags: 'l' print definition, not name

'h' omit 'func' and receiver from function types, short type names
'u' package name, not prefix (FTypeId mode, sticky)

func Tempname

func Tempname(nn *Node, t *Type)

* make a new off the books

func Umagic

func Umagic(m *Magic)

* magic number for unsigned division * see hacker's delight chapter 10

func Vconv

func Vconv(v *Val, flag int) string

Fmt "%V": Values

func Warn

func Warn(fmt_ string, args ...interface{})

func Warnl

func Warnl(line int, fmt_ string, args ...interface{})

func Yyerror

func Yyerror(format string, args ...interface{})

Types

type Arch

type Arch struct {
	Thechar      int
	Thestring    string
	Thelinkarch  *obj.LinkArch
	Typedefs     []Typedef
	REGSP        int
	REGCTXT      int
	REGCALLX     int // BX
	REGCALLX2    int // AX
	REGRETURN    int // AX
	REGMIN       int
	REGMAX       int
	REGZERO      int // architectural zero register, if available
	FREGMIN      int
	FREGMAX      int
	MAXWIDTH     int64
	ReservedRegs []int

	AddIndex     func(*Node, int64, *Node) bool // optional
	Betypeinit   func()
	Bgen_float   func(*Node, int, int, *obj.Prog) // optional
	Cgen64       func(*Node, *Node)               // only on 32-bit systems
	Cgenindex    func(*Node, *Node, bool) *obj.Prog
	Cgen_bmul    func(int, *Node, *Node, *Node) bool
	Cgen_float   func(*Node, *Node) // optional
	Cgen_hmul    func(*Node, *Node, *Node)
	Cgen_shift   func(int, bool, *Node, *Node, *Node)
	Clearfat     func(*Node)
	Cmp64        func(*Node, *Node, int, int, *obj.Prog) // only on 32-bit systems
	Defframe     func(*obj.Prog)
	Dodiv        func(int, *Node, *Node, *Node)
	Excise       func(*Flow)
	Expandchecks func(*obj.Prog)
	Getg         func(*Node)
	Gins         func(int, *Node, *Node) *obj.Prog
	Ginscon      func(int, int64, *Node)
	Ginsnop      func()
	Gmove        func(*Node, *Node)
	Igenindex    func(*Node, *Node, bool) *obj.Prog
	Linkarchinit func()
	Peep         func(*obj.Prog)
	Proginfo     func(*obj.Prog) // fills in Prog.Info
	Regtyp       func(*obj.Addr) bool
	Sameaddr     func(*obj.Addr, *obj.Addr) bool
	Smallindir   func(*obj.Addr, *obj.Addr) bool
	Stackaddr    func(*obj.Addr) bool
	Stackcopy    func(*Node, *Node, int64, int64, int64)
	Sudoaddable  func(int, *Node, *obj.Addr) bool
	Sudoclean    func()
	Excludedregs func() uint64
	RtoB         func(int) uint64
	FtoB         func(int) uint64
	BtoR         func(uint64) int
	BtoF         func(uint64) int
	Optoas       func(int, *Type) int
	Doregbits    func(int) uint64
	Regnames     func(*int) []string
	Use387       bool // should 8g use 387 FP instructions instead of sse2.
}
var Thearch Arch

type BasicBlock

type BasicBlock struct {
	// contains filtered or unexported fields
}

An ordinary basic block.

Instructions are threaded together in a doubly-linked list. To iterate in program order follow the link pointer from the first node and stop after the last node has been visited

for(p = bb->first;; p = p->link) {
  ...
  if(p == bb->last)
    break;
}

To iterate in reverse program order by following the opt pointer from the last node

for(p = bb->last; p != nil; p = p->opt) {
  ...
}

type Bits

type Bits struct {
	// contains filtered or unexported fields
}

Bits represents a set of Vars, stored as a bit set of var numbers (the index in vars, or equivalently v.id).

func (Bits) String

func (bits Bits) String() string

String returns a space-separated list of the variables represented by bits.

type Bvec

type Bvec struct {
	// contains filtered or unexported fields
}

A Bvec is a bit vector.

type Dlist

type Dlist struct {
	// contains filtered or unexported fields
}

type Error

type Error struct {
	// contains filtered or unexported fields
}

type EscState

type EscState struct {
	// contains filtered or unexported fields
}

type Flow

type Flow struct {
	Prog   *obj.Prog // actual instruction
	P1     *Flow     // predecessors of this instruction: p1,
	P2     *Flow     // and then p2 linked though p2link.
	P2link *Flow
	S1     *Flow // successors of this instruction (at most two: s1 and s2).
	S2     *Flow
	Link   *Flow // next instruction in function code

	Active int32 // usable by client

	Id     int32  // sequence number in flow graph
	Rpo    int32  // reverse post ordering
	Loop   uint16 // x5 for every loop
	Refset uint8  // diagnostic generated

	Data interface{} // for use by client
}

func Uniqp

func Uniqp(r *Flow) *Flow

func Uniqs

func Uniqs(r *Flow) *Flow

type Func

type Func struct {
	Shortname *Node
	Enter     *NodeList
	Exit      *NodeList
	Cvars     *NodeList // closure params
	Dcl       *NodeList // autodcl for this func/closure
	Inldcl    *NodeList // copy of dcl for use in inlining
	Closgen   int
	Outerfunc *Node

	Inl     *NodeList // copy of the body for use in inlining
	InlCost int32

	Endlineno int32

	Nosplit        bool // func should not execute on separate stack
	Nowritebarrier bool // emit compiler error instead of write barrier
	Dupok          bool // duplicate definitions ok
	Wrapper        bool // is method wrapper
	Needctxt       bool // function uses context register (has closure variables)
}

Func holds Node fields used only with function-like nodes.

type Graph

type Graph struct {
	Start *Flow
	Num   int

	// After calling flowrpo, rpo lists the flow nodes in reverse postorder,
	// and each non-dead Flow node f has g->rpo[f->rpo] == f.
	Rpo []*Flow
}

func Flowstart

func Flowstart(firstp *obj.Prog, newData func() interface{}) *Graph

type Idir

type Idir struct {
	// contains filtered or unexported fields
}

type InitEntry

type InitEntry struct {
	Xoffset int64 // struct, array only
	Expr    *Node // bytes of run-time computed expressions
}

type InitPlan

type InitPlan struct {
	Lit  int64
	Zero int64
	Expr int64
	E    []InitEntry
}

type Io

type Io struct {
	// contains filtered or unexported fields
}

type Iter

type Iter struct {
	Done  int
	Tfunc *Type
	T     *Type
}

type Label

type Label struct {
	Used uint8
	Sym  *Sym
	Def  *Node
	Use  *NodeList
	Link *Label

	// for use during gen
	Gotopc   *obj.Prog // pointer to unresolved gotos
	Labelpc  *obj.Prog // pointer to code
	Breakpc  *obj.Prog // pointer to code
	Continpc *obj.Prog // pointer to code
}

type Liveness

type Liveness struct {
	// contains filtered or unexported fields
}

A collection of global state used by liveness analysis.

type Loophack

type Loophack struct {
	// contains filtered or unexported fields
}

type Magic

type Magic struct {
	W   int // input for both - width
	S   int // output for both - shift
	Bad int // output for both - unexpected failure

	// magic multiplier for signed literal divisors
	Sd int64 // input - literal divisor
	Sm int64 // output - multiplier

	// magic multiplier for unsigned literal divisors
	Ud uint64 // input - literal divisor
	Um uint64 // output - multiplier
	Ua int    // output - adder
}

* argument passing to/from * smagic and umagic

type Mpcplx

type Mpcplx struct {
	Real Mpflt
	Imag Mpflt
}

Mpcplx represents a complex constant.

type Mpflt

type Mpflt struct {
	Val big.Float
}

Mpflt represents a floating-point constant.

type Mpint

type Mpint struct {
	Val big.Int
	Ovf bool // set if Val overflowed compiler limit (sticky)
}

Mpint represents an integer constant.

type Node

type Node struct {
	// Tree structure.
	// Generic recursive walks should follow these fields.
	Left  *Node
	Right *Node
	Ntest *Node
	Nincr *Node
	Ninit *NodeList
	Nbody *NodeList
	Nelse *NodeList
	List  *NodeList
	Rlist *NodeList

	Op          uint8
	Nointerface bool
	Ullman      uint8 // sethi/ullman number
	Addable     bool  // addressable
	Etype       uint8 // op for OASOP, etype for OTYPE, exclam for export
	Bounded     bool  // bounds check unnecessary
	Class       uint8 // PPARAM, PAUTO, PEXTERN, etc
	Method      bool  // OCALLMETH is direct method call
	Embedded    uint8 // ODCLFIELD embedded type
	Colas       bool  // OAS resulting from :=
	Diag        uint8 // already printed error about this
	Noescape    bool  // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
	Walkdef     uint8
	Typecheck   uint8
	Local       bool
	Dodata      uint8
	Initorder   uint8
	Used        bool
	Isddd       bool // is the argument variadic
	Readonly    bool
	Implicit    bool
	Addrtaken   bool  // address taken, even if not moved to heap
	Assigned    bool  // is the variable ever assigned to
	Captured    bool  // is the variable captured by a closure
	Byval       bool  // is the variable captured by value or by reference
	Reslice     bool  // this is a reslice x = x[0:y] or x = append(x, ...)
	Likely      int8  // likeliness of if statement
	Hasbreak    bool  // has break statement
	Needzero    bool  // if it contains pointers, needs to be zeroed on function entry
	Esc         uint8 // EscXXX
	Funcdepth   int32

	// most nodes
	Type  *Type
	Orig  *Node // original form, for printing, and tracking copies of ONAMEs
	Nname *Node

	// func
	Func *Func

	// OLITERAL
	Val Val

	// OREGISTER, OINDREG
	Reg int16

	// ONAME
	Ntype     *Node
	Defn      *Node // ONAME: initializing assignment; OLABEL: labeled statement
	Pack      *Node // real package for import . names
	Curfn     *Node // function for local variables
	Paramfld  *Type // TFIELD for this PPARAM; also for ODOT, curfn
	Decldepth int   // declaration loop depth, increased for every loop or label

	// ONAME func param with PHEAP
	Heapaddr   *Node // temp holding heap address of param
	Outerexpr  *Node // expression copied into closure for variable
	Stackparam *Node // OPARAM node referring to stack copy of param
	Alloc      *Node // allocation call

	// ONAME closure param with PPARAMREF
	Outer   *Node // outer PPARAMREF in nested closure
	Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF
	Top     int   // top context (Ecall, Eproc, etc)

	// ONAME substitute while inlining
	Inlvar *Node

	// OPACK
	Pkg *Pkg

	// OARRAYLIT, OMAPLIT, OSTRUCTLIT.
	Initplan *InitPlan

	// Escape analysis.
	Escflowsrc   *NodeList // flow(this, src)
	Escretval    *NodeList // on OCALLxxx, list of dummy return values
	Escloopdepth int       // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes

	Sym      *Sym  // various
	Vargen   int32 // unique name for OTYPE/ONAME
	Lineno   int32
	Xoffset  int64
	Stkdelta int64 // offset added by stack frame compaction phase.
	Ostk     int32 // 6g only
	Iota     int32
	Walkgen  uint32
	Esclevel int32
	Opt      interface{} // for optimization passes
}

A Node is a single node in the syntax tree. Actually the syntax tree is a syntax DAG, because there is only one node with Op=ONAME for a given instance of a variable x. The same is true for Op=OTYPE and Op=OLITERAL.

var Curfn *Node
var Deferproc *Node
var Deferreturn *Node
var Newproc *Node
var Panicindex *Node

func Nod

func Nod(op int, nleft *Node, nright *Node) *Node

func Nodbool

func Nodbool(b bool) *Node

func Nodintconst

func Nodintconst(v int64) *Node

func Sysfunc

func Sysfunc(name string) *Node

func (*Node) Line

func (n *Node) Line() string

type NodeList

type NodeList struct {
	N    *Node
	Next *NodeList
	End  *NodeList
}

A NodeList is a linked list of nodes. TODO(rsc): Some uses of NodeList should be made into slices. The remaining ones probably just need a simple linked list, not one with concatenation support.

type OptStats

type OptStats struct {
	Ncvtreg int32
	Nspill  int32
	Nreload int32
	Ndelmov int32
	Nvar    int32
	Naddr   int32
}
var Ostats OptStats

type Order

type Order struct {
	// contains filtered or unexported fields
}

Order holds state during the ordering process.

type Pkg

type Pkg struct {
	Name     string // package name
	Path     string // string literal used in import statement
	Pathsym  *Sym
	Prefix   string // escaped path for use in symbol table
	Imported uint8  // export data of this package was parsed
	Exported int8   // import line written in export data
	Direct   int8   // imported directly
	Safe     bool   // whether the package is marked as safe
	Syms     map[string]*Sym
}
var Runtimepkg *Pkg // package runtime

func (*Pkg) Lookup

func (pkg *Pkg) Lookup(name string) *Sym

func (*Pkg) LookupBytes

func (pkg *Pkg) LookupBytes(name []byte) *Sym

type ProgGen

type ProgGen struct {
	// contains filtered or unexported fields
}

Helper object for generation of GC programs.

type Reg

type Reg struct {
	// contains filtered or unexported fields
}

A Reg is a wrapper around a single Prog (one instruction) that holds register optimization information while the optimizer runs. r->prog is the instruction.

type Rgn

type Rgn struct {
	// contains filtered or unexported fields
}

A Rgn represents a single regopt variable over a region of code where a register could potentially be dedicated to that variable. The code encompassed by a Rgn is defined by the flow graph, starting at enter, flood-filling forward while varno is refahead and backward while varno is refbehind, and following branches. A single variable may be represented by multiple disjoint Rgns and each Rgn may choose a different register for that variable. Registers are allocated to regions greedily in order of descending cost.

type Sig

type Sig struct {
	// contains filtered or unexported fields
}

type Sym

type Sym struct {
	Lexical   uint16
	Flags     uint8
	Link      *Sym
	Uniqgen   uint32
	Importdef *Pkg   // where imported definition was found
	Linkname  string // link name

	// saved and restored by dcopy
	Pkg        *Pkg
	Name       string // variable name
	Def        *Node  // definition: ONAME OTYPE OPACK or OLITERAL
	Label      *Label // corresponding label (ephemeral)
	Block      int32  // blocknumber to catch redeclaration
	Lastlineno int32  // last declaration for diagnostic
	Origpkg    *Pkg   // original package for . import
	Lsym       *obj.LSym
	Fsym       *Sym // funcsym
}

func Lookup

func Lookup(name string) *Sym

func LookupBytes

func LookupBytes(name []byte) *Sym

func Lookupf

func Lookupf(format string, a ...interface{}) *Sym

func Pkglookup

func Pkglookup(name string, pkg *Pkg) *Sym
type Symlink struct {
	// contains filtered or unexported fields
}

* code to help generate trampoline * functions for methods on embedded * subtypes. * these are approx the same as * the corresponding adddot routines * except that they expect to be called * with unique tasks and they return * the actual methods.

type TempVar

type TempVar struct {
	// contains filtered or unexported fields
}

type Type

type Type struct {
	Etype       uint8
	Nointerface bool
	Noalg       uint8
	Chan        uint8
	Trecur      uint8 // to detect loops
	Printed     uint8
	Embedded    uint8 // TFIELD embedded type
	Siggen      uint8
	Funarg      uint8 // on TSTRUCT and TFIELD
	Copyany     uint8
	Local       bool // created in this file
	Deferwidth  uint8
	Broke       uint8 // broken type definition.
	Isddd       bool  // TFIELD is ... argument
	Align       uint8
	Haspointers uint8 // 0 unknown, 1 no, 2 yes

	Nod    *Node // canonical OTYPE node
	Orig   *Type // original type (type literal or predefined type)
	Lineno int

	// TFUNC
	Thistuple int
	Outtuple  int
	Intuple   int
	Outnamed  uint8

	Method  *Type
	Xmethod *Type

	Sym    *Sym
	Vargen int32 // unique name for OTYPE/ONAME

	Nname  *Node
	Argwid int64

	// most nodes
	Type  *Type // actual type for TFIELD, element type for TARRAY, TCHAN, TMAP, TPTRxx
	Width int64 // offset in TFIELD, width in all others

	// TFIELD
	Down  *Type   // next struct field, also key type in TMAP
	Outer *Type   // outer struct
	Note  *string // literal string annotation

	// TARRAY
	Bound int64 // negative is dynamic array

	// TMAP
	Bucket *Type // internal type representing a hash bucket
	Hmap   *Type // internal type representing a Hmap (map header object)
	Hiter  *Type // internal type representing hash iterator state
	Map    *Type // link from the above 3 internal types back to the map type.

	Maplineno   int32 // first use of TFORW as map key
	Embedlineno int32 // first use of TFORW as embedded type

	// for TFORW, where to copy the eventual value to
	Copyto *NodeList

	Lastfn *Node // for usefield
}

func Getoutarg

func Getoutarg(t *Type) **Type

func Ptrto

func Ptrto(t *Type) *Type

func Structfirst

func Structfirst(s *Iter, nn **Type) *Type

* iterator to walk a structure declaration

type TypeList

type TypeList struct {
	// contains filtered or unexported fields
}

* when a type's width should be known, we call checkwidth * to compute it. during a declaration like * * type T *struct { next T } * * it is necessary to defer the calculation of the struct width * until after T has been initialized to be a pointer to that struct. * similarly, during import processing structs may be used * before their definition. in those situations, calling * defercheckwidth() stops width calculations until * resumecheckwidth() is called, at which point all the * checkwidths that were deferred are executed. * dowidth should only be called when the type's size * is needed immediately. checkwidth makes sure the * size is evaluated eventually.

type TypePairList

type TypePairList struct {
	// contains filtered or unexported fields
}

type Typedef

type Typedef struct {
	Name   string
	Etype  int
	Sameas int
}

type Val

type Val struct {
	Ctype int16
	U     struct {
		Bval bool    // bool value CTBOOL
		Xval *Mpint  // int CTINT, rune CTRUNE
		Fval *Mpflt  // float CTFLT
		Cval *Mpcplx // float CTCPLX
		Sval string  // string CTSTR
	}
}

type Var

type Var struct {
	// contains filtered or unexported fields
}

A Var represents a single variable that may be stored in a register. That variable may itself correspond to a hardware register, to represent the use of registers in the unoptimized instruction stream.

Directories

Path Synopsis
Package big implements multi-precision arithmetic (big numbers).
Package big implements multi-precision arithmetic (big numbers).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL