summaryrefslogtreecommitdiff
path: root/src/ir/module-utils.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [NominalFuzzing] Fix getHeapTypeCounts() on unreachable casts (#4609)Alon Zakai2022-04-221-53/+53
| | | | | | | | | | | The cast instruction may be unreachable but the intended type for the cast still needs to be collected. Otherwise we end up with problems both during optimizations that look at heap types and in printing (which will use the heap type in code but not declare it). Diff without whitespace is much smaller: this just moves code around so that we can use a template to avoid code duplication. The actual change is just to scan ->intendedType unconditionally, and not ignore it if the cast is unreachable.
* CRTP topological sort utility (#4499)Thomas Lively2022-02-031-67/+34
| | | | | | | | Refactor the `TopologicalSortStack` into a `TopologicalSort` CRTP utility that manipulates the DFS stack internally instead of exposing it to the user. The only method users have to implement to use the utility is `pushPredecessors`, which should call the provided `push` method on all the predecessors of a given item. The public interface to `TopologicalSort` is an input iterator, so it can easily be used in range-based for loops.
* [NFC] Simplify TopologicalSortStack (#4498)Thomas Lively2022-02-031-13/+5
| | | | | | | Using a vector and lazily skipping finished items in `pop` rather than using a linked list and eagerly removing duplicated items makes the code simpler and more than twice as fast on my test case. The algorithmic complexity is unchanged because the work to skip duplicates remains linear in the number of duplicates added, it's just not spread out over the linear duplicate pushes any more.
* Topological sorting of types in isorecursive output (#4492)Thomas Lively2022-02-021-56/+161
| | | | | | | | | | | | | | | | | | | Generally we try to order types by decreasing use count so that frequently used types get smaller indices. For the equirecursive and nominal systems, there are no contraints on the ordering of types, so we just have to sort them according to their use counts. For the isorecursive type system, however, there are a number of ordering constraints that have to be met for the type section to be valid. First, types in the same recursion group must be adjacent so they can be grouped together. Second, groups must be ordered topologically so that they only refer to types in themselves or prior groups. Update type ordering to produce a valid isorecursive output by performing a topological sort on the recursion groups. While performing the sort, prefer to visit and finish processing the most used groups first as a heuristic to improve the final ordering. Do not reorder types within groups, since doing so would change type identity and could affect the external interface of the module. Leave that reordering to an optimization pass (not yet implemented) that users can explicitly opt in to.
* Parse, create, and print isorecursive recursion groups (#4464)Thomas Lively2022-01-211-5/+50
| | | | | | | | | | | | | In `--hybrid` isorecursive mode, associate each defined type with a recursion group, represented as a `(rec ...)` wrapping the type definitions in the text format. Parse that text format, create the rec groups using a new TypeBuilder method, and print the rec groups in the printer. The only semantic difference rec groups currently make is that if one type in a rec group will be included in the output, all the types in that rec group will be included. This is because changing a rec group in any way (for example by removing a type) changes the identity of the types in that group in the isorecursive type system. Notably, rec groups do not yet participate in validation, so `--hybrid` is largely equivalent to `--nominal` for now.
* Refactor ModuleUtils::collectHeapTypes (#4455)Thomas Lively2022-01-141-15/+50
| | | | | Update the API to make both the type indices and optimized sorting optional. It will become more important to avoid unnecessary sorting once isorecursive types have been implemented because they will make the sorting more complicated.
* [NFC] Move ModuleUtils::collectHeapTypes to a .cpp file (#4458)Thomas Lively2022-01-131-0/+174
In preparation for the refactoring in #4455.