Commit Graph

255 Commits

Author SHA1 Message Date
Pietro Fezzardi f598df6113 DLA: fix moveEdgeTargetWithoutSumming
Before this commit, the method could partly fail in moving the edge
target even in legitimate scenarios, because of a bug in how it fixed up
the Successors link in the edge source.
This commit fixes the bug.
2024-01-26 16:49:52 +01:00
Pietro Fezzardi 9db3c53f1e Convert FIXMEs to TODOs 2024-01-26 16:45:20 +01:00
Massimo Fioravanti 86e45461a0 Introduce pipeline execution context 2024-01-02 11:05:50 +01:00
Alessandro Di Federico d5ad77d2d9 Adopt model::QualifiedType::stripPointer 2023-12-12 12:04:19 +01:00
Alessandro Di Federico d267c49a58 Minor changes 2023-12-12 12:04:13 +01:00
Pietro Fezzardi 7c1021ffc1 DLA: rearrange Middleend steps
Now CompactCompatibleArrays runs after ArrangeAccessesHierarchically.
Rearranging the accesses hierarchically first allows the following step,
that compacts compatible arrays, to achieve better results, and overall
recover much better looking arrays.
2023-12-05 16:59:08 +01:00
Pietro Fezzardi 7ea3b507df DLA: CompactCompatibleArrays on non-strided
This commit extends the CompactCompatibleArrays DLAStep to also consider
non-strided accesses.
Strided accesses are still always considered first, and they are still
considered the only real source of information on arrays, but after
having tried to compact all the compatible arrays,
CompactCompatibleArrays now also considers non-strided instance edges to
see if they can be compacted with the rest of the inferred array.
This has shown to handle gracefully a number of real-world examples and
reduce unions.
2023-12-05 16:59:08 +01:00
Pietro Fezzardi bf69d271cf DLA: replace some auto with uint64_t
Explicit is better than implicit.
2023-12-05 16:59:08 +01:00
Pietro Fezzardi aa1d6f5bc7 DLA: make CompactCompatibleArray commutative
Before this commit, the CompactCompatibleArray DLAStep had that caused
the compaction to be sensible to the order of the pairs of edges that
were compacted, and that also caused the compaction operation to overrun
the end of the containing struct in some corner cases.

This commit fixes both bugs.

Now the compaction routine is not ordering-sensitive anymore.
For each pair of edges <A, B> to compact it tries to compact them in 2
possible ways: by aligning A to B shifting A to lower offsets, and by
aligning B to A shifting B to lower offsets.
If both succeed, it picks the best result among the two, which doesn't
depend on the ordering of A and B.
This fixes the order-sensitiveness.

While reworking this logic, the logic was fixed so that if any of the
two compaction attempts causes to overrun the end of the containing
struct, the attempt is not considered successful anymore, and it's
discarded altogether.
2023-12-05 16:59:08 +01:00
Pietro Fezzardi 2268d84037 DLA: refactor offset-based stride computation 2023-12-05 16:59:08 +01:00
Pietro Fezzardi 24cb43ce9c Make RawFunctionType::StackArgumentsType a TTR
This is homogeneous with all other nullable references to types in the
model, such as the StackFrameType in model::Function, and others.
2023-12-05 16:56:52 +01:00
Pietro Fezzardi 842b5e1075 Make Segment::Type a TupleTreeReference
This is homogeneous with all other nullable references to types in the
model, such as the StackFrameType in model::Function, and others.
2023-12-05 16:56:52 +01:00
Pietro Fezzardi 2653a6ec6b DLA: don't link formal arguments with constant
The inter-procedural part of the DLA frontend connects actual arguments
of function calls with formal arguments of the callee functions, with
instance links at offset 0.
This represents the information that the type pointed-to by the actual
argument has an instance of the type pointed-to by the formal argument
at offset 0.

Before this commit, this was done even when the actual argument was an
integer constant leading to various problems:
1. Most of the times, small integer constants passed as actual
   cannot represent valid pointers, leading to graphs bigger than
   necessary.
