-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedup: hash modules back->front (#7820)
Hashing modules back->front lets us be a bit leaner with the state we have to track, and hopefully will give us a nice speed improvement. In the old algorithm, as we hashed each operation or block in the module, we would store its position as an index into a side-table. When a value is used, we could record the use by hashing-in the result-no and the defining operation's index (or argument-no and block index, resp). This index table is a major performance bottleneck for dedup: in a large module, this table can be massive. The observation made is that values tend to only be used near their definition. After we hash the last use of an operation or block, we should be safe to remove its index from the index table, and keep the index table as small as possible. This PR modifies the hasher to walk the module backwards. When a value is first encountered (while hashing a use/operand), we assign an ID to the defining operation. We use that ID to hash all future uses. When the defining op is hashed, we hash its ID once more (recording the fact that the ID is defined by the op), and remove the ID from the table--a value can only be used after it is defined. This ensures that we only track the ID of an operation for its live range in the IR. The IDs are assigned according to their "first occurrence" in the backwards walk of the IR. Since the assignment of IDs is derived from the structure of the IR, two equivalent modules should assign the same IDs to the same ops. This PR also updates the hashing of inner-symbols to be handled in a similar way. When an inner symbol is referenced, we assign an ID and record the reference by hashing the ID. When an inner symbol is defined, we record the definition by, again, hashing the ID. Unlike values, a symbol can be referenced before it is defined, so we can never free inner symbol IDs. This corrects an old logical "bug" in dedup, which never arises in practice because chisel cannot generate it.
- Loading branch information
Showing
1 changed file
with
97 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters