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