Commit Graph

153 Commits

Author SHA1 Message Date
Andrea Gussoni ba7ee595b5 BeautifyGHAST: introduce soft failure
Introduce an additional consistency check for loops having an empty body
at the beginning of the `beautify` pipeline.
2025-07-23 13:39:30 +02:00
Ivan Krysak a285ad2785 IRHelperRegister: get a comment from Description 2025-07-23 11:38:53 +02:00
Andrea Gussoni 6a90277db2 ScopeGraph: rename scope-graph-dumper 2025-07-23 11:34:13 +02:00
Andrea Gussoni c060f07ecd ScopeGraph: add scope-graph-output cl::opt 2025-07-23 11:34:13 +02:00
Andrea Gussoni 1ccce1c76a ScopeGraph: remove the ScopeGraphLogger library 2025-07-23 11:34:13 +02:00
Andrea Gussoni 1faa781e6a CommandLine: drop pathToStream
Remove `pathToStream` in favour of `llvm::ToolOutputFile`.
2025-07-23 11:34:13 +02:00
Andrea Gussoni 137a9384af BeautifyGHAST: introduce soft failure
Introduce a consistency check for ensuring that all the `ASTNode`s in
the `ASTTree` have a valid `Kind`. If this is not true, we soft fail.
2025-06-26 12:02:38 +02:00
Andrea Gussoni 506fdaabeb InlineDispatcherSwitch: soft fail
Relax assumption for `simplifySwitchBreak`.
2025-06-26 12:02:38 +02:00
Andrea Gussoni ecb823b120 InlineDispatcherSwitch: do not inspect empty loop
Do not inspect a loop with an empty `Body` (a `do-while` can legally
have it).
2025-06-26 12:02:38 +02:00
Andrea Gussoni c05ed14d23 BeautifyGHAST: introduce soft failure
Introduce a consistency check for loops having an empty body and not
being `DoWhile`s (the only type of empty loops admitted) before they
reach the serialization backend.
2025-06-26 12:02:26 +02:00
Andrea Gussoni 9ed971ab75 ASTTree: introduce soft failure
Soft fail for `copyASTNodesFrom`.
2025-06-26 09:34:26 +02:00
Andrea Gussoni 93b1205a5a BeautifyGHAST: drop matchSwitch
Remove the dead `matchSwitch` beautify pass.
2025-06-25 09:05:19 +02:00
Andrea Gussoni 0308a881ed BeautifyGHAST: introduce soft failure
Soft fail for `simplifyShortCircuit` and `simplifyTrivialShortCircuit`.
2025-06-23 12:00:59 +02:00
Andrea Gussoni 82c66fd4ca BeautifyGHAST: early return failure handling 2025-06-23 12:00:59 +02:00
Andrea Gussoni a5100a32ce RestructureCFG: introduce soft failure
Soft fail for `ContinueBackedges` size.
2025-06-20 14:04:51 +02:00
Andrea Gussoni abbca85036 RestructureCFG: introduce soft failure
Soft fail for `ShortestPathFromEntry`.
2025-06-20 13:45:01 +02:00
Andrea Gussoni a521b9d760 RegionCFGTree: introduce soft failure
Soft fail for `insertBulkNodes`.
2025-06-20 13:38:05 +02:00
Andrea Gussoni 7550753081 ASTTree: introduce soft failure
Soft fail for `copyASTNodesFrom`.
2025-06-20 10:29:04 +02:00
Andrea Gussoni 12bf4e7db0 RestructureCFG: fail on unexpected dummy purge
When attempting to simplify away a dummy that simply connects a
Predecessor and a Successor, fail if Predecessor and Successor are
already connected.

In order to handle such failure, we need to decorate a lot of function
on the stack trace in order to be able to propagate the failure code.
2025-06-19 11:36:49 +02:00
Andrea Gussoni f45b706972 RestructureCFG: fail when retreating not to head
Introduce decompilation failure when not all the retreatings of a
`Region` point to the elected head node.
2025-06-19 11:36:49 +02:00
Andrea Gussoni 2ed4bffc53 DecompileFunction: early return failure handling 2025-06-19 11:36:49 +02:00
Andrea Gussoni 3b76bbb3e7 RestructureCFG: fix exit dispatcher deduplication
Fix the deduplication of dummy nodes in exit dispatcher creation,
checking that no other path using them exists before their removal.
2025-06-18 18:18:11 +02:00
Andrea Gussoni 4a2594f0ed RestructureCFG: log MetaRegions after update 2025-06-18 18:18:11 +02:00
Andrea Gussoni be72da8b48 IDS: improve collection restart criterion
We now reduce the number of cases in which we restart the collection of
the `DivergenceDescriptor`s after a IDS modification on the `ScopeGraph`
is performed.

