Skip to content

Commit 7e68f81

Browse files
committed
cmd/compile: in poset, refactor aliasnode
In preparation for allowing to make multiple nodes as aliases in a single pass, refactor aliasnode splitting out the case in which one of the nodes is not in the post into a new funciton (aliasnewnode). No functional changes, passes toolstash -cmp Change-Id: I19ca6ef8426f8aec9f2622b6151c5c617dbb25b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/200859 Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Giovanni Bajo <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent c3e8a20 commit 7e68f81

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

src/cmd/compile/internal/ssa/poset.go

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -407,56 +407,64 @@ func (po *poset) newconst(n *Value) {
407407
po.upushconst(i, 0)
408408
}
409409

410-
// aliasnode records that n2 is an alias of n1
410+
// aliasnewnode records that a single node n2 (not in the poset yet) is an alias
411+
// of the master node n1.
412+
func (po *poset) aliasnewnode(n1, n2 *Value) {
413+
i1, i2 := po.values[n1.ID], po.values[n2.ID]
414+
if i1 == 0 || i2 != 0 {
415+
panic("aliasnewnode invalid arguments")
416+
}
417+
418+
po.values[n2.ID] = i1
419+
po.upushalias(n2.ID, 0)
420+
}
421+
422+
// aliasnode records that n2 (already in the poset) is an alias of n1
411423
func (po *poset) aliasnode(n1, n2 *Value) {
412424
i1 := po.values[n1.ID]
413425
if i1 == 0 {
414426
panic("aliasnode for non-existing node")
415427
}
416428

417429
i2 := po.values[n2.ID]
418-
if i2 != 0 {
419-
// Rename all references to i2 into i1
420-
// (do not touch i1 itself, otherwise we can create useless self-loops)
421-
for idx, n := range po.nodes {
422-
if uint32(idx) != i1 {
423-
l, r := n.l, n.r
424-
if l.Target() == i2 {
425-
po.setchl(uint32(idx), newedge(i1, l.Strict()))
426-
po.upush(undoSetChl, uint32(idx), l)
427-
}
428-
if r.Target() == i2 {
429-
po.setchr(uint32(idx), newedge(i1, r.Strict()))
430-
po.upush(undoSetChr, uint32(idx), r)
431-
}
430+
if i2 == 0 {
431+
panic("aliasnode for non-existing node")
432+
}
433+
// Rename all references to i2 into i1
434+
// (do not touch i1 itself, otherwise we can create useless self-loops)
435+
for idx, n := range po.nodes {
436+
if uint32(idx) != i1 {
437+
l, r := n.l, n.r
438+
if l.Target() == i2 {
439+
po.setchl(uint32(idx), newedge(i1, l.Strict()))
440+
po.upush(undoSetChl, uint32(idx), l)
432441
}
433-
}
434-
435-
// Reassign all existing IDs that point to i2 to i1.
436-
// This includes n2.ID.
437-
for k, v := range po.values {
438-
if v == i2 {
439-
po.values[k] = i1
440-
po.upushalias(k, i2)
442+
if r.Target() == i2 {
443+
po.setchr(uint32(idx), newedge(i1, r.Strict()))
444+
po.upush(undoSetChr, uint32(idx), r)
441445
}
442446
}
447+
}
443448

444-
if n2.isGenericIntConst() {
445-
val := n2.AuxInt
446-
if po.flags&posetFlagUnsigned != 0 {
447-
val = int64(n2.AuxUnsigned())
448-
}
449-
if po.constants[val] != i2 {
450-
panic("aliasing constant which is not registered")
451-
}
452-
po.constants[val] = i1
453-
po.upushconst(i1, i2)
449+
// Reassign all existing IDs that point to i2 to i1.
450+
// This includes n2.ID.
451+
for k, v := range po.values {
452+
if v == i2 {
453+
po.values[k] = i1
454+
po.upushalias(k, i2)
454455
}
456+
}
455457

456-
} else {
457-
// n2.ID wasn't seen before, so record it as alias to i1
458-
po.values[n2.ID] = i1
459-
po.upushalias(n2.ID, 0)
458+
if n2.isGenericIntConst() {
459+
val := n2.AuxInt
460+
if po.flags&posetFlagUnsigned != 0 {
461+
val = int64(n2.AuxUnsigned())
462+
}
463+
if po.constants[val] != i2 {
464+
panic("aliasing constant which is not registered")
465+
}
466+
po.constants[val] = i1
467+
po.upushconst(i1, i2)
460468
}
461469
}
462470

@@ -1093,11 +1101,11 @@ func (po *poset) SetEqual(n1, n2 *Value) bool {
10931101
i1 = po.newnode(n1)
10941102
po.roots = append(po.roots, i1)
10951103
po.upush(undoNewRoot, i1, 0)
1096-
po.aliasnode(n1, n2)
1104+
po.aliasnewnode(n1, n2)
10971105
case f1 && !f2:
1098-
po.aliasnode(n1, n2)
1106+
po.aliasnewnode(n1, n2)
10991107
case !f1 && f2:
1100-
po.aliasnode(n2, n1)
1108+
po.aliasnewnode(n2, n1)
11011109
case f1 && f2:
11021110
if i1 == i2 {
11031111
// Already aliased, ignore

0 commit comments

Comments
 (0)