Introduce the untangle pass.
This preprocessing phase is in charge of the untangling optimization.
This optimization searches for conditional node, where, if a branch is
completely inlined (i.e., the entire path until reaching the exit is
duplicated and directly attached to it) we can save duplication in the
combing phase.
The untanle is based on a euristics, which consists of estimating the
duplication that could be introduced by the combing (computing the
weight for the nodes not dominated from the conditional node, of both
branches), with respect to the weight of duplicating the path that will
be inlined (the weight of all the nodes of the branch inlined plus the
weight of the nodes from the immediate postdominator of the conditional
until the exits).
The current implementation of the untangle is very conservative (no
untangle is performed if the `then` and `else` branches share some
nodes, or if there isn't at least one of the two branches which
dominates all the nodes until the postdominator).
The euristics also does not take into consideration the weight for
collapsed nodes.
Implementation of the `comb` algorithm without dominator and
postdominator trees.
The comb now uses a list of nodes kept in reverse postorder (and updated
at each dummy insertion, node duplication and node removal), and various
sets of nodes that contains elements still to eplore under a certain
conditional node, nodes already visited, and so on.
Also the set of immediate post dominator (the point at which the comb
stops during its exploration) is computed only once at the beginning of
the algorithm, and simply kept updated at dummy insertion and removal.
The phase that checked if a conditional node dominates all the nodes
until the postdominator, has been replaced by a check which looks if all
the predecessors of a certain node have been visited during the current
exploration (which is perfomed in reverse postorder). If this condition
does not verify, it means that there is an incoming arc incoming in the
node under analysis which is not dominated by the current conditional
node.
There is still margin for improving the performance of this, this is
only a first implementation.
Dropped the use of a temporary file containing the necessary includes
for clang-tooling to work correctly (at the moment `#include <stdint.h>`
) in favor of a single file which is installed in `root/share/revngc`
and used by clang-tooling.
If the `-decompiled-prefix` is passed to the `revng opt` command the
decompilation pass takes care of serializing the decompiled code of each
function in a different file.
The filename is composed by the prefix string passed as parameter and by
the function name.
To avoid skeing the results the serialization of `DOT` intermediate file
for both restructuring and AST semplification passes are now serialized
only when the corresponding loggers (`CombLogger` and `BeautifyLogger`)
are enabled.
When a retreating edge involves as source node a `SetNode` belonging to
an internal region (which should be the default `SetNode` that remains
outside the collpased node), move it just after the `CheckNode` that is
being introduced, so that the semantics of the code remains untouched.
We used to list all the architectures supported by QEMU in tests,
however this not optimal. This commit switches to a whitelist for the
list of architectures to tests so that we don't test architectures for
which we have a toolchain but aren't ready for the testsuite.
We can currently successfully translate only dynamic binaries for
x86-64. Warn the user about this early on instead of failing in
`revng-merge-dynamic`.
Use a `llvm::SmallString` for the `Name` field of `BasicBlockNode`.
This enables us to modify the name of the node, which is very useful
during debugging and manual inspection of the graph serialized in
output.
Fix the metaregion identification phase, in particular the add of the
addditional nodes merged when encountering a node which is the target of
a backedge identifying another metaregion.
The add of the additional nodes must be done in a fixed point fashion,
otherwise in case of dependent insertions the order of the nodes
triggers different behaviours (and bugs).
`BasicBlockNode` and `RegionCFG` classes are now template classes. This
means that the `BasicBlockNode` class can be used as a generic wrapper
for any type of object in the original graph (it is usually used to wrap
a `llvm::BasicBlock *` for decompilation purposes, but in tests it can
be used to wrap a `DotNode` object) that implementes `GraphTraits`.
Improved the interaction with the `StringRef` name field of
`BasicBlockNode`.
In case of artificial nodes, the name is left empty and created
on-the-fly for serialization purposes.
Removed the computation of the information contained in the
`NDuplicates` prevously done in the `MarkForSerialization` pass, since
the information is now precomputed in the `RestructureCFG` pass and
exposed with a dedicated method.
Add a `DotGraph` and `DotNode` classes, which implements `GraphTraits`,
so that we can create a `RegionCFG` starting from a graph specified in
a `.dot` file.
The `DotClass` implements a minimal parser for graph specified in `.dot`
format.
The `.dot` should begin with the specification of the name of the graph
`digraph TestGraph {`, followed by an arbitrary number of lines which
specify the edges in the graph (no attributes allowed, e.g., `a -> b;`).
The file should end with a single line ending in `}`.
Add helpers to test if two `RegionCFG` objects can be considered
equivalent.
This will be used in the test environment to check if the comb
transformation is consistent with the expected behavior.
Update the `OriginalBB` map (which will be later used for retrieving the
original basic block linked to a certain BBNode) during nested
`RegionCFG` creation and during flattening, which are steps that modify
the allocation of the `BBNode` objects.