This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profdata] Use string ref for FunctionSamplesMap
AbandonedPublic

Authored by huangjd on May 10 2023, 5:33 PM.

Details

Summary

Use string ref instead of std::string for the key type of FunctionSamplesMap.

In all usages of FunctionSamplesMap, the key type (function name) always comes from existing StringRef (which is backed by memory somewhere else) or from a string which is a part of the sample profile. There is no need store a copy of the function name here,

Diff Detail

Event Timeline

huangjd created this revision.May 10 2023, 5:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 5:33 PM
huangjd requested review of this revision.May 10 2023, 5:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 5:33 PM

is there way to make sure the lifetime of underlying strings out lasts the SampleMap?

For testing purpose, run the reader (via compiler and llvm-profdata) built with address sanitizer will help.

For testing purpose, run the reader (via compiler and llvm-profdata) built with address sanitizer will help.

How do you build it with address sanitizer? Is this a LLVM component?

see https://llvm.org/docs/CMake.html about LLVM_USE_SANTIZER:STRING which passes -fsanitize= .. option. Here STRING should be Address.

hoy added a comment.May 11 2023, 3:38 PM

is there way to make sure the lifetime of underlying strings out lasts the SampleMap?

It should be ok, as the compiler and llvm-profdata both keep the underlying sample reader alive to the last minute. llvm-profgen should be fine too.

Wondering if Google's create-profile tool ever uses this DS.

wenlei added inline comments.May 11 2023, 3:38 PM
llvm/lib/ProfileData/SampleProf.cpp
517

This is now creating a StringRef out of a temp string OrigChildContext.getName().str().

hoy added inline comments.May 11 2023, 3:44 PM
llvm/lib/ProfileData/SampleProf.cpp
517

Good catch! Should just use OrigChildContext.getName().

wenlei added inline comments.May 11 2023, 3:45 PM
llvm/lib/ProfileData/SampleProf.cpp
517

This is why it'd be safer to run through asan for this kind of change.

huangjd updated this revision to Diff 521503.May 11 2023, 5:02 PM

Updated a few missed std::string -> StringRef

huangjd marked 3 inline comments as done.May 11 2023, 5:03 PM

What is the highest level of undefined behavior check that can be reasonably specified? I rebuilt the project with -DLLVM_USE_SANITIZER=Address and confirmed there is no new failed tests, and searched through all usage of FunctionSampleMap

davidxl accepted this revision.May 12 2023, 9:58 AM

lgtm.

This revision is now accepted and ready to land.May 12 2023, 9:58 AM
wenlei accepted this revision.May 12 2023, 10:04 AM
huangjd abandoned this revision.Sep 14 2023, 2:54 PM