Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi dfec3ef61a generateAst: fix corner case in tile generation
The generation of tiles for nodes with two successors was broken for
nodes with two successors because it assumed that at least one of them
was inlined.
This is may not be true in general.
This commit fixes the tile generation for  those cases.
2020-10-26 14:00:00 +01:00
Pietro Fezzardi cfde9afbe1 Combing: remove sink 2020-10-26 13:59:45 +01:00
Pietro Fezzardi be35e578ad generateAst: fix tile for Collapsed nodes 2020-10-26 13:59:30 +01:00
Pietro Fezzardi 96e8830b92 generateAst: fix typo causing emission of wrong if 2020-10-26 13:59:14 +01:00
Pietro Fezzardi a78fb89518 RestructureCFG: fix creation of Switch labels
Before this commit, outgoing edges from switch nodes were not created
with correct case labels.
For a while we assumed this was fine as long as we fixed them later,
with the tagCaseEdges() method.
However, we didn't realize that adding labels later could not handle
correctly come situation, namely switches with a case that was a set
node followed by a break node to the outermost RegionCFG.

The only way to handle that situation correctly without pattern matching
is to construct the RegionCFG with the correct labels in the first
place.
This is exactly what this commit does.
2020-10-26 13:58:57 +01:00
Pietro Fezzardi 6535f29e9f RegionCFGTree: remove outdate comment 2020-10-26 13:58:40 +01:00
Pietro Fezzardi 55e252d0c6 BasicBlockNode: add access methods for edge labels 2020-10-26 13:58:23 +01:00
Andrea Gussoni eea15d9c18 [TILING] Do not remove dandling nodes after tiling 2020-10-26 13:58:07 +01:00
Andrea Gussoni c292f08218 [TILING] Implement AST generation memoization
We now do not generate again the AST for collapsed node that have been
duplicated.

If we encounter a region for which the AST was already generated, we
simply use the already computed AST (also because the tiling now
destroys the `RegionCFG` while it build the AST).
2020-10-26 13:57:52 +01:00
Andrea Gussoni dd3325f8a3 [INLINING] TEMP: skip tile nodes 2020-10-26 13:57:43 +01:00
Andrea Gussoni a71f06ebe6 Handle SwitchNode in flipEmptyThen method 2020-10-26 13:57:34 +01:00
Andrea Gussoni ced4f1a6a8 [TILING] Fix NDuplicates counting
Count the number of duplication (needed later in the `Mark` pass) right
before the AST generation phase, where the `RegionCFG` will be destroyed
by the tiling matching.
2020-10-26 13:57:17 +01:00
Andrea Gussoni b52206cb68 [TILING] Implement tiles creation
Now we implement correct tiles creation, and we handle correctly handle
different situations were inlining is present
2020-10-26 13:56:57 +01:00
Andrea Gussoni 5d640dd06b [TILING] Iterate on the graph in pot
When generating the AST, we now iterate directly on the non-filtered
graph in post order, instead of computing a depth first iteration on the
dominator tree built on the non filtered graph.
2020-10-26 13:56:17 +01:00
Andrea Gussoni db2e3a1b9e [TILING] Inlined edges in 2 successors node tile 2020-10-26 13:56:11 +01:00
Andrea Gussoni 0841f36834 [TILING] Fix erroneous successors initialization 2020-10-26 12:27:51 +01:00
Andrea Gussoni b0206f5039 [TILING] Handle 2 successor and 1 dominated node
Handle the situation where we have 2 successors, and we dominate only 1
node.

This tile can be generated only when we have 2 successors, and one of
this successors is an inlined node. No common postdominator in
contemplated in this tile.
2020-10-26 12:20:45 +01:00
Andrea Gussoni e41a063348 [TILING] Handle 2 successors and 2 dominated nodes
Handle the situation where we have 2 successor nodes, but we only
dominate 1 of them.

