Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
b308805
start
kripken May 16, 2024
8c55b6f
fix
kripken May 16, 2024
835622f
fix
kripken May 16, 2024
d09f4a0
show problem
kripken May 16, 2024
1c52de6
work
kripken May 16, 2024
927897c
fix
kripken May 16, 2024
de1d20d
test
kripken May 16, 2024
6cf9fb3
work
kripken May 16, 2024
322bc71
exllore
kripken May 17, 2024
0b2f8a9
fail
kripken May 17, 2024
407bad3
try
kripken May 17, 2024
a88c8c4
work
kripken May 17, 2024
7de4b4d
Merge remote-tracking branch 'origin/main' into globses
kripken May 17, 2024
08e07cb
undo
kripken May 17, 2024
38ac562
heapify
kripken May 17, 2024
ad78406
heapify
kripken May 17, 2024
c4da577
fix
kripken May 17, 2024
f90da11
work
kripken May 17, 2024
8d54784
todo
kripken May 17, 2024
6000256
work
kripken May 17, 2024
0baee6b
fix
kripken May 17, 2024
ddc8f47
undo
kripken May 17, 2024
52ebfae
undo
kripken May 17, 2024
fac33e4
format
kripken May 17, 2024
2fd4ec0
fancy
kripken May 17, 2024
dbf7673
notes
kripken May 17, 2024
c1bd7c6
test
kripken May 17, 2024
d325aba
test
kripken May 17, 2024
c8f6c2d
test
kripken May 17, 2024
84b0bc8
test
kripken May 17, 2024
47c7449
test
kripken May 17, 2024
eb69de7
test
kripken May 17, 2024
de3b7aa
fix
kripken May 17, 2024
22f40a9
note
kripken May 17, 2024
fa2f756
typo
kripken May 17, 2024
0d345a8
Merge remote-tracking branch 'origin/main' into globses
kripken May 17, 2024
207634c
import
kripken May 17, 2024
9629291
import
kripken May 17, 2024
e3b3b09
work
kripken May 20, 2024
c1827c4
bigpicture
kripken May 20, 2024
ab04d1e
builds
kripken May 20, 2024
4b0ba5b
works
kripken May 20, 2024
9f50ace
test.bad"
kripken May 20, 2024
3da13d7
bad
kripken May 20, 2024
fc5bf12
wrong
kripken May 20, 2024
4b74dd5
wrong
kripken May 20, 2024
64462c7
fix
kripken May 21, 2024
6d00b1e
work
kripken May 21, 2024
c23a4f2
fix
kripken May 21, 2024
985294c
test
kripken May 21, 2024
fe754da
test
kripken May 21, 2024
29c5852
comment
kripken May 21, 2024
f6cd1eb
moar
kripken May 21, 2024
f54d8a3
work
kripken May 21, 2024
96c1f1a
test
kripken May 21, 2024
ffd1fe7
builds
kripken May 21, 2024
5b4a499
test
kripken May 21, 2024
592da79
work
kripken May 21, 2024
65f5f8d
test
kripken May 21, 2024
35a7441
fix
kripken May 21, 2024
a81f708
clean
kripken May 22, 2024
9e3d467
work
kripken May 22, 2024
c17d1b3
indices
kripken May 22, 2024
4bf17c6
actually indices
kripken May 22, 2024
8834d84
actually indices
kripken May 22, 2024
e189d66
clean
kripken May 22, 2024
838b3b3
format
kripken May 22, 2024
567e25d
comments
kripken May 22, 2024
57eb5df
fix
kripken May 22, 2024
280cfd7
fix comment
kripken May 22, 2024
dda7b3d
Update src/passes/ReorderGlobals.cpp
kripken May 30, 2024
ff792bc
comment
kripken May 30, 2024
055f296
typo
kripken May 30, 2024
bd77630
use topological sort utility
kripken May 30, 2024
b68359e
Merge remote-tracking branch 'myself/globses' into globses
kripken May 30, 2024
8ffc896
typo
kripken May 30, 2024
507dff8
optimize
kripken May 30, 2024
3353220
Update src/passes/ReorderGlobals.cpp
kripken May 30, 2024
7da3b03
Update src/passes/ReorderGlobals.cpp
kripken May 30, 2024
4ee047b
missing work
kripken May 30, 2024
35405ca
Merge remote-tracking branch 'myself/globses' into globses
kripken May 30, 2024
9cc3be5
format
kripken May 30, 2024
044a7cf
clarify sort
kripken May 31, 2024
d191ce1
Update src/passes/ReorderGlobals.cpp
kripken May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
note
  • Loading branch information
kripken committed May 17, 2024
commit 22f40a9cb06f615baf01369938ae6fde7985eabe
28 changes: 21 additions & 7 deletions src/passes/ReorderGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct ReorderGlobals : public Pass {
}
}

// To sort the globals we use the simple approach of always picking the
// To sort the globals we do a simple greedy approach of always picking the
// global with the highest count at every point in time, subject to the
// constraint that we can only emit globals that have all of their
// dependencies already emitted. To do so we keep a list of the "available"
Expand All @@ -119,12 +119,26 @@ struct ReorderGlobals : public Pass {
//
// Other approaches here could be to do a topological sort, but we do need
// this fully general algorithm, because the optimal order may not require
// strict ordering by topological depth. That is, the dependencies imply a
// partial order, not a total one. By doing the optimal thing at each step -
// picking the available global with the highest count - we ensure we are
// doing the best thing in the greedy sense, at least, which is better than
// a naive topological sort. Note that this algorithm remains linear in the
// size of the input.
// strict ordering by topological depth, e.g.:
//
// $c - $a
// /
// $e
// \
// $d - $b
//
// Here $e depends on $c and $d, $c depends on $a, and $d on $b. This is a
// partial order, as $d can be before or after $a, for example. As a result,
// if we sorted topologically by sub-trees here then we'd keep $c and $a
// together, and $d and $b, but a better order might interleave them. A good
// order also may not keep topological depths separated, e.g. we may want to
// put $a in between $c and $d despite it having a greater depth.
//
// The greedy approach here may also be unoptimal, however. Consider that we
// might see that the best available global is $a, but if we popped $b
// instead that could unlock $c which depends on $b and $c might have a much
// higher use count than $a. This algorithm often does well, however, and it
// runs in linear time in the size of the input.
std::vector<Name> availableHeap;

// To break ties we use the original order, to avoid churn.
Expand Down