Commit Graph

3168 Commits

Author SHA1 Message Date
Pietro Fezzardi b6327b0526 PromoteCSVs: fix CSV list initialization 2021-04-30 14:52:25 +02:00
Pietro Fezzardi 49a493ebbb DLA: handle extractvalue from struct_initalizers 2021-04-29 15:16:08 +02:00
Pietro Fezzardi 80b1a9e7fa Add RemoveLLVMDbgIntrinsicsPass
This pass removes all llvm debug intrinsics from the IR.
It is enabled by default in all decompilation pipelines.
2021-04-29 03:06:58 +02:00
Pietro Fezzardi 0cd27eed3f Drop loads from cpu_loop_exiting 2021-04-29 03:04:39 +02:00
Pietro Fezzardi 5aaff6a524 AddSCEVBarrierPass: handle barriers on struct ptrs 2021-04-28 18:14:41 +02:00
Pietro Fezzardi 3be9d0a9a1 Fix missing parenthesis around ConditionalOperator 2021-04-27 21:19:06 +02:00
Pietro Fezzardi 572e04751f CDecompilerAction: fix parens in negateExpr 2021-04-27 21:19:06 +02:00
Pietro Fezzardi cdb8f84f48 DLA: Handle StructInitializers 2021-04-27 21:19:06 +02:00
Pietro Fezzardi 39eb322820 FilterForDecompilation: mark Functions optnone
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.
2021-04-27 21:19:06 +02:00
Pietro Fezzardi 36a525314a Detect isolated functions using FunctionTags 2021-04-27 21:19:06 +02:00
Alessandro Di Federico 53f6328507 Introduce PromoteCSVs
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.
2021-04-22 18:07:24 +02:00
Alessandro Di Federico 2e9c2ee275 Introduce FunctionTags
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.
2021-04-22 18:07:24 +02:00
Alessandro Di Federico 2ea5723a53 s/getCalledValue/getCalledOperand/g 2021-04-22 18:06:27 +02:00
Alessandro Di Federico aeb81c4218 Don't implicitly use StringRef as std::string 2021-04-22 18:06:27 +02:00
Alessandro Di Federico 90c93bfc26 Do not include PassSupport.h directly 2021-04-22 18:06:27 +02:00
Alessandro Di Federico fee270b64e Minor changes 2021-04-22 18:06:27 +02:00
Alessandro Di Federico 618dbf3673 s/CSVsUsedByHelperCall/CSVsUsage/g 2021-04-22 18:03:53 +02:00
Alessandro Di Federico b29fc4c59c Ignore nulls in revng.csvs 2021-04-22 18:03:53 +02:00
Alessandro Di Federico 651282a85a Introduce constructors
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.
2021-04-22 14:45:52 +02:00
Alessandro Di Federico 2b9cbb98ec Introduce --invoke-isolated-functions
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.
2021-04-22 14:45:52 +02:00
Alessandro Di Federico 081809ec38 Adopt EliminateUnreachableBlocks 2021-04-22 14:45:52 +02:00
Alessandro Di Federico 71044a9277 Drop setNoInline from invokes
This is no longer necessary, since we now use invoke instructions
properly and it's no longer possible to demote them to calls.
2021-04-22 14:45:52 +02:00
Alessandro Di Federico 40ecee6482 Make SA tests more deterministic
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.
2021-04-22 14:45:52 +02:00
Pietro Fezzardi fc7a8cac1a RestructureCFG: optimize updating Backedges 2021-04-15 11:16:57 +02:00
Pietro Fezzardi 56ed3f3904 RestructureCFG: fix typo in comments 2021-04-15 09:47:53 +02:00
Pietro Fezzardi 11906b8977 libIsolatedFunctions: fix CMakeLists.txt 2021-04-15 09:46:55 +02:00
Andrea Gussoni 4bdfb2713a Number the beautification passes debug graphs 2021-04-07 11:56:06 +02:00
Andrea Gussoni 0502b2345d Implement NoFallThroughPromoter
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
2021-04-07 11:53:32 +02:00
Andrea Gussoni ddbb10f3fa Fix flipEmptyThen beautify
Do not invoke the `flipEmptyThen` beautify if we are in presence of a
`ScsNode` without body.
2021-04-07 10:42:17 +02:00
Pietro Fezzardi f49a8ce1e2 CDecompilerAction: fix order of type declarations 2021-04-01 12:51:02 +02:00
Pietro Fezzardi e4dbdeaf99 CDecompilerPass: refactor per-function ostreams 2021-04-01 12:47:48 +02:00
Pietro Fezzardi 42531f1701 Decompiler: avoid code duplication in do-while
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.
2021-03-29 17:49:25 +02:00
Pietro Fezzardi 52e29ccdbf PromoteStackPointer: do nothing with missing sp
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.
2021-03-29 17:21:34 +02:00
Pietro Fezzardi 45c586d0b3 MarkForSerialization: better model side-effects
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.
2021-03-29 17:20:43 +02:00
Pietro Fezzardi 7e553762b9 CDecompilerBeautify: omit more continue statements 2021-03-29 17:18:39 +02:00
Alessandro Di Federico 690e5fd9bd Update LoadModelPass usage 2021-03-16 12:01:15 +01:00
Alessandro Di Federico b25c43705c SerializeModelPass: support new pass manager 2021-03-16 11:55:58 +01:00
Alessandro Di Federico c2d6631216 LoadModelPass: support new pass manager 2021-03-16 11:55:58 +01:00
Alessandro Di Federico 830ef23fe8 Whitespace changes 2021-03-16 11:36:32 +01:00
Alessandro Di Federico 1217296328 TypeShrinking has been moved to revng 2021-03-08 10:26:44 +01:00
Alessandro Di Federico d73f93f936 TypeShrinking: inject zext close to users 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 035b75d540 TypeShrinking: do not expose dependency on MFP.h 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 23470dc911 Convert TypeShrinking to new pass manager 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 8f05cbf1ee Convert BitLiveness to the new pass manager 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 8a5cc6a020 Import TypeShrinking 2021-03-08 10:15:50 +01:00
Alessandro Di Federico 4780457c53 Drop StackAnalysis<false> and FBDP
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.
2021-03-06 17:35:30 +01:00
Pietro Fezzardi b092c4f505 Add ThreadSafeClangTooling library
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.
2021-03-05 16:12:41 +01:00
Pietro Fezzardi 2277bc898a Drop unused DecompilerResourceFinder
Now the decompiler does not need to find resources on disk anymore.
2021-03-05 16:12:41 +01:00
Pietro Fezzardi 81413c4b64 IRASTTypeTranslation: enable floats and bitfields 2021-03-05 16:10:00 +01:00
Pietro Fezzardi 475dc4462c Fix createTypeFromLayout for structs and unions 2021-03-05 16:10:00 +01:00