Commit Graph

105 Commits

Author SHA1 Message Date
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
Andrea Gussoni 5c5ae0a9de Improve metaregion collapse 2019-05-27 18:12:35 +02:00
Andrea Gussoni dd772f5f5f Enhance findReachableNodes algorithm
Enhanced the `findReachableNodes` algorithm, with a new `StackSet`
parallel data structure which is used to quickly check if we are
encountering a node already on the visit stack.

Modified the `findReachableNodes` to include in the returned set of
nodes also nodes which are encountered on self loop paths and that
should consequently be included in this set.
2019-05-24 18:35:52 +02:00
Andrea Gussoni 4777c81800 Add dummy node as source of retreating edges
Add a new dummy node as the source of each backedge found in the graph,
during the preprocessing.

This help in the semplification phase of the SCS, since the new dummy
node helps triggering merging of metaregions with have a non empty
intersection.
2019-05-24 18:35:52 +02:00
Andrea Gussoni 84aec352a3 Head election now always elect the first RPOT node
For now, we disable the complex criterion for the head election of an
SCS with a simple election of the first node of the region in RPOT
2019-05-24 18:35:52 +02:00
Andrea Gussoni ac34e38b2f New merge criterion for SCS regions
The new SCS merging criterion, checks that there are no abnormal
retreating nodes between SCS, meaning retreatings which exit from the
current SCS and do not point to the head of another SCS.

This kind of situation, if ignored could cause the introduction of some
cycles between outlined nodes and existing nodes, inserting new cycles
during the restructuring, which is a behavior which we aim to avoid.
2019-05-24 18:35:45 +02:00
Andrea Gussoni ead83260d6 Outlined nodes inserted in parent metaregions
When outlining nodes, we now include them in eventual parent metaregions
that included the nodes collapsed.

This should lead to minor duplication (as in the `cp` benchmark), since
we avoid duplicating two times nodes if also the external region causes
the first iteration outlining.
2019-05-24 16:10:02 +02:00
Andrea Gussoni f9a46b26c1 Update RPOT instead of re-computing it
We know keep updated the RPOT during node removals (otherwise we have
situation of pointer clashes) instead of recomputing it at each
metaregion restructuring iteration.
2019-05-22 16:03:10 +02:00
Andrea Gussoni e8ad1e542b Fixes and improvements suggested by MR 2019-05-03 15:46:07 +02:00
Andrea Gussoni dee4db8216 DOT and AST only enabled in debug mode
To avoid skeing the results the serialization of `DOT` intermediate file
for both restructuring and AST semplification passes are now serialized
only when the corresponding loggers (`CombLogger` and `BeautifyLogger`)
are enabled.
2019-04-24 16:21:34 +02:00
Andrea Gussoni 2999e442c4 Move internal SetNode before extern CheckNode
When a retreating edge involves as source node a `SetNode` belonging to
an internal region (which should be the default `SetNode` that remains
outside the collpased node), move it just after the `CheckNode` that is
being introduced, so that the semantics of the code remains untouched.
2019-04-23 14:37:13 +02:00
Andrea Gussoni 0bbfeff053 clang-format 2019-04-19 12:30:13 +02:00
Andrea Gussoni cfa2ba41f4 Use llvm::SmallString' for BBNode` name field
Use a `llvm::SmallString` for the `Name` field of `BasicBlockNode`.
This enables us to modify the name of the node, which is very useful
during debugging and manual inspection of the graph serialized in
output.
2019-04-19 12:13:22 +02:00
Andrea Gussoni 675ed76ea1 Clang-format 2019-04-19 11:36:54 +02:00
Andrea Gussoni 1a63c6ced6 Add assertion to early catch bugs
Add some assertions in the restructuring phase aimed to early catch bugs
which we found in the last bugfix iteration.
2019-04-19 11:34:27 +02:00
Andrea Gussoni e0d605ca8c Fix metaregions identification phase
Fix the metaregion identification phase, in particular the add of the
addditional nodes merged when encountering a node which is the target of
a backedge identifying another metaregion.

The add of the additional nodes must be done in a fixed point fashion,
otherwise in case of dependent insertions the order of the nodes
triggers different behaviours (and bugs).
2019-04-19 11:04:11 +02:00
Andrea Gussoni 67bbd24361 Improve metaregions creation order 2019-04-19 10:55:53 +02:00
Andrea Gussoni d9d1730f5e Improve debug information for metaregions
Improved the debugging informations provided by the restructuring pass
on the identified metaregions.
2019-04-19 10:47:14 +02:00
Andrea Gussoni 485a253dec Improve serialization on files 2019-04-19 10:34:31 +02:00
Andrea Gussoni 8a90516915 Update the reverse post order
Update the reverse post order at each restructuring iteration.
2019-04-19 09:49:47 +02:00
Andrea Gussoni abb72c3b23 Coding style and improvements in MR 2019-04-16 17:37:57 +02:00
Andrea Gussoni 95ddb2b36b BasicBlockNode and RegionCFG now template
`BasicBlockNode` and `RegionCFG` classes are now template classes. This
means that the `BasicBlockNode` class can be used as a generic wrapper
for any type of object in the original graph (it is usually used to wrap
a `llvm::BasicBlock *` for decompilation purposes, but in tests it can
be used to wrap a `DotNode` object) that implementes `GraphTraits`.
2019-04-15 17:30:37 +02:00
Andrea Gussoni 6574255e8a Improve StringRef use for BasicBlockNode
Improved the interaction with the `StringRef` name field of
`BasicBlockNode`.

In case of artificial nodes, the name is left empty and created
on-the-fly for serialization purposes.
2019-04-15 10:22:11 +02:00
Andrea Gussoni 20b380c0d1 NDuplicates passed as reference to Mark
Removed the computation of the information contained in the
`NDuplicates` prevously done in the `MarkForSerialization` pass, since
the information is now precomputed in the `RestructureCFG` pass and
exposed with a dedicated method.
2019-04-15 10:16:05 +02:00
Andrea Gussoni 2b53f04f31 Compute information about node cloning
Compute how many times an original `llvm::BasicBlock` has been
duplicated during the comb pass.
2019-04-15 10:05:17 +02:00
Andrea Gussoni 3aaf4d939e Update OriginalBB map when moving nodes.
Update the `OriginalBB` map (which will be later used for retrieving the
original basic block linked to a certain BBNode) during nested
`RegionCFG` creation and during flattening, which are steps that modify
the allocation of the `BBNode` objects.
2019-04-15 10:05:17 +02:00
Andrea Gussoni 1c66c145cb RegionCFG::initialize method now template
The `RegionCFG::initialize` method is now a template method, which
accepts as input any kind of object which exposes the `GraphTraits`.

In this way we can build a `RegionCFG` object not only starting from
LLVM IR, which can be very useful for testing purpose.

Since we also removed the information about the original
`llvm::BasicBlock` inside the `BasicBlockNode`, we need to keep this
link to later feed this information to the GHAST in an external data
structure (potentially a `std::map`).
2019-04-15 10:04:40 +02:00
Andrea Gussoni 2c3056527d Remove any pointer to BasicBlock inside BBNode
The `BasicBlockNode` does not contain anymore any pointer to the
`llvm::BasicBlock` object that generated the `BasicBlockNode`.

This change is necessary for decoupling completely the `BasicBlockNode`
and `RegionCFG` classes from the LLVM IR, so that we can build up a
`RegionCFG` from any object which implements the `GraphTraits`.

The `RegionCFG` does not contain anymore a map between
`llvm::BasicBlock` and `BasicBlockNode`.
2019-04-15 10:03:08 +02:00