...
Run Format

Source file src/cmd/compile/internal/ssa/cache.go

Documentation: cmd/compile/internal/ssa

     1  // Copyright 2017 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 ssa
     6  
     7  import (
     8  	"cmd/internal/obj"
     9  	"sort"
    10  )
    11  
    12  // A Cache holds reusable compiler state.
    13  // It is intended to be re-used for multiple Func compilations.
    14  type Cache struct {
    15  	// Storage for low-numbered values and blocks.
    16  	values [2000]Value
    17  	blocks [200]Block
    18  	locs   [2000]Location
    19  
    20  	// Reusable stackAllocState.
    21  	// See stackalloc.go's {new,put}StackAllocState.
    22  	stackAllocState *stackAllocState
    23  
    24  	domblockstore []ID         // scratch space for computing dominators
    25  	scrSparseSet  []*sparseSet // scratch sparse sets to be re-used.
    26  	scrSparseMap  []*sparseMap // scratch sparse maps to be re-used.
    27  	scrPoset      []*poset     // scratch poset to be reused
    28  
    29  	ValueToProgAfter []*obj.Prog
    30  	debugState       debugState
    31  
    32  	Liveness interface{} // *gc.livenessFuncCache
    33  }
    34  
    35  func (c *Cache) Reset() {
    36  	nv := sort.Search(len(c.values), func(i int) bool { return c.values[i].ID == 0 })
    37  	xv := c.values[:nv]
    38  	for i := range xv {
    39  		xv[i] = Value{}
    40  	}
    41  	nb := sort.Search(len(c.blocks), func(i int) bool { return c.blocks[i].ID == 0 })
    42  	xb := c.blocks[:nb]
    43  	for i := range xb {
    44  		xb[i] = Block{}
    45  	}
    46  	nl := sort.Search(len(c.locs), func(i int) bool { return c.locs[i] == nil })
    47  	xl := c.locs[:nl]
    48  	for i := range xl {
    49  		xl[i] = nil
    50  	}
    51  
    52  }
    53  

View as plain text