This tile can generate different situations, depending on the actual
structure: we can have a diamond shaped region with an inlined edge, we
can have a diamond without the postdominator and no inlined edge.
2020-10-26 12:19:55 +01:00
Andrea Gussoni 2ec9a402d1 [TILING] Handle 2 successors and 0 dominated nodes
Handle the situation where we have 0 dominated nodes and 2 successors.
This situation should never arise.
2020-10-26 12:17:50 +01:00
Andrea Gussoni 98eb2af0eb [TILING] Introduce tiling in generateAST
Begin the introduction of tiling in the `generateAST` method, handling
for now nodes with two successors.
2020-10-26 12:17:48 +01:00
Andrea Gussoni 130c27be83 [TILING] contains helper for SmallVector
Add an helper function to check if a `SmallVector` type object contains
a certain element.
2020-10-26 12:17:45 +01:00
Andrea Gussoni 1a8e6d671f [TILING] Inline edge check helper
Introduce an helper function used to check if an edge has been inlined.
2020-10-26 12:17:43 +01:00
Andrea Gussoni 94243938e4 [TILING] Collect successor nodes
Collect also the successor nodes during the AST generation phase in
addition to the dominated nodes.
2020-10-26 12:17:41 +01:00
Andrea Gussoni cc12c01a27 [TILING] Add RegionCFG method for building tiles 2020-10-26 12:17:39 +01:00
Andrea Gussoni ba4de66ee0 [TILING] New Tile node in RegionCFG
Introduce the new node type representing the node created after a node
collapse during the tiling procedure.
2020-10-26 12:17:37 +01:00
Andrea Gussoni 4a1479766e TEMP: Disable some assertion not needed anymore 2020-10-26 12:17:34 +01:00
Andrea Gussoni 3088391e22 [EDGEINLINE] Use filtered reverse postorder
Use the Filtered GraphTraits for automaticcaly ignored inlined edges
(instead of filtering them by hand in an ad-hoc way).
2020-10-26 12:17:32 +01:00
Andrea Gussoni 8cec35b349 Change ReversePostOrderTraversalExt interface
Change the call to the `Initialize` method in order to forward a
`GraphT` parameter instead of a `NodeRed` one. This is needed so that
external users can pass a node wrapped inside a graph object, that later
the `po_iterator_ext` will unwrap using the `getEntryNode` method.

