Source file src/cmd/compile/internal/ssacompile/writebarrier_test.go

     1  // Copyright 2016 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 ssacompile
     6  
     7  import (
     8  	"testing"
     9  
    10  	"cmd/compile/internal/ssa/ssaop"
    11  	"cmd/compile/internal/types"
    12  )
    13  
    14  func TestWriteBarrierStoreOrder(t *testing.T) {
    15  	// Make sure writebarrier phase works even StoreWB ops are not in dependency order
    16  	c := testConfig(t)
    17  	ptrType := c.config.Types.BytePtr
    18  	fun := c.Fun("entry",
    19  		Bloc("entry",
    20  			Valu("start", ssaop.OpInitMem, types.TypeMem, 0, nil),
    21  			Valu("sb", ssaop.OpSB, c.config.Types.Uintptr, 0, nil),
    22  			Valu("sp", ssaop.OpSP, c.config.Types.Uintptr, 0, nil),
    23  			Valu("v", ssaop.OpConstNil, ptrType, 0, nil),
    24  			Valu("addr1", ssaop.OpAddr, ptrType, 0, nil, "sb"),
    25  			Valu("wb2", ssaop.OpStore, types.TypeMem, 0, ptrType, "addr1", "v", "wb1"),
    26  			Valu("wb1", ssaop.OpStore, types.TypeMem, 0, ptrType, "addr1", "v", "start"), // wb1 and wb2 are out of order
    27  			Goto("exit")),
    28  		Bloc("exit",
    29  			Exit("wb2")))
    30  
    31  	CheckFunc(fun.f)
    32  	writebarrier(fun.f)
    33  	CheckFunc(fun.f)
    34  }
    35  
    36  func TestWriteBarrierPhi(t *testing.T) {
    37  	// Make sure writebarrier phase works for single-block loop, where
    38  	// a Phi op takes the store in the same block as argument.
    39  	// See issue #19067.
    40  	c := testConfig(t)
    41  	ptrType := c.config.Types.BytePtr
    42  	fun := c.Fun("entry",
    43  		Bloc("entry",
    44  			Valu("start", ssaop.OpInitMem, types.TypeMem, 0, nil),
    45  			Valu("sb", ssaop.OpSB, c.config.Types.Uintptr, 0, nil),
    46  			Valu("sp", ssaop.OpSP, c.config.Types.Uintptr, 0, nil),
    47  			Goto("loop")),
    48  		Bloc("loop",
    49  			Valu("phi", ssaop.OpPhi, types.TypeMem, 0, nil, "start", "wb"),
    50  			Valu("v", ssaop.OpConstNil, ptrType, 0, nil),
    51  			Valu("addr", ssaop.OpAddr, ptrType, 0, nil, "sb"),
    52  			Valu("wb", ssaop.OpStore, types.TypeMem, 0, ptrType, "addr", "v", "phi"), // has write barrier
    53  			Goto("loop")))
    54  
    55  	CheckFunc(fun.f)
    56  	writebarrier(fun.f)
    57  	CheckFunc(fun.f)
    58  }
    59  

View as plain text