We previously restarted the collection after each IDS transformation.

Now, restart is only performed after IDS is applied on a `Conditional`
node whose all successors are divergent exits which are `goto` exits.
After such `Conditional` is processed, it may happen that a new `goto`
exit becomes divergent for another `Conditional` upwards in the
`ScopeGraph`.
Therefore, if we do not restart, it may happen that a non-`goto` exit is
processed before a `goto` exit, which may lead to suboptimal situations
in the emitted number of `goto`s, due to how IDS interacts with
`MaterializeTrivialGotos`.
2025-06-12 15:31:38 +02:00
Andrea Gussoni b786a657bf IDS: collect multiple divergent successors
When performing the IDS procedure for a divergence which is entered
through multiple `Successor`s of the `Conditional`, we insert a `Head`
header which collects the entry to the scope, in order to maintain
decidedness if there is a common post-dominator to all the `Successor`s
(similar to what weaving did).
2025-06-12 15:31:38 +02:00
Andrea Gussoni 3527291bd9 IDS: multiple divergence implementation
Perform the IDS transformation, by taking into account possible multiple
divergent scopes for a certain conditional node at the same time.

This reduces the run times, since it reduces the number of time IDS is
called on a conditional, but mostly proceduce a more _compact_
`ScopeGraph`, where all the divergent scopes for a certain conditional
node rejoing the path toward the one true exit in a single point,
instead of having a chain of IDS resulting regions.

Make IDS unit tests compliant with the new multiple divergence
implementation.
2025-06-12 15:31:38 +02:00
Andrea Gussoni 349192d404 SelectScope: single ScopeGraphBuilder instance 2025-06-12 15:31:38 +02:00
Andrea Gussoni 458ca46b02 ESE: single ScopeGraphBuilder instance 2025-06-12 15:31:38 +02:00
Andrea Gussoni cf7fba7beb DAGify: single ScopeGraphBuilder instance 2025-06-12 15:31:38 +02:00
Andrea Gussoni 9ddb7465ba ScopeGraph: optimize ScopeGraphBuilder 2025-06-12 15:31:38 +02:00
Andrea Gussoni 333903e86e ScopeGraph: ScopeGraphBuilder const methods 2025-06-12 15:31:38 +02:00
Andrea Gussoni 8b87854a11 IDS: improve goto exit ordering criterion
Perform the IDS operation for the exit nodes corresponding to `goto`
blocks afterwards the other _standard_ exits have been processed.

In addition, order the `GotoBlock`s according to the `post_order` of the
target blocks of the `goto` themselves. This should maximize the
opportunities for later runs of `MaterializeTrivialGoto`.
2025-04-30 16:10:54 +02:00
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 8ff68174ea ScopeGraph: use snake_case for Markers 2025-04-30 16:10:54 +02:00
Andrea Gussoni 71988af041 Fix MIT license 2025-04-30 16:10:54 +02:00
Ivan Krysak 18829dc7e4 RestructureCFG: adopt helper registry 2025-04-17 11:19:17 +03: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 e0ff6f1360 ESE: extend command line flag 2025-04-02 16:47:14 +02:00
Andrea Gussoni c14c2d64dc DAGify: reorder FunctionPass method declarations 2025-04-02 16:47:14 +02:00
Andrea Gussoni 023807f0bb DAGify: remove useless llvm:: namespace 2025-04-02 16:47:14 +02:00
Andrea Gussoni f92db5d4a6 DAGify: use the makeGotoEdge helper 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 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 d5b26a9346 GenericRegion: add support for ScopeGraph
Add the needed support for running `GenericRegionInfo` on the
`ScopeGraph`.

This needs a new ad-hoc `getGenericCycleInfo` helper in order to unwrap
the `Graph` object (pointing to the underlying `Function *`) from the
`Scope` wrapper object.
2025-03-11 12:25:24 +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 f5b3feb738 ESE: fix comment 2025-03-11 12:25:24 +01:00