This way of doing things, has the advantage of enabling us to pass also
nodes wrapped in Filtered GraphTraits, and to operate on them (beacause
the `GraphT` template parameter will be a wrapped object, we can't rely
on `po_iterator_begin` to specify the Graph Traits, because it doesn't
accept a GT template parameter, and therefore the parameter must be of
the same type of the first template parameter, on which type the
GraphTraits will be initialized.
2020-10-26 12:17:30 +01:00
Andrea Gussoni 3e7671395f [EDGEINLINE] Ignore unexpectedpc during weaving.
During the RPOT visit used in the weaving pass, ignore the edge
conducting to the `unexpectedpc` basic block, by adding it to the set of
nodes not touched during the rpot computation.

This is done due to the fact that we know a priori that the edge
conduting to the `unexpectedpc` block has been inlined in a
pre-processing phase, and therefore we do not want to explore this part
of the graph.

A better solution would be to just implement the rpot visit over the
same filtered graph.
2020-10-26 12:17:28 +01:00
Andrea Gussoni 493ce6da1d [EDGEINLINE] Use filtered PostDom in weave 2020-10-26 12:17:26 +01:00
Andrea Gussoni 3c250b89a9 [EDGEINLINE] Mark default case inlined
Add a pre-processing pass that mark as inlined all the edges connecting
the `switch` statements recovered by revng with their default case
pointing to the `UnexpectedPC` block.
2020-10-26 12:17:24 +01:00
Andrea Gussoni 987563f555 [EDGEINLINE] Handle VirtualRoot in untangle.
Handle the situation in which the immediate post dominator of a
conditional node is the `VirtualRoot` node on the filtered post
dominator tree. In this case, we do not have a correspondent node on the
graph, and so we must handle this situation in an ad-hoc manner.

In this case, we extend the `findReachableNodes` helper function in
order to be able to perform the visit even if the `Target` parameter is
`nullptr`. In this situation, simply, we continue our visit and we
consider every node that as no successors (which means that virtually
the node is connected to the `VirtualRoot` node) as a possible `Target`
for our visit.
2020-10-26 12:17:22 +01:00
Andrea Gussoni bee02ee5d1 [EDGEINLINE] Change findReachableNodes interface
Change the interface of the `findReachableNodes` helper function, so
that now accepts arguments passed by pointer instead of by reference.
Also, the helper function now does not accept a `nullptr` `Source`
parameter.
2020-10-26 12:17:20 +01:00
Andrea Gussoni 71b72c224f [EDGEINLINE] Refactor conditional blacklisting
We now add every conditional node to the set of node processed by the
`inflate` procedure. The postdom computation done on the inline filtered
postdominator tree should automatically avoid the duplication which was
previosuly prevented by the conditonal blacklisting.
2020-10-26 12:17:18 +01:00
Andrea Gussoni addb6503a4 [EDGEINLINE] Process all conditionals in inflate
Insert all the conditional nodes in the `ConditionalNodesSet`, in order
to make conditional blacklisting ineffective.

The conditional nodes previously blacklisted should now not generate
duplication thanks to the new way in which the IFPDT is built. In
particular, a node that previously was blacklisted, now should have on
of his successors (or itself) as the immediate postdominator.
2020-10-26 12:17:16 +01:00
Andrea Gussoni 8fa9b2f449 [EDGEINLINE] Inline on conditional blacklisting 2020-10-26 12:17:14 +01:00
Andrea Gussoni ccc4c988e6 [EDGEINLINE] Use filtered PostDom in inflate 2020-10-26 12:17:11 +01:00
Andrea Gussoni cf61e82212 [EDGEINLINE] Use Filtered PostDom in untangle
We now use the filtered PostDom tree in the untangle method, instead of
removing and re-adding the inlined edges during the PostDom computation.
2020-10-26 12:17:09 +01:00
Andrea Gussoni 7c469fbd8e [EDGEINLINE] Activate inline tagging for untangle 2020-10-26 12:17:07 +01:00
Andrea Gussoni 2a88e45735 [EDGEINLINE] Implement inlined edge helper
For this, we also implement the spaceship operator for the `EdgeInfo`
struct.
2020-10-26 12:17:05 +01:00
Andrea Gussoni 4cf21a9cfe [EDGEINLINE] Filtered PostDomTree on inlined edges
Initialize a Filtered PostDomTree, ignoring the inlined edges.

This PostDomTree should be useful to compute the post-dominance taking
into account only the "main" exit path towards the "non-inlined" edges.
2020-10-26 12:17:03 +01:00
Andrea Gussoni f4aa4e8489 [EDGEINLINE] Filtered DomTree on inlined edges
Create and instantiate a Filtered DomTree. This DomTree, filters over
edges representing inlined edges.
2020-10-26 12:17:01 +01:00
Andrea Gussoni a7c6cee7d3 [EDGEINFO] Factor out standard switch edge tagging
Move the standard switches edge tagging out of the weaving procedure, in
a dedicated method, so that the correct functioning of the decompilation
pipeline does not depend on the execution of the weaving.
In this way we can independently disable the weaving.
2020-10-26 12:16:59 +01:00
Andrea Gussoni 1d1fb0e644 [EDGEINFO] Improve documentation of EdgeInfo 2020-10-26 12:16:57 +01:00
Andrea Gussoni 24712518b3 [EDGEINFO] Implement EdgeInfo for inlining info
The `Successors` and `Predecessors` field on the `BasicBlockNode` are
now promoted from being a `std::pair` composed by the pointer to the
successor and the set representing the cases, to a pair between the
pointer to the successor and a new struct called `EdgeInfo`.

This struct is used to contain both the information about the cases, the
information representing whether and edge is inlined or not, and
possibly more information in the future.
2020-10-26 12:16:55 +01:00
Alessandro Di Federico 5791429f91 ABIIR: prune on finalization
Under certain conditions, we ended up having code in the ABI IR which
was not reachable. This was due to the fact that a certain instruction
was initially detected as an indirect call, triggering inclusion in the
function of the fallthrough code, and then as a return, which has no
successors within the function.

This commit simply prunes the ABI IR in the finalization method.
2020-10-24 17:40:54 +02:00
Alessandro Di Federico a08d5a14e0 scripts/revng: fix matching libraries to link 2020-10-23 17:40:13 +02:00
Alessandro Di Federico 393508d92b Drop superflous -fno-rtti flags 2020-10-22 14:36:27 +02:00
Alessandro Di Federico cfaa453253 revng_add_analyses_library: fix CMake package name 2020-10-22 14:36:27 +02:00
Alessandro Di Federico 2e995fdaa7 Pretty print JSONs 2020-10-22 11:25:31 +02:00