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.
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).
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.
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).
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.
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.
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.
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.
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').
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.
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.
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.
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.