Skip to content

Commit e8a999b

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd3d856ad8469' from llvm.org/main into next
2 parents 8a3cce9 + d3d856a commit e8a999b

31 files changed

+130
-94
lines changed

bolt/lib/Rewrite/PseudoProbeRewriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
147147
if (!Name)
148148
continue;
149149
SymName = *Name;
150-
uint64_t GUID = Function::getGUID(SymName);
150+
uint64_t GUID = Function::getGUIDAssumingExternalLinkage(SymName);
151151
FuncStartAddrs[GUID] = F->getAddress();
152152
if (ProfiledOnly && HasProfile)
153153
GuidFilter.insert(GUID);
@@ -173,7 +173,7 @@ void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
173173
const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap();
174174
// Checks GUID in GUID2Func and returns it if it's present or null otherwise.
175175
auto checkGUID = [&](StringRef SymName) -> uint64_t {
176-
uint64_t GUID = Function::getGUID(SymName);
176+
uint64_t GUID = Function::getGUIDAssumingExternalLinkage(SymName);
177177
if (GUID2Func.find(GUID) == GUID2Func.end())
178178
return 0;
179179
return GUID;
@@ -435,7 +435,7 @@ void PseudoProbeRewriter::encodePseudoProbes() {
435435
for (const BinaryFunction *F : BC.getAllBinaryFunctions()) {
436436
const uint64_t Addr =
437437
F->isEmitted() ? F->getOutputAddress() : F->getAddress();
438-
FuncStartAddrs[Function::getGUID(
438+
FuncStartAddrs[Function::getGUIDAssumingExternalLinkage(
439439
NameResolver::restore(F->getOneName()))] = Addr;
440440
}
441441
DummyDecoder.buildAddress2ProbeMap(

llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class DuplicateDefinitionInSummary
7777

7878
void log(raw_ostream &OS) const override {
7979
OS << "Duplicate symbol for global value '" << GlobalValueName
80-
<< "' (GUID: " << GlobalValue::getGUID(GlobalValueName) << ") in:\n";
80+
<< "' (GUID: "
81+
<< GlobalValue::getGUIDAssumingExternalLinkage(GlobalValueName)
82+
<< ") in:\n";
8183
for (const std::string &Path : ModulePaths) {
8284
OS << " " << Path << "\n";
8385
}
@@ -110,8 +112,9 @@ class DefinitionNotFoundInSummary
110112
}
111113

112114
void log(raw_ostream &OS) const override {
113-
OS << "No symbol for global value '" << GlobalValueName
114-
<< "' (GUID: " << GlobalValue::getGUID(GlobalValueName) << ") in:\n";
115+
OS << "No symbol for global value '" << GlobalValueName << "' (GUID: "
116+
<< GlobalValue::getGUIDAssumingExternalLinkage(GlobalValueName)
117+
<< ") in:\n";
115118
for (const std::string &Path : ModulePaths) {
116119
OS << " " << Path << "\n";
117120
}
@@ -135,7 +138,8 @@ char DefinitionNotFoundInSummary::ID = 0;
135138
Expected<StringRef> getMainModulePath(StringRef FunctionName,
136139
ModuleSummaryIndex &Index) {
137140
// Summaries use unmangled names.
138-
GlobalValue::GUID G = GlobalValue::getGUID(FunctionName);
141+
GlobalValue::GUID G =
142+
GlobalValue::getGUIDAssumingExternalLinkage(FunctionName);
139143
ValueInfo VI = Index.getValueInfo(G);
140144

141145
// We need a unique definition, otherwise don't try further.

llvm/include/llvm/IR/GlobalValue.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ class GlobalValue : public Constant {
568568
return Name;
569569
}
570570

571+
/// Declare a type to represent a global unique identifier for a global value.
572+
/// This is a 64 bits hash that is used by PGO and ThinLTO to have a compact
573+
/// unique way to identify a symbol.
574+
using GUID = uint64_t;
575+
571576
/// Return the modified name for a global value suitable to be
572577
/// used as the key for a global lookup (e.g. profile or ThinLTO).
573578
/// The value's original name is \c Name and has linkage of type
@@ -576,22 +581,22 @@ class GlobalValue : public Constant {
576581
GlobalValue::LinkageTypes Linkage,
577582
StringRef FileName);
578583

584+
private:
579585
/// Return the modified name for this global value suitable to be
580586
/// used as the key for a global lookup (e.g. profile or ThinLTO).
581587
std::string getGlobalIdentifier() const;
582588

583-
/// Declare a type to represent a global unique identifier for a global value.
584-
/// This is a 64 bits hash that is used by PGO and ThinLTO to have a compact
585-
/// unique way to identify a symbol.
586-
using GUID = uint64_t;
587-
588-
/// Return a 64-bit global unique ID constructed from global value name
589-
/// (i.e. returned by getGlobalIdentifier()).
590-
static GUID getGUID(StringRef GlobalName);
589+
public:
590+
/// Return a 64-bit global unique ID constructed from the name of a global
591+
/// symbol. Since this call doesn't supply the linkage or defining filename,
592+
/// the GUID computation will assume that the global has external linkage.
593+
static GUID getGUIDAssumingExternalLinkage(StringRef GlobalName);
591594

592595
/// Return a 64-bit global unique ID constructed from global value name
593596
/// (i.e. returned by getGlobalIdentifier()).
594-
GUID getGUID() const { return getGUID(getGlobalIdentifier()); }
597+
GUID getGUID() const {
598+
return getGUIDAssumingExternalLinkage(getGlobalIdentifier());
599+
}
595600

596601
/// @name Materialization
597602
/// Materialization is used to construct functions only as they're needed.

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,14 +1321,14 @@ class CfiFunctionIndex {
13211321

13221322
template <typename... Args> void emplace(Args &&...A) {
13231323
StringRef S(std::forward<Args>(A)...);
1324-
GlobalValue::GUID GUID =
1325-
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S));
1324+
GlobalValue::GUID GUID = GlobalValue::getGUIDAssumingExternalLinkage(
1325+
GlobalValue::dropLLVMManglingEscape(S));
13261326
Index[GUID].emplace(S);
13271327
}
13281328

13291329
size_t count(StringRef S) const {
1330-
GlobalValue::GUID GUID =
1331-
GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S));
1330+
GlobalValue::GUID GUID = GlobalValue::getGUIDAssumingExternalLinkage(
1331+
GlobalValue::dropLLVMManglingEscape(S));
13321332
auto I = Index.find(GUID);
13331333
if (I == Index.end())
13341334
return 0;
@@ -1731,8 +1731,10 @@ class ModuleSummaryIndex {
17311731
/// Add a global value summary for a value of the given name.
17321732
void addGlobalValueSummary(StringRef ValueName,
17331733
std::unique_ptr<GlobalValueSummary> Summary) {
1734-
addGlobalValueSummary(getOrInsertValueInfo(GlobalValue::getGUID(ValueName)),
1735-
std::move(Summary));
1734+
addGlobalValueSummary(
1735+
getOrInsertValueInfo(
1736+
GlobalValue::getGUIDAssumingExternalLinkage(ValueName)),
1737+
std::move(Summary));
17361738
}
17371739

17381740
/// Add a global value summary for the given ValueInfo.
@@ -1869,19 +1871,22 @@ class ModuleSummaryIndex {
18691871
/// This accessor can mutate the map and therefore should not be used in
18701872
/// the ThinLTO backends.
18711873
TypeIdSummary &getOrInsertTypeIdSummary(StringRef TypeId) {
1872-
auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId));
1874+
auto TidIter = TypeIdMap.equal_range(
1875+
GlobalValue::getGUIDAssumingExternalLinkage(TypeId));
18731876
for (auto &[GUID, TypeIdPair] : make_range(TidIter))
18741877
if (TypeIdPair.first == TypeId)
18751878
return TypeIdPair.second;
1876-
auto It = TypeIdMap.insert({GlobalValue::getGUID(TypeId),
1877-
{TypeIdSaver.save(TypeId), TypeIdSummary()}});
1879+
auto It =
1880+
TypeIdMap.insert({GlobalValue::getGUIDAssumingExternalLinkage(TypeId),
1881+
{TypeIdSaver.save(TypeId), TypeIdSummary()}});
18781882
return It->second.second;
18791883
}
18801884

18811885
/// This returns either a pointer to the type id summary (if present in the
18821886
/// summary map) or null (if not present). This may be used when importing.
18831887
const TypeIdSummary *getTypeIdSummary(StringRef TypeId) const {
1884-
auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId));
1888+
auto TidIter = TypeIdMap.equal_range(
1889+
GlobalValue::getGUIDAssumingExternalLinkage(TypeId));
18851890
for (const auto &[GUID, TypeIdPair] : make_range(TidIter))
18861891
if (TypeIdPair.first == TypeId)
18871892
return &TypeIdPair.second;

llvm/include/llvm/IR/ModuleSummaryIndexYAML.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
314314
static void inputOne(IO &io, StringRef Key, TypeIdSummaryMapTy &V) {
315315
TypeIdSummary TId;
316316
io.mapRequired(Key.str().c_str(), TId);
317-
V.insert({GlobalValue::getGUID(Key), {Key, TId}});
317+
V.insert({GlobalValue::getGUIDAssumingExternalLinkage(Key), {Key, TId}});
318318
}
319319
static void output(IO &io, TypeIdSummaryMapTy &V) {
320320
for (auto &TidIter : V)

llvm/include/llvm/ProfileData/SampleProf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ class FunctionSamples {
12991299
static inline FunctionId getRepInFormat(StringRef Name) {
13001300
if (Name.empty() || !FunctionSamples::UseMD5)
13011301
return FunctionId(Name);
1302-
return FunctionId(Function::getGUID(Name));
1302+
return FunctionId(Function::getGUIDAssumingExternalLinkage(Name));
13031303
}
13041304

13051305
raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS);

llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ class PseudoProbeManager {
110110
}
111111

112112
const PseudoProbeDescriptor *getDesc(StringRef FProfileName) const {
113-
return getDesc(Function::getGUID(FProfileName));
113+
return getDesc(Function::getGUIDAssumingExternalLinkage(FProfileName));
114114
}
115115

116116
const PseudoProbeDescriptor *getDesc(const Function &F) const {
117-
return getDesc(Function::getGUID(FunctionSamples::getCanonicalFnName(F)));
117+
return getDesc(Function::getGUIDAssumingExternalLinkage(
118+
FunctionSamples::getCanonicalFnName(F)));
118119
}
119120

120121
bool profileIsHashMismatched(const PseudoProbeDescriptor &FuncDesc,

llvm/lib/Analysis/CtxProfAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ PreservedAnalyses AssignGUIDPass::run(Module &M, ModuleAnalysisManager &MAM) {
436436
GlobalValue::GUID AssignGUIDPass::getGUID(const Function &F) {
437437
if (F.isDeclaration()) {
438438
assert(GlobalValue::isExternalLinkage(F.getLinkage()));
439-
return GlobalValue::getGUID(F.getGlobalIdentifier());
439+
return F.getGUID();
440440
}
441441
auto *MD = F.getMetadata(GUIDMetadataName);
442442
assert(MD && "guid not found for defined function");

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ static void addIntrinsicToSummary(
222222
auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
223223
if (!TypeId)
224224
break;
225-
GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
225+
GlobalValue::GUID Guid =
226+
GlobalValue::getGUIDAssumingExternalLinkage(TypeId->getString());
226227

227228
// Produce a summary from type.test intrinsics. We only summarize type.test
228229
// intrinsics that are used other than by an llvm.assume intrinsic.
@@ -250,7 +251,8 @@ static void addIntrinsicToSummary(
250251
auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
251252
if (!TypeId)
252253
break;
253-
GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
254+
GlobalValue::GUID Guid =
255+
GlobalValue::getGUIDAssumingExternalLinkage(TypeId->getString());
254256

255257
SmallVector<DevirtCallSite, 4> DevirtCalls;
256258
SmallVector<Instruction *, 4> LoadedPtrs;
@@ -904,7 +906,8 @@ static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
904906

905907
// Set LiveRoot flag on entries matching the given value name.
906908
static void setLiveRoot(ModuleSummaryIndex &Index, StringRef Name) {
907-
if (ValueInfo VI = Index.getValueInfo(GlobalValue::getGUID(Name)))
909+
if (ValueInfo VI =
910+
Index.getValueInfo(GlobalValue::getGUIDAssumingExternalLinkage(Name)))
908911
for (const auto &Summary : VI.getSummaryList())
909912
Summary->setLive(true);
910913
}

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9055,7 +9055,7 @@ bool LLParser::parseTypeIdEntry(unsigned ID) {
90559055
for (auto TIDRef : FwdRefTIDs->second) {
90569056
assert(!*TIDRef.first &&
90579057
"Forward referenced type id GUID expected to be 0");
9058-
*TIDRef.first = GlobalValue::getGUID(Name);
9058+
*TIDRef.first = GlobalValue::getGUIDAssumingExternalLinkage(Name);
90599059
}
90609060
ForwardRefTypeIds.erase(FwdRefTIDs);
90619061
}
@@ -9160,7 +9160,7 @@ bool LLParser::parseTypeIdCompatibleVtableEntry(unsigned ID) {
91609160
for (auto TIDRef : FwdRefTIDs->second) {
91619161
assert(!*TIDRef.first &&
91629162
"Forward referenced type id GUID expected to be 0");
9163-
*TIDRef.first = GlobalValue::getGUID(Name);
9163+
*TIDRef.first = GlobalValue::getGUIDAssumingExternalLinkage(Name);
91649164
}
91659165
ForwardRefTypeIds.erase(FwdRefTIDs);
91669166
}
@@ -9476,7 +9476,7 @@ bool LLParser::addGlobalValueToIndex(
94769476
assert(
94779477
(!GlobalValue::isLocalLinkage(Linkage) || !SourceFileName.empty()) &&
94789478
"Need a source_filename to compute GUID for local");
9479-
GUID = GlobalValue::getGUID(
9479+
GUID = GlobalValue::getGUIDAssumingExternalLinkage(
94809480
GlobalValue::getGlobalIdentifier(Name, Linkage, SourceFileName));
94819481
VI = Index->getOrInsertValueInfo(GUID, Index->saveString(Name));
94829482
}

0 commit comments

Comments
 (0)