Commit Graph

2939 Commits

Author SHA1 Message Date
Pietro Fezzardi f4d5fec5bc First fully functional EnforceCFGComingPass 2019-02-11 12:18:44 +01:00
Pietro Fezzardi 463c40a9cf Add ASTNode children BreakNode and ContinueNode 2019-02-11 12:18:44 +01:00
Pietro Fezzardi 2b1843d898 Fix AST in EnforceCFGCombingPass 2019-02-11 12:18:44 +01:00
Andrea Gussoni 02e1b94daa Added RemoveSwitchPass
Added a new `FunctionPass` which converts `switch` instructions in a
nested chain of `if` checks.
2019-02-11 12:18:44 +01:00
Andrea Gussoni 929c0c4cdf Flattening for AST
Implemented the flattening also for the AST trees, taking also care of
adjusting the pointers to the new BBNode in the `root` `RegionCFG`.
2019-02-11 12:18:44 +01:00
Andrea Gussoni dbffa54124 Handle check BBNode in inflate
Considering the `check` BBNode during the `inflate` procedure, and
fixing the functions handling edges and nodes successors accordingly.
2019-02-11 12:18:44 +01:00
Alessandro Di Federico d00bf31bca Reorganize the build system 2019-02-10 16:20:24 +01:00
Alain Carlucci b2629efd05 Avoid useless computations when decompiling a single function 2019-02-08 11:44:17 +01:00
Alain Carlucci 2cda9be797 Decompile one function + write on raw_ostream 2019-02-08 11:44:17 +01:00
Andrea Gussoni eba245d35e RemoveBadPC pass
Added a pass that removes the `bad_return_pc` check, which is useful
only when we want to preserve semantics, but it is useless and harmful
for decompilation.
2019-02-07 19:27:08 +01:00
Pietro Fezzardi 7fc7ac4c7b Finish EnforceCFGCombingPass 2019-02-07 19:26:37 +01:00
Pietro Fezzardi c455b516d2 Add Liveness again 2019-02-07 14:44:32 +01:00
Pietro Fezzardi de19c3fd26 Fix BasicBlockNode::isBasicBlock() 2019-02-06 19:24:44 +01:00
Andrea Gussoni 2e9ff8449f Improved debugging messages 2019-02-05 10:17:47 +01:00
Andrea Gussoni 6231ba7bed Comb ignores useless conditional nodes
When the `then` and `else` branches of a conditional node reach two
disjoint sets of exit nodes do not consider that nodes in the `inflate`
procedure.
2019-02-05 09:54:23 +01:00
Andrea Gussoni 414aba5f66 Dot serialize function now const 2019-02-05 09:54:14 +01:00
Andrea Gussoni 54880d3a38 Fix dispatcher edge creation
Add the correct predecessor when setting the `true` or `false` branches
of the dispatcher check nodes.
2019-02-05 09:32:09 +01:00
Pietro Fezzardi 10fcd9bbdc Fix getters for Check BasicBlockNodes 2019-02-02 01:40:19 +01:00
Pietro Fezzardi 2afd5053e6 Rework exit and entry dispatcher trees 2019-02-01 19:24:56 +01:00
Pietro Fezzardi 7399590079 BasicBlockNode: remove usesless setter methods
Removing this methods also guarantees that the NodeType of a
BasicBlockNode is never changed after construction.
2019-02-01 17:59:23 +01:00
Pietro Fezzardi 2c93512f90 Rework BasicBlockNode class 2019-02-01 15:08:53 +01:00
Andrea Gussoni 0cdb63630e Restructure ASTTree anatomy
Added a pointer to the `RootNode` in the ASTTree, and added a
`dumpOnFile` method for easier serialization.
2019-01-30 18:35:24 +01:00
Pietro Fezzardi 099ae4d479 First stub of flattening 2019-01-30 09:22:20 +01:00
Andrea Gussoni c88ccdff43 Fix include guards
Fixed some include guards in the header files of the imported libraries,
which where missing or not conform to the convention.
2019-01-28 18:54:10 +01:00
Andrea Gussoni e5187a61d9 Use new DominatorTree update features
Instead of rebuilding the dominator and postdominator at each iteration
of the inflate procedure, use the utilities introduced in LLVM 7.0 to
keep the data structures updated after each change to the RegionCFG.
2019-01-28 15:13:25 +01:00
Pietro Fezzardi 20a336344e Add state variable info to dummy BasicBlockNodes 2019-01-25 18:36:37 +01:00
Andrea Gussoni c70b6f1097 Implemented de-optimization on RegionCFGTree
Now, during the simplification of short-circuits the so called
`de-optimization` is also applied to the corresponding `RegionCFGTree`.

This allows us to avoid loss of information during the iterative
refinement phase, which basically divides for ever the existencies of
two nodes that have been cloned starting from a single original one.
2019-01-25 13:45:03 +01:00
Andrea Gussoni 05d736cbb1 AST serialization is now performed on file
We now perform the AST serialization directly on file, without using
stderr. In this way we can follow the evolution of simplifications and
changes to the AST tree.
2019-01-25 13:35:20 +01:00
Andrea Gussoni 7de353785e Implemented conditional node list for IfNode
After short-circuit simplification, we can have that a conditional node
corresponds to more than one `BasicBlockNode`.

This change reflects this fact, and takes care of merging blocks during
short-circuit simplification, and of representing this change in the
serialization.
2019-01-25 13:32:29 +01:00
Andrea Gussoni d591ae13e6 Improved serialization of graphs during inflate
Improved the `dumpOnDotFile` function to take as a parameter also a
sub-folder name.

Modified the `inflate` function to dump on file the graphs after each
modification.
2019-01-25 13:32:28 +01:00
Pietro Fezzardi f5fcc4aa24 Completely redesign ownership model for RegionCFG 2019-01-25 13:13:35 +01:00
Pietro Fezzardi 6ef68f2ca2 Remove unused headers 2019-01-23 17:03:17 +01:00
Andrea Gussoni 578772ddb4 Fix isDummy for ASTNode
Now the `isDummy` method is invoked on the underlying `CFGNode` only
when we actually have a corresponding node.
2019-01-22 19:16:48 +01:00
Andrea Gussoni 9876e514d5 Improved isEqual operator with deep comparison
Now the `isEqual` operator does what we call a `deep` comparison,
meaning for every type of `ASTNode` it recursively check if the
structures of the AST tree originating in that node can be considered
equivalent (e.g., two sequence nodes are considered equal if every node
they contain is in turn equal).

This operator gives more space to the short-circuit simplification,
which relies heavily on the `isEqual` operator.
2019-01-22 19:16:48 +01:00
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 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 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 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 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
Pietro Fezzardi da299f3095 EnforceCFGCombingPass: inject dummy nodes in CFG 2019-01-16 12:53:08 +01:00
Pietro Fezzardi dc430e446b RegionCFGTree.h: add missing #include<set> 2019-01-15 16:57:15 +01:00