Commit Graph

255 Commits

Author SHA1 Message Date
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
Pietro Fezzardi 695c1529db dla::LayoutTypeSystem add eraseEdge method 2022-09-12 17:52:50 +02:00
Pietro Fezzardi 38e4658762 Add LayoutTypeSystem::NeighborIterator type 2022-09-12 12:28:48 +02:00
Pietro Fezzardi f83e513eb7 DLA: fix bug in DeduplicateFields
A logic bug caused the wrong detection of nodes with many fields.
As a result, the field deduplication was only executed on a subset of
the real candidates.
This caused the following two problems.
- Degradation of the quality of the results, i.e. unions that could be
  deduplicated were not deduplicated.
- Failing assertions in rare cases.
  The algorithm assumes that if it's looking at the children
  (C1, ..., Cn) of node A to be deduplicated, then all (C1, ..., Cn)
  have beed already visited, hence they don't have children that should
  be duplicated because they would have been deduplicated already, when
  looking at (C1, ..., Cn). The bug possibly caused to miss the
  deduplication of children of Ci (for some i) causing assertions to
  fail when looking at A to deduplicate (C1, ..., Cn).
2022-09-12 12:14:52 +02:00
Massimo Fioravanti 370b081c0e Moved kinds to kinds namespace 2022-08-25 17:09:15 +02:00
Pietro Fezzardi a60fa30d5b DLA/Frontend: handle indirect calls prototypes 2022-08-09 08:02:10 +02:00
Pietro Fezzardi c1641afeb6 Add LayoutTypeSystem::createArtificialLayoutTypes
This helper allows creating many artifical types at once.
2022-08-09 08:02:10 +02:00
Alessandro Di Federico 662cbfda84 Minor changes 2022-08-08 16:22:14 +02:00
Antonio Frighetto e06f9841ed DLA/Frontend: support Segment.Type struct already filled
Avert DLA's middle-end from performing optimizations by
making new segment nodes point placeholder nodes.
2022-07-29 11:05:22 +02:00
Antonio Frighetto a7ddddce92 DLA: recover model::Segment type
DLA now handles `segmentRef` opaque function calls.
2022-07-19 13:51:06 +02:00
Alvise de Faveri 221b8f74d9 Add reference semantics to stack opcodes
`revng_stack_frame` and `revng_stack_args` are treated as returning
a reference, and are always followed by an `AddressOf` call.
2022-06-28 10:23:45 +02:00
Pietro Fezzardi 8b812680ea DLACollapsSingleChild: push padding to parent 2022-06-14 12:51:48 +02:00