This commits adds two passes
- FilterForDecompilationFunctionPass deletes the body of a Function if
it's not a isolated function produced by revng
- FilterForDecompilationModulePass deletes all the bodies of the
functions that are not isolated functions generated by revng
These passes are used at the beginning of the decompilation pipeline, to
prevent all the passes of the decompilation pipeline to run on root and
other big functions coming from QEMU that do not need to be decompiled.
This fixes an issue causing crashes when calling the public API
`decompileFunction`, that was internally adding a `MakeEnvNullPass`
(formerly a `ModulePass`) to a `FunctionPassManager.
This pass substitutes the `@env` global variable with a null pointer
`@env` is a pointer to the CPU state in QEMU, and is not meant to be
visible in the decompiled code.
This pass is used to remove all references to it before decompilation.
When the `Successor` field is consumed to create the `Sequence` nodes,
we blank the field so that we do not have redundant information in our
graph representation.
Change the AST debug printing from a recursive descent on the AST nodes
in the graph, to an iterative printing of respectively nodes and their
outgoing edges.
Also, we now print the edge going to the `Successor` field, if present.
Reorganize the AST dot printing in order to use LLVM facilities for
files handling. In addition, clean up the code, and add a function
(useful in debug) in order to dump the dot of and AST from GDB (accepts
a `char *` instead of a `std::string`.
Now, when the `debug-log=restructure` flag is active, debug graphs are
organized in a more rational way.
First of all, all the graphs are now put in a single directory, and are
divided first by function name and then by type.
Also, as in the case of the tiling debug graphs, their name is more
consistent with the rest of the codebase.
We now craft a new decompilation pipeline. We remove the exceptions
introduced as fallbacks to preserve the semantics, and we perform passes
of `dce` and `simplifycfg` to remove all the superfluos basic block
remaining after this change. To do this, we need an additional pass that
removes also the calls to the `llvm.assume` intrinsic, and another pass
of `dce` to remove all the dead uses.
In addition, we also remove dead stores to the `cpu_loop_exiting` global
variable in order to improve the decompiled code.
As a byproduct of this, we remove also the dependency from the
`-remove-pc-stores` pass, since its jobs is included by the changes
mentioned above.
Now cover a corner case where we have a tile composed by two successors,
which we entirely dominate, and a common postdominator which we don't
postdominate (basically we miss a superfluos dummy here).
In this case, include in the tile `then` and `else` bodies, but do not
include in the tile the common postdom (it will be taken care by someone
else more higher in the CFG).
The simplifyLastContinue beautifier was too ambitious and there were
many corner cases that it handled in the wrong way, leaving the AST in a
shape that could not be emitted, or breaking the semantics.
This commit severely weakens the simplifyLastContinue, so that it does
not break things anymore.
It is now able to match only continue statements that are in the last
position of a sequence node which is the body of a ScsNode.
This obviously is not enough but allows revng-c to pass all the
decompilation tests.
In the future we will need to extend simplifyLastContinue to match more
cases in a sane way.
Before this commit, we couldn't handle simplification of atomic
sequences in cases of switches that had a default.
The reason is that if you remove a case from a switch that has a
default, you are implicitly saying that the case that you remove will be
handled by the default, hence you're changing the semantics.
Now we handle this case by not removing the case, substituting it with a
SwitchBreak node instead.
This commit fixes a bug causing iterator invalidation in
`markUnexpectedPCAsInlined`.
Before this commit we were iterating over a graph while adding nodes,
which could cause iteration invalidation on realloc.