Skip to content
Artem Usov edited this page Nov 24, 2020 · 1 revision

When to upgrade shared ptr to unique ptr

If ptr is passed through arguments: Ptr is is either not captured, or is captured exactly once and original reference is no longer used. If capture causes ptr to escape, then is not upgraded. Returning the ptr does not count as escape

If ptr is created inside method: Ptr is is either not captured, or is captured exactly once and original reference is no longer used. If capture causes ptr to escape, then is not upgraded. Returning the ptr counts as escape and disqualifies ptr from being unique due to unknown amounts of calling contexts it could be used it.

The algorithm

to be decided

Ideally, create an abstraction such that escape/capture information can be summarized for each function/method, and so can be cached. This means that the same computed information can be used in different calling contexts.

The usage

To follow LLVM design, we might want to design the tool such, that the LLVM IR handling and escape algorithm that uses it, can be packaged up as a library, to be potentially used by other LLVM frontends

The complexity

Start from intra-procedural, to module-level interprocedural, to perhaps analysis across modules, using llvm-link