mirror of
https://github.com/golang/go.git
synced 2025-11-10 13:41:05 +00:00
cmd/compile/internal/ir: remove AsNode
Except for a single call site in escape analysis, every use of ir.AsNode involves a types.Object that's known to contain an *ir.Name. Asserting directly to that type makes the code simpler and more efficient. The one use in escape analysis is extended to handle nil correctly without it. Change-Id: I694ae516903e541341d82c2f65a9155e4b0a9809 Reviewed-on: https://go-review.googlesource.com/c/go/+/520775 TryBot-Bypass: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
parent
4089b6a5b1
commit
7af28fa90e
6 changed files with 13 additions and 17 deletions
|
|
@ -321,7 +321,10 @@ func (e *escape) tagHole(ks []hole, fn *ir.Name, param *types.Field) hole {
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.inMutualBatch(fn) {
|
if e.inMutualBatch(fn) {
|
||||||
return e.addr(ir.AsNode(param.Nname))
|
if param.Nname == nil {
|
||||||
|
return e.discardHole()
|
||||||
|
}
|
||||||
|
return e.addr(param.Nname.(*ir.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call to previously tagged function.
|
// Call to previously tagged function.
|
||||||
|
|
|
||||||
|
|
@ -1110,7 +1110,7 @@ func IsReflectHeaderDataField(l Node) bool {
|
||||||
func ParamNames(ft *types.Type) []Node {
|
func ParamNames(ft *types.Type) []Node {
|
||||||
args := make([]Node, ft.NumParams())
|
args := make([]Node, ft.NumParams())
|
||||||
for i, f := range ft.Params().FieldSlice() {
|
for i, f := range ft.Params().FieldSlice() {
|
||||||
args[i] = AsNode(f.Nname)
|
args[i] = f.Nname.(*Name)
|
||||||
}
|
}
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -462,13 +462,6 @@ const (
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func AsNode(n types.Object) Node {
|
|
||||||
if n == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return n.(Node)
|
|
||||||
}
|
|
||||||
|
|
||||||
var BlankNode *Name
|
var BlankNode *Name
|
||||||
|
|
||||||
func IsConst(n Node, ct constant.Kind) bool {
|
func IsConst(n Node, ct constant.Kind) bool {
|
||||||
|
|
|
||||||
|
|
@ -153,8 +153,8 @@ func hashFunc(t *types.Type) *ir.Func {
|
||||||
sym.Def = fn.Nname
|
sym.Def = fn.Nname
|
||||||
fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining.
|
fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining.
|
||||||
|
|
||||||
np := ir.AsNode(fn.Type().Params().Field(0).Nname)
|
np := fn.Type().Params().Field(0).Nname.(*ir.Name)
|
||||||
nh := ir.AsNode(fn.Type().Params().Field(1).Nname)
|
nh := fn.Type().Params().Field(1).Nname.(*ir.Name)
|
||||||
|
|
||||||
switch t.Kind() {
|
switch t.Kind() {
|
||||||
case types.TARRAY:
|
case types.TARRAY:
|
||||||
|
|
@ -375,9 +375,9 @@ func eqFunc(t *types.Type) *ir.Func {
|
||||||
sym.Def = fn.Nname
|
sym.Def = fn.Nname
|
||||||
fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining.
|
fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining.
|
||||||
|
|
||||||
np := ir.AsNode(fn.Type().Params().Field(0).Nname)
|
np := fn.Type().Params().Field(0).Nname.(*ir.Name)
|
||||||
nq := ir.AsNode(fn.Type().Params().Field(1).Nname)
|
nq := fn.Type().Params().Field(1).Nname.(*ir.Name)
|
||||||
nr := ir.AsNode(fn.Type().Results().Field(0).Nname)
|
nr := fn.Type().Results().Field(0).Nname.(*ir.Name)
|
||||||
|
|
||||||
// Label to jump to if an equality test fails.
|
// Label to jump to if an equality test fails.
|
||||||
neq := typecheck.AutoLabel(".neq")
|
neq := typecheck.AutoLabel(".neq")
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func tokenize(src string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyParamResultOffset(t *testing.T, f *types.Field, r abi.ABIParamAssignment, which string, idx int) int {
|
func verifyParamResultOffset(t *testing.T, f *types.Field, r abi.ABIParamAssignment, which string, idx int) int {
|
||||||
n := ir.AsNode(f.Nname).(*ir.Name)
|
n := f.Nname.(*ir.Name)
|
||||||
if n.FrameOffset() != int64(r.Offset()) {
|
if n.FrameOffset() != int64(r.Offset()) {
|
||||||
t.Errorf("%s %d: got offset %d wanted %d t=%v",
|
t.Errorf("%s %d: got offset %d wanted %d t=%v",
|
||||||
which, idx, r.Offset(), n.Offset_, f.Type)
|
which, idx, r.Offset(), n.Offset_, f.Type)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ func LookupRuntime(name string) *ir.Name {
|
||||||
if s == nil || s.Def == nil {
|
if s == nil || s.Def == nil {
|
||||||
base.Fatalf("LookupRuntime: can't find runtime.%s", name)
|
base.Fatalf("LookupRuntime: can't find runtime.%s", name)
|
||||||
}
|
}
|
||||||
return ir.AsNode(s.Def).(*ir.Name)
|
return s.Def.(*ir.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubstArgTypes substitutes the given list of types for
|
// SubstArgTypes substitutes the given list of types for
|
||||||
|
|
@ -126,5 +126,5 @@ func LookupCoverage(name string) *ir.Name {
|
||||||
if sym == nil {
|
if sym == nil {
|
||||||
base.Fatalf("LookupCoverage: can't find runtime/coverage.%s", name)
|
base.Fatalf("LookupCoverage: can't find runtime/coverage.%s", name)
|
||||||
}
|
}
|
||||||
return ir.AsNode(sym.Def).(*ir.Name)
|
return sym.Def.(*ir.Name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue