Skip to content

[memory-ownership] Enable on-demand memory analyzers - #160

Open
keremsahn wants to merge 2 commits into
compiler-research:mainfrom
keremsahn:on-demand-analyzer
Open

keremsahn wants to merge 2 commits into
compiler-research:mainfrom
keremsahn:on-demand-analyzer

Conversation

@keremsahn

Copy link
Copy Markdown
Contributor

Built upon #158, just third commit is relevant

cppjit now reads a function body when no ownership attribute answers for that function. The analyzer only guesses, so it stays off by default and cppjit.use_memory_analyzer(True) turns it on.

  • Wrap Cpp::GetAllocType and Cpp::GetDeallocType as interop::GetAllocType and interop::GetDeallocType.
  • Add the UseMemoryAnalyzer entry point and the cppjit.use_memory_analyzer() wrapper. One flag drives both analyzers, and it is off by default.
  • Ask the allocation analyzer in GetAllocBehaviour when the attribute checker reports Unknown.
  • Merge the two deallocation answers per parameter in FillDeallocBehaviour. An attribute wins, and the analyzer answer moves by one slot for a method

@Vipul-Cariappa

ll_dealloc freed fBuf, the address of the pointer slot, so every owning view
leaked its buffer. It now frees get_buf(), and the new kIsNew flag, exposed as
__is_new__, separates new, new[] and malloc. HandleReturn takes ownership of a
returned view and writes the allocation kind. The release loop clears the
ownership of a view argument that the callee frees.
The attribute checkers give no answer for a function that carries no
ownership attribute. In that case cppjit can read the function body
instead. The analyzer only guesses, so it stays off until
use_memory_analyzer(True) turns it on. An attribute always wins over the
analyzer, per parameter on the deallocation side.
@keremsahn

Copy link
Copy Markdown
Contributor Author
@@                Benchmark Diff (geomean)                @@
  ##                                main   analyzer     +/- ##
  ============================================================
    first/callback                616.4 M    617.6 M    +0.20%
    first/class                   9.581 M    9.597 M    +0.16%
    first/overload                9.606 M    9.615 M    +0.10%
    first/primitive               8.745 M     8.75 M    +0.06%
    first/string                  10.08 M    10.08 M    +0.01%
    first/template                11.26 M    11.28 M    +0.14%
    first/template_overload       13.93 M    13.95 M    +0.15%
    hot/callback                  8.516 k    8.627 k    +1.30%
    hot/class                     3.129 k    3.207 k    +2.48%
    hot/overload                  2.909 k    3.017 k    +3.73%
    hot/primitive                 2.289 k    2.334 k    +1.98%
    hot/string                    8.891 k    8.903 k    +0.13%
    hot/template                  4.565 k    4.635 k    +1.54%
    hot/template_overload          3.01 k    3.092 k    +2.73%
  ============================================================
  - Slower                                                   3
  + Faster                                                   0
    Unchanged                                              219

Benchmarks against main, for all tests analyzers are enabled.
@Vipul-Cariappa

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant