47 Commits

Author SHA1 Message Date
Alessandro Di Federico c883bed765 Drop Logger's StaticEnabled feature 2025-10-31 17:25:03 +01:00
Alessandro Di Federico f8bd4c3bac Move around some files in preparation for libtcg
* Make the following private headers public:
  * Lift/CPUStateAccessAnalysisPass.h
  * Lift/CSVOffsets.h
  * Lift/PTCDump.h
  * Lift/VariableManager.h
* Move from revngSupport to revngLift:
  * IRAnnotators.{h,cpp}
  * SelfReferencingDbgAnnotationWriter.{h,cpp}
* Move from revngSupport to revngModel:
  * FunctionTags.{h,cpp}
  * ProgramCounterHandler.{h,cpp}
* Move from revngSupport to revngRecompile:
  * OriginalAssemblyAnnotationWriter.{h,cpp}
2025-10-24 15:34:11 +02:00
Ivan Krysak 77ea07c364 Minor improvements 2025-10-08 12:22:30 +03:00
Andrea Gussoni 1faa781e6a CommandLine: drop pathToStream
Remove `pathToStream` in favour of `llvm::ToolOutputFile`.
2025-07-23 11:34:13 +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 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
Ivan Krysak 705e4a5955 auto [...] -> auto &&[...] 2025-02-13 13:10:51 +02:00
Alessandro Di Federico 143c315196 Merge revng-c into revng 2024-11-21 10:50:55 +01:00
Andrea Gussoni 0fb60b5c0c BeautifyGHAST: remove unused using 2024-05-07 09:18:20 +02:00
Alessandro Di Federico 31344a3270 Add missing includes 2024-05-03 21:55:33 +02:00
Pietro Fezzardi 8b0f4e035c RestructureCFG: update deduplicated dummy nodes
Before this commit, it could happen that some duplicated dummy node
(used to mark backedges) could be left lingering in wrong regions when
collapsing a regions, if they were first iteration outlined.

This commit fixes the problem, by collecting them and letting
`updateNodes` take care of them, removing them from the containing
region and all its parents.
2024-03-25 18:08:35 +01:00
Pietro Fezzardi 454e38e4ff RestructureCFG: handle retreating from SetNodes 2024-03-25 18:08:35 +01:00
Pietro Fezzardi d84f099af7 RestructureCFG: fix iterator invalidation 2024-03-19 17:46:32 +01:00
Pietro Fezzardi e58531b88d RestructureCFG: flush logger 2024-03-19 17:46:32 +01:00
Pietro Fezzardi 37340a91a7 Don't skip non-isolated Function in FunctionPass
Before this commit, many passes in revng-c were skipping over
non-isolated functions.

Now revng-pipeline takes care of removing non-isolated functions so that
check can be omitted everywhere.
2024-03-19 09:44:00 +01:00
Andrea Gussoni 6c8d963f69 RestructureCFG: Reorganize debug graphs
Various improvements to the debug graphs for `restructure-cfg` and
`beautify`:
- Normalize casing and syntax of debug graphs.
- Improve the graph folders name and layout.
- Implement `CFGDumper` and `ASTDumper` for when we need a serialization
  with incremental indexes.
- Remove old and stale graph serializations.
2024-03-11 19:08:34 +01:00
Alessandro Di Federico 0c212b66d9 Relicense to MIT 2024-02-29 17:03:36 +01:00
Andrea Gussoni 1b19e5a9ef ASTNode: introduce DispatcherKind attribute
Introduce the `DispatcherKind` attribute as a field in the
`BasicBlockNode` and `ASTNode` classes, in order to be able to
distinguish entry and exit dispatchers, and the related set nodes.
2023-11-28 16:19:08 +01:00
Andrea Gussoni deee899ad0 RestructureCFG: improve first iteration outline
Improve the logic of the first iteration outline:
1) The cloning of the nodes involved in the first iteration outlining,
   is now performed with a series of DFS visits from all the late entry
   nodes in the `MetaRegion`, instead of performing a blind clone of all
   the nodes and removing those not needed.
2) Restoring the edges between the cloned nodes has been subject to
   minor changes.
3) The outline nodes are now assigned to a `MetaRegion` using a new
   logic, instead of blindly assigning them to the parent `MetaRegion`.
2023-10-09 10:34:41 +02:00
Andrea Gussoni 496f0becd7 RestructureCFG: remove old Set node handling
Remove old broken code that handled `Set` nodes as source of retreatings
when inserting an `entry` dispatcher. This situation should no longer be
the case, because a `Set` node should not be the `source` of a
retreating edge. We assert this situation.
2023-10-09 10:34:41 +02:00
Andrea Gussoni 4161834bc5 RestructureCFG: improve handling of retreatings
We now explicitly store the retreatings edges, that will eventually be
connected to the `continue` nodes, so that we can explicitly handle
them, without resorting to iterating over the predecessors of the
`EntryNode`, which although correct is a fragile method with respect to
defective situations.

