113 Commits

Author SHA1 Message Date
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 1ccf0bd5df DLA: simplify constructor of DeduplicateFields 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 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 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
Pietro Fezzardi 8b812680ea DLACollapsSingleChild: push padding to parent 2022-06-14 12:51:48 +02:00
Pietro Fezzardi af760942e7 DLATypeSystem: add API to move edge target 2022-06-14 12:51:48 +02:00
Pietro Fezzardi 6f41e625e7 DeduplicateUnionFields is now DeduplicateFields
Before this commit, the dla::Step depended on InterferingInfo, but this
was superfluous.

This commit drops the dependency and enables the Step to run before
ComputeNonInterferingComponents.

This also avoids the need to run ComputeNonInterferingComponents twice
(one before and one after DeduplicateUnionFields), so it can only run
once.
2022-06-08 14:16:51 +02:00
Pietro Fezzardi 3e53eced5d CollapseSingleChild: ignore InterferingInfo
Before this commit, CollapseSingleChild Step was thinkering around
with InterferingInfo.

Now CollapseSingleChild does not care about InterferingInfo anymore, so
the code handling it can just be dropped.
2022-06-08 14:13:01 +02:00
Pietro Fezzardi 5a37fe8a84 DLA: add MergePointerNodes Step
This Step merges nodes with outgoing pointer-edges pointing to the same
pointee node.
2022-06-08 10:22:35 +02:00
Pietro Fezzardi ba50eb4a55 DLA: revive and rework CollapseSingleChild Step
The step now collapse parents with their single child if they are
indistinguishable, i.e. if the parent has only that single child, at
offset zero, and their size is the same.
2022-06-08 10:21:44 +02:00
Pietro Fezzardi be999ebda8 DLAComputeNonInterferingComponents: drop assert 2022-06-08 10:21:01 +02:00
Pietro Fezzardi 5c9ae203e6 DLA: fix deps for ComputeUpperMemberAccesses 2022-06-08 10:20:13 +02:00
Pietro Fezzardi 546175cc75 Fix typo in comment 2022-06-08 10:18:40 +02:00
Pietro Fezzardi 2651b8765b DLA: drop CollapseCompatibleArrays
This pass was never implemented and we don't have plans to do it soon.
This commit just drops it to reduce the noise.
Whenever we decide to implement something similar we'll do it from
scratch.
2022-05-27 17:06:49 +02:00
Pietro Fezzardi 31419a5fd1 Remove old unused dla::Layout class
This class was introduced before having model::Type, to represent
roughly the same information.

Now it's dead code and this commit removes it.
2022-05-26 16:46:47 +02:00
Giacomo Vercesi ab125b35b0 Fix License headers
Change company name to "rev.ng Labs Srl" in all license headers
to reflect changed company name and legal status
Add missing license headers to files that didn't have one
2022-04-19 12:17:59 +02:00
Pietro Fezzardi 593cc584cb DLA: propagate type info between loads and stores 2022-04-13 12:41:17 +02: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 ed5f4ac3e9 RemoveInvalidStrideEdges: handle 0-sized nodes
Before this commit, the dla::Step RemoveInvalidStrideEdges was not
taking into account that dropping edges could change the size of the
node where the edges originated from.

This commit fixes the problem, a) recomputing the size automatically
when needed, and b) adding proper dependencies in the dla middleend
pipeline, so that these changes are properly propagated updwards and
don't break any pre-conditions of following dla::Steps.
2022-03-21 17:15:27 +01:00
Pietro Fezzardi 3678e4f730 DLA: completely remove Inheritance edges 2022-03-21 17:08:46 +01:00
Pietro Fezzardi 7192cedcbb DLA: turn off Inheritance edges 2022-03-21 17:08:46 +01:00
Pietro Fezzardi 7971f0a20d Add dla::Step SimplifyInstanceAtOffset0
This step removes redundant instance-at-offset-0, collapsing the child
into the parent, whenever this operation does not induce instance-loops
on the graph.

This is intended to reduce the number of shallow wrapper structs and
unions.
2022-03-21 11:25:55 +01:00
Pietro Fezzardi 8c4784d076 DLA: split collapsing of SCC into many DLASteps
Before this commit there was a single pass removing equality SCC and
inheritance SCC.
This commit splits the removal of each kind of SCC in a separate
DLAStep, and adds handling of instance-at-offset-0 SCCs that were not
considered before.
2022-03-21 11:19:18 +01:00
Pietro Fezzardi 651ebe4cb6 Add LayoutTypeSystem::verifyInstanceAtOffset0DAG()
This new verification method is propedeutic to switching off Inheritance
nodes entirely.
2022-03-21 11:19:18 +01:00
Pietro Fezzardi d6ae6fd650 Add dla::Step RemoveInvalidStrideEdges 2022-03-21 09:43:10 +01:00
Pietro Fezzardi 0f00d29464 DLA: assert stride nesting in FieldSizeComputation 2022-03-21 09:38:25 +01:00
Pietro Fezzardi ff0a1b8eab DLADeduplicateUnionFields.cpp: fix linkOrderLess
The linkOrderLess comparison function is used for sorting the children
edges of a node.

Before this commit, it could not handle the case of comparing an edge
with itself, yielding wrong results (or assertion failure if assertions
were compiled in).

This commit fixes linkOrderLess to handle that case without asserting,
and adds an early return for it, without requiring to inspect the edges
in depth.
2022-03-10 18:00:05 +01:00
Pietro Fezzardi a8da5e14ec DLA: enable union dedup w/o CollapseSingleChild
DeduplicateUnionFields does not depend on CollapseSingleChild, but can
break if CollapseSingleChild has not run.
However, we don't want to introduce an explicit dependency between the
two steps, because CollapseSingleChild could soon become obsolete on
its own, superseeded by a more powerful and costly step.

This commit changes DeduplicateUnionFields with an additional
pre-processing that runs CollapseSingleChild on each node at step one,
to ensure the step does not fail if CollapseSingleChild child is not
executed.
2022-03-10 12:21:01 +01:00
Pietro Fezzardi 8e3b1c0080 DLACollapseSingleChild: preserve InterferingInfo 2022-03-08 17:21:08 +01:00
Pietro Fezzardi 9a6a0369e7 DLADeduplicateUnionFields.cpp: fix log 2022-03-08 17:20:32 +01:00
Pietro Fezzardi cb51965f6e DLAComputeNonInterferingComponents: fix moveEdges
This DLAStep was moving edges improperly before this commit.
In particular, edges were detected solely looking at source and target
edge, not looking at the edge itself. This was leading to wrong results
whenever a node N1 had many outgoing edges to a child node N2, at
different offsets, where all the edges were moved instead of just the
correct ones.

In order to fix this, this commit:
- reworks the logic of `moveEdges`, switching to iterator-based logic
- reworks the struct OrderedChild used internally by
  DLAComputeNonInterferingComponents, so that it is also iterator-based
- re-uses common code for field size computation
2022-03-01 12:52:58 +01:00
Pietro Fezzardi 3a94aab82a DLA: extract field size computation logic
This commit moves the logic for the computation of field sizes to a
separate .cpp file.
At the moment this is only used by DLAComputeUpperMemberAccess, but in
the future it will also be re-used DLAComputeNonInterferingComponents,
which at the moment employs very similar code.
2022-03-01 12:52:58 +01:00
Pietro Fezzardi 60f9141a07 DLA: move DLAHelpers.{cpp,h} to Middleend 2022-03-01 12:18:23 +01:00
Pietro Fezzardi b0d3ab2b84 DLACollapseSingleChild: relax assertion on node collapse 2022-03-01 11:38:04 +01:00
Pietro Fezzardi e2a82f8dfc Drop useless include DLAHelpers.h 2022-03-01 11:38:04 +01:00
Pietro Fezzardi b6520330fb DLADeduplicateUnionFields: fix use-after-poison
This commit fixes a use-after-poison bug.

DLADeduplicateUnionFields::runOnTypeSystem iterates over the DLA graph
while mutating it.
Due to iterations on copies of the edges, there were some edges to dead
nodes that were still hanging around and could be accessed.

This commit fixes the problem by not saving copies of the edges, but
saving LayoutTypeSystemNode * and iterating lazily on the edges starting
from the node itself every time.
In this way, if the graph is mutated, we never have outdated edges
pointing to dead nodes, and we don't have use-after-poison.
2022-02-28 18:11:49 +01:00
Pietro Fezzardi a58d960440 DLA: avoid late insertion of Inheritance edges
Inheritance edges have a specific semantic that must derive directly
from the binary, and are often treated specially by DLA steps.
For this reason is not correct to inject them late in the pipeline.
2022-02-28 18:10:57 +01:00
Pietro Fezzardi bd99db4711 DLADeduplicateUnionFields: fix use-after-free
This DLA Step works iterating in post-order on a graph while mutating
it. The post-order traversal is done with llvm::post_order, which holds
an iterator to the next children to visit.
Before this commit, the mutation of the graph could invalidate this
iterator.
This commit fixes the iteration logic, by computing the post-order ahead
of time, without holding around iterators that could be invalidated.
This is possible thanks to the fact that the mutation applied by the
DLADeduplicateUnionFields step on the graph do not change the post-order
visit, so the order computed beforehand remains valid throughout all the
computation despite the mutations that could take place.
2022-02-28 18:10:20 +01:00
Pietro Fezzardi 078c56bbb1 DLAComputeUpperMemberAccess: improve debug logging 2022-02-28 18:06:28 +01:00
Pietro Fezzardi 5cdc63cda6 Apply new revng coding conventions 2022-02-28 18:02:25 +01:00