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