[PATCH] D157061: [SampleProfile] Potential use after move in SampleProfileLoader::promoteMergeNotInlinedContextSamples
William Junda Huang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 4 09:05:21 PDT 2023
huangjd added inline comments.
================
Comment at: llvm/lib/Transforms/IPO/SampleProfile.cpp:1632
+ } else
+ NewFunctionSamples.emplace_back(Callee, *FS);
}
----------------
davidxl wrote:
> is it enough to just use a flag to indicate insertion happens (instead of using a vector)? The getOrCreateSamples can set the flag.
The vector also stores a deep copy of the caller's FunctionSamples that's to be merged with newly created outlined function's FunctionSamples. Note that NonInlinedCallSites uses pointers to existing FunctionSamples, which will be invalidated if relocation happens, so we need a copy instead.
================
Comment at: llvm/lib/Transforms/IPO/SampleProfile.cpp:1648
+ // existing FunctionSamples, so we need to update any fields with them.
+ if (NewFunctionSamples.size() > 0) {
+ updateFunctionSamplesPointers(F);
----------------
davidxl wrote:
> insertion does not mean rehashing happens. Is there a better way to avoid the unncessary update?
C++ unordered_map or llvm::DenseMap does not provide an interface to check if data are relocated. There's ugly way to check it such as comparing the address to the first element. However, rehashing is likely to happen if insertion happens, because the profile reader reserves the exact number of FunctionSamples in the map. Meanwhile insertion itself is unlikely to happen as this function is called very few times in a large production project, so it wouldn't matter for performance.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157061/new/
https://reviews.llvm.org/D157061
More information about the llvm-commits
mailing list