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.
diff --git a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
index 9d6e914..ee021fe 100644
--- a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
+++ b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
@@ -147,7 +147,7 @@
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 @@
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 @@
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(
diff --git a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
index 78152af..c55aa73 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp
@@ -77,7 +77,9 @@
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 @@
}
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 @@
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.
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index 2176e2c..d9ecbb9 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -570,6 +570,11 @@
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 @@
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.
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index d563817..5080fa2 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1321,14 +1321,14 @@
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,8 +1731,10 @@
/// 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)),
- std::move(Summary));
+ addGlobalValueSummary(
+ getOrInsertValueInfo(
+ GlobalValue::getGUIDAssumingExternalLinkage(ValueName)),
+ std::move(Summary));
}
/// Add a global value summary for the given ValueInfo.
@@ -1869,19 +1871,22 @@
/// 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),
- {TypeIdSaver.save(TypeId), TypeIdSummary()}});
+ auto It =
+ TypeIdMap.insert({GlobalValue::getGUIDAssumingExternalLinkage(TypeId),
+ {TypeIdSaver.save(TypeId), TypeIdSummary()}});
return It->second.second;
}
/// 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;
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
index d5a9176..531de51 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
@@ -314,7 +314,7 @@
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)
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 66fe0da..c7155b3 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -1299,7 +1299,7 @@
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);
diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h b/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
index d714dba..12d1031 100644
--- a/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
+++ b/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
@@ -109,11 +109,12 @@
}
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,
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp
index 0f0999c..a363bce 100644
--- a/llvm/lib/Analysis/CtxProfAnalysis.cpp
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -436,7 +436,7 @@
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");
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 4b50f1e..0227669 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -222,7 +222,8 @@
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 @@
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 @@
// 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);
}
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index af0422f..370d124 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -9049,7 +9049,7 @@
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 @@
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 @@
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));
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index b152adf..1d7aa18 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -7166,10 +7166,10 @@
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";
diff --git a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp
index 5dda383..618deef 100644
--- a/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp
@@ -34,7 +34,7 @@
// 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);
diff --git a/llvm/lib/CodeGen/PseudoProbeInserter.cpp b/llvm/lib/CodeGen/PseudoProbeInserter.cpp
index 913e003..c911e84 100644
--- a/llvm/lib/CodeGen/PseudoProbeInserter.cpp
+++ b/llvm/lib/CodeGen/PseudoProbeInserter.cpp
@@ -129,7 +129,7 @@
private:
uint64_t getFuncGUID(Module *M, DILocation *DL) {
auto Name = DL->getSubprogramLinkageName();
- return Function::getGUID(Name);
+ return Function::getGUIDAssumingExternalLinkage(Name);
}
bool ShouldRun = false;
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 8ef9534..80b1648 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -3226,7 +3226,7 @@
// 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);
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 401f8ac..7b799c7 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -73,8 +73,9 @@
removeSanitizerMetadata();
}
-GlobalValue::GUID GlobalValue::getGUID(StringRef GlobalName) {
- return MD5Hash(GlobalName);
+GlobalValue::GUID
+GlobalValue::getGUIDAssumingExternalLinkage(StringRef GlobalIdentifier) {
+ return MD5Hash(GlobalIdentifier);
}
void GlobalValue::removeFromParent() {
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 4b6a87e..613e2d9 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1043,8 +1043,9 @@
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 @@
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 @@
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 @@
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))
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 9e7f818..42dba0a 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -295,7 +295,8 @@
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 @@
// 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, "")));
}
}
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 8862178..b738d9d0 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -557,8 +557,8 @@
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 @@
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))
diff --git a/llvm/lib/ProfileData/MemProf.cpp b/llvm/lib/ProfileData/MemProf.cpp
index 0af08ca..c3a2767 100644
--- a/llvm/lib/ProfileData/MemProf.cpp
+++ b/llvm/lib/ProfileData/MemProf.cpp
@@ -263,7 +263,7 @@
// 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) {
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index d97cc47..343104e 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -908,7 +908,7 @@
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
diff --git a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
index 738fabe..8f201e5 100644
--- a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
@@ -176,7 +176,8 @@
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:
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index f07331b..85155c9 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -3139,9 +3139,8 @@
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);
}
diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
index 5ec8c22..b824b9a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
@@ -454,7 +454,7 @@
? 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
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 12da7f5..8aeeb4e 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -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 @@
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 @@
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 @@
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 @@
// 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());
}
}
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 8f62ff1..f8205fb 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2112,7 +2112,8 @@
->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 @@
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) {
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 0d299b8..ec158af 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -4974,7 +4974,8 @@
// 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 @@
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 @@
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
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index d89da76..4947a0d 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -361,7 +361,7 @@
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 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
// 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;
}
diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
index 16f2090..dda3d5a 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -350,7 +350,7 @@
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
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 0680b2c..49c9515 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -2243,7 +2243,8 @@
"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 @@
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 @@
// 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 @@
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
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
index 67eba05..e34956d 100644
--- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
@@ -973,7 +973,7 @@
// '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 @@
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
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 472e49a..6847ba1 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -409,17 +409,18 @@
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 @@
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);
}