[llvm-profdata] Handle internal linkage functions in profile supplementation
This patch has the following changes: (1) Handling of internal linkage functions (static functions) Static functions in FDO have a prefix of source file name, while they do not have one in SampleFDO. Current implementation does not handle this and we are not updating the profile for static functions. This patch fixes this. (2) Handling of -funique-internal-linakge-symbols Again this is for the internal linkage functions. Option -funique-internal-linakge-symbols can now be applied to both FDO and SampleFDO compilation. When it is used, it demangles internal linkage function names and adds a hash value as the postfix. When both SampleFDO and FDO profiles use this option, or both not use this option, changes in (1) should handle this. Here we also handle when the SampleFDO profile using this option while FDO profile not using this option, or vice versa. There is one case where this patch won't work: If one of the profiles used mangled name and the other does not. For example, if the SampleFDO profile uses clang c-compiler and without -funique-internal-linakge-symbols, while the FDO profile uses -funique-internal-linakge-symbols. The SampleFDO profile contains unmangled names while the FDO profile contains mangled names. If both profiles use c++ compiler, this won't happen. We think this use case is rare and does not justify the effort to fix. Differential Revision: https://reviews.llvm.org/D132600
This commit is contained in:
@@ -60,12 +60,12 @@
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/ProfileSummary.h"
|
||||
#include "llvm/ProfileData/InstrProfReader.h"
|
||||
#include "llvm/ProfileData/SampleProf.h"
|
||||
#include "llvm/Support/CRC.h"
|
||||
#include "llvm/Support/CodeGen.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/MD5.h"
|
||||
#include "llvm/Support/TimeProfiler.h"
|
||||
#include "llvm/Support/X86TargetParser.h"
|
||||
#include "llvm/Support/xxhash.h"
|
||||
@@ -208,22 +208,7 @@ CodeGenModule::CodeGenModule(ASTContext &C,
|
||||
Path = Entry.second + Path.substr(Entry.first.size());
|
||||
break;
|
||||
}
|
||||
llvm::MD5 Md5;
|
||||
Md5.update(Path);
|
||||
llvm::MD5::MD5Result R;
|
||||
Md5.final(R);
|
||||
SmallString<32> Str;
|
||||
llvm::MD5::stringifyResult(R, Str);
|
||||
// Convert MD5hash to Decimal. Demangler suffixes can either contain
|
||||
// numbers or characters but not both.
|
||||
llvm::APInt IntHash(128, Str.str(), 16);
|
||||
// Prepend "__uniq" before the hash for tools like profilers to understand
|
||||
// that this symbol is of internal linkage type. The "__uniq" is the
|
||||
// pre-determined prefix that is used to tell tools that this symbol was
|
||||
// created with -funique-internal-linakge-symbols and the tools can strip or
|
||||
// keep the prefix as needed.
|
||||
ModuleNameHash = (Twine(".__uniq.") +
|
||||
Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str();
|
||||
ModuleNameHash = llvm::getUniqueInternalLinkagePostfix(Path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user