Commit Graph

176 Commits

Author SHA1 Message Date
Ivan Krysak 77ea07c364 Minor improvements 2025-10-08 12:22:30 +03:00
Andrea Gussoni 855a9309ec MaterializeLoopScopes: drop pass
Drop the `MaterializeLoopScopes` pass after the re-design the loop
matching stage to work entirely on `clift`, without the need to insert a
`scope_closer` edge to guide the emission.

Simultaneously, drop the DAGify `Head` metadata insertion, since it will
not be checked anymore during the `MaterializeLoopScopes` pass.
2025-09-26 10:39:09 +02:00
Andrea Gussoni 92e8ec3982 ScopeGraphUtils: improve isDAG check
We now ensure that even in case of blocks disconnected from the entry,
the `isDAG` function still search for loops in such parts of the graph.

This is achieved by instantiating multiple `scc_iterator` on the blocks
composing the underlying `Graph`.
2025-09-26 10:39:09 +02:00
Andrea Gussoni e34b6db644 SelectScope: assert no disconnected blocks 2025-09-24 15:51:06 +02:00
Andrea Gussoni b679c8c611 MTGoTo: assert no disconnected blocks 2025-09-24 15:51:06 +02:00
Andrea Gussoni b18cd59d31 ESE: assert no disconnected blocks 2025-09-24 15:51:06 +02:00
Andrea Gussoni a5c1fdb3fe IDS: assert no disconnected blocks 2025-09-24 15:51:06 +02:00
Andrea Gussoni 46fe7415ca DAGify: assert no disconnected blocks 2025-09-24 15:51:06 +02:00
Andrea Gussoni 2ba365bc45 DAGify: fix Head election
During the `Head` election phase, we now introduce the following
additional criterion:
When processing a `GenericRegion` nested into an outer one (its
`ParentRegion`), if the inner `Region` contains the block that has been
elected as `Head` of the `ParentRegion`, we also force that block to be
the `Head` of the inner `GenericRegion`.

We add a unit test to check this behavior.
2025-09-24 15:51:06 +02:00
Andrea Gussoni d010ab806d MLoopScopes: introduce pass
The `MaterializeLoopScopes` is a scope-inducing transformation, with the
goal of inserting a `scope_closer` edge targeting the immediate post
dominator, outside each `GenericRegion`, in order to materialize the
scope representing the body of each `GenericRegion` on the `ScopeGraph`.
2025-09-10 13:36:09 +02:00
Andrea Gussoni 0281dbe040 DAGify: insert Head metadata 2025-09-10 13:36:09 +02:00
Andrea Gussoni 7965fa3039 DAGify: implement abnormal entry normalization
Perform the abnormal (late) entries normalization in the DAGify pass.

In this way, we are exploiting the information computed by
`GenericRegionInfo` as close as possible to where it is computed the
first time (in DAGify).

Actualize the unit tests to reflect these changes.
2025-09-10 13:36:09 +02:00
Andrea Gussoni fbd8c827e1 ScopeGraph: move helper functions
Move the `replaceSuccessors` and `simplifyTerminator` helper in the
`ScopeGraphUtils` library.
2025-09-10 13:36:08 +02:00
Andrea Gussoni 0332fda68d SelectScope: improve logging 2025-09-10 13:36:08 +02:00
Andrea Gussoni 53b756d169 GenericRegionPass: run on the ScopeGraph 2025-09-10 13:36:08 +02:00
Andrea Gussoni c0b9e3b425 DAGify: rename Logger 2025-09-10 13:36:08 +02:00
Andrea Gussoni 4143187942 DAGify: Logger typo 2025-09-10 13:36:08 +02:00
Andrea Gussoni 95ecd2d519 DAGify: compute GenericRegionInfo on raw CFG
Compute the `GenericRegionInfo` analysis on the raw CFG and not on the
`ScopeGraph`.
2025-09-10 13:36:08 +02:00
Andrea Gussoni 4b4fe388cb DAGify: improve variable name 2025-09-10 13:36:08 +02:00
Andrea Gussoni 0f85e5263c ScopeGraph: assert when moving scope_closer
Assert if we try to make a `scope_closer` edge a `goto` edge, since we
do not support this possibility.
2025-09-10 13:36:07 +02:00
Andrea Gussoni 4bfef217b6 IDS: preserve dbg metadata 2025-09-10 13:36:07 +02:00
Andrea Gussoni 70d7901648 ScopeGraph: preserve dbg for scope_closer 2025-09-10 13:36:07 +02:00
Andrea Gussoni bdb58a3b98 ScopeGraph: preserve dbg metadata for goto 2025-09-10 13:36:07 +02:00
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