In addition, we check that after the restructuring, all the retreating
edges that we connect to `continue` nodes, do point to the `EntryNode`
before the transformation.
2023-10-09 10:34:41 +02:00
Andrea Gussoni 935dcdbdec RestructureCFG: improve ShortestPath
Add a dedicated Logger for the `ShortestPath` computation.
2023-10-09 10:34:41 +02:00
Andrea Gussoni 6d4f3daf30 RestructureCFG: improve code layout
Improve the code layout and the logging of the `Backedge`s insertion.
Add the `debug_function` attribute to the `LogMetaRegions` function.
2023-10-09 10:34:41 +02:00
Pietro Fezzardi 4cda5259e5 RestructureCFG: improve inclusion dominated nodes
Before this commit, the code was using an old arcane algorithm that was
adding and removing dummy frontier nodes, and relying on the
DominatorTree.

This commit drops the DominatorTree altogether, drops the use of
frontier nodes, and rewrites the algorithm only using successors and
predecessors.

Now a node outside a metaregion M is included in the metaregion only if
all its predecessors are part of the metaregion, and none of them is
already in another metaregion that is a transitive parent of M.
2023-10-09 10:34:41 +02:00
Pietro Fezzardi 1ed19a35e2 RestructureCFG: try skip first iteration outlining
Before this commit, the whole body of each loop was outlined and
duplicated, only to be removed later if not necessary.
Now we only do this if there is more than one entry to the loop, which
is the simplest condition to detect when first iteration outlining is
needed.
2023-10-09 10:34:41 +02:00
Pietro Fezzardi b8810858c8 RestructureCFG: drop RootMetaRegion placeholder 2023-10-09 10:34:41 +02:00
Pietro Fezzardi 68fca82f46 RestructureCFG: call updateNodes more efficiently
Before this commit it was called on all metaregions, now only on parent
metaregions.
2023-10-09 10:34:41 +02:00
Pietro Fezzardi 3cfad9f3f9 MetaRegion::updateNodes: simplify and add assert 2023-10-09 10:34:41 +02:00
Andrea Gussoni 42f74ad998 RestructureCFG: use nodesBetween helper
Use the `nodesBetween` helper provided by the `GraphAlgorithms` header
instead of the custom `findReachableNodes` implementation.
2023-07-19 16:31:48 +02:00
Andrea Gussoni a715b89cf9 RestructureCFG: use getBackedges helper
Use the `getBackedges` helper provided by the `GraphAlgorithms` header
instead of the custom own implementation.
2023-07-19 16:30:14 +02:00
Ivan Krysak fe0531868c Use Container::contains() where appropriate 2023-07-05 06:07:09 +00:00
Ivan Krysak 888e5371eb Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-05 06:06:07 +00:00
Giacomo Vercesi a4ad571e61 rcc: Fix typos
Fix the typos detected by `codespell`
2023-05-11 10:04:32 +02:00
Andrea Gussoni ca540399d4 Ensure that no backedges are left
Ensure that no backedges are left after the restructuring of all the
metaregions.

This additional assertion should help ensuring that no entries in the
`Backedges` set are left after the restructuring process, in turn making
it easier to spot bugs if backedges references are not handled correctly
during the steps of the restructuring.
2023-01-31 11:55:52 +01:00
Andrea Gussoni db48424629 Handle Code and Collapsed node in shortest path
Assign a value to cloned and collapsed nodes in terms of shortest path
from entry, which is a criterion we use to elect region entry.
The shortest path is computed at the beginning for the nodes present in
the CFG, but needs to keep updated for additional nodes that we insert
that may become loop entry candidates.
2023-01-20 17:03:24 +00:00
Andrea Gussoni febd4a2777 Remove from Backedges set retreating edges
During the creation of the exit dispatcher, take care of removing from
the `Backedges` set the additional backedge that is collapsed in case
two exiting backedges do target the same destination.

When this is not done, a ghost backedge is left inside the set, making
it not coherent with the state of the graph.

In addition, we add an assertion which ensures that during this phase of
the restructuring dummy nodes are present only as source of retreating
edges, and have one and only one successor.
2023-01-20 17:02:18 +00:00
Pietro Fezzardi 5e12f66ffb Drop old logger, use CombLogger instead 2023-01-18 17:58:09 +01:00
Pietro Fezzardi a18cc9078f RestructureCFG.cpp: drop legacy removeFromRPOT
This can be replaced with concise idiomatic llvm::erase_value
2022-12-01 12:15:12 +01:00
Pietro Fezzardi 02bafadce7 RestructureCFG: new election of loop entry points
The new criterion for electing the entry point of a loop is based on the
number of edges that jump to the candidate entry from outside the
region.
2022-12-01 12:15:12 +01:00
Pietro Fezzardi c73b447c60 Use MFP in RegionCFG::inflate for reachable exits 2022-12-01 12:14:37 +01:00
Pietro Fezzardi 604d370239 Remove LLVM passes RestructureCFG, BeautifyGHAST
Now that the late stage of the decompilation pipeline is managed with
revng-pipeline, and we have a standalone tool for decompilation, we
have no need to use LLVM passes anymore for those stages.

This commit also renames the directories to avoid the confusing Pass
suffix, not what LLVM passes are gone.
2022-05-11 15:19:34 +02:00