Skip to content

Commit 553443d

Browse files
committed
cmd/compile: move limit fact table in prove pass to dense encoding
Here begins a pretty major rewrite of the prove pass. The fundamental observation is that although keeping facts about relations between two SSA values could use O(n^2) space, keeping facts about relations between an SSA value and constants needs only O(n) space. We can just keep track of min/max for every SSA value at little cost. Redo the limit table to just keep track of limits for all SSA values. Use just a slice instead of a map. It may use more space (but still just O(n) space), but accesses are a lot faster. And with the cache in the compiler, that space will be reused quickly. This is part of my planning to add lots more constant limits in the prove pass. Change-Id: Ie36819fad5631a8b79c3630fe0e819521796551a Reviewed-on: https://go-review.googlesource.com/c/go/+/599255 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent e705a2d commit 553443d

File tree

4 files changed

+111
-84
lines changed

4 files changed

+111
-84
lines changed

src/cmd/compile/internal/ssa/_gen/allocators.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ func genAllocators() {
4646
maxLog: 32,
4747
},
4848
{
49-
name: "Int64Slice",
50-
typ: "[]int64",
49+
name: "LimitSlice",
50+
typ: "[]limit", // the limit type is basically [4]uint64.
5151
capacity: "cap(%s)",
52-
mak: "make([]int64, %s)",
52+
mak: "make([]limit, %s)",
5353
resize: "%s[:%s]",
54-
clear: "for i := range %[1]s {\n%[1]s[i] = 0\n}",
55-
minLog: 5,
56-
maxLog: 32,
54+
clear: "for i := range %[1]s {\n%[1]s[i] = limit{}\n}",
55+
minLog: 3,
56+
maxLog: 30,
5757
},
5858
{
5959
name: "SparseSet",
@@ -92,30 +92,35 @@ func genAllocators() {
9292
typ: "[]*Block",
9393
base: "ValueSlice",
9494
},
95+
{
96+
name: "Int64",
97+
typ: "[]int64",
98+
base: "LimitSlice",
99+
},
95100
{
96101
name: "IntSlice",
97102
typ: "[]int",
98-
base: "Int64Slice",
103+
base: "LimitSlice",
99104
},
100105
{
101106
name: "Int32Slice",
102107
typ: "[]int32",
103-
base: "Int64Slice",
108+
base: "LimitSlice",
104109
},
105110
{
106111
name: "Int8Slice",
107112
typ: "[]int8",
108-
base: "Int64Slice",
113+
base: "LimitSlice",
109114
},
110115
{
111116
name: "BoolSlice",
112117
typ: "[]bool",
113-
base: "Int64Slice",
118+
base: "LimitSlice",
114119
},
115120
{
116121
name: "IDSlice",
117122
typ: "[]ID",
118-
base: "Int64Slice",
123+
base: "LimitSlice",
119124
},
120125
}
121126

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

Lines changed: 64 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Cache struct {
3434
// Free "headers" for use by the allocators in allocators.go.
3535
// Used to put slices in sync.Pools without allocation.
3636
hdrValueSlice []*[]*Value
37-
hdrInt64Slice []*[]int64
37+
hdrLimitSlice []*[]limit
3838
}
3939

4040
func (c *Cache) Reset() {

0 commit comments

Comments
 (0)