Clean up external users of GlobalValue::getGUID(StringRef) (#129644)

See https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801
for context.

This is a non-functional change which just changes the interface of
GlobalValue, in preparation for future functional changes. This part
touches a fair few users, so is split out for ease of review. Future
changes to the GlobalValue implementation can then be focused purely on
that class.

This does the following:

* Rename GlobalValue::getGUID(StringRef) to
  getGUIDAssumingExternalLinkage. This is simply making explicit at the
  callsite what is currently implicit.
* Where possible, migrate users to directly calling getGUID on a
  GlobalValue instance.
* Otherwise, where possible, have them call the newly renamed
  getGUIDAssumingExternalLinkage, to make the assumption explicit.


There are a few cases where neither of the above are possible, as the
caller saves and reconstructs the necessary information to compute the
GUID themselves. We want to migrate these callers eventually, but for
this first step we leave them be.
This commit is contained in:
Owen Rodley 2025-04-28 11:09:43 +10:00 committed by GitHub
parent ed3c8702a2
commit d3d856ad84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 130 additions and 94 deletions

View File

@ -147,7 +147,7 @@ void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
if (!Name)
continue;
SymName = *Name;
uint64_t GUID = Function::getGUID(SymName);
uint64_t GUID = Function::getGUIDAssumingExternalLinkage(SymName);
FuncStartAddrs[GUID] = F->getAddress();
if (ProfiledOnly && HasProfile)
GuidFilter.insert(GUID);
@ -173,7 +173,7 @@ void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap();
// Checks GUID in GUID2Func and returns it if it's present or null otherwise.
auto checkGUID = [&](StringRef SymName) -> uint64_t {
uint64_t GUID = Function::getGUID(SymName);
uint64_t GUID = Function::getGUIDAssumingExternalLinkage(SymName);
if (GUID2Func.find(GUID) == GUID2Func.end())
return 0;
return GUID;
@ -435,7 +435,7 @@ void PseudoProbeRewriter::encodePseudoProbes() {
for (const BinaryFunction *F : BC.getAllBinaryFunctions()) {
const uint64_t Addr =
F->isEmitted() ? F->getOutputAddress() : F->getAddress();
FuncStartAddrs[Function::getGUID(
FuncStartAddrs[Function::getGUIDAssumingExternalLinkage(
NameResolver::restore(F->getOneName()))] = Addr;
}
DummyDecoder.buildAddress2ProbeMap(

View File

@ -77,7 +77,9 @@ public:
void log(raw_ostream &OS) const override {
OS << "Duplicate symbol for global value '" << GlobalValueName
<< "' (GUID: " << GlobalValue::getGUID(GlobalValueName) << ") in:\n";
<< "' (GUID: "
<< GlobalValue::getGUIDAssumingExternalLinkage(GlobalValueName)
<< ") in:\n";
for (const std::string &Path : ModulePaths) {
OS << " " << Path << "\n";
}
@ -110,8 +112,9 @@ public:
}
void log(raw_ostream &OS) const override {
OS << "No symbol for global value '" << GlobalValueName
<< "' (GUID: " << GlobalValue::getGUID(GlobalValueName) << ") in:\n";
OS << "No symbol for global value '" << GlobalValueName << "' (GUID: "
<< GlobalValue::getGUIDAssumingExternalLinkage(GlobalValueName)
<< ") in:\n";
for (const std::string &Path : ModulePaths) {
OS << " " << Path << "\n";
}
@ -135,7 +138,8 @@ char DefinitionNotFoundInSummary::ID = 0;
Expected<StringRef> getMainModulePath(StringRef FunctionName,
ModuleSummaryIndex &Index) {
// Summaries use unmangled names.
GlobalValue::GUID G = GlobalValue::getGUID(FunctionName);
GlobalValue::GUID G =
GlobalValue::getGUIDAssumingExternalLinkage(FunctionName);
ValueInfo VI = Index.getValueInfo(G);
// We need a unique definition, otherwise don't try further.

View File

@ -570,6 +570,11 @@ public:
return Name;
}
/// Declare a type to represent a global unique identifier for a global value.
/// This is a 64 bits hash that is used by PGO and ThinLTO to have a compact
/// unique way to identify a symbol.
using GUID = uint64_t;
/// Return the modified name for a global value suitable to be
/// used as the key for a global lookup (e.g. profile or ThinLTO).
/// The value's original name is \c Name and has linkage of type
@ -578,22 +583,22 @@ public:
GlobalValue::LinkageTypes Linkage,
StringRef FileName);
private:
/// Return the modified name for this global value suitable to be
/// used as the key for a global lookup (e.g. profile or ThinLTO).
std::string getGlobalIdentifier() const;
/// Declare a type to represent a global unique identifier for a global value.
/// This is a 64 bits hash that is used by PGO and ThinLTO to have a compact
/// unique way to identify a symbol.
using GUID = uint64_t;
public:
/// Return a 64-bit global unique ID constructed from the name of a global
/// symbol. Since this call doesn't supply the linkage or defining filename,
/// the GUID computation will assume that the global has external linkage.
static GUID getGUIDAssumingExternalLinkage(StringRef GlobalName);
/// Return a 64-bit global unique ID constructed from global value name
/// (i.e. returned by getGlobalIdentifier()).
static GUID getGUID(StringRef GlobalName);
/// Return a 64-bit global unique ID constructed from global value name
/// (i.e. returned by getGlobalIdentifier()).
GUID getGUID() const { return getGUID(getGlobalIdentifier()); }
GUID getGUID() const {
return getGUIDAssumingExternalLinkage(getGlobalIdentifier());
}
/// @name Materialization
/// Materialization is used to construct functions only as they're needed.

View File

@ -1321,14 +1321,14 @@ public:
template <typename... Args> void emplace(Args &&...A) {
StringRef S(std::forward<Args>(A)...);
GlobalValue::GUID GUID =
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S));
GlobalValue::GUID GUID = GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::dropLLVMManglingEscape(S));
Index[GUID].emplace(S);
}
size_t count(StringRef S) const {
GlobalValue::GUID GUID =
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S));
GlobalValue::GUID GUID = GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::dropLLVMManglingEscape(S));
auto I = Index.find(GUID);
if (I == Index.end())
return 0;
@ -1731,7 +1731,9 @@ public:
/// Add a global value summary for a value of the given name.
void addGlobalValueSummary(StringRef ValueName,
std::unique_ptr<GlobalValueSummary> Summary) {
addGlobalValueSummary(getOrInsertValueInfo(GlobalValue::getGUID(ValueName)),
addGlobalValueSummary(
getOrInsertValueInfo(
GlobalValue::getGUIDAssumingExternalLinkage(ValueName)),
std::move(Summary));
}
@ -1869,11 +1871,13 @@ public:
/// This accessor can mutate the map and therefore should not be used in
/// the ThinLTO backends.
TypeIdSummary &getOrInsertTypeIdSummary(StringRef TypeId) {
auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId));
auto TidIter = TypeIdMap.equal_range(
GlobalValue::getGUIDAssumingExternalLinkage(TypeId));
for (auto &[GUID, TypeIdPair] : make_range(TidIter))
if (TypeIdPair.first == TypeId)
return TypeIdPair.second;
auto It = TypeIdMap.insert({GlobalValue::getGUID(TypeId),
auto It =
TypeIdMap.insert({GlobalValue::getGUIDAssumingExternalLinkage(TypeId),
{TypeIdSaver.save(TypeId), TypeIdSummary()}});
return It->second.second;
}
@ -1881,7 +1885,8 @@ public:
/// This returns either a pointer to the type id summary (if present in the
/// summary map) or null (if not present). This may be used when importing.
const TypeIdSummary *getTypeIdSummary(StringRef TypeId) const {
auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId));
auto TidIter = TypeIdMap.equal_range(
GlobalValue::getGUIDAssumingExternalLinkage(TypeId));
for (const auto &[GUID, TypeIdPair] : make_range(TidIter))
if (TypeIdPair.first == TypeId)
return &TypeIdPair.second;

View File

@ -314,7 +314,7 @@ template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
static void inputOne(IO &io, StringRef Key, TypeIdSummaryMapTy &V) {
TypeIdSummary TId;
io.mapRequired(Key.str().c_str(), TId);
V.insert({GlobalValue::getGUID(Key), {Key, TId}});
V.insert({GlobalValue::getGUIDAssumingExternalLinkage(Key), {Key, TId}});
}
static void output(IO &io, TypeIdSummaryMapTy &V) {
for (auto &TidIter : V)

View File

@ -1299,7 +1299,7 @@ private:
static inline FunctionId getRepInFormat(StringRef Name) {
if (Name.empty() || !FunctionSamples::UseMD5)
return FunctionId(Name);
return FunctionId(Function::getGUID(Name));
return FunctionId(Function::getGUIDAssumingExternalLinkage(Name));
}
raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS);

View File

@ -109,11 +109,12 @@ public:
}
const PseudoProbeDescriptor *getDesc(StringRef FProfileName) const {
return getDesc(Function::getGUID(FProfileName));
return getDesc(Function::getGUIDAssumingExternalLinkage(FProfileName));
}
const PseudoProbeDescriptor *getDesc(const Function &F) const {
return getDesc(Function::getGUID(FunctionSamples::getCanonicalFnName(F)));
return getDesc(Function::getGUIDAssumingExternalLinkage(
FunctionSamples::getCanonicalFnName(F)));
}
bool profileIsHashMismatched(const PseudoProbeDescriptor &FuncDesc,

View File

@ -436,7 +436,7 @@ PreservedAnalyses AssignGUIDPass::run(Module &M, ModuleAnalysisManager &MAM) {
GlobalValue::GUID AssignGUIDPass::getGUID(const Function &F) {
if (F.isDeclaration()) {
assert(GlobalValue::isExternalLinkage(F.getLinkage()));
return GlobalValue::getGUID(F.getGlobalIdentifier());
return F.getGUID();
}
auto *MD = F.getMetadata(GUIDMetadataName);
assert(MD && "guid not found for defined function");

View File

@ -222,7 +222,8 @@ static void addIntrinsicToSummary(
auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
if (!TypeId)
break;
GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
GlobalValue::GUID Guid =
GlobalValue::getGUIDAssumingExternalLinkage(TypeId->getString());
// Produce a summary from type.test intrinsics. We only summarize type.test
// intrinsics that are used other than by an llvm.assume intrinsic.
@ -250,7 +251,8 @@ static void addIntrinsicToSummary(
auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
if (!TypeId)
break;
GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
GlobalValue::GUID Guid =
GlobalValue::getGUIDAssumingExternalLinkage(TypeId->getString());
SmallVector<DevirtCallSite, 4> DevirtCalls;
SmallVector<Instruction *, 4> LoadedPtrs;
@ -904,7 +906,8 @@ static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
// Set LiveRoot flag on entries matching the given value name.
static void setLiveRoot(ModuleSummaryIndex &Index, StringRef Name) {
if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
if (ValueInfo VI =
Index.getValueInfo(GlobalValue::getGUIDAssumingExternalLinkage(Name)))
for (const auto &Summary : VI.getSummaryList())
Summary->setLive(true);
}

View File

@ -9049,7 +9049,7 @@ bool LLParser::parseTypeIdEntry(unsigned ID) {
for (auto TIDRef : FwdRefTIDs->second) {
assert(!*TIDRef.first &&
"Forward referenced type id GUID expected to be 0");
*TIDRef.first = GlobalValue::getGUID(Name);
*TIDRef.first = GlobalValue::getGUIDAssumingExternalLinkage(Name);
}
ForwardRefTypeIds.erase(FwdRefTIDs);
}
@ -9154,7 +9154,7 @@ bool LLParser::parseTypeIdCompatibleVtableEntry(unsigned ID) {
for (auto TIDRef : FwdRefTIDs->second) {
assert(!*TIDRef.first &&
"Forward referenced type id GUID expected to be 0");
*TIDRef.first = GlobalValue::getGUID(Name);
*TIDRef.first = GlobalValue::getGUIDAssumingExternalLinkage(Name);
}
ForwardRefTypeIds.erase(FwdRefTIDs);
}
@ -9470,7 +9470,7 @@ bool LLParser::addGlobalValueToIndex(
assert(
(!GlobalValue::isLocalLinkage(Linkage) || !SourceFileName.empty()) &&
"Need a source_filename to compute GUID for local");
GUID = GlobalValue::getGUID(
GUID = GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::getGlobalIdentifier(Name, Linkage, SourceFileName));
VI = Index->getOrInsertValueInfo(GUID, Index->saveString(Name));
}

View File

@ -7166,10 +7166,10 @@ void ModuleSummaryIndexBitcodeReader::setValueGUID(
StringRef SourceFileName) {
std::string GlobalId =
GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName);
auto ValueGUID = GlobalValue::getGUID(GlobalId);
auto ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage(GlobalId);
auto OriginalNameID = ValueGUID;
if (GlobalValue::isLocalLinkage(Linkage))
OriginalNameID = GlobalValue::getGUID(ValueName);
OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName);
if (PrintSummaryGUIDs)
dbgs() << "GUID " << ValueGUID << "(" << OriginalNameID << ") is "
<< ValueName << "\n";

View File

@ -34,7 +34,7 @@ void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,
// Use caching to avoid redundant md5 computation for build speed.
uint64_t &CallerGuid = NameGuidMap[Name];
if (!CallerGuid)
CallerGuid = Function::getGUID(Name);
CallerGuid = Function::getGUIDAssumingExternalLinkage(Name);
uint64_t CallerProbeId = PseudoProbeDwarfDiscriminator::extractProbeIndex(
InlinedAt->getDiscriminator());
ReversedInlineStack.emplace_back(CallerGuid, CallerProbeId);

View File

@ -129,7 +129,7 @@ public:
private:
uint64_t getFuncGUID(Module *M, DILocation *DL) {
auto Name = DL->getSubprogramLinkageName();
return Function::getGUID(Name);
return Function::getGUIDAssumingExternalLinkage(Name);
}
bool ShouldRun = false;

View File

@ -3226,7 +3226,7 @@ void AssemblyWriter::printModuleSummaryIndex() {
// Print the TypeIdCompatibleVtableMap entries.
for (auto &TId : TheIndex->typeIdCompatibleVtableMap()) {
auto GUID = GlobalValue::getGUID(TId.first);
auto GUID = GlobalValue::getGUIDAssumingExternalLinkage(TId.first);
Out << "^" << Machine.getTypeIdCompatibleVtableSlot(TId.first)
<< " = typeidCompatibleVTable: (name: \"" << TId.first << "\"";
printTypeIdCompatibleVtableSummary(TId.second);

View File

@ -73,8 +73,9 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
removeSanitizerMetadata();
}
GlobalValue::GUID GlobalValue::getGUID(StringRef GlobalName) {
return MD5Hash(GlobalName);
GlobalValue::GUID
GlobalValue::getGUIDAssumingExternalLinkage(StringRef GlobalIdentifier) {
return MD5Hash(GlobalIdentifier);
}
void GlobalValue::removeFromParent() {

View File

@ -1043,8 +1043,9 @@ Error LTO::addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
SymbolResolution Res = *ResITmp++;
if (!Sym.getIRName().empty()) {
auto GUID = GlobalValue::getGUID(GlobalValue::getGlobalIdentifier(
Sym.getIRName(), GlobalValue::ExternalLinkage, ""));
auto GUID = GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::getGlobalIdentifier(Sym.getIRName(),
GlobalValue::ExternalLinkage, ""));
if (Res.Prevailing)
ThinLTO.PrevailingModuleForGUID[GUID] = BM.getModuleIdentifier();
}
@ -1064,8 +1065,9 @@ Error LTO::addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
SymbolResolution Res = *ResI++;
if (!Sym.getIRName().empty()) {
auto GUID = GlobalValue::getGUID(GlobalValue::getGlobalIdentifier(
Sym.getIRName(), GlobalValue::ExternalLinkage, ""));
auto GUID = GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::getGlobalIdentifier(Sym.getIRName(),
GlobalValue::ExternalLinkage, ""));
if (Res.Prevailing) {
assert(ThinLTO.PrevailingModuleForGUID[GUID] ==
BM.getModuleIdentifier());
@ -1174,7 +1176,7 @@ Error LTO::run(AddStreamFn AddStream, FileCache Cache) {
if (Res.second.IRName.empty())
continue;
GlobalValue::GUID GUID = GlobalValue::getGUID(
GlobalValue::GUID GUID = GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::dropLLVMManglingEscape(Res.second.IRName));
if (Res.second.VisibleOutsideSummary && Res.second.Prevailing)
@ -1950,7 +1952,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
if (Res.second.Partition != GlobalResolution::External ||
!Res.second.isPrevailingIRSymbol())
continue;
auto GUID = GlobalValue::getGUID(
auto GUID = GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::dropLLVMManglingEscape(Res.second.IRName));
// Mark exported unless index-based analysis determined it to be dead.
if (ThinLTO.CombinedIndex.isGUIDLive(GUID))

View File

@ -295,7 +295,8 @@ addUsedSymbolToPreservedGUID(const lto::InputFile &File,
DenseSet<GlobalValue::GUID> &PreservedGUID) {
for (const auto &Sym : File.symbols()) {
if (Sym.isUsed())
PreservedGUID.insert(GlobalValue::getGUID(Sym.getIRName()));
PreservedGUID.insert(
GlobalValue::getGUIDAssumingExternalLinkage(Sym.getIRName()));
}
}
@ -308,8 +309,9 @@ static void computeGUIDPreservedSymbols(const lto::InputFile &File,
// compute the GUID for the symbol.
for (const auto &Sym : File.symbols()) {
if (PreservedSymbols.count(Sym.getName()) && !Sym.getIRName().empty())
GUIDs.insert(GlobalValue::getGUID(GlobalValue::getGlobalIdentifier(
Sym.getIRName(), GlobalValue::ExternalLinkage, "")));
GUIDs.insert(GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::getGlobalIdentifier(Sym.getIRName(),
GlobalValue::ExternalLinkage, "")));
}
}

View File

@ -557,8 +557,8 @@ Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
return E;
bool Inserted = true;
std::tie(std::ignore, Inserted) =
MD5VTableMap.try_emplace(GlobalValue::getGUID(Name), &VTable);
std::tie(std::ignore, Inserted) = MD5VTableMap.try_emplace(
GlobalValue::getGUIDAssumingExternalLinkage(Name), &VTable);
if (!Inserted)
LLVM_DEBUG(dbgs() << "GUID conflict within one module");
return Error::success();
@ -676,7 +676,7 @@ Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName,
auto NameToGUIDMap = [&](StringRef Name) -> Error {
if (Error E = addFuncName(Name))
return E;
MD5FuncMap.emplace_back(Function::getGUID(Name), &F);
MD5FuncMap.emplace_back(Function::getGUIDAssumingExternalLinkage(Name), &F);
return Error::success();
};
if (Error E = NameToGUIDMap(PGOFuncName))

View File

@ -263,7 +263,7 @@ GlobalValue::GUID IndexedMemProfRecord::getGUID(const StringRef FunctionName) {
// We use the function guid which we expect to be a uint64_t. At
// this time, it is the lower 64 bits of the md5 of the canonical
// function name.
return Function::getGUID(CanonicalName);
return Function::getGUIDAssumingExternalLinkage(CanonicalName);
}
Expected<MemProfSchema> readMemProfSchema(const unsigned char *&Buffer) {

View File

@ -908,7 +908,7 @@ std::error_code SampleProfileReaderExtBinaryBase::readFuncProfiles(
DenseSet<uint64_t> FuncGuidsToUse;
if (useMD5()) {
for (auto Name : FuncsToUse)
FuncGuidsToUse.insert(Function::getGUID(Name));
FuncGuidsToUse.insert(Function::getGUIDAssumingExternalLinkage(Name));
}
// For each function in current module, load all context profiles for

View File

@ -176,7 +176,8 @@ void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) {
case Mips::JAL:
case Mips::JAL_MM:
if (MI.getOperand(0).isGlobal() &&
MI.getOperand(0).getGlobal()->getGlobalIdentifier() == "_mcount")
MI.getOperand(0).getGlobal()->hasExternalLinkage() &&
MI.getOperand(0).getGlobal()->getName() == "_mcount")
emitMCountABI(MI, MBB, MF);
break;
case Mips::JALRPseudo:

View File

@ -3139,9 +3139,8 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
if (Aliasee->hasCommonLinkage()) {
report_fatal_error("Aliases to common variables are not allowed on AIX:"
"\n\tAlias attribute for " +
Alias.getGlobalIdentifier() +
" is invalid because " + Aliasee->getName() +
" is common.",
Alias.getName() + " is invalid because " +
Aliasee->getName() + " is common.",
false);
}

View File

@ -454,7 +454,7 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
? SPIRV::LinkageType::LinkOnceODR
: SPIRV::LinkageType::Export);
buildOpDecorate(FuncVReg, MIRBuilder, SPIRV::Decoration::LinkageAttributes,
{static_cast<uint32_t>(LnkTy)}, F.getGlobalIdentifier());
{static_cast<uint32_t>(LnkTy)}, F.getName());
}
// Handle function pointers decoration

View File

@ -19,6 +19,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalObject.h"
@ -607,7 +608,7 @@ class WorkloadImportsManager : public ModuleImportsManager {
if (PotentialCandidates.empty()) {
LLVM_DEBUG(dbgs() << "[Workload] Not importing " << VI.name()
<< " because can't find eligible Callee. Guid is: "
<< Function::getGUID(VI.name()) << "\n");
<< VI.getGUID() << "\n");
continue;
}
/// We will prefer importing the prevailing candidate, if not, we'll
@ -660,8 +661,7 @@ class WorkloadImportsManager : public ModuleImportsManager {
continue;
}
LLVM_DEBUG(dbgs() << "[Workload][Including]" << VI.name() << " from "
<< ExportingModule << " : "
<< Function::getGUID(VI.name()) << "\n");
<< ExportingModule << " : " << VI.getGUID() << "\n");
ImportList.addDefinition(ExportingModule, VI.getGUID());
GVI.onImportingSummary(*GVS);
if (ExportLists)
@ -1807,7 +1807,8 @@ void llvm::thinLTOInternalizeModule(Module &TheModule,
std::string OrigId = GlobalValue::getGlobalIdentifier(
OrigName, GlobalValue::InternalLinkage,
TheModule.getSourceFileName());
GS = DefinedGlobals.find(GlobalValue::getGUID(OrigId));
GS = DefinedGlobals.find(
GlobalValue::getGUIDAssumingExternalLinkage(OrigId));
if (GS == DefinedGlobals.end()) {
// Also check the original non-promoted non-globalized name. In some
// cases a preempted weak value is linked in as a local copy because
@ -1815,7 +1816,8 @@ void llvm::thinLTOInternalizeModule(Module &TheModule,
// In that case, since it was originally not a local value, it was
// recorded in the index using the original name.
// FIXME: This may not be needed once PR27866 is fixed.
GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName));
GS = DefinedGlobals.find(
GlobalValue::getGUIDAssumingExternalLinkage(OrigName));
assert(GS != DefinedGlobals.end());
}
}

View File

@ -2112,7 +2112,8 @@ bool LowerTypeTestsModule::lower() {
->getValue()
->getUniqueInteger()
.getZExtValue());
const GlobalValue::GUID GUID = GlobalValue::getGUID(
const GlobalValue::GUID GUID =
GlobalValue::getGUIDAssumingExternalLinkage(
GlobalValue::dropLLVMManglingEscape(FunctionName));
// Do not emit jumptable entries for functions that are not-live and
// have no live references (and are not exported with cross-DSO CFI.)
@ -2318,8 +2319,9 @@ bool LowerTypeTestsModule::lower() {
DenseMap<GlobalValue::GUID, TinyPtrVector<Metadata *>> MetadataByGUID;
for (auto &P : TypeIdInfo) {
if (auto *TypeId = dyn_cast<MDString>(P.first))
MetadataByGUID[GlobalValue::getGUID(TypeId->getString())].push_back(
TypeId);
MetadataByGUID[GlobalValue::getGUIDAssumingExternalLinkage(
TypeId->getString())]
.push_back(TypeId);
}
for (auto &P : *ExportSummary) {

View File

@ -4974,7 +4974,8 @@ static ValueInfo findValueInfoForFunc(const Function &F, const Module &M,
// See if theFn was internalized, by checking index directly with
// original name (this avoids the name adjustment done by getGUID() for
// internal symbols).
TheFnVI = ImportSummary->getValueInfo(GlobalValue::getGUID(F.getName()));
TheFnVI = ImportSummary->getValueInfo(
GlobalValue::getGUIDAssumingExternalLinkage(F.getName()));
if (TheFnVI)
return TheFnVI;
// Now query with the original name before any promotion was performed.
@ -5005,7 +5006,8 @@ static ValueInfo findValueInfoForFunc(const Function &F, const Module &M,
SrcFile = dyn_cast<MDString>(SrcFileMD->getOperand(0))->getString();
std::string OrigId = GlobalValue::getGlobalIdentifier(
OrigName, GlobalValue::InternalLinkage, SrcFile);
TheFnVI = ImportSummary->getValueInfo(GlobalValue::getGUID(OrigId));
TheFnVI = ImportSummary->getValueInfo(
GlobalValue::getGUIDAssumingExternalLinkage(OrigId));
// Internal func in original module may have gotten a numbered suffix if we
// imported an external function with the same name. This happens
// automatically during IR linking for naming conflicts. It would have to
@ -5016,7 +5018,8 @@ static ValueInfo findValueInfoForFunc(const Function &F, const Module &M,
OrigName = F.getName().rsplit('.').first;
OrigId = GlobalValue::getGlobalIdentifier(
OrigName, GlobalValue::InternalLinkage, SrcFile);
TheFnVI = ImportSummary->getValueInfo(GlobalValue::getGUID(OrigId));
TheFnVI = ImportSummary->getValueInfo(
GlobalValue::getGUIDAssumingExternalLinkage(OrigId));
}
// The only way we may not have a VI is if this is a declaration created for
// an imported reference. For distributed ThinLTO we may not have a VI for

View File

@ -361,7 +361,7 @@ public:
for (const auto &F : CurrentModule) {
StringRef OrigName = F.getName();
CurrentGUIDToFuncNameMap.insert(
{Function::getGUID(OrigName), OrigName});
{Function::getGUIDAssumingExternalLinkage(OrigName), OrigName});
// Local to global var promotion used by optimization like thinlto
// will rename the var and add suffix like ".llvm.xxx" to the
@ -373,7 +373,7 @@ public:
StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
if (CanonName != OrigName)
CurrentGUIDToFuncNameMap.insert(
{Function::getGUID(CanonName), CanonName});
{Function::getGUIDAssumingExternalLinkage(CanonName), CanonName});
}
// Update GUIDToFuncNameMap for each function including inlinees.
@ -820,7 +820,7 @@ static bool doesHistoryAllowICP(const Instruction &Inst, StringRef Candidate) {
// If the promotion candidate has NOMORE_ICP_MAGICNUM count in the
// metadata, it means the candidate has been promoted for this
// indirect call.
if (V.Value == Function::getGUID(Candidate))
if (V.Value == Function::getGUIDAssumingExternalLinkage(Candidate))
return false;
NumPromoted++;
// If already have MaxNumPromotions promotion, don't do it anymore.
@ -951,7 +951,8 @@ bool SampleProfileLoader::tryPromoteAndInlineCandidate(
// For promoted target, set its value with NOMORE_ICP_MAGICNUM count
// in the value profile metadata so the target won't be promoted again.
SmallVector<InstrProfValueData, 1> SortedCallTargets = {InstrProfValueData{
Function::getGUID(R->second->getName()), NOMORE_ICP_MAGICNUM}};
Function::getGUIDAssumingExternalLinkage(R->second->getName()),
NOMORE_ICP_MAGICNUM}};
updateIDTMetaData(CI, SortedCallTargets, 0);
auto *DI = &pgo::promoteIndirectCall(
@ -1038,8 +1039,8 @@ void SampleProfileLoader::findExternalInlineCandidate(
// Samples may not exist for replayed function, if so
// just add the direct GUID and move on
if (!Samples) {
InlinedGUIDs.insert(
Function::getGUID(CB->getCalledFunction()->getName()));
InlinedGUIDs.insert(Function::getGUIDAssumingExternalLinkage(
CB->getCalledFunction()->getName()));
return;
}
// Otherwise, drop the threshold to import everything that we can
@ -2280,7 +2281,8 @@ bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM)
// cold in sampled binary will actually not be cold after current build.
StringRef CanonName = FunctionSamples::getCanonicalFnName(F);
if ((FunctionSamples::UseMD5 &&
GUIDsInProfile.count(Function::getGUID(CanonName))) ||
GUIDsInProfile.count(
Function::getGUIDAssumingExternalLinkage(CanonName))) ||
(!FunctionSamples::UseMD5 && NamesInProfile.count(CanonName)))
initialEntryCount = -1;
}

View File

@ -350,7 +350,7 @@ void SampleProfileProber::instrumentOneFunc(Function &F, TargetMachine *TM) {
if (FName.empty())
FName = SP->getName();
}
uint64_t Guid = Function::getGUID(FName);
uint64_t Guid = Function::getGUIDAssumingExternalLinkage(FName);
// Assign an artificial debug line to a probe that doesn't come with a real
// line. A probe not having a debug line will get an incomplete inline

View File

@ -2243,7 +2243,8 @@ DevirtModule::lookUpFunctionValueInfo(Function *TheFn,
"Caller guarantees ExportSummary is not nullptr");
const auto TheFnGUID = TheFn->getGUID();
const auto TheFnGUIDWithExportedName = GlobalValue::getGUID(TheFn->getName());
const auto TheFnGUIDWithExportedName =
GlobalValue::getGUIDAssumingExternalLinkage(TheFn->getName());
// Look up ValueInfo with the GUID in the current linkage.
ValueInfo TheFnVI = ExportSummary->getValueInfo(TheFnGUID);
// If no entry is found and GUID is different from GUID computed using
@ -2344,8 +2345,9 @@ bool DevirtModule::run() {
DenseMap<GlobalValue::GUID, TinyPtrVector<Metadata *>> MetadataByGUID;
for (auto &P : TypeIdMap) {
if (auto *TypeId = dyn_cast<MDString>(P.first))
MetadataByGUID[GlobalValue::getGUID(TypeId->getString())].push_back(
TypeId);
MetadataByGUID[GlobalValue::getGUIDAssumingExternalLinkage(
TypeId->getString())]
.push_back(TypeId);
}
for (auto &P : *ExportSummary) {
@ -2428,8 +2430,8 @@ bool DevirtModule::run() {
// llvm.type.test intrinsics to the function summaries so that the
// LowerTypeTests pass will export them.
if (ExportSummary && isa<MDString>(S.first.TypeID)) {
auto GUID =
GlobalValue::getGUID(cast<MDString>(S.first.TypeID)->getString());
auto GUID = GlobalValue::getGUIDAssumingExternalLinkage(
cast<MDString>(S.first.TypeID)->getString());
for (auto *FS : S.second.CSInfo.SummaryTypeCheckedLoadUsers)
FS->addTypeTest(GUID);
for (auto &CCS : S.second.ConstCSInfo)
@ -2485,7 +2487,8 @@ void DevirtIndex::run() {
DenseMap<GlobalValue::GUID, std::vector<StringRef>> NameByGUID;
for (const auto &P : ExportSummary.typeIdCompatibleVtableMap()) {
NameByGUID[GlobalValue::getGUID(P.first)].push_back(P.first);
NameByGUID[GlobalValue::getGUIDAssumingExternalLinkage(P.first)].push_back(
P.first);
// Create the type id summary resolution regardlness of whether we can
// devirtualize, so that lower type tests knows the type id is used on
// a global and not Unsat. We do this here rather than in the loop over the

View File

@ -973,7 +973,7 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
// 'unique-internal-linkage-names' can make MemProf work better for local
// linkage function.
auto FuncName = F.getName();
auto FuncGUID = Function::getGUID(FuncName);
auto FuncGUID = Function::getGUIDAssumingExternalLinkage(FuncName);
std::optional<memprof::MemProfRecord> MemProfRec;
auto Err = MemProfReader->getMemProfRecord(FuncGUID).moveInto(MemProfRec);
if (Err) {
@ -1099,7 +1099,7 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();
if (Name.empty())
Name = DIL->getScope()->getSubprogram()->getName();
auto CalleeGUID = Function::getGUID(Name);
auto CalleeGUID = Function::getGUIDAssumingExternalLinkage(Name);
auto StackId = computeStackId(CalleeGUID, GetOffset(DIL),
ProfileHasColumns ? DIL->getColumn() : 0);
// Check if we have found the profile's leaf frame. If yes, collect

View File

@ -409,17 +409,18 @@ void ProfiledBinary::decodePseudoProbe(const ELFObjectFileBase *Obj) {
FuncStartAddresses = SymbolStartAddrs;
} else {
for (auto &F : DisassembleFunctionSet) {
auto GUID = Function::getGUID(F.first());
auto GUID = Function::getGUIDAssumingExternalLinkage(F.first());
if (auto StartAddr = SymbolStartAddrs.lookup(GUID)) {
FuncStartAddresses[GUID] = StartAddr;
FuncRange &Range = StartAddrToFuncRangeMap[StartAddr];
GuidFilter.insert(Function::getGUID(Range.getFuncName()));
GuidFilter.insert(
Function::getGUIDAssumingExternalLinkage(Range.getFuncName()));
}
}
}
} else {
for (auto *F : ProfiledFunctions) {
GuidFilter.insert(Function::getGUID(F->FuncName));
GuidFilter.insert(Function::getGUIDAssumingExternalLinkage(F->FuncName));
for (auto &Range : F->Ranges) {
auto GUIDs = StartAddrToSymMap.equal_range(Range.first);
for (const auto &[StartAddr, Func] : make_range(GUIDs))
@ -774,7 +775,7 @@ void ProfiledBinary::populateElfSymbolAddressList(
for (const SymbolRef &Symbol : Obj->symbols()) {
const uint64_t Addr = unwrapOrError(Symbol.getAddress(), FileName);
const StringRef Name = unwrapOrError(Symbol.getName(), FileName);
uint64_t GUID = Function::getGUID(Name);
uint64_t GUID = Function::getGUIDAssumingExternalLinkage(Name);
SymbolStartAddrs[GUID] = Addr;
StartAddrToSymMap.emplace(Addr, GUID);
}