github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/cmd/compile/internal/ssa/cache.go (about)

     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  	scrSparse     []*sparseSet // scratch sparse sets to be re-used.
    26  
    27  	ValueToProgAfter []*obj.Prog
    28  	debugState       debugState
    29  }
    30  
    31  func (c *Cache) Reset() {
    32  	nv := sort.Search(len(c.values), func(i int) bool { return c.values[i].ID == 0 })
    33  	xv := c.values[:nv]
    34  	for i := range xv {
    35  		xv[i] = Value{}
    36  	}
    37  	nb := sort.Search(len(c.blocks), func(i int) bool { return c.blocks[i].ID == 0 })
    38  	xb := c.blocks[:nb]
    39  	for i := range xb {
    40  		xb[i] = Block{}
    41  	}
    42  	nl := sort.Search(len(c.locs), func(i int) bool { return c.locs[i] == nil })
    43  	xl := c.locs[:nl]
    44  	for i := range xl {
    45  		xl[i] = nil
    46  	}
    47  
    48  }
    49