Commit Graph

2366 Commits

Author SHA1 Message Date
Andrea Gussoni 371dc7ea97 Remove exceptions before decompilation in pipeline
We now craft a new decompilation pipeline. We remove the exceptions
introduced as fallbacks to preserve the semantics, and we perform passes
of `dce` and `simplifycfg` to remove all the superfluos basic block
remaining after this change. To do this, we need an additional pass that
removes also the calls to the `llvm.assume` intrinsic, and another pass
of `dce` to remove all the dead uses.

In addition, we also remove dead stores to the `cpu_loop_exiting` global
variable in order to improve the decompiled code.

As a byproduct of this, we remove also the dependency from the
`-remove-pc-stores` pass, since its jobs is included by the changes
mentioned above.
2020-11-02 18:33:57 +01:00
Alessandro Di Federico ccb0b183a5 FunctionIsolation: member.type, not function_call
FunctionIsolation used to base its work on calls to the marker function
`function_call`, as opposed to information provided by the StackAnalysis
(i.e., `revng.member.type` along with `func.call`).

This also affected EnforceABI, which took care of finishing the work
left over by FunctionIsolation. This was hackish and inelegant.

This commit makes FunctionIsolation work exclusively employing
information from StackAnalysis and purges away code that is no longer
necessary from EnforceABI.
2020-11-02 11:21:07 +01:00
Alessandro Di Federico 51b29afc30 Make ABIAnalysis mandatory 2020-11-02 09:05:12 +01:00
Alessandro Di Federico f7cb681b23 Whitespace changes 2020-11-02 09:05:12 +01:00
Andrea Gussoni f57a96ab95 generateAst: Fix two successors two dominated tile
Now cover a corner case where we have a tile composed by two successors,
which we entirely dominate, and a common postdominator which we don't
postdominate (basically we miss a superfluos dummy here).

In this case, include in the tile `then` and `else` bodies, but do not
include in the tile the common postdom (it will be taken care by someone
else more higher in the CFG).
2020-10-30 16:58:00 +01:00
Pietro Fezzardi 2b599d0ebc RestructureCFG: fix NDuplicates 2020-10-30 01:12:03 +01:00
Pietro Fezzardi b2437ddabc Drop old unused pass RemoveUnexpectedPCPass 2020-10-29 09:34:05 +01:00
Pietro Fezzardi 6cea19ef4d generateAst: update ASTDT instead of recomputing 2020-10-28 18:34:09 +01:00
Pietro Fezzardi 4dcc02c550 weaving: avoid using Sink
Thanks to inlined edges, this is now not necessary anymore.
2020-10-26 17:05:15 +01:00
Pietro Fezzardi 7c2f70cdac Drop RemoveSwitchPass
Now that we fully support switches, there's no need for this pass to
exist anymore.
2020-10-26 14:48:37 +01:00
Pietro Fezzardi 049e687e3b Remove flattening 2020-10-26 14:29:47 +01:00
Pietro Fezzardi c2e8e65baa CDecompilerBeautify: weaken simplifyLastContinue
The simplifyLastContinue beautifier was too ambitious and there were
many corner cases that it handled in the wrong way, leaving the AST in a
shape that could not be emitted, or breaking the semantics.

This commit severely weakens the simplifyLastContinue, so that it does
not break things anymore.
It is now able to match only continue statements that are in the last
position of a sequence node which is the body of a ScsNode.

This obviously is not enough but allows revng-c to pass all the
decompilation tests.
In the future we will need to extend simplifyLastContinue to match more
cases in a sane way.
2020-10-26 14:17:25 +01:00
Pietro Fezzardi f5e26febe2 Fix simplifyAtomicSequence for switches
Before this commit, we couldn't handle simplification of atomic
sequences in cases of switches that had a default.
The reason is that if you remove a case from a switch that has a
default, you are implicitly saying that the case that you remove will be
handled by the default, hence you're changing the semantics.

