Commit Graph

3168 Commits

Author SHA1 Message Date
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
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 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 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
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 5805679ead RestructureCFGPass: fix use of include directory 2019-01-15 16:57:15 +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 ef2d16db15 Install headers and libraries 2018-12-15 08:34:36 +01:00
Alessandro Di Federico ac5dea43b4 Reduce exceptions thrown (e.g., due to tail calls)
In function isolation, every time we met a jump to an unexpected basic
block (i.e., a basic block that is not part of the current function), we
used to throw an exception. However this is unnecessary since oftentimes
it is sufficient to call the `function_dispatcher` or even perform a
regular function call.

The most obvious example is the case of a direct tail call. In this
situation performing a function call to the corresponding isolated
function is the most appopriate thing to do.
2018-12-15 08:34:36 +01:00
Alessandro Di Federico cb425c6a7a FCI: use previously detected fallthrough addresses
When going through basic blocks, FCI ignores basic blocks that have
already been identified as function calls. However, this lead to exclude
their fallthrough addresses from the list of fallthrough addresses.

This commit fixes this situation.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico a43fad370f GCBI: introduce the EntryPoint BlockType
`getType` didn't have a `BlockType` to represent the entry basic block
of the `root` function. Therefore, such basic block was erroneously
identified as a translated basic block.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 787b45630d Fix assertion messages
Assertion used to erroneously print part of the message on `stdout`.
2018-12-13 18:03:11 +01:00
Alessandro Di Federico 5cc504e117 Whitespace and other minor changes 2018-12-13 18:03:11 +01:00
Alessandro Di Federico a1120e4caf SA: precompute CSV indices
The stack analysis identifies CSV as `CPU+x` where `x` is an index that
uniquely identifies a CSV. We used to compute this index multiple times,
going through the list of global variables.

After we switched from metadata to global variables for strings
representing disassembled instructions, such process became very slow to
the point of being a bottleneck due to the large amount of global
variables.

This commit precomputes, once and for all, the unique identifier of each
CSV and saves it in a `std::set`.
2018-12-13 18:03:07 +01:00
Alessandro Di Federico e2abcbffe8 Test usage of revamb's headers/libraries 2018-12-05 12:23:52 +01:00
Alessandro Di Federico 7d4abadced Initial import 2018-12-04 22:40:50 +01:00
Alessandro Di Federico e21eed118c Tag function_call targeting external symbols
This commit uses SET, information about canonical values and labels to
detect if an indirect function call is targeting an external symbol.

The strings used for the name of external symbols are uniqued global
variables. This commit also uses this approach for the disassembly of
original instructions, which used to be metadata.
2018-11-15 16:03:09 +01:00
Alessandro Di Federico abb47bb964 Minor changes 2018-11-15 08:48:26 +01:00
Alessandro Di Federico 3a4d994d16 Fix disassembly (for delay slots and other stuff) 2018-11-14 09:34:49 +01:00
Alessandro Di Federico 37b4917ea5 delay slots are no longer relevant 2018-11-14 09:34:49 +01:00
Alessandro Di Federico bdd327e127 Function calls have a single link register
In certain cases we find more than one instruction storing the return
address to a register. In particular, this happens with a `bltzal`
instruction in MIPS, where the return address is stored both in `ra` and
`btarget`.

For now, do not consider these as actual function calls.
2018-11-14 09:34:49 +01:00
Alessandro Di Federico 09b9fbba39 Drop trailing semi-colon in messageless assertions 2018-11-14 09:34:49 +01:00
Alessandro Di Federico 509625cb30 Do not clobber helper functions' debug info
`DebugAnnotationWriter` creates debug information for each instruction
in the generated LLVM IR module. Before this commit, it used to clobber
any debug information in any function, which lead to wrong debug
information on helper functions.

This commit ensures that debug information of helper functions are
untouched, so that they can be used while debugging.
2018-11-14 09:34:49 +01:00