diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -527,7 +527,11 @@ uint64_t Threshold) const { if (TotalSamples <= Threshold) return; - S.insert(getGUID(Name)); + auto *F = M->getFunction(getFuncName()); + if (!F || !F->getSubprogram()) { + // Add to the import list only when it's defined out of module. + S.insert(getGUID(Name)); + } // Import hot CallTargets, which may not be available in IR because full // profile annotation cannot be done until backend compilation in ThinLTO. for (const auto &BS : BodySamples) diff --git a/llvm/test/Transforms/SampleProfile/function_metadata.ll b/llvm/test/Transforms/SampleProfile/function_metadata.ll --- a/llvm/test/Transforms/SampleProfile/function_metadata.ll +++ b/llvm/test/Transforms/SampleProfile/function_metadata.ll @@ -36,7 +36,7 @@ ; Check GUIDs for both foo and foo_available are included in the metadata to ; make sure the liveness analysis can capture the dependency from test_liveness ; to foo_available. -; CHECK: ![[ENTRY_TEST_LIVENESS]] = !{!"function_entry_count", i64 1, i64 4005816710939881937, i64 6699318081062747564} +; CHECK: ![[ENTRY_TEST_LIVENESS]] = !{!"function_entry_count", i64 1, i64 6699318081062747564} !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!8, !9}