Before this commit we dropped the body altogether. This was bad because
dropping the body of a Function also clears metadata, preventing the
propagation of FunctionTags from revng.
Now all the functions that are not isolated are simply marked optnone
noinline, so that all the optimizations we do for decompilation are only
restricted to isolated functions.
This commit takes out of EnforceABI the part taking care of creating
wrappers for calls to helpers and promoting CSV to local variables.
This decoupling, enables to run -promote-csvs multiple times, for
instance after inlining.
FunctionTags goal is to solve the long-standing problem of identifying
what type of function are we dealing with. Is it a lifted function? An
helper?
Now we have a sane way to determine this using Metadata and a proper
API.
Isolated functions return structs. These structs used to be constructed
using `IRBuilder::CreateAggregateRet`, which is implemented using
`insertvalue` instructions. However, this approach led to ugly
decompiled code.
This commit introduces "constructor" functions that can be easily
pattern matched down the pipeline.
This commit ensures that FunctionIsolation and EnforceABI do only
thing. This means that they no longer modify `root`.
Instead, we have a new pass, `invoke-isolated-functions` that needs to
be run after them and replaces the entry point of the functions with
invokes to the isolated functions, possibly with the appropriate
arguments.
When we compare StackAnalysis test results, the order in which things
appear in the JSON is relevant. However, the output was
non-deterministic due to a `std::map` using a pointer as key.
This commit improves the situation by sorting the elements by name
before dumping them in JSON.
Implement a beautify phase which does the following:
- Compute, for every scope in the AST, if that scope is `fallthrough`
or `nofallthrough` scope. Basically, the `nofallthrough` scopes are
scope which ends with a `return`, `continue', or `break`.
- Using the information computed before, we can promote the scope of an
`IfNode` using the following criterion: if one of the two branches of
the `IfNode` is a `nofallthrough` scope, we are sure that the other
branch is not reachable from the former one. We can therefore, promote
the latter as `fallthrough` block of the `IfNode` (of course taking care
of inverting the condition statement if we are promoting to
`fallthrough` the `then` branch.
If both the `then` and the `else` branches can be promoted as
`nofallthrough`, we have a function that evaluates the weight of the two
branches, and promotes the heavier one. This helps reducing the
Cognitive Complexity of the generated code
When printing do-while loops in C, we wrongly emitted redundant
statements before the `do`, representing computation necessary for
evaluating the exit condition from the loop.
These statements were duplicated at end of the loop body, and were
entirely redundant before the `do`.
This commit removes them.
The PromoteStackPointerPass now trivially handles running on modules
where the global variable for the stack pointer is missing.
When the global is not found, the pass just does nothing and returns
false.
This is necessary to handle very small functions, typically from tests.
Before this commit, whenever an Instruction needed to be serialized, it
forced to serialize all the pending Instructions.
Now this happens only for Instructions with side effect, that may
interfere with the pending Instructions if they are not serialized as
well.
In all the other cases, serializing an Instruction does not force
serialization of other Instructions.
This commit drops support for running StackAnalysis without ABI
analysis. This has been broken for quite some time and a source of slow
downs in (badly) crafted optimization pipelines.
This library provides a thin locking wrapper around clang::tooling
invocations.
It should be used instead of performing direct clang::tooling
invocations by all programs that use revng-c and may run more than one
ClangTool concurrently.
This is necessary because clang::tooling internally uses llvm's cl::opt
for parsing command line options.
cl::opt uses a global variable for the parser under the hood so parsing
two command lines concurrently is not safe.
Similarly, cl::opt typically uses global variables to hold options, so
it is not safe to execute a ClangTool concurrently to another tool
that is parsing a new set of options, because there might be race
conditions between threads reading and writing the same options at the
same time.
The new library introduces a thin locking layer so that the end-user
does not need to know or worry about these details.