78 Commits

Author SHA1 Message Date
Antonio Frighetto 765219d58c Support for control-flow graph out of the model
The control-flow graph has been taken out of the model. Related changes
to `getCallSitePrototype` have been here addressed.
2022-04-06 16:25:05 +02:00
Pietro Fezzardi 0796e00d71 DLAMakeModelTypes: fix array fields 2022-03-28 09:51:01 +02:00
Alvise de Faveri ddf8adca70 DLA: drop ModelFuncHelpers and use shared ones 2022-03-22 10:55:16 +01:00
Pietro Fezzardi f69f68fe35 DLA: dump .dot for debug in dla::StepManager
Before this commit, each dla::Step handled the printing of its own .dot
files for debug.
This commit moves the logic for dumping the .dot files into the main
loop of dla::StepManager, guarding it with a single Logger.
2022-03-22 10:48:03 +01:00
Pietro Fezzardi 9f1bbc8b49 Drop deprecated \brief Doxygen directive
\brief is a stupid feature that we should stop using:
https://lists.llvm.org/pipermail/llvm-dev/2015-May/085152.html
2022-03-22 10:48:03 +01:00
Pietro Fezzardi 3678e4f730 DLA: completely remove Inheritance edges 2022-03-21 17:08:46 +01:00
Pietro Fezzardi c98794d9b0 Rework DLAMakeModelTypes to fix several bugs
Before this commit, DLAMakeModelTypes was generating broken types in
several corner cases involving unions with children at offset different
than zero, and strided accesses.

This commit fixes these issues and reworks the pass to also consider
strides and model::Qualifiers in the correct order.
2022-03-21 09:48:26 +01:00
Pietro Fezzardi c3cf053b58 DLAMakeLayouts: fix order of strides 2022-03-21 09:40:31 +01:00
Pietro Fezzardi ed4942a8b0 DLAMakeModelTypes.cpp: assert verifyPointerDAG 2022-03-18 16:49:28 +01:00
Pietro Fezzardi 901c6e76ca lib/DataLayoutAnalysis/Backend: drop public using 2022-03-18 12:38:25 +01:00
Pietro Fezzardi e2a82f8dfc Drop useless include DLAHelpers.h 2022-03-01 11:38:04 +01:00
Pietro Fezzardi 7132ffa3e3 DLA: improve handling of stack arguments
Before this commit the case where the DLA recovered narrower sizes for
stack arguments than what expected on the Model was not handled
properly.

Now the scenario is handled explicitly, in two ways
- if the DLA recovers a stack argument with struct type, the fields are
  copied to the model in the type representing the stack argument;
- if the DLA recovers a stack argument with a type T that is non-struct,
  then the type in the model representing that stack argument is a
  struct with a single field at offset 0 and type T.
2022-02-28 18:12:27 +01:00
Pietro Fezzardi 1f39ed42e6 Fix update of stack sizes on Model by DLA
Before this commit, if the DLA was detecting stack sizes that were
smaller than expected by the Model, the size of struct recovered by the
DLA was edited in-place, enlarging it an possibly leading to a
malformed Model.

This commit fixes the problem:
- the size of the stack struct recovered by DLA is not changed
- the fields of the stack struct recovered by DLA are copied inside
  inside the Model in the struct representing the stack
2022-02-28 18:12:06 +01:00
Pietro Fezzardi 5cdc63cda6 Apply new revng coding conventions 2022-02-28 18:02:25 +01:00
Filippo Cremonese b940af4692 Import recent changes to the model 2022-01-14 14:06:59 +01:00
Pietro Fezzardi 818156e06a DLA upgrades stack's and stack arguments' types 2022-01-04 16:21:07 +01:00
Alessandro Di Federico cdc05640b8 DLA: handle the extra argument for stack arguments 2021-12-17 14:01:05 +01:00
Pietro Fezzardi 39ec9a32ee DLAMakeLayouts: drop too strict assertion
This assertion was conceived to check that DLADeduplicateUnionFields was
doing its job, ensuring that we never created a union with only one
field.

However, the assertion is too strict, and there are situation that union
deduplication cannot handle and that still generate a union with one
single field. Here's an example

    Node A, with Interfering Children
       Instance Edge -> Node B
       Offset 12 Edge -> Node C

    Node C
       Offset 12 Edge -> Node D

    Node C: uint32_t

    Node D: uint32_t

Hence we need to remove the assertion.
2021-12-17 11:02:14 +01:00
Pietro Fezzardi 3a28bb0611 DLAMakeModelTypes: use isValid for TTR 2021-12-01 17:40:01 +01:00
Alvise de Faveri 5b8529edd5 DLA: Generate Model Types
Add `MakeModelTypes` and `UpdateFuncPrototypes` to the DLA backend:
* `MakeModelTypes` adds to the model all the types recovered by the DLA
* `UpdateFuncPrototypes` updates function prototypes in the model that
have generic return values or arguments to use the types recovered by
the DLA
2021-11-16 17:00:53 +01:00
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 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 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
Pietro Fezzardi ae0095e90a DLA: handle Values with unknown Layouts 2021-07-20 15:20:53 +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
Pietro Fezzardi d09c7c6ab3 Handle inheritance in with interfering children
Until now, in makeLayout, inheritance edges were ignored when the
children were interfering.
Now the inheritance edges are treated as if they were instance edges at
offset 0.
2021-06-24 17:24:59 +02:00
Pietro Fezzardi 18bff2dba1 DLAMakeLayouts.cpp: drop unused variable 2021-06-24 17:24:59 +02:00
Alvise de Faveri bfdef657f2 Move DLA files to separate folder 2021-06-18 18:24:04 +02:00