-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: better job of naming compound types
Compound AUTO types weren't named previously. That was because live variable analysis (plive.go) doesn't handle spilling to compound types. It can't handle them because there is no valid place to put VARDEFs when regalloc is spilling compound types. compound types = multiword builtin types: complex, string, slice, and interface. Instead, we split named AUTOs into individual one-word variables. For example, a string s gets split into a byte ptr s.ptr and an integer s.len. Those two variables can be spilled to / restored from independently. As a result, live variable analysis can handle them because they are one-word objects. This CL will change how AUTOs are described in DWARF information. Consider the code: func f(s string, i int) int { x := s[i:i+5] g() return lookup(x) } The old compiler would spill x to two consecutive slots on the stack, both named x (at offsets 0 and 8). The new compiler spills the pointer of x to a slot named x.ptr. It doesn't spill x.len at all, as it is a constant (5) and can be rematerialized for the call to lookup. So compound objects may not be spilled in their entirety, and even if they are they won't necessarily be contiguous. Such is the price of optimization. Re-enable live variable analysis tests. One test remains disabled, it fails because of #14904. Change-Id: I8ef2b5ab91e43a0d2136bfc231c05d100ec0b801 Reviewed-on: https://go-review.googlesource.com/21233 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
- Loading branch information
Showing
10 changed files
with
1,253 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,92 @@ | ||
// Copyright 2016 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// This file contains rules to decompose builtin compound types | ||
// (complex,string,slice,interface) into their constituent | ||
// types. These rules work together with the decomposeBuiltIn | ||
// pass which handles phis of these types. | ||
|
||
// complex ops | ||
(ComplexReal (ComplexMake real _ )) -> real | ||
(ComplexImag (ComplexMake _ imag )) -> imag | ||
|
||
(Load <t> ptr mem) && t.IsComplex() && t.Size() == 8 -> | ||
(ComplexMake | ||
(Load <config.fe.TypeFloat32()> ptr mem) | ||
(Load <config.fe.TypeFloat32()> | ||
(OffPtr <config.fe.TypeFloat32().PtrTo()> [4] ptr) | ||
mem) | ||
) | ||
(Store [8] dst (ComplexMake real imag) mem) -> | ||
(Store [4] | ||
(OffPtr <config.fe.TypeFloat32().PtrTo()> [4] dst) | ||
imag | ||
(Store [4] dst real mem)) | ||
(Load <t> ptr mem) && t.IsComplex() && t.Size() == 16 -> | ||
(ComplexMake | ||
(Load <config.fe.TypeFloat64()> ptr mem) | ||
(Load <config.fe.TypeFloat64()> | ||
(OffPtr <config.fe.TypeFloat64().PtrTo()> [8] ptr) | ||
mem) | ||
) | ||
(Store [16] dst (ComplexMake real imag) mem) -> | ||
(Store [8] | ||
(OffPtr <config.fe.TypeFloat64().PtrTo()> [8] dst) | ||
imag | ||
(Store [8] dst real mem)) | ||
|
||
// string ops | ||
(StringPtr (StringMake ptr _)) -> ptr | ||
(StringLen (StringMake _ len)) -> len | ||
|
||
(Load <t> ptr mem) && t.IsString() -> | ||
(StringMake | ||
(Load <config.fe.TypeBytePtr()> ptr mem) | ||
(Load <config.fe.TypeInt()> | ||
(OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr) | ||
mem)) | ||
(Store [2*config.PtrSize] dst (StringMake ptr len) mem) -> | ||
(Store [config.PtrSize] | ||
(OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst) | ||
len | ||
(Store [config.PtrSize] dst ptr mem)) | ||
|
||
// slice ops | ||
(SlicePtr (SliceMake ptr _ _ )) -> ptr | ||
(SliceLen (SliceMake _ len _)) -> len | ||
(SliceCap (SliceMake _ _ cap)) -> cap | ||
|
||
(Load <t> ptr mem) && t.IsSlice() -> | ||
(SliceMake | ||
(Load <t.ElemType().PtrTo()> ptr mem) | ||
(Load <config.fe.TypeInt()> | ||
(OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr) | ||
mem) | ||
(Load <config.fe.TypeInt()> | ||
(OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] ptr) | ||
mem)) | ||
(Store [3*config.PtrSize] dst (SliceMake ptr len cap) mem) -> | ||
(Store [config.PtrSize] | ||
(OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] dst) | ||
cap | ||
(Store [config.PtrSize] | ||
(OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst) | ||
len | ||
(Store [config.PtrSize] dst ptr mem))) | ||
|
||
// interface ops | ||
(ITab (IMake itab _)) -> itab | ||
(IData (IMake _ data)) -> data | ||
|
||
(Load <t> ptr mem) && t.IsInterface() -> | ||
(IMake | ||
(Load <config.fe.TypeBytePtr()> ptr mem) | ||
(Load <config.fe.TypeBytePtr()> | ||
(OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] ptr) | ||
mem)) | ||
(Store [2*config.PtrSize] dst (IMake itab data) mem) -> | ||
(Store [config.PtrSize] | ||
(OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] dst) | ||
data | ||
(Store [config.PtrSize] dst itab mem)) |
Oops, something went wrong.