113 Commits

Author SHA1 Message Date
Alvise de Faveri 4c8215fc47 DLA: Add pointers
* Changes to the `LayoutTypeSystem` graph

Pointers are identified in the TypeSystem graph as leaf nodes which
have a new type of edge (PointerEdge) that connects them to another
node of the graph. The destination of the edge represents the layout of
the pointed type.

* Changes to the Front-end

Pointer edges, and their destination nodes, are created by the DLA
front-end (`DLACreateIntraProceduralTypes`) whenever an access node has
a size that is compatible with the size of a pointer in the current
Architecture.
Successors might then be added to the newly generated node, if any,
by looking up the llvm::Value it is attached to.

* Changes to the Middle-end

Most of the DLA passes should ignore Pointer Edges, so they are modified
accordingly. Most notably, nodes that represent pointed layouts should
never be merged/pruned-off.

* Changes to the Back-end

The `TypeDeclCreationAction` of the decompiler and the `DLAMakeLayouts`
step of the DLA back-end are modified to take into account the new
information about pointers.

⚠️ There is a known issue with this version of the decompiler,
namely the fact that type loops are not detected and can cause the
emitter to enter an infinite loop.
2021-11-16 17:00:34 +01:00
Alvise de Faveri 92712396ee DLA: Fix multi-edge children in DedupUnionFields
When deduplicating unions, for each union we compare each successor
with all other successors. However, the same successor node might be
reachable by more than one edge from the parent.

This can cause problems when a node gets merged while the comparison is
still ongoing. In particular, since the comparison is done using a copy
of the successor list, to avoid iterator invalidation, the links in
the worklist are not updated when a node gets merged, causing links to
the merged node to have an invalid destination.

The fix here is to keep a list of **nodes** to visit, and a list of
**edges** that have already been visited, so that, if a node is merged
through one of its links, we are not visiting other links connected to
the same node after the merge.
2021-11-16 17:00:34 +01:00
Alvise de Faveri e90020b94c Don't visit the same union twice during dedup
Optimization to avoid checking the same union node multiple times.
2021-10-11 18:28:03 +02:00
Alvise de Faveri a6d0d52107 Remove leftover call from debugging session
RemoveConflicts should not be needed here, as it runs before in a
separate step and is also ran during deduplication.
2021-10-11 18:25:18 +02:00
Alvise de Faveri e2dd34e08e Avoid comparing a node with itself in union dedup 2021-10-11 18:21:53 +02:00
Alvise de Faveri 43ae7a91cb DLA: Add DeduplicateUnionFields Step
Add a step that recognizes if two subtrees of a union node are
topologically equivalent and merges them. This corresponds to removing
duplicate fields in unions.

This deduplication was prevously done while emitting layouts.

A check is inserted into DLAMakeLayouts to assert that, after
constructing unions, no union has only one child, which could be the
case if we didn't deduplicate union fields in the graph.
2021-10-06 16:37:37 +02:00
Alvise de Faveri 637bf70ff3 DLA: Make CollapseSingleChild a function
Since the reasoning behind single child collapsing can be reused in
other points of the DLA pipeline, move the logic that acts on a single
node in a static function out of the CollapseSingleChild step.
2021-10-05 18:16:21 +02:00
Alvise de Faveri 7e72fc4be1 DLA: Add RemoveConflictingEdges step
Add a DLA step that removes all instance-at-offset-0 edges between nodes
that already have an inheritance edge between them.
2021-10-05 18:16:21 +02:00
Alvise de Faveri a0f95e0370 Modify CollapseSingleChild to allow single members
* Inheritance straight lines are now collapsed by CollapseSingleChild
* Don't collapse if parent has more than one parent or if the child has
more than one parent
* Allow the possibility to construct single-member struct: if this
struct is inherited by many other structs, "flattening" the struct is not
the most sensible thing to do, since inheritance information is something
we want to preserve in these cases.
2021-07-27 11:59:48 +02:00
Alvise de Faveri 4eb50d0bb5 Add Unit Test for DLACollapseSingleChild 2021-06-30 17:50:12 +02:00
Alvise de Faveri c1e4b940d0 Add CollapseSingleChild step to DLA 2021-06-30 17:50:12 +02:00
Alvise de Faveri 47db3fdb11 Promote AccessSizes to full-fledged TS nodes
While doing thie, also drop `printAccessNode()` from DLA DebugPrinter.

The information about which LLVM instruction originated a given access
node is already available in the csv generated by the `dla-accesses-log`
logger.
2021-06-25 18:07:17 +02:00
Alvise de Faveri bfdef657f2 Move DLA files to separate folder 2021-06-18 18:24:04 +02:00