|
Jlm
|
#include <LocalAliasAnalysis.hpp>


Classes | |
| struct | TraceCollection |
| struct | TracedPointerOrigin |
Public Member Functions | |
| LocalAliasAnalysis () | |
| ~LocalAliasAnalysis () noexcept override | |
| std::string | ToString () const override |
| AliasQueryResponse | Query (const rvsdg::Output &p1, size_t s1, const rvsdg::Output &p2, size_t s2) override |
Public Member Functions inherited from jlm::llvm::aa::AliasAnalysis | |
| AliasAnalysis () | |
| virtual | ~AliasAnalysis () noexcept |
Private Member Functions | |
| bool | IsOriginalOriginFullyTraceable (const rvsdg::Output &pointer) |
| bool | HasOnlyFullyTraceableTopOrigins (TraceCollection &traces) |
Static Private Member Functions | |
| static std::optional< int64_t > | CalculateGepOffset (const rvsdg::SimpleNode &gepNode) |
| static TracedPointerOrigin | TracePointerOriginPrecise (const rvsdg::Output &p) |
| static AliasQueryResponse | QueryOffsets (std::optional< int64_t > offset1, size_t s1, std::optional< int64_t > offset2, size_t s2) |
| static bool | TraceAllPointerOrigins (TracedPointerOrigin p, TraceCollection &traceCollection) |
| static bool | IsOriginalOrigin (const rvsdg::Output &pointer) |
| static bool | HasOnlyOriginalTopOrigins (TraceCollection &traces) |
| static std::optional< size_t > | GetOriginalOriginSize (const rvsdg::Output &pointer) |
| static std::optional< size_t > | GetRemainingSize (TracedPointerOrigin trace) |
| static void | RemoveTopOriginsWithRemainingSizeBelow (TraceCollection &traces, size_t s) |
| static size_t | GetMinimumOffsetFromStart (TraceCollection &traces) |
| static void | RemoveTopOriginsSmallerThanSize (TraceCollection &traces, size_t s) |
| static void | RemoveTopOriginsWithinTheFirstNBytes (TraceCollection &traces, size_t s, size_t N) |
| static bool | DoTraceCollectionsOverlap (TraceCollection &tc1, size_t s1, TraceCollection &tc2, size_t s2) |
Private Attributes | |
| std::unordered_map< const rvsdg::Output *, bool > | IsFullyTraceable_ |
Static Private Attributes | |
| static constexpr size_t | MaxTraceCollectionSize = 1000 |
Additional Inherited Members | |
Public Types inherited from jlm::llvm::aa::AliasAnalysis | |
| enum | AliasQueryResponse { NoAlias , MayAlias , MustAlias } |
Class for making alias analysis queries using stateless ad hoc IR traversal. It roughly corresponds to BasicAA from LLVM. It is unable to trace via memory or across function calls. It tries to keep track of pointer offsets when possible, and can respond NoAlias when the queried pointers are based on distinct offsets into the same base pointer. If the offsets are identical, MustAlias is returned.
Definition at line 25 of file LocalAliasAnalysis.hpp.
|
default |
|
overridedefaultnoexcept |
|
staticprivate |
Calculates the byte offset applied by the GEP, if the offset is static. The offset is the number of bytes needed to satisfy output ptr = input ptr + offset in bytes
| gepNode | the node representing the GetElementPtrOperation |
Definition at line 242 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Checks if any of the top origins in the two trace collections are the same, and have overlapping offsets. Only identical top origins are considered, so if two distinct top origins point to the same memory, that aliasing will not be detected by this method.
| tc1 | the collection of traces of p1 |
| s1 | the size of the operation performed at p1 |
| tc2 | the collection of traces of p2 |
| s2 | the size of the operation performed at p2 |
Definition at line 601 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Finds the minimum distance into some memory region the traced pointer is pointing. For example, if the trace collection only contains the trace p = b + 12 we know that any operation on p will not touch the first 12 bytes of whatever region b is in. The region must also be at least 12 + s bytes large.
| traces |
Definition at line 540 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Gets the size of the memory location(s) defined at the given output's operation. If the output is not an original origin, or the size is unknown, nullopt is returned.
| pointer | a pointer output, should be from a memory location defining operation |
Definition at line 466 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Given a traced pointer origin like p, where b = alloca[3 x i32] p = b + 8
we know that an operation starting at p can have a maximum size of 4 bytes. This function attempts to calculate this size, known as the pointer's remaining size.
If the offset is larger than the size of the target, the size 0 is returned. If the offset is unknown, the size of the target is returned.
| trace | the traced pointer |
Definition at line 499 of file LocalAliasAnalysis.cpp.
|
private |
Checks if the given trace collection only contains top origins that are fully traced.
| traces | the trace collection |
Definition at line 752 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Checks if all top origins in the trace collection are original.
| traces | the trace collection |
Definition at line 455 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Checks if the given pointer is the direct result of a memory location defining operation. These operations are guaranteed to output pointers that do not alias any pointer, except for those that are based on the original pointer itself. The pointer is also guaranteed to be at the very beginning of the memory region.
For example, the output of an AllocaOperation, a DeltaOperation, or a rvsdg::GraphImport, are such original origins.
| pointer | the pointer value to check |
Definition at line 429 of file LocalAliasAnalysis.cpp.
|
private |
Checks if the given pointer is the output of an original memory location, AND that the address of the memory location is never passed anywhere that is not traceable back to the original operation.
Only AllocaOperation is fully traceable, and only when the address can be traced to all uses, and all uses are loads and stores. If the address is passed to a function, or stored in a variable, the AllocaOperation is not fully traceable. For a fully traceable AllocaOperation, any use of its address can therefore be traced back to the AllocaOperation using the TraceAllPointerOrigins function
In summary: this function performs a simple, local, escape analysis for ALLOCAs. Its result is cached for performance.
| pointer | the pointer output to be analyzed |
Definition at line 622 of file LocalAliasAnalysis.cpp.
|
overridevirtual |
Queries the alias analysis about two memory regions represented as pointer + size pairs.
| p1 | the first pointer value |
| s1 | the byte size of the first pointer access |
| p2 | the second pointer value |
| s2 | the byte size of the second pointer access |
Implements jlm::llvm::aa::AliasAnalysis.
Definition at line 72 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Given two pointers with the same base pointer p1 = base + offset1 p2 = base + offset2 Answers if the regions [p1, p1 + s1) and [p2, p2 + s2) may alias. If p1 == p2, MustAlias is returned.
| offset1 | the offset of the first pointer. If it is nullopt, the offset is unknown. |
| s1 | the size of the first memory region |
| offset2 | the offset of the second pointer. If it is nullopt, the offset is unknown. |
| s2 | the size of the second memory region |
Definition at line 299 of file LocalAliasAnalysis.cpp.
|
staticprivate |
For each top origin in the given trace collection, it is removed if it is too small. This function considers the total size of the target, and ignores the offset.
| traces | the trace collection |
| s | the minimum size of remaining top origins |
Definition at line 567 of file LocalAliasAnalysis.cpp.
|
staticprivate |
When a top origin represents an original memory location, its offset indicates how far into the memory region the operation is accessing memory. If this access only touches memory within the first N bytes, remove the top origin.
| traces | the traces of some pointer p being accessed |
| s | the size of the memory access performed at the traced pointer |
| N | the number of bytes into its memory region an access must be to be kept. |
Definition at line 581 of file LocalAliasAnalysis.cpp.
|
staticprivate |
For each top origin in the given trace collection, it is removed if it is deemed too small. Let p be the traced pointer, and let the TraceCollection contain p = b + o, where b is an original origin with a statically known size of S bytes.
We know that the operation being performed at p has a length of s bytes. If o + s > S, the operation would exceed the bounds of b. The traced origin p = b + o can therefore be removed as an impossibility.
Further, if we have a trace p = c + unknown offset, where c is an original origin whose size is exactly equal to s, then we replace the unknown offset with a 0, as that is the only possible offset that leaves s bytes remaining in the trace.
| traces | the trace collection |
| s | the size of the operation being performed at the traced pointer |
Definition at line 516 of file LocalAliasAnalysis.cpp.
|
overridevirtual |
Implements jlm::llvm::aa::AliasAnalysis.
Definition at line 30 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Traces to find all possible origins of the given pointer. Traces through GetElementPtrOperation, including those with offsets that are not known at compile time. Also traces through gamma and theta nodes, building a set of multiple possibilities. Tracing stops at "top origins", for example an AllocaOperation, a LoadNonVolatileOperation, the return value of a CallOperation etc.
| p | the pointer to trace from |
| traceCollection | the collection of trace points being created |
Definition at line 326 of file LocalAliasAnalysis.cpp.
|
staticprivate |
Returns the result of tracing the origin of p as far as possible, without tracing through operations that add an unknown offsets, or add multiple possible origins. Since the pointer has exactly one possible origin with a statically known offset, it may be possible to give MustAlias responses. If not, more extensive tracing can be performed using TraceAllPointerOrigins.
| p | the pointer value to trace |
Definition at line 266 of file LocalAliasAnalysis.cpp.
|
private |
Memoization of "fully traceable" (escape analysis) queries. It assumes that no changes are made to the underlying RVSDG between queries.
Definition at line 250 of file LocalAliasAnalysis.hpp.
|
staticconstexprprivate |
Definition at line 28 of file LocalAliasAnalysis.hpp.