266 Commits

Author SHA1 Message Date
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
Alessandro Di Federico f86ca062b4 DLA: handle scSequentialUMinExpr 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 340f64e150 Drop usages of PointerType::getElementType 2023-04-14 14:54:14 +02:00
Alessandro Di Federico b9dcb977bd Adopt CallBase::arg_size 2023-04-14 14:54:14 +02:00
Alessandro Di Federico dd383076ab Drop arg_operands in favor of args 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ab089a6d3a Adopt clang-format 16 2023-04-14 14:54:14 +02:00
Kacper Kołodziej 9decc1fe51 DLA Frontend: Create nodes for StringLiterals
For segmentRef type of the segment and type returned by segmentRef
function are the same.

For cstringLiteral every call returns pointer to 1-byte type. Pointer is
offsetted by value of strlen+1. strlen is fetched from metadata.

Additionally, all uses of cstringLiteral function has same type as the
type of cstringLiteral (pointer to 1-byte).
2023-04-04 09:31:10 +02:00
Ivan Krysak d08c9387d2 DLA: stop updating aggregate return value types 2023-03-15 10:28:24 +01:00
Pietro Fezzardi 4e1fb3a854 DLA: fix CompactCompatibleArrays
Before this commit, the dla::Step CompactCompatibleArrays was
occasionally generating artificial nodes that were larger than the inner
data, forcing their size to Stride - AvailableSlack.
This commit fixes the problem keeping track of the actual size that is
consumed in the array element, and forcing the size of the artificial
nodes to that.
2023-01-24 16:50:42 +01:00
Pietro Fezzardi 3fe74cdb0d DLA: single-step ArrangeAccessesHierarchically
The dla::Step ArrangeAccessesHierarchically looks throught the DLA graph
and for each node with many outgoing instance edges tries to see if some
of them are hierachically contained within each other.

In order to do this, before this commit, we were building an auxiliary
graph representing this hierarchy, and in order to build it we had to
perform a number of comparisons between edges that was quadratic with
the number of edges.
Moreover, once all the comparisons were done, we had a deep graph
representing inclusion between edges, but we only cared about the
top-level of this graph, i.e. only the edges that contained other edges
hierarchically, but were not contained in other edges (we'll call them
the root edges).
So we were doing a quadratic number of comparisons but possibly many of
them were useless.
Finally, all the edges that were included in root edges, were pushed
down, but only for a single layer, because they needed to be re-compared
later with the children of the root edges they were being pushed
through. This latter part was responsible for a lot of wasted
computation that just needed to be done over and over at all the layers.
Overall this algorithm was doing a lot of wasted computation.

This commit replaces this logic with a new algorithm.
Now we keep track only of the root edges, and we compare only root edges
with other root edges.
Initially all edges are root edges.
Then we start comparing them.
If a root edge A is included in another one B, then A is not a root edge
anymore, and all the edges that were previously found to be included in
A are not included in B.
This algorithm still does a worst case of quadratic number of
comparisons, but drastically reduces the amount of useless computation
that is redone later. In particular:
- in cases where there are a lot of root edges (meaning that only a few,
  or no edge can be included in others) we do a number of comparison
  close to quadratic, but we're only pushing non-root edges down, so
  we'll never have to redo comparisons in deeper layers
- in cases where there is only a small number of root edges, we're doing
  a number of comparisons close to linear, and we never compare non-root
  edges with each other, so we're saving a lot of computation that would
  be wasted (because it would need to be redone in deeper layers).
2023-01-20 00:45:09 +01:00
Pietro Fezzardi 682cf2067c DLA: ArrangeAccessHierarchically uses RPOT
Before this commit we were manually building a topological ordering,
that resulted in worse overall performance in some scenarios.

This commit changes the dla::Step to temporarily introduce a fake root
node, and computes a RPOT from there, which overall yields better
results.
2023-01-19 14:51:35 +01:00
Massimo Fioravanti 87aef3fbad revng-c now uses Model accessors 2022-12-12 11:35:52 +01:00
Pietro Fezzardi a72f24ef5a DLAUpdateModelTypes.cpp: fix update of stack frame 2022-12-05 17:03:21 +01:00
Pietro Fezzardi d3f2584158 DLA: fully support update of CABIFunctionTypes 2022-11-30 18:16:13 +01:00
Pietro Fezzardi f7f5e5fd28 DLA: fix CompactCompatibleArrays 2022-11-30 11:37:00 +01:00
Pietro Fezzardi 1b05ff38be DLAPass: verify model after updating it 2022-11-30 11:37:00 +01:00
Pietro Fezzardi 1af6c75fc5 DLAUpdateModelTypes.cpp: new assertions & comments 2022-11-30 11:37:00 +01:00
Massimo Fioravanti 335d402245 Change signatures to forward metadata cache. 2022-11-22 12:27:02 +01:00
Pietro Fezzardi 70a6185ce8 DLA/Frontend: don't skip calls with 0 uses
Before this commit we were not adding nodes to DLATypeSystem for calls
with 0 uses.

This commit fixes the problem, and only avoids adding nodes for calls
that return void.
2022-11-09 16:23:34 +01:00
Pietro Fezzardi 9440aa434d DLA: pointer edges only for pointer-sized nodes
Before this commit, the creation of intra-procedural types and edges
was too liberal, possibly leading to creation of pointer edges starting
from nodes that were not pointer-sized.

