Commit 1b853006 authored by Cherry Zhang's avatar Cherry Zhang

cmd/compile: clean up SSA-building code

Now that the write barrier insertion is moved to SSA, the SSA
building code can be simplified.

Updates #17583.

Change-Id: I5cacc034b11aa90b0abe6f8dd97e4e3994e2bc25
Reviewed-on: https://go-review.googlesource.com/36840
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 9ebf3d51
This diff is collapsed.
......@@ -95,6 +95,9 @@ type Logger interface {
// Fatal reports a compiler error and exits.
Fatalf(pos src.XPos, msg string, args ...interface{})
// Error reports a compiler error but keep going.
Error(pos src.XPos, msg string, args ...interface{})
// Warnl writes compiler messages in the form expected by "errorcheck" tests
Warnl(pos src.XPos, fmt_ string, args ...interface{})
......@@ -354,6 +357,7 @@ func (c *Config) NewFunc() *Func {
func (c *Config) Logf(msg string, args ...interface{}) { c.fe.Logf(msg, args...) }
func (c *Config) Log() bool { return c.fe.Log() }
func (c *Config) Fatalf(pos src.XPos, msg string, args ...interface{}) { c.fe.Fatalf(pos, msg, args...) }
func (c *Config) Error(pos src.XPos, msg string, args ...interface{}) { c.fe.Error(pos, msg, args...) }
func (c *Config) Warnl(pos src.XPos, msg string, args ...interface{}) { c.fe.Warnl(pos, msg, args...) }
func (c *Config) Debug_checknil() bool { return c.fe.Debug_checknil() }
func (c *Config) Debug_wb() bool { return c.fe.Debug_wb() }
......
......@@ -96,6 +96,7 @@ func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, arg
func (d DummyFrontend) Log() bool { return true }
func (d DummyFrontend) Fatalf(_ src.XPos, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) }
func (d DummyFrontend) Error(_ src.XPos, msg string, args ...interface{}) { d.t.Errorf(msg, args...) }
func (d DummyFrontend) Warnl(_ src.XPos, msg string, args ...interface{}) { d.t.Logf(msg, args...) }
func (d DummyFrontend) Debug_checknil() bool { return false }
func (d DummyFrontend) Debug_wb() bool { return false }
......
......@@ -27,6 +27,9 @@ type Func struct {
scheduled bool // Values in Blocks are in final order
NoSplit bool // true if function is marked as nosplit. Used by schedule check pass.
NoWB bool // write barrier is not allowed
WBPos src.XPos // line number of first write barrier
// when register allocation is done, maps value ids to locations
RegAlloc []Location
......
......@@ -19,7 +19,7 @@ func needwb(v *Value) bool {
if !t.HasPointer() {
return false
}
if IsStackAddr(v.Args[0]) {
if isStackAddr(v.Args[0]) {
return false // write on stack doesn't need write barrier
}
return true
......@@ -207,6 +207,12 @@ func writebarrier(f *Func) {
memElse = bElse.NewValue3I(pos, op, TypeMem, siz, ptr, val, memElse)
}
if f.NoWB {
f.Config.fe.Error(pos, "write barrier prohibited")
}
if !f.WBPos.IsKnown() {
f.WBPos = pos
}
if f.Config.fe.Debug_wb() {
f.Config.Warnl(pos, "write barrier")
}
......@@ -309,8 +315,8 @@ func round(o int64, r int64) int64 {
return (o + r - 1) &^ (r - 1)
}
// IsStackAddr returns whether v is known to be an address of a stack slot
func IsStackAddr(v *Value) bool {
// isStackAddr returns whether v is known to be an address of a stack slot
func isStackAddr(v *Value) bool {
for v.Op == OpOffPtr || v.Op == OpAddPtr || v.Op == OpPtrIndex || v.Op == OpCopy {
v = v.Args[0]
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment