Commit Graph

6113 Commits

Author SHA1 Message Date
Andrea Gussoni 05a5d80151 Short-circuit simplification concept
First concept of short-circuit simplification.
The `isEqual` operator between ASTNodes is very limited (it does only
check if two nodes originate from the same `BasicBlock` in the original
IR.
2019-01-22 19:16:48 +01:00
Andrea Gussoni 8f89ea0f7d Outline not reachable nodes removal
Outlined the removal of nodes not reachable from the entry node in an
external function. This is useful to reuse the function not only for the
main graph, but also for the collapsed regions.
In this way we can remove not reachable nodes in the inner regions, such
as dandling `break` and `continue` nodes (found in an endless loop).
2019-01-21 18:28:59 +01:00
Andrea Gussoni f94bd7d99a Refresh backedges after each transformation
This fix enables the correct updating of the backedges present in the
graph, since each transformation pass could in principle modify some of
the backedges present in the graph
2019-01-21 18:28:59 +01:00
Andrea Gussoni a540a08c38 Added RemovePCStores pass
Added a new pass that simply purge all the functions in a module from
the useless basic blocks that simply do the `pc` serialization.

Without this until we have available the optimization/comb iterative
refinement, we would not be able to test the short-circuit
simplification.
2019-01-21 18:28:48 +01:00
Alessandro Di Federico 2382c5e638 Merge branch 'feature/employ-stackanalysis' 2019-01-18 15:38:20 +01:00
Pietro Fezzardi e594de5b3e Remove unused data members from VariableManager 2019-01-18 15:18:47 +01:00
Andrea Gussoni 5069ed44c6 Change linkage of isolated functions
Change the linkage of functions created during isolation to
`InternalLinkage`, to give more space to optimizations.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico ee1c8cae15 Add opt options to moderate runtime
Pass to the Global Value Numbering pass the `enable-pre=false` and
`enable-load-pre=false` since they have been identified as a major
source of slowdown with very large binaries.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 524862679a Enable PIC project-wide 2019-01-18 15:18:47 +01:00
Alessandro Di Federico a2b30ceb42 Update FunctionIsolation to use the new FBDP
This commit updates the function isolation transformation to handle the
metadata as provided by the new `FunctionBoundariesDetectionPass`.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 2e241acae3 Introduce SA-based ABIDetection and FBD passes
This commit drops the old FunctionBoundariesDetectionPass and introduces
a new one based on the results provided by the StackAnalysis. A very
similar pass, the ABIDetectionPass, is now available to offer the
results of the ABI analysis too.

These two new passes are a thin shim depending on the appropriate
version of the StackAnalysis (with or withour ABI anlysis) and simply
call `serializeMetadata`, which decorates the LLVM IR with the requested
information.

In addition to drop the old analysis, this commit also isolates the
function boundaries detection pass from `revamb` making it available as
a library only.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 7a045d0c0d Drop revamb-dump in favor of plain passes
This commit does the following:

* It drops `revamb-dump` and transforms all the passes it featured in
  passes that can be used directly from `opt`.
* It rename `revamb` to `revng-lift`.
* It introduces a script called `revng` which acts as a driver for the
  whole rev.ng project. It replaces `translate`, `revcc`,
  `csv-to-ld-options` and `revamb-dump`, since it offers an `opt`
  subcommand which allows to easily invoke all the analysis passes.
* It makes the project a CMake package that can be easily used
  externally.
* It allows to easily create libraries of analysis to use through
  `revng-opt`.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 14476a354c Fix function isolation test dependencies 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 25bf160910 Improve detection of stack alignment in SA 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 9ad7a7dbab Minor fixes to StackAnalysis' logging 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 05b1833ee6 Add ExternalJumpsHandlerBlock to BlockType 2019-01-18 15:18:47 +01:00
Alessandro Di Federico ef708e9912 Let --debug-log work without main involvement 2019-01-18 15:18:47 +01:00
Alessandro Di Federico 9985ff5fb6 Drop const in FunctionsSummary-related code 2019-01-18 15:18:47 +01:00
Alessandro Di Federico e9b4b8edf1 Use stack analysis in RDA
This commit lets the reaching definitions analysis employ results from
the stack analysis to propagate definitions across functions
calls. Specifically, the stack analysis provides a list of registers
that might be clobbered by the callee: definitions concerning those are
not propagated, all the others are propagated.

This change is key to detect jump tables whose address has been
materialized *before* a function call. A test for such situation has
been introduced.

To make this work, the RDA now works over the CFG provided by the
function identification analysis.
2019-01-18 15:18:47 +01:00
Alessandro Di Federico 98c99e9406 Make StackAnalysis::getClobbered const 2019-01-18 15:18:47 +01:00
Alessandro Di Federico bd09716534 FCI: provide a custom CFG
The `FunctionCallIdentification` analysis now provides a custom view on
the CFG where 1) dispatcher-related basic blocks are absent, 2) nodes
performing functions calls have an edge to their return address and 3)
nodes ending with a return instruction have no successor.

This CFG is now employed by the reaching definitions analysis and OSRA.

Additionally, the implementation of the `visitSuccessors` and
`visitPredecessors` method has been reviewed. It now consists in a class
that needs to be inherited and for which two methods should be
implemented, one to perform the visit of a block and another one to
enumerate the successors.

In addition, all the users of `visitSuccessors`/`visitPredecessors` have
been updated, a simple set of tests has been introduced and
`GeneratedCodeBasicInfo::visitPredecessors` has been dropped.
2019-01-18 15:18:46 +01:00
Alessandro Di Federico 9cbcef37d5 Disallow #if [01]
Sometimes code is commented using preprocessor directives. This is fine
for temporary testing stuffs, but it should never end up in a commit.
2019-01-18 08:38:46 +01:00
Andrea Gussoni 13d057b478 Improved indentation 2019-01-17 17:31:31 +01:00
Andrea Gussoni 5245cd71e5 Added assertions
Added more asserts to quickly identify problems in which we already
incurred
2019-01-17 17:29:39 +01:00
Andrea Gussoni c9ca88c12f Improved debugging information
Enriched the debuggin information provided by the logger, and also
manually enabled it, until `opt` will accept additional command line
parameters
2019-01-17 17:27:33 +01:00
Andrea Gussoni d6ba63aa71 Fix SCS successor node connection
If no `exit dispatcher` has been created, connect the possible unique
successor to the SCS collapsed node
2019-01-17 17:25:11 +01:00
Andrea Gussoni b0d3190c4c Moved the getID method to the CFG class
Moved the creation of unique IDs inside the CFG object, in such a way
that we do not need a global function and variable anymore
2019-01-17 17:23:58 +01:00
Andrea Gussoni 659441eb85 Introduced useless dummy simplification
Added a post processing phase on the ASTTree which is in charge of
removing useless dummy nodes
2019-01-17 17:19:08 +01:00
Andrea Gussoni b08da2c045 Serializing CFGs to file 2019-01-17 17:05:10 +01:00
Andrea Gussoni 46aafe13fc Avoid absorption of nodes already in other SCS
We now avoid the absorption of some successor node in a metaregion, if
such node is already part of another processed metaregion, to avoid
breaking the nested structure of the metaregions.
2019-01-16 14:56:39 +01:00
Pietro Fezzardi da299f3095 EnforceCFGCombingPass: inject dummy nodes in CFG 2019-01-16 12:53:08 +01:00
Pietro Fezzardi 828a1ad6de Add EnforceCFGCombingPass 2019-01-16 11:49:32 +01:00
Pietro Fezzardi dc430e446b RegionCFGTree.h: add missing #include<set> 2019-01-15 16:57:15 +01:00
Pietro Fezzardi 5805679ead RestructureCFGPass: fix use of include directory 2019-01-15 16:57:15 +01:00
Pietro Fezzardi 4e941de03a LivenessAnalysis: fix successor_size method 2019-01-15 12:54:19 +01:00
Pietro Fezzardi 68425a71ca Use consistent naming in include guards in headers 2019-01-15 11:19:59 +01:00
Pietro Fezzardi a478de61e5 Create a separate include directory 2019-01-15 11:19:59 +01:00
Pietro Fezzardi d6a4fcdfb5 Add LivenessAnalysisPass::getLiveIn() method
This method exposes the results of the analysis to the outside world.
2019-01-15 11:00:45 +01:00
Pietro Fezzardi 020aeb9497 LivenessAnalysis: split in multiple files
This is a preliminary commit to cleanup the directory structure before
adding unit tests.
2019-01-15 00:50:54 +01:00
Andrea Gussoni d729ba21ac Moved reachability inside revng-c 2019-01-14 16:14:00 +01:00
Andrea Gussoni b66774bcd2 Connect the successor of an SCS only once
In case we do not emit an exit dispatcher, take care of connecting the
successor of a SCS only once.
2019-01-14 15:45:08 +01:00
Andrea Gussoni 06717a6185 Import RestructureCFGPass from revamb branch
Import the RestructureCFGPass from the `feature/the-comb` branch on the
`revamb` repository.
2019-01-14 15:45:08 +01:00
Pietro Fezzardi 5fac4e9eaf Add Liveness Analysis 2019-01-14 11:31:32 +01:00
Pietro Fezzardi 1110587416 First implementation of the DecompilationPass 2019-01-11 00:52:48 +01:00
Alessandro Di Federico 034621e2ec monotone-framework.py: restore Python 3 compat
Due to a minor error, `monotone-framework.py` loss its Python 3
compatibility. This commit fixes the situation.
2019-01-09 22:31:26 +01:00
Alessandro Di Federico 1fb8b1a6ec Merge branch 'feature/improve-performance' 2018-12-17 08:51:45 +01:00
Alessandro Di Federico 7ead8d68cc Collect simple literals (return addresses) as JTs
This commit fixes a problem that led to use SET to discover very very
simple jump targets: the return addresses of functions call.

Since in this situation, for each call, we needed to run SET, this
commit leads to a *huge* improvements in terms of translation
performance.

This commit also enforces renaming of the translated basic blocks after
they get split and update the ground truth for several analysis tests.
2018-12-17 08:15:45 +01:00
Alessandro Di Federico 9ce805415b Improve Reaching Definitions Analysis
The Reaching Definitions Analysis used to ignore all the memory access
that were not relative to a CSV or an `alloca`. In certain situations,
in particular in x86 which makes heavy use of the stack, this led to
miss certain links that were vital for a correct identification of
certain jump targets.

As an example consider the following example:

    cmp    DWORD PTR [rbx+0x8],0x5
    ja     4bc5c8 <uw_update_context_1+0x148>
    mov    eax,DWORD PTR [rbx+0x8]
    movsxd rax,DWORD PTR [r12+rax*4]
    add    rax,r12
    jmp    rax

The constaint on `rbx+0x8` is not propagated to the use after the jump,
due to a missing link.

This commit fixes this by tracking all the memory accesses within the
expressive power of the `MemoryAccess` class, in particular those
expressed as register plus offset.

Additionally, this commit also makes RDA consider as reaching
definitions for a `load` only those definitions that match exactly the
load address, while previously we were considering all the `mayAlias`
definitions. This situation, in combination with the previous change,
led to have paths with multiple reaching definitions, which was
problematic for the path sensitive merge.

Finally, we consider a definition to be clobbered only if there's an
exact store to the esame address, instead of a store on an aliasing
address.
2018-12-17 08:15:45 +01:00
Pietro Fezzardi dbb25bef2c Apply information about CSV aliasing
This commit introduces alias information to state that memory accesses
relative to CSVs do not alias memory accesses of the original program.
2018-12-17 08:15:45 +01:00
Alessandro Di Federico ef2d16db15 Install headers and libraries 2018-12-15 08:34:36 +01:00