2. Even when an integer constant might actually represent a pointer into
   valid memory, if it does it should fall into some segment.
   If it does, by the time DLA runs, those integer constants should have
   already converted into calls to the special SegmentRef opcode, which
   is already handled properly.
3. Finally, those constants end up being very connected in the DLA
   graph, creating connections between other nodes that are otherwise
   unrelated or very far from each other. This pollutes the graph and
   rapidly degrades the quality of the results.

This commit properly guards the code so that the instance-at-offset-0
link between actual and formal arguments is never injected if the actual
argument is an integer constant.
2023-11-22 10:16:06 +01:00
Pietro Fezzardi ebb2b6a45b DLA: enable Frontend to see through ZExt 2023-11-22 00:59:52 +01:00
Pietro Fezzardi 2bca392be3 Fix typo 2023-11-22 00:59:30 +01:00
Pietro Fezzardi 71b2e8e799 DLA: drop old Logger that was creating files 2023-11-22 00:59:08 +01:00
Pietro Fezzardi d8cc7091ee DLA: improve logging for StepManager 2023-11-20 22:35:06 +01:00
Pietro Fezzardi 5a0d11ec32 SimplifyInstanceAtOffset0.cpp: drop old comment 2023-11-20 22:34:46 +01:00
Alessandro Di Federico d19a7c0c5d DLA: handle scPtrToInt 2023-11-20 15:52:34 +01:00
Pietro Fezzardi 75aff6a4a9 DLA: always copy fields when updating Model
Before this commit, DLA's backend often emitted things like:

```c
struct x {
  struct y {
    int32_t z;
    uint8_t padding[4];
  } _offset_0;
  uint8_t padding[8];
};
```

This is suboptimal, since the fields of y actually can just be inlined
into x, giving:

```c
struct x {
  int32_t z;
  uint8_t padding[12];
};
```

This behaviour was due to a logic bug carried over from old versions of
the code, and partially extended, but never revisited nor thought
through.

This commit fixes the problem, making the second behaviour the only
thing DLA ever does when updating the model.
Basically, struct fields are copied over field by field, instead of
inserting the bulk struct (y in the example) inside the larger struct to
update (x in the example).
2023-10-18 15:19:52 +02:00
Alessandro Di Federico cb8aa3d929 Adopt .prototype()
Also adopt `QualifiedType::getFunctionType` where appropriate in order
to unwrap typedefs.
2023-10-05 19:18:38 +02:00
Alessandro Di Federico cae213b36b Minor changes 2023-10-05 18:45:17 +02:00
Pietro Fezzardi 07cf95159e DLA Frontend: fix handling of pointer-typed SCEVs
Before this commit the DLA frontend was not ready to handle all the
possible combinations of integer- and pointer-typed arithmetic that was
used to compute SCEVs.
This could cause crashes when dealing with pointer-typed SCEVs.
This commit fixes the issues by converting all pointer-typed expressions
to integers, and resizing integers to the same size before adding them.
2023-09-21 15:18:32 +02:00
Pietro Fezzardi ca2f26e40a DLA: don't dump .dot files with VerifyLog 2023-09-21 15:18:23 +02:00
Pietro Fezzardi 267e06c052 DLA: add caching to SimplifyInstanceAtOffset0
This commit adds caching for mutual reachability among children of a
node, in SimplifyInstanceAtOffset0.
This makes the DLAStep 10% to 50% faster on real-world benchmarks we
have measured, such as `updatedb.plocate` and `df` for Ubuntu 22.04
x86_64.
2023-09-20 16:36:48 +02:00
Pietro Fezzardi 990f8aab03 Drop unused set from DLATypeSystem.cpp 2023-09-20 16:36:34 +02:00
Pietro Fezzardi c04b96f72a DLA: RemoveBackedges.cpp uses EquivalenceClasses
llvm::EquivalenceClasses is an efficient data structure from LLVM, to
compute equivalence classes among objects with Tarjan's union-find.

