Commit Graph

2366 Commits

Author SHA1 Message Date
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 0e4c4aad59 Make --use-debug-symbols the default 2020-10-21 10:34:34 +02:00
Alessandro Di Federico d72f69c975 Import GenericGraph
This commit imports `GenericGraph`, its tests and fixes some related
issues in `FilteredGraphTraits`.
2020-10-21 10:34:01 +02:00
Pietro Fezzardi 6313b3229a Decompiler: fix detection of revng-c include file.
This commit fixes the detection of the revng-c include file in build
directory, using the PathList facility provided by revng.
Before this commit, running revng-c from build directory failed to
properly identify the revng-c include if it was not already installed
but only available in the build directory itself.
2020-10-12 11:42:06 +02:00
Pietro Fezzardi 05e34ef6f9 Add functions to get installed resource files 2020-10-05 14:09:53 +02:00
Pietro Fezzardi a94371cca2 EnforceABI: promote CSV in ConstantExprs casts
EnforceABI promotes global variables representing parts of the CPU
states to arguments and return values of isolated functions.

This commit enables the promotion of CSV that are used in isolated
functions only indirectly, through `ConstantExpr`s casts.
2020-10-01 18:17:53 +02:00
Pietro Fezzardi 510f503716 IRHelpers: improve prints for llvm::Value
This commit improves prints of Argument, Function, ConstantInt
2020-10-01 18:17:53 +02:00
Pietro Fezzardi 408b2c9592 IRHelpers: improve replaceAllUsesInFunctionWith
This helper function is now able to replace also uses that are inside
`ConstantExpr`s.
Before this commit they were not substituted correctly, causing problems
down the decompilation pipeline.
2020-10-01 18:17:53 +02:00
Alessandro Di Federico 72b840605c AVI: fix out-of-bound access
In `AdvancedValueInfo` we used to access an element in a vector that has
been shrinked.
2020-10-01 17:41:44 +02:00
Alessandro Di Federico 60fdcbc66a Whitespace changes 2020-10-01 17:40:17 +02:00
Andrea Gussoni 50f59b0eb9 Move ReachabilityPass to tests folder
Move the `ReachabilityPass` library to the `tests` folder, the only
place where it is used, and change it from static library to dynamic
library.
2020-09-09 11:16:50 +02:00
Alessandro Di Federico ae3c800109 Implement MetaAddress::{from,to}String 2020-09-02 18:21:07 +02:00
Alessandro Di Federico e62cbb5ceb Implement comparison operators for MetaAddress 2020-09-02 16:55:20 +02:00
Antonio Frighetto 76a6403ebd FunctionIsolation: drop ExceptionFlag
ExceptionFlag has been superseded by proper use of stack unwinding.
Our custom personality routine has been replaced with the GNU GCC
personality one.
2020-08-03 22:11:06 +02:00
Pietro Fezzardi a89b4a32d9 RegionCFG: prevent inserting nodes while iterating 2020-07-27 16:57:35 +02:00
Pietro Fezzardi 41ab9f3c72 Flattening: avoid removing SetNodes
This was a leftover from when we were trying to restructure the LLVM IR
like the combed RegionCFG, and was not necessary anymore.
2020-07-27 15:20:17 +02:00
Pietro Fezzardi 37b894b36c RegionCFG: fix combing for switches
Before this commit, switches were treated as normal conditional nodes.
This was wrong, because treating a switch as a conditional node does not
guarantee that all the parts of the control flow representing each case
are really combed.

This commit removes switch nodes from conditional nodes, and creates a
dummy for each case. All the dummy cases are treated as conditional
nodes inducing duplication separately, instead of the actual switch.
This has the consequence of enabling the combing to proper comb the
switch cases from each other, without altering the combing algorithm.

Each switch case is combed until the combing finds the post-dominator
of the switch, not the post-dominator of the case.
2020-07-27 12:15:40 +02:00
Pietro Fezzardi 342300cf9c RegionCFGTree: remove costly method orderNodes
This method was used to sort vector of nodes either in post-order or in
reverse-post-order.

It had 2 problems:
- the boolean argument used to select between POT and RPOT was no longer
  used, since all the remaining call sites passed false.
- it was expensive to call, because it took a vector, it created a set
  from it, and performed a reverse-post-order-traversal of the whole
  graph while pushing the nodes to sort back into a newly allocated
  vector. This was particularly problematic because in one of the call
  sites a reverse-post-order-traversal was already available, but the
  method did calculate a new one nonetheless.

The method is removed in this commit.
All the call sites have been modified to use the
reverse-post-order-traversal object if already available, and they
avoid allocating a new set for the computation and a new vector for the
results. The initialization is now performed directly into a set, and
the sorted results are pushed into a vector. This effectively saves the
allocation of a vector in each call site.
2020-07-27 12:15:40 +02:00
Pietro Fezzardi 140f0962ab weave: remove useless early exit on cases
The weaving routine included a check that the candidate node for weaving
was not one of the case blocks of the switch. This check was likely
introduce to mask an old malfunction, caused by a missing update of the
CaseSet data structure, that has since then been removed.
This check was now useless and this commit removes it.
2020-07-27 12:15:40 +02:00
Pietro Fezzardi 3dd149f995 RegionCFGTree: remove useless recomputation of DT 2020-07-27 12:15:40 +02:00
Pietro Fezzardi 1664c6b060 RegionCFGTree: improve logging 2020-07-27 12:15:40 +02:00
Pietro Fezzardi 08bcfa3384 RegionCFGTree: remove unused local variable 2020-07-27 12:15:40 +02:00
Pietro Fezzardi 8c936422f4 RegionCFGTree: remove method getInterestingNodes
The removed method was now unused.
2020-07-27 12:15:40 +02:00
Pietro Fezzardi 3286789a9e SwitchNode: fix embedding of original BasicBlock
Before this commit, the original llvm BasicBlock was not embedded
properly in the GHAST SwitchNodes. This caused problems and crashes in
decompilation.

This commit SwitchNode constructors so the that the BasicBlock properly
reaches the GHAST and it is printed correctly by the decompiler.
2020-07-23 18:51:15 +02:00