Commit Graph

132 Commits

Author SHA1 Message Date
Pietro Fezzardi 93d9cbb67b Enforce new include conventions 2020-11-12 18:00:45 +01:00
Alessandro Di Federico 37fde04594 Move licensing details to LICENSE.md 2020-11-09 10:03:33 +01:00
Andrea Gussoni f3f11533b8 ASTTree: Reorganize AST dot printing
Reorganize the AST dot printing in order to use LLVM facilities for
files handling. In addition, clean up the code, and add a function
(useful in debug) in order to dump the dot of and AST from GDB (accepts
a `char *` instead of a `std::string`.
2020-11-06 15:08:00 +01:00
Andrea Gussoni df0985f1fc RegionCFG: dumpOnFile to dumpASTOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni eb1ddab86c RegionCFG: dumpDotOnFile to dumpCFGOnFile 2020-11-06 15:08:00 +01:00
Andrea Gussoni 7362e7beeb RegionCFG: Reorganize graph debug
Now, when the `debug-log=restructure` flag is active, debug graphs are
organized in a more rational way.

First of all, all the graphs are now put in a single directory, and are
divided first by function name and then by type.

Also, as in the case of the tiling debug graphs, their name is more
consistent with the rest of the codebase.
2020-11-06 15:08:00 +01:00
Pietro Fezzardi 217a18edb1 Update copyright notice 2020-11-06 15:07:45 +01:00
Pietro Fezzardi 2b599d0ebc RestructureCFG: fix NDuplicates 2020-10-30 01:12:03 +01:00
Pietro Fezzardi 049e687e3b Remove flattening 2020-10-26 14:29:47 +01:00
Pietro Fezzardi cc3ed6c508 Remove all blacklisted function from decompilation 2020-10-26 14:17:02 +01:00
Pietro Fezzardi 38935f3a40 Remove functions from decompilation blacklist
We're now able to handle them, so there's no need to skip them anymore.
2020-10-26 14:13:31 +01:00
Pietro Fezzardi ee5e934e86 RestructureCFG: merge debug prints 2020-10-26 14:10:44 +01:00
Pietro Fezzardi c7b05cbb2c RestructureCFG: fix CollapsedMap 2020-10-26 14:09:41 +01:00
Pietro Fezzardi 432957c649 RestructureCFG: cleanump AST and NDuplicates 2020-10-26 14:09:26 +01:00
Andrea Gussoni 3128c1a4b6 Factor generateAST out as function 2020-10-26 14:07:54 +01:00
Pietro Fezzardi b16d6dde86 RestructureCFG: prevent computing useless PDT 2020-10-26 14:00:16 +01:00
Andrea Gussoni ced4f1a6a8 [TILING] Fix NDuplicates counting
Count the number of duplication (needed later in the `Mark` pass) right
before the AST generation phase, where the `RegionCFG` will be destroyed
by the tiling matching.
2020-10-26 13:57:17 +01:00
Andrea Gussoni b52206cb68 [TILING] Implement tiles creation
Now we implement correct tiles creation, and we handle correctly handle
different situations were inlining is present
2020-10-26 13:56:57 +01:00
Andrea Gussoni bee02ee5d1 [EDGEINLINE] Change findReachableNodes interface
Change the interface of the `findReachableNodes` helper function, so
that now accepts arguments passed by pointer instead of by reference.
Also, the helper function now does not accept a `nullptr` `Source`
parameter.
2020-10-26 12:17:20 +01:00
Andrea Gussoni 24712518b3 [EDGEINFO] Implement EdgeInfo for inlining info
The `Successors` and `Predecessors` field on the `BasicBlockNode` are
now promoted from being a `std::pair` composed by the pointer to the
successor and the set representing the cases, to a pair between the
pointer to the successor and a new struct called `EdgeInfo`.

This struct is used to contain both the information about the cases, the
information representing whether and edge is inlined or not, and
possibly more information in the future.
2020-10-26 12:16:55 +01:00
Pietro Fezzardi 66243838c8 Allow decompiling functions called bb.main
They were disabled before this commit, to work around some limitation of
an old benchmark suite.
2020-09-11 18:29:37 +02:00
Pietro Fezzardi fc98fc69f5 Fix detection of isolated functions using metadata 2020-07-22 17:27:02 +02:00
Pietro Fezzardi 1a9ae59e4a RestructureCFG: major refactoring of switches
Now edges have sets representing labels.
There's no distinction between Dispatchers and Regular switches at the
GHAST level anymore.
2020-07-20 19:02:19 +02:00
Pietro Fezzardi 7f6ce70c82 Refactor RegionCFG::inflate() method 2020-07-16 10:48:12 +02:00
Pietro Fezzardi a078be2478 RestructureCFG: avoid dedicated untangling of root
This commit removes a call to untangle() that was performed before the
whole combing algorithm on the root RegionCFG.

The call was redundant before introducing the weaving, and became
plainly wrong after adding the weaving, because it ended up trying to
untangle the root RegionCFG before weaving (which is supposed to run
first).

Removing the dedicated call fixes the bug, because weaving is performed
first as part of the call to generateAst().
2020-07-09 18:17:20 +02:00
Pietro Fezzardi f7e8599c5e Enforce check-conventions.sh
All commits should pass check-conventions.sh from now on.
2020-06-15 15:40:02 +02:00
Andrea Gussoni 933dd20e44 Restructure dispatcher creation
Now that `Check` nodes are nomore a thing, restructure the dispatcher
creation code in order to be more clean.
2020-06-15 15:06:23 +02:00
Andrea Gussoni e611e47a20 Remove Check nodes
Check nodes are nomore a thing. Remove all methods and accessor related
to them.
2020-06-15 15:06:23 +02:00
Andrea Gussoni 1c842fbd28 Rework Dispatcher kind attribute and constructor
Reorganize attribute `Kind` incorporating it into the `Type` attribute,
by lowering its memory footprint.
Modified the constructors, some accessors and helpers accordingly.
2020-06-15 15:06:23 +02:00
Andrea Gussoni be39c9a5e3 Actualize assert to new node types 2020-06-15 15:06:23 +02:00
Andrea Gussoni a8b25fdd52 Differentiate entry and exit dispatcher
Differentiate the entry and exit dispatchers introduced during the
restructuring with a different `Kind` enum inside the node.
2020-06-15 15:06:23 +02:00
Andrea Gussoni 1f94d0fdd7 Remove assertions on SwitchNode
Disable assertions which are no more valid since `CheckNodes` are no
more present in the `RegionCFG`.
2020-06-15 15:06:22 +02:00
Andrea Gussoni 0fb4fc6503 Enable the untangle procedure again 2020-06-15 15:06:22 +02:00
Andrea Gussoni ca747929e8 Build new dispatchers during restructuring
Build the new dispatcher nodes type (switches instead of nested trees of
`if`) during the control flow restructuring phase.
2020-06-15 15:06:22 +02:00
Andrea Gussoni aacb65238a HACK: temporarily disable untangle
Disable the untangle processing until we understand what we need to do
with the new switch nodes.

In this way we can proceed with the prototyping.
2020-06-15 15:06:22 +02:00
Andrea Gussoni 86f35b6d93 Various Untangle improvements
Introduced various untangle algorithm improvements:
- Improve untangle edge reorganization: improve the criterion used for
  reorganizing the edges between the old postdominator and the cloned
  one, after an inline procedure is attempted during the untangle.
- Untangle counter: introduce two new counters which take into account
  the number of times the untangle procedure is attempted and the actual
  times it is performed.
- Disable not dominated restriction: disable the criterion which
  restricts the untangle opportunities if we do not dominate entirely
  at least one of the two branches. This has likely broken the
  assumption that the postdominators of nodes do not changes after each
  untangle step has been carried out.
- Change dominance criterion: the dominance of the nodes belonging to
  the `then` and `else` nodes is now checked not with respect to the
  conditional node, but to the `then` and `else` edges of the conditional
  node.
- Untangle eager inlining: now, when the untangle procedure finds a
  suitable candidate for the inlining, proceed the complete inlining
  starting from the selected branch. By default new clones of all the
  nodes till the exit are created and attached to the branch, while the
  original nodes are detached. An additional pass which removes eventual
  dandling nodes (nodes which are not reachable from the entry node of
  the graph) is performed after the eager inlining. This means that if
  no other incoming edges to this group of nodes is present the original
  nodes will be purged.
  The post dominator now is updated during the inlining analysis, and
  the paths conducting to inlined exits are not taken into account for
  the post dominator computation.
- Enable untangle for mixed branches: perform the untangle even if the
  `then` and `else` branches share nodes. This was not feasible before
  because without the eager inlining we couldn't decide which edge to
  attach to the new postdominator clone. This problem is not present
  anymore, so we can handle any kind of topology in the untangle.
- Improved also the analysis information serialized by the decompiler.
2020-01-13 12:13:42 +01:00
Andrea Gussoni f0bedc973e Improve graph weight computation
Improve the duplication weight computation with the percentage increase.
2020-01-13 11:57:04 +01:00
Andrea Gussoni 30bc1d333e Decompile a single function
Add a flag to enable the decompilation of a single function.
In order to have a single flag shared between the `RestructureCFGPass`
and the `CDecompilerPass`, we added a new dedicated decompilation unit
called `TargetFunctionOption`.
2020-01-13 11:55:32 +01:00
Andrea Gussoni b5c00f7dfc Fix inclusion and library linking 2019-11-20 15:16:17 +01:00
Andrea Gussoni 46e8447032 Fix indentation 2019-11-20 15:16:17 +01:00
Pietro Fezzardi c6c6f19535 Enforce check-conventions 2019-11-20 15:16:17 +01:00
Pietro Fezzardi 429233f054 Fix more warnings left from -Weverything 2019-11-20 15:16:17 +01:00
Pietro Fezzardi cb58b8a526 Fix destruction of ExprNodes class hierarchy
`ExprNode` and its child classes use LLVM-style RTTI.

Until now their destruction was not handled properly, causing the
constructor-destructor type mismatch warnings on ASAN.
Despite this all the code was working properly, but just for luck,
because of the fact that these classes are very shallow.

This commit fixes the issue, and allow `ExprNode` and its child classes
to be extended without worrying about wrong destructors being invoked.
2019-11-20 15:16:17 +01:00
Andrea Gussoni b214dd1921 Enforce check-conventions.sh
Replicate this commit 72f836d30079c191d1c30e185114c4c0a0f914df made by
Pietro.
2019-11-20 15:16:17 +01:00
Andrea Gussoni 560a345a2c Enforce -Weverything extensively
Replicate the changes made by this commit
f2a0df309f78e1b5d7c5f81ada5110523644559e perfomed by Pietro on the
branch containing the development fixes for `revng-c`.
2019-11-20 15:16:17 +01:00
Andrea Gussoni 7cae83a3bb Template instance declaration for -Weverything
Add new headers files (terminating with `BB`, as `BasicBlockNodeBB.h`),
which will be used as the new header files by the users, and which
contain a declaration of the template instantiation, and a `using`
aliasing the instantiation.

This has been made to comply with the `-Wundefined-func-template` flag,
automatically enabled when using `-Weverything`
2019-11-20 15:16:17 +01:00
Pietro Fezzardi 569ec5658e Add and enforce -Wall and -Werror 2019-11-20 15:16:14 +01:00
Andrea Gussoni fdda9fdd70 Collect metrics about duplication
Collect the metrics regarding duplication during the combing pass, and
output them in `.csv` format.
2019-07-30 18:24:16 +02:00
Andrea Gussoni 9127dba961 TEMP: soft fail 2019-07-23 09:10:04 +00:00
Andrea Gussoni c76ba641aa Fix head region candidate election 2019-05-27 18:23:50 +02:00