Skip to content

Commit 9d65a90

Browse files
committed
go/ssa: print dominator tree
This CL adds the immediate dominator to the information displayed about each basic block in the control flow graph printed by the ssadump -build=F flag. Change-Id: I130458c7f698bed90f09a931ef3261ac5e7c0486 Reviewed-on: https://go-review.googlesource.com/c/tools/+/716840 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Markus Kusano <kusano@google.com>
1 parent 7086838 commit 9d65a90

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

go/ssa/builder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,12 @@ func init():
327327
0: entry P:0 S:2
328328
t0 = *init$guard bool
329329
if t0 goto 2 else 1
330-
1: init.start P:1 S:1
330+
1: init.start P:1 S:1 idom:0
331331
*init$guard = true:bool
332332
t1 = errors.init() ()
333333
*i = 42:int
334334
jump 2
335-
2: init.done P:2 S:0
335+
2: init.done P:2 S:0 idom:0
336336
return
337337
338338
`},

go/ssa/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ func Example_buildPackage() {
100100
// 0: entry P:0 S:2
101101
// t0 = *init$guard bool
102102
// if t0 goto 2 else 1
103-
// 1: init.start P:1 S:1
103+
// 1: init.start P:1 S:1 idom:0
104104
// *init$guard = true:bool
105105
// t1 = fmt.init() ()
106106
// jump 2
107-
// 2: init.done P:2 S:0
107+
// 2: init.done P:2 S:0 idom:0
108108
// return
109109
//
110110
// # Name: hello.main

go/ssa/func.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,11 @@ func WriteFunction(buf *bytes.Buffer, f *Function) {
668668
continue
669669
}
670670
n, _ := fmt.Fprintf(buf, "%d:", b.Index)
671+
// (|predecessors|, |successors|, immediate dominator)
671672
bmsg := fmt.Sprintf("%s P:%d S:%d", b.Comment, len(b.Preds), len(b.Succs))
673+
if b.Idom() != nil {
674+
bmsg = fmt.Sprintf("%s idom:%d", bmsg, b.Idom().Index)
675+
}
672676
fmt.Fprintf(buf, "%*s%s\n", punchcard-1-n-len(bmsg), "", bmsg)
673677

674678
if false { // CFG debugging

0 commit comments

Comments
 (0)