This commit uses that to avoid an hand-crafted very inefficient
algorithm.
2023-09-07 12:19:35 +02:00
Pietro Fezzardi b8c48be350 Add progress bars to DLA 2023-09-07 12:19:35 +02:00
Alessandro Di Federico 489dddd0e7 TupleTreeReference::isValid is for assertions only 2023-08-23 16:37:39 +02:00
Pietro Fezzardi f3bec5673a DLA: emit NonScalar nodes as StructTypes 2023-08-21 16:18:31 +02:00
Pietro Fezzardi 6c78270b6f DLA: CollapseSingleChild preserves NonScalar nodes 2023-08-21 16:18:31 +02:00
Pietro Fezzardi c3b69be618 DLA: ArrangeAccessesHierarchically keeps NonScalar 2023-08-21 16:18:31 +02:00
Pietro Fezzardi 5c132e7956 DLA: CollapseSCC preserves NonScalar nodes 2023-08-21 16:17:36 +02:00
Pietro Fezzardi 4e32f05aba DLA: mergeNodes now uses ArrayRef argument
This allows for a greater flexibility in its users.
2023-08-21 16:17:36 +02:00
Pietro Fezzardi cac7fee07d LayoutTypeSystemNode: add NonScalar field
This field represents that fact that a node of the DLA Graph is not a
scalar and it comes from the Model.
2023-08-21 16:17:36 +02:00
Pietro Fezzardi 552b8a96d9 DLA: print number of collapsed nodes for each Node 2023-08-21 16:17:21 +02:00
Ivan Krysak 2987b5621b Model: update constuctors with an extra field 2023-07-21 04:58:50 +00:00
Pietro Fezzardi 10efe0f19d DLA: switch to revng's isCallToIsolatedFunction 2023-07-10 12:30:35 +02:00
Ivan Krysak b0dcc3d9ee Formatting: forbid clang format off 2023-07-05 14:33:06 +02:00
Ivan Krysak fe0531868c Use Container::contains() where appropriate 2023-07-05 06:07:09 +00:00
Ivan Krysak 888e5371eb Formatting: change PenaltyReturnTypeOnItsOwnLine
The new value is 21.
2023-07-05 06:06:07 +00:00
Ivan Krysak 3c584cfabc Formatting: set AllowShortEnumsOnASingleLine
The new value is `false`.
2023-07-05 06:05:04 +00:00
Pietro Fezzardi e2791443fb Remove extractvalue instructions in decompilation
Now extractvalue instruction are replaced by dedicated
OpaqueExtractValue custom opcode, that prevents LLVM from doing strange
things with extractvalues during optimizations (such as e.g. sinking).

This is important since extractvalue instructions and struct-typed
values in general in our LLVM IR are not real first-class citizens, but
only a byproduct of the binary lifting process, and they actually
represent bundles of registers that are returned from isolated
functions.
2023-06-30 10:48:59 +02:00
Giacomo Vercesi a4ad571e61 rcc: Fix typos
Fix the typos detected by `codespell`
2023-05-11 10:04:32 +02:00
Alessandro Di Federico a9eae1c96b Purge remaining traces of InsertValueInst
InsertValue has long been superseded by `struct_initialier`, so we don't
expect it in the IR we work on.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico ba05ddfaaf DLA: handle ConstantPointerNull 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 6610213da4 DLA: drop support for InsertValue
They shouldn't appear in the IR at this stage of the pipeline.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 03bbf22a48 DLA: improve handling of phis
DLA used to support phis in return values, but didn't handle phis
referring to other phis.
This commit fixes that.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 237aefcc9a DLA: drop LoopInfoWrapperPass
It was not being used.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 4c469e5180 Adopt getCallToTagged
`isCallToTagged` used to return a pointer in case of success.
We now have `getCallToTagged` for that.

Also, these functions have been moved to revng.
2023-04-14 14:54:14 +02:00