Commit Graph

23 Commits

Author SHA1 Message Date
Andrea Gussoni 5698284bea MTGoTo: introduce the MaterializeTrivialGoto pass
The MaterializeTrivialGoto pass, tries to remove superfluous `goto` from
the `ScopeGraph`, by verifying that the resulting `ScopeGraph` does not
become cyclic or undecided.
In that case, it rolls back the changes.
2025-04-30 16:10:54 +02:00
Andrea Gussoni 307110fcfb ScopeGraph: introduce isScopeGraphDecided helper 2025-04-30 16:10:54 +02:00
Andrea Gussoni 2c19f69a74 ScopeGraph: ScopeGraph manipulation helpers
Introduce some helpers used to manipulate `goto_block` and
`scope_closer` annotations on the `ScopeGraph`.
2025-04-30 16:10:54 +02:00
Andrea Gussoni e093a1c7ed SelectScope: extract reusable helpers
Extract reusable helpers in `ScopeGraphAlgorithms.h`, so they can be
reused.
2025-04-30 16:10:54 +02:00
Andrea Gussoni 10055101c5 ScopeGraph: detail namespace to avoid clash
Define the `getScopeGraphSuccessors` and `getScopeGraphPredecessors`
in the `detail` namespace in order to avoid clashes.
2025-04-30 16:10:54 +02:00
Andrea Gussoni 71988af041 Fix MIT license 2025-04-30 16:10:54 +02:00
Andrea Gussoni 40ebac06cc IDS: introduce pass
Introduce the `inline-divergent-scopes` pass. This pass in is charge of
reducing the exit nodes in a `ScopeGraph`, applying the _Inline
Divergent Scopes_ transformation, which is able, in presence of
divergent exits nodes, wrt. to a conditional, to remove the exit node
and to transform the `ScopeGraph` in a form where semantics is
preserved.
2025-04-02 16:47:14 +02:00
Andrea Gussoni 47fac0d948 SelectScope: introduce pass
Introduce the `select-scope` pass. This pass is in charge of enforcing
the relative decidedness property for all the nodes in the `ScopeGraph`,
wrt. to all the conditional nodes. It does this by applying the
relative decidedness definition, electing one scope for each conditional
node in the graph, and by transforming all the edges that would violate
the property into goto edges.
2025-04-02 16:47:14 +02:00
Andrea Gussoni 21be052d6f ScopeGraph: introduce the makeGotoEdge helper
Introduce the `makeGotoEdge` helper to the `ScopeGraphBuilder` class,
that can be used to handle the transformation of a solid edge into a
`goto` edge, taking care of the creation of the `goto` block and the
redirection of the edges.
2025-04-02 16:47:14 +02:00
Andrea Gussoni 1482a5e110 ScopeGraph: improve ScopeGraph .dot name
Include the function name in the filename of the dumped `.dot` of the
`ScopeGraph`.
2025-04-02 16:47:14 +02:00
Andrea Gussoni 93f4a620dd DAGify: implement the DAGify pass
Implement the DAGify pass. This pass, using the results exposed by the
`GenericRegionInfo` analysis, transforms all the retreating edges of
each identified `GenericRegion`, processed in a bottom-up fashion, into
a `goto` edge on the `ScopeGraph`.
2025-03-11 12:26:36 +01:00
Andrea Gussoni 3499d10154 GenericRegion: remove retreatings edges
Remove retreating edges from the `GenericRegion` class, and the
collection of them in `GenericRegionInfo`.
2025-03-11 12:25:24 +01:00
Andrea Gussoni ec8972cbed ScopeGraph: require pointer type for ScopeGraph 2025-03-11 12:25:23 +01:00
Andrea Gussoni ce6f9ddb69 ScopeGraph: do not assert when marker not present
Do not assert if the marker function is not present in the input IR, the
`Builder` instantiation takes care of its on-the-fly declaration
instantiation.
2025-03-11 09:28:04 +01:00
Ivan Krysak 705e4a5955 auto [...] -> auto &&[...] 2025-02-13 13:10:51 +02:00
Andrea Gussoni 9af0c2962c ScopeGraph: dump .dot of the ScopeGraph
Dump the `.dot` file representing the `ScopeGraph` in the
`dumpScopeGraph` debug function.
2025-01-15 11:54:28 +01:00
Andrea Gussoni d2fa797d5e ScopeGraph: implement DOTGraphTraits
Provide the `Scope<llvm::Function *>` specialization implementation for
the `DOTGraphTraits`.
2025-01-15 11:54:28 +01:00
Andrea Gussoni db719a23be ScopeGraph: delete Scope(&&) constructor
Delete the `Scope(const GraphType &&)` constructor, in order to avoid
potential bugs due to the storage of a temporary reference in the `const
GraphType &Graph` member.
2025-01-15 11:54:28 +01:00
Andrea Gussoni 684cbf649a ScopeGraph: implement Inverse<Scope<>>
Implement the `Inverse<Scope<...>>` `GraphTraits`. This are needed in
order to support the computation of the `PostDominatorTree` on a
`ScopeGraph`.

Add some `FileCheck` tests to test the dominator and postdominator trees
on the `ScopeGraph`.
2025-01-15 11:48:28 +01:00
Pietro Fezzardi f81bbcc754 Add new EagerMaterializationRangeIterator
Introduce the `EagerMaterializationRangeIterator`, which substitutes the
`GeneratorIterator`, and is used to materialize the successors of a
node in the `ScopeGraph`.

In addition, remove the `GeneratorIterator`.
2025-01-15 11:48:28 +01:00
Andrea Gussoni 26cf42eb12 ESE: Introduce the Enforce Single Exit pass
Introduce the Enforce Single Exit pass, whose task is to normalize a
generic `ScopeGraph`, which may have multiple exit blocks (and/or
infinite loop regions), in order to have a single `sink_block` as exit
block.

This is done by adding a new entry block, a `sink_block`, and some
`scope_closer` edges (which are visible only on the `ScopeGraph`) that
enforce the property.

This is done taking inspiration from how the internally the
`PostDominatorTree` pass construct the temporary graph on which the post
dominance information is computed on.

Some unit tests are added in order to verify that the pass works as
expected.
2024-12-18 10:51:40 +01:00
Andrea Gussoni fa69bd24e5 ScopeGraph: introduce the ScopeGraph
Introduce the `ScopeCloser` and `GotoTarget` annotations in the IR, and
the relative necessary machinery, needed to handle scope closer and goto
edges for the new backend.

A specialization of the `llvm::GraphTraits`, called `ScopeGraph`, that
is able to handle both the above mentioned annotations is provided.

For the `llvm::GraphTraits` implementation, we introduce the
`GeneratorIterator` class, which uses a coroutine to store the status of
the iteration.

A debug logger pass is added, so that we are able to test the
functionality with `FileCheck`.
2024-12-05 15:43:57 +01:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00