Now we handle this case by not removing the case, substituting it with a
SwitchBreak node instead.
2020-10-26 14:16:38 +01:00
Pietro Fezzardi acb21bba5e RegionCFG: remove wrong assertion 2020-10-26 14:16:22 +01:00
Pietro Fezzardi 7ff0d0b8d0 RestructureCFG: Mark anyPC as inlined 2020-10-26 14:15:39 +01:00
Pietro Fezzardi 4fc2ab56a0 RegionCFG::inflate(): fix assertion 2020-10-26 14:15:28 +01:00
Pietro Fezzardi 6024ce9a1b RegionCFG: fix bug ini markUnexpectedPCAsInlined()
This commit fixes a bug causing iterator invalidation in
`markUnexpectedPCAsInlined`.
Before this commit we were iterating over a graph while adding nodes,
which could cause iteration invalidation on realloc.
2020-10-26 14:13:46 +01:00
Pietro Fezzardi 6dbb11f39b Drop RemoveBadPCPass
This pass is now useless in revng-c, since we have the
--isolate-no-safety-checks flag in revng.
2020-10-26 14:13:25 +01:00
Andrea Gussoni 9ef2cc7f04 RegionCFGTree: harden combing of inlined paths
Added assertions that checks that, once, during combing, we start
analyzing a path deriving from an inlined edge, we only encounter nodes
which do not require combing (all predecessors have been visited), or
that are reachable only from inlined edges (this is usually the case for
edges bringing to the `UnexpectedPC` basic block).
2020-10-26 14:13:05 +01:00
Andrea Gussoni b25ed2fae7 RegionCFGTree: Do not process inlined edges.
Whem enqueing the successor of a conditional node, skip the inlined
edges
2020-10-26 14:12:50 +01:00
Andrea Gussoni 4962bcf11b RegionCFGTree: Clone UnexpectedPC in inlining
When we perform the tagging of the inlined edges in occurence of, we
also perform a duplication of the `UnexpectedPC` basic block.
In this way, we can avoid, walking through inlined edges during the
combing, since we now that all the nodes following an inlined edges will
be dominated by the corresponding conditional bringing to it.
2020-10-26 14:12:35 +01:00
Andrea Gussoni 0bc1326e3c RegionCFGTree: print as purple the inlined edges 2020-10-26 14:12:21 +01:00
Pietro Fezzardi 3b630b2f3d generateAst: fix tiles for switch with fallthrough 2020-10-26 14:12:06 +01:00
Pietro Fezzardi a84f69e7c9 ASTTree: add Successor edges to dot dumps 2020-10-26 14:11:49 +01:00
Andrea Gussoni 71bcaff852 generateAst: update SCS body AST in AST gen
Update the `Body` pointer inside an `ScsNode` when processing the
`copyASTNodesFrom` method, in order to update the `Body` pointer of
nested collapsed nodes.
2020-10-26 14:11:32 +01:00
Andrea Gussoni 7783794aa2 generateAst: delete old AST simplification helpers
Remove from the `RegionCFGTreeImpl.h` header the helper functions used
for the first AST simplification that are now part of the
`GenerateAst.h` header.
2020-10-26 14:11:16 +01:00
Pietro Fezzardi 55731fd100 generateAst: fix createSequence 2020-10-26 14:10:58 +01:00
Pietro Fezzardi a4eefdf7f8 ASTNode: drop old useless comments 2020-10-26 14:10:19 +01:00
Pietro Fezzardi 3df53164c4 Fix weight computation for BasicBlockNodes 2020-10-26 14:09:57 +01:00
Pietro Fezzardi c7b05cbb2c RestructureCFG: fix CollapsedMap 2020-10-26 14:09:41 +01:00
Pietro Fezzardi a2e9a7660d ASTNode and ASTTree: cleanup of data members
This commit removes the old unused field `Processed` from `ASTNode`, and
fixes the default construction of `ASTTree` data memebers.
2020-10-26 14:09:02 +01:00
Pietro Fezzardi a69cefde9b ASTNode: make the Clone method const
In this way we have guarantees that cloning a node does not change it.
2020-10-26 14:08:00 +01:00
Andrea Gussoni 3128c1a4b6 Factor generateAST out as function 2020-10-26 14:07:54 +01:00
Pietro Fezzardi 9d07b639f9 RegionCFGTree: fix creation of switch edge labels 2020-10-26 14:00:30 +01:00
Pietro Fezzardi dfec3ef61a generateAst: fix corner case in tile generation
The generation of tiles for nodes with two successors was broken for
nodes with two successors because it assumed that at least one of them
was inlined.
This is may not be true in general.
This commit fixes the tile generation for  those cases.
2020-10-26 14:00:00 +01:00
Pietro Fezzardi cfde9afbe1 Combing: remove sink 2020-10-26 13:59:45 +01:00
Pietro Fezzardi be35e578ad generateAst: fix tile for Collapsed nodes 2020-10-26 13:59:30 +01:00
Pietro Fezzardi 96e8830b92 generateAst: fix typo causing emission of wrong if 2020-10-26 13:59:14 +01:00
Pietro Fezzardi a78fb89518 RestructureCFG: fix creation of Switch labels
Before this commit, outgoing edges from switch nodes were not created
with correct case labels.
For a while we assumed this was fine as long as we fixed them later,
with the tagCaseEdges() method.
However, we didn't realize that adding labels later could not handle
correctly come situation, namely switches with a case that was a set
node followed by a break node to the outermost RegionCFG.

The only way to handle that situation correctly without pattern matching
is to construct the RegionCFG with the correct labels in the first
place.
This is exactly what this commit does.
2020-10-26 13:58:57 +01:00
Pietro Fezzardi 6535f29e9f RegionCFGTree: remove outdate comment 2020-10-26 13:58:40 +01:00
Pietro Fezzardi 55e252d0c6 BasicBlockNode: add access methods for edge labels 2020-10-26 13:58:23 +01:00
Andrea Gussoni eea15d9c18 [TILING] Do not remove dandling nodes after tiling 2020-10-26 13:58:07 +01:00
Andrea Gussoni c292f08218 [TILING] Implement AST generation memoization
We now do not generate again the AST for collapsed node that have been
duplicated.

If we encounter a region for which the AST was already generated, we
simply use the already computed AST (also because the tiling now
destroys the `RegionCFG` while it build the AST).
2020-10-26 13:57:52 +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 5d640dd06b [TILING] Iterate on the graph in pot
When generating the AST, we now iterate directly on the non-filtered
graph in post order, instead of computing a depth first iteration on the
dominator tree built on the non filtered graph.
2020-10-26 13:56:17 +01:00
Andrea Gussoni db2e3a1b9e [TILING] Inlined edges in 2 successors node tile 2020-10-26 13:56:11 +01:00
Andrea Gussoni 0841f36834 [TILING] Fix erroneous successors initialization 2020-10-26 12:27:51 +01:00
Andrea Gussoni b0206f5039 [TILING] Handle 2 successor and 1 dominated node
Handle the situation where we have 2 successors, and we dominate only 1
node.

This tile can be generated only when we have 2 successors, and one of
this successors is an inlined node. No common postdominator in
contemplated in this tile.
2020-10-26 12:20:45 +01:00
Andrea Gussoni e41a063348 [TILING] Handle 2 successors and 2 dominated nodes
Handle the situation where we have 2 successor nodes, but we only
dominate 1 of them.

This tile can generate different situations, depending on the actual
structure: we can have a diamond shaped region with an inlined edge, we
can have a diamond without the postdominator and no inlined edge.
2020-10-26 12:19:55 +01:00