...

Source file src/pkg/cmd/compile/internal/gc/go.go

     1	// Copyright 2009 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	package gc
     6	
     7	import (
     8		"cmd/compile/internal/ssa"
     9		"cmd/compile/internal/types"
    10		"cmd/internal/obj"
    11		"cmd/internal/src"
    12		"sync"
    13	)
    14	
    15	const (
    16		BADWIDTH = types.BADWIDTH
    17	)
    18	
    19	var (
    20		// maximum size variable which we will allocate on the stack.
    21		// This limit is for explicit variable declarations like "var x T" or "x := ...".
    22		// Note: the flag smallframes can update this value.
    23		maxStackVarSize = int64(10 * 1024 * 1024)
    24	
    25		// maximum size of implicit variables that we will allocate on the stack.
    26		//   p := new(T)          allocating T on the stack
    27		//   p := &T{}            allocating T on the stack
    28		//   s := make([]T, n)    allocating [n]T on the stack
    29		//   s := []byte("...")   allocating [n]byte on the stack
    30		// Note: the flag smallframes can update this value.
    31		maxImplicitStackVarSize = int64(64 * 1024)
    32	)
    33	
    34	// isRuntimePkg reports whether p is package runtime.
    35	func isRuntimePkg(p *types.Pkg) bool {
    36		if compiling_runtime && p == localpkg {
    37			return true
    38		}
    39		return p.Path == "runtime"
    40	}
    41	
    42	// The Class of a variable/function describes the "storage class"
    43	// of a variable or function. During parsing, storage classes are
    44	// called declaration contexts.
    45	type Class uint8
    46	
    47	//go:generate stringer -type=Class
    48	const (
    49		Pxxx      Class = iota // no class; used during ssa conversion to indicate pseudo-variables
    50		PEXTERN                // global variable
    51		PAUTO                  // local variables
    52		PAUTOHEAP              // local variable or parameter moved to heap
    53		PPARAM                 // input arguments
    54		PPARAMOUT              // output results
    55		PFUNC                  // global function
    56	
    57		PDISCARD // discard during parse of duplicate import
    58		// Careful: Class is stored in three bits in Node.flags.
    59		// Adding a new Class will overflow that.
    60	)
    61	
    62	func init() {
    63		if PDISCARD != 7 {
    64			panic("PDISCARD changed; does all Class values still fit in three bits?")
    65		}
    66	}
    67	
    68	// note this is the runtime representation
    69	// of the compilers arrays.
    70	//
    71	// typedef	struct
    72	// {				// must not move anything
    73	// 	uchar	array[8];	// pointer to data
    74	// 	uchar	nel[4];		// number of elements
    75	// 	uchar	cap[4];		// allocated number of elements
    76	// } Array;
    77	var array_array int // runtime offsetof(Array,array) - same for String
    78	
    79	var array_nel int // runtime offsetof(Array,nel) - same for String
    80	
    81	var array_cap int // runtime offsetof(Array,cap)
    82	
    83	var sizeof_Array int // runtime sizeof(Array)
    84	
    85	// note this is the runtime representation
    86	// of the compilers strings.
    87	//
    88	// typedef	struct
    89	// {				// must not move anything
    90	// 	uchar	array[8];	// pointer to data
    91	// 	uchar	nel[4];		// number of elements
    92	// } String;
    93	var sizeof_String int // runtime sizeof(String)
    94	
    95	var pragcgobuf [][]string
    96	
    97	var outfile string
    98	var linkobj string
    99	
   100	// nerrors is the number of compiler errors reported
   101	// since the last call to saveerrors.
   102	var nerrors int
   103	
   104	// nsavederrors is the total number of compiler errors
   105	// reported before the last call to saveerrors.
   106	var nsavederrors int
   107	
   108	var nsyntaxerrors int
   109	
   110	var decldepth int32
   111	
   112	var nolocalimports bool
   113	
   114	var Debug [256]int
   115	
   116	var debugstr string
   117	
   118	var Debug_checknil int
   119	var Debug_typeassert int
   120	
   121	var localpkg *types.Pkg // package being compiled
   122	
   123	var inimport bool // set during import
   124	
   125	var itabpkg *types.Pkg // fake pkg for itab entries
   126	
   127	var itablinkpkg *types.Pkg // fake package for runtime itab entries
   128	
   129	var Runtimepkg *types.Pkg // fake package runtime
   130	
   131	var racepkg *types.Pkg // package runtime/race
   132	
   133	var msanpkg *types.Pkg // package runtime/msan
   134	
   135	var unsafepkg *types.Pkg // package unsafe
   136	
   137	var trackpkg *types.Pkg // fake package for field tracking
   138	
   139	var mappkg *types.Pkg // fake package for map zero value
   140	
   141	var gopkg *types.Pkg // pseudo-package for method symbols on anonymous receiver types
   142	
   143	var zerosize int64
   144	
   145	var myimportpath string
   146	
   147	var localimport string
   148	
   149	var asmhdr string
   150	
   151	var simtype [NTYPE]types.EType
   152	
   153	var (
   154		isInt     [NTYPE]bool
   155		isFloat   [NTYPE]bool
   156		isComplex [NTYPE]bool
   157		issimple  [NTYPE]bool
   158	)
   159	
   160	var (
   161		okforeq    [NTYPE]bool
   162		okforadd   [NTYPE]bool
   163		okforand   [NTYPE]bool
   164		okfornone  [NTYPE]bool
   165		okforcmp   [NTYPE]bool
   166		okforbool  [NTYPE]bool
   167		okforcap   [NTYPE]bool
   168		okforlen   [NTYPE]bool
   169		okforarith [NTYPE]bool
   170		okforconst [NTYPE]bool
   171	)
   172	
   173	var (
   174		okfor [OEND][]bool
   175		iscmp [OEND]bool
   176	)
   177	
   178	var minintval [NTYPE]*Mpint
   179	
   180	var maxintval [NTYPE]*Mpint
   181	
   182	var minfltval [NTYPE]*Mpflt
   183	
   184	var maxfltval [NTYPE]*Mpflt
   185	
   186	var xtop []*Node
   187	
   188	var exportlist []*Node
   189	
   190	var importlist []*Node // imported functions and methods with inlinable bodies
   191	
   192	var (
   193		funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym)
   194		funcsyms   []*types.Sym
   195	)
   196	
   197	var dclcontext Class // PEXTERN/PAUTO
   198	
   199	var Curfn *Node
   200	
   201	var Widthptr int
   202	
   203	var Widthreg int
   204	
   205	var nblank *Node
   206	
   207	var typecheckok bool
   208	
   209	var compiling_runtime bool
   210	
   211	// Compiling the standard library
   212	var compiling_std bool
   213	
   214	var use_writebarrier bool
   215	
   216	var pure_go bool
   217	
   218	var flag_installsuffix string
   219	
   220	var flag_race bool
   221	
   222	var flag_msan bool
   223	
   224	var flagDWARF bool
   225	
   226	// Whether we are adding any sort of code instrumentation, such as
   227	// when the race detector is enabled.
   228	var instrumenting bool
   229	
   230	// Whether we are tracking lexical scopes for DWARF.
   231	var trackScopes bool
   232	
   233	// Controls generation of DWARF inlined instance records. Zero
   234	// disables, 1 emits inlined routines but suppresses var info,
   235	// and 2 emits inlined routines with tracking of formals/locals.
   236	var genDwarfInline int
   237	
   238	var debuglive int
   239	
   240	var Ctxt *obj.Link
   241	
   242	var writearchive bool
   243	
   244	var Nacl bool
   245	
   246	var nodfp *Node
   247	
   248	var disable_checknil int
   249	
   250	var autogeneratedPos src.XPos
   251	
   252	// interface to back end
   253	
   254	type Arch struct {
   255		LinkArch *obj.LinkArch
   256	
   257		REGSP     int
   258		MAXWIDTH  int64
   259		Use387    bool // should 386 backend use 387 FP instructions instead of sse2.
   260		SoftFloat bool
   261	
   262		PadFrame     func(int64) int64
   263		ZeroRange    func(*Progs, *obj.Prog, int64, int64, *uint32) *obj.Prog
   264		Ginsnop      func(*Progs) *obj.Prog
   265		Ginsnopdefer func(*Progs) *obj.Prog // special ginsnop for deferreturn
   266	
   267		// SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
   268		SSAMarkMoves func(*SSAGenState, *ssa.Block)
   269	
   270		// SSAGenValue emits Prog(s) for the Value.
   271		SSAGenValue func(*SSAGenState, *ssa.Value)
   272	
   273		// SSAGenBlock emits end-of-block Progs. SSAGenValue should be called
   274		// for all values in the block before SSAGenBlock.
   275		SSAGenBlock func(s *SSAGenState, b, next *ssa.Block)
   276	
   277		// ZeroAuto emits code to zero the given auto stack variable.
   278		// ZeroAuto must not use any non-temporary registers.
   279		// ZeroAuto will only be called for variables which contain a pointer.
   280		ZeroAuto func(*Progs, *Node)
   281	}
   282	
   283	var thearch Arch
   284	
   285	var (
   286		staticbytes,
   287		zerobase *Node
   288	
   289		assertE2I,
   290		assertE2I2,
   291		assertI2I,
   292		assertI2I2,
   293		deferproc,
   294		deferprocStack,
   295		Deferreturn,
   296		Duffcopy,
   297		Duffzero,
   298		gcWriteBarrier,
   299		goschedguarded,
   300		growslice,
   301		msanread,
   302		msanwrite,
   303		newobject,
   304		newproc,
   305		panicdivide,
   306		panicshift,
   307		panicdottypeE,
   308		panicdottypeI,
   309		panicnildottype,
   310		panicoverflow,
   311		raceread,
   312		racereadrange,
   313		racewrite,
   314		racewriterange,
   315		x86HasPOPCNT,
   316		x86HasSSE41,
   317		arm64HasATOMICS,
   318		typedmemclr,
   319		typedmemmove,
   320		Udiv,
   321		writeBarrier,
   322		zerobaseSym *obj.LSym
   323	
   324		BoundsCheckFunc [ssa.BoundsKindCount]*obj.LSym
   325		ExtendCheckFunc [ssa.BoundsKindCount]*obj.LSym
   326	
   327		// GO386=387
   328		ControlWord64trunc,
   329		ControlWord32 *obj.LSym
   330	
   331		// Wasm
   332		WasmMove,
   333		WasmZero,
   334		WasmDiv,
   335		WasmTruncS,
   336		WasmTruncU,
   337		SigPanic *obj.LSym
   338	)
   339	

View as plain text