This commit fixes the issue, never creating outgoing pointer edges from
non-pointer-sized nodes.
2022-11-08 11:47:50 +01:00
Antonio Frighetto 9aa9007f18 DLA/Backend: do not add new overlapping fields
Make sure we do not introduce new fields that overlap the
original ones, should they exist.
2022-11-03 14:47:47 +01:00
Pietro Fezzardi 994280ba34 DLA: fix slack in CompactCompatibleArrays
Before this commit, a logic mistake made the AvailableSlack too large
for arrays that started near the beginning of their parent.
This in turn allowed a compacted array to "underflow" on lower addresses
w.r.t. the parent.

This commit fixes the problem by properly computing the AvailableSlack,
restraining it in cases where the array under analysis is close to the
beginning of the parent.
2022-11-03 13:23:59 +01:00
Pietro Fezzardi 2c228a52d5 DLA: avoid copies in SimplifyInstanceAtOffset0
This commits starts using llvm::df_iterator explicitly, and to use its
skipChildren method to prevent unnecessary copies and speed up the
algorithm.
2022-11-02 08:14:59 +01:00
Pietro Fezzardi bf83f40e3b Move SCEVBaseAddressExplorer.h from public headers 2022-10-21 10:00:23 +02:00
Pietro Fezzardi 8d7568710a DLA: add PushDownPointers dla::Step 2022-09-30 18:34:10 +02:00
Pietro Fezzardi fbc9844499 DLA: add ResolveLeafUnions dla::Step 2022-09-29 18:38:11 +02:00
Pietro Fezzardi 8e75677307 ArrangeAccessesHierarchically: push down pointers
This commit enables ArrangeAccessesHierachically to push down pointer
edges when rearranging accesses hierarchically.

In particular, if an edge N is being pushed down another edge M, and M
is at offset 0, and N reaches a pointer edge PE that points to a
grandparent G of M at offset 0, then we want to push down the pointer
edge PE so that it points to the target of M, unless there is another
edge M' different from M, such that M' has the same properties of M but
target(M) != target(M').
2022-09-29 18:38:11 +02:00
Pietro Fezzardi b4e57e2799 DLA: ArrangeAccessesHierarchically uses mergeNodes
Before this commit, ArrangeAccesseHierachically was removing nodes from
the graph, instead of merging them.
This degraded the information collected on the graph useful for debug.
This commit drops the use of removeNode method, and switches to using
mergeNodes, that preserves the useful debug information when merging.
2022-09-29 18:38:11 +02:00
Pietro Fezzardi cdd6e57a27 DLA: DLATypeSystem::dropOutgoingEdges
This method removes all the outgoing edges starting from a given
LayoutTypeSystemNode.
2022-09-29 18:38:11 +02:00
Pietro Fezzardi 84d427d240 DLAMakeModelTypes: emit Generic instead of Number 2022-09-29 18:38:11 +02:00
Pietro Fezzardi 1ccf0bd5df DLA: simplify constructor of DeduplicateFields 2022-09-29 18:38:11 +02:00
Pietro Fezzardi ac29a77a70 DLAPass: improve pipeline
This commit introduces an additional run of CollapseSingleChild and
DeduplicateFields before CompactCompatibleArrays and
ArrangeAccessesHierarchically.

This is meant to cleanup the graph so that the two latter steps can be
more effective.
2022-09-29 18:38:11 +02:00
Pietro Fezzardi 0298db677d DLA: add CompactCompatibleArrays dla::Step 2022-09-29 18:38:11 +02:00
Pietro Fezzardi 07dc677196 dla::CollapseSingleChild: remove invalidation
The invalidation was overly strict and not necessary.
2022-09-29 18:38:11 +02:00
Pietro Fezzardi 1bc708fadc Drop postProcessMerge from dla::DeduplicateFields
Before this commit postProcessMerge was making some strong assumptions
about dla::CollapseSingleChild::collapseSingle that no longer hold.

Namely the (now) wrong assumption is that collapseSingle would not break
post_order iteration, which is now false because collapseSingle can
change the incoming edges of the node it's called on, and those incoming
edges are on the visit stack of the post_order iteration itself.

This required making a copy of the post order, and resulted in dropping
the postProcessMerge function alltogether.
2022-09-29 18:38:11 +02:00
Pietro Fezzardi c5236310a9 Use uint64_t only in dla::OffsetExpression
Before this commit we were using int64_t for Offset, Strides, and
TripCounts.

Originally, this choice was intended because for some time we envisioned
actually having a use for negative values, but in the end we decided
there's no use for those.

This commit switches all to unsigned integers, allowing to remove some
static_cast across the codebase, and overall easing typicall computation
we have to perform on those fields.
2022-09-29 18:38:11 +02:00
Pietro Fezzardi e47733eb66 DLA: new Middleend pipeline 2022-09-15 11:47:11 +02:00
Pietro Fezzardi f0a1903201 DLA: add ArrangeAccessesHierarchically dla::Step 2022-09-15 11:47:11 +02:00
Pietro Fezzardi 8ff8a795e4 DLA: Add DecomposeStridedEdges dla::Step 2022-09-14 11:33:37 +02:00
Pietro Fezzardi 47c06350ca FieldSizeComputation: add #include <cstdint> 2022-09-12 17:52:53 +02:00