From 47c1f2741fe7d24e02c3f54bcb723994292c54c3 Mon Sep 17 00:00:00 2001 From: Hongtao Yu Date: Mon, 11 May 2020 09:38:29 -0700 Subject: [PATCH] Properly add out-of-module functions to the import list This patch addresses two issues related to adding inline functions to the import list while recursively going through the profiling data. 1. For callsite samples, only add an inlined function to the import list if it's from outside of the module (i.e. only has a declaration inside the module). 2. For body samples, add each target function to the import list if it's from outside of the module (i.e. only has a declaration inside the module). Previously we were using getSubProgram() to check whether it has dbg info, which is inaccurate. This fix properly add imports and could improve the quality of the pass. Added a few changes to the test to catch these cases. Differential Revision: https://reviews.llvm.org/D79379 --- llvm/include/llvm/ProfileData/SampleProf.h | 10 ++++++++-- .../SampleProfile/Inputs/function_metadata.compact.afdo | Bin 295 -> 288 bytes .../SampleProfile/Inputs/function_metadata.prof | 3 ++- llvm/test/Transforms/SampleProfile/function_metadata.ll | 15 ++++++++++----- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h index b2975bf..af636a9 100644 --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -527,14 +527,20 @@ public: uint64_t Threshold) const { if (TotalSamples <= Threshold) return; - S.insert(getGUID(Name)); + auto isDeclaration = [](const Function *F) { + return !F || F->isDeclaration(); + }; + if (isDeclaration(M->getFunction(getFuncName()))) { + // 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) for (const auto &TS : BS.second.getCallTargets()) if (TS.getValue() > Threshold) { const Function *Callee = M->getFunction(getFuncName(TS.getKey())); - if (!Callee || !Callee->getSubprogram()) + if (isDeclaration(Callee)) S.insert(getGUID(TS.getKey())); } for (const auto &CS : CallsiteSamples) diff --git a/llvm/test/Transforms/SampleProfile/Inputs/function_metadata.compact.afdo b/llvm/test/Transforms/SampleProfile/Inputs/function_metadata.compact.afdo index 20bd89670777ed360bea415c608af8291ceb9406..c9de6e755c434a7ef66e6d0a41d38c0b89ea046f 100644 GIT binary patch literal 288 zcmezW^uoq3C#S3kPTyg0fuDhsNnnEC1%Ac_y=*}8z$_jh`Cz#akZjm0@q(RY!67*y zdEmSXkbH1Q3rIG+G60ExH(S8Q`r)tTK1Q|;+iX%eZv3&~;=I#r%f-2^1xV}%5nM@$ zMGQb3pIDZdnUk25lM3dgB&7rCDu%TDd=NGS5k?@wn4u)KxCBhZ=VX?p=A{-FGca&8 zNHQ@pq%bf6F*7p*%L{f!Mur7!42;YS3?~>FnHcslGBC0*FmnN!Tnr2>46I-kFW5nB jHYl5s9mMAZ5QxH!WLnV*blo1x5x4U~iCQVq^e18;F^i8JJ$MGcqzP zU}IopW?(qM$jHR7kCB0qg@KU^$mC*RU}0bet9Zc