From 5e275525318b45a957c002d765d5392a0a9cbf2d Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Tue, 2 Sep 2025 13:52:05 +1000 Subject: [PATCH 01/30] Compute GUIDs once and store in metadata This allows us to keep GUIDs consistent across compilation phases which may change the name or linkage type. See https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801 --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 36 ++-------- llvm/include/llvm/Bitcode/BitcodeReader.h | 4 +- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 3 + llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h | 33 ++++++++-- llvm/include/llvm/IR/Module.h | 16 +++++ llvm/include/llvm/IR/ModuleSummaryIndex.h | 16 +++-- llvm/include/llvm/LTO/LTO.h | 17 +++++ .../llvm/Transforms/Utils/AssignGUID.h | 42 ++++++++++++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 44 ++----------- llvm/lib/AsmParser/LLParser.cpp | 12 +++- llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp | 1 + llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 66 ++++++++++++++----- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 47 ++++++++++++- llvm/lib/IR/Globals.cpp | 42 ++++++++++++ llvm/lib/LTO/LTO.cpp | 51 ++++++++------ llvm/lib/LTO/LTOBackend.cpp | 9 ++- llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 ++- llvm/lib/Transforms/IPO/FunctionImport.cpp | 60 +++++++++++------ .../Transforms/IPO/ThinLTOBitcodeWriter.cpp | 2 + .../lib/Transforms/IPO/WholeProgramDevirt.cpp | 7 ++ .../Instrumentation/PGOCtxProfFlattening.cpp | 4 +- .../Instrumentation/PGOCtxProfLowering.cpp | 3 +- .../Transforms/Scalar/JumpTableToSwitch.cpp | 5 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 31 +++++++++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +- llvm/lib/Transforms/Utils/CloneModule.cpp | 6 +- .../Transforms/Utils/FunctionImportUtils.cpp | 19 +++++- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- llvm/test/Assembler/index-value-order.ll | 9 ++- llvm/test/Bitcode/thinlto-alias.ll | 1 + ...allgraph-partial-sample-profile-summary.ll | 5 +- .../thinlto-function-summary-callgraph-pgo.ll | 1 + ...ction-summary-callgraph-profile-summary.ll | 5 +- ...ummary-callgraph-sample-profile-summary.ll | 5 +- .../thinlto-function-summary-callgraph.ll | 1 + .../thinlto-function-summary-refgraph.ll | 1 + llvm/test/Bitcode/thinlto-function-summary.ll | 1 + llvm/test/CodeGen/X86/fat-lto-section.ll | 2 +- llvm/test/Linker/funcimport2.ll | 2 +- llvm/test/Other/new-pm-O0-defaults.ll | 3 +- llvm/test/Other/new-pm-defaults.ll | 3 +- .../Other/new-pm-thinlto-prelink-defaults.ll | 3 +- .../new-pm-thinlto-prelink-pgo-defaults.ll | 3 +- ...w-pm-thinlto-prelink-samplepgo-defaults.ll | 1 + llvm/test/ThinLTO/AArch64/aarch64_inline.ll | 2 +- llvm/test/ThinLTO/X86/ctor-dtor-alias.ll | 4 +- llvm/test/ThinLTO/X86/ctor-dtor-alias2.ll | 4 +- llvm/test/ThinLTO/X86/deadstrip.ll | 8 +-- llvm/test/ThinLTO/X86/distributed_import.ll | 4 +- .../X86/funcattrs-prop-exported-internal.ll | 4 +- .../ThinLTO/X86/funcattrs-prop-unknown.ll | 6 +- llvm/test/ThinLTO/X86/globals-import.ll | 4 +- .../ThinLTO/X86/hidden-escaped-symbols-alt.ll | 2 +- .../ThinLTO/X86/hidden-escaped-symbols.ll | 2 +- llvm/test/ThinLTO/X86/import-ro-constant.ll | 2 +- .../ThinLTO/X86/index-const-prop-alias.ll | 2 +- llvm/test/ThinLTO/X86/index-const-prop.ll | 6 +- .../ThinLTO/X86/linkonce_resolution_comdat.ll | 16 ++--- llvm/test/ThinLTO/X86/memprof-dups.ll | 2 +- .../X86/memprof_callee_type_mismatch.ll | 2 +- .../ThinLTO/X86/memprof_imported_internal.ll | 2 +- .../ThinLTO/X86/memprof_imported_internal2.ll | 2 +- .../X86/prevailing_weak_globals_import.ll | 2 +- llvm/test/ThinLTO/X86/visibility-elf.ll | 6 +- llvm/test/ThinLTO/X86/visibility-macho.ll | 4 +- llvm/test/ThinLTO/X86/windows-vftable.ll | 4 +- llvm/test/ThinLTO/X86/writeonly.ll | 4 +- .../test/Transforms/AssignGUID/assign_guid.ll | 18 +++++ .../test/Transforms/EmbedBitcode/embed-wpd.ll | 2 +- llvm/test/Transforms/EmbedBitcode/embed.ll | 13 ++-- .../funcimport-debug-retained-nodes.ll | 3 +- .../Transforms/FunctionImport/funcimport.ll | 24 +++---- .../LowerTypeTests/cfi-icall-alias.ll | 2 +- .../thinlto_indirect_call_promotion.ll | 4 +- .../speculative-devirt-then-inliner.ll | 2 +- .../test/Transforms/SampleProfile/ctxsplit.ll | 8 +-- .../ThinLTOBitcodeWriter/split-internal2.ll | 6 +- .../ThinLTOBitcodeWriter/split-vfunc.ll | 14 ++-- .../ThinLTOBitcodeWriter/unsplittable.ll | 2 +- .../branch-funnel-profile.ll | 44 ++++++------- .../WholeProgramDevirt/export-single-impl.ll | 4 +- .../WholeProgramDevirt/export-vcp.ll | 6 +- llvm/tools/llvm-link/llvm-link.cpp | 4 +- llvm/tools/opt/NewPMDriver.cpp | 8 +++ 87 files changed, 605 insertions(+), 296 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp create mode 100644 llvm/test/Transforms/AssignGUID/assign_guid.ll diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index 5c9823b0f6cc1..90b1d3fc0a688 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -47,9 +47,6 @@ class PGOContextualProfile { // we'll need when we maintain the profiles during IPO transformations. std::map FuncInfo; - /// Get the GUID of this Function if it's defined in this module. - LLVM_ABI GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -68,9 +65,7 @@ class PGOContextualProfile { LLVM_ABI bool isInSpecializedModule() const; - bool isFunctionKnown(const Function &F) const { - return getDefinedFunctionGUID(F) != 0; - } + bool isFunctionKnown(const Function &F) const { return !F.isDeclaration(); } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -81,22 +76,22 @@ class PGOContextualProfile { uint32_t getNumCounters(const Function &F) const { assert(isFunctionKnown(F)); - return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex; + return FuncInfo.find(F.getGUID())->second.NextCounterIndex; } uint32_t getNumCallsites(const Function &F) const { assert(isFunctionKnown(F)); - return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex; + return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex; } uint32_t allocateNextCounterIndex(const Function &F) { assert(isFunctionKnown(F)); - return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++; + return FuncInfo.find(F.getGUID())->second.NextCounterIndex++; } uint32_t allocateNextCallsiteIndex(const Function &F) { assert(isFunctionKnown(F)); - return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++; + return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++; } using ConstVisitor = function_ref; @@ -188,26 +183,5 @@ class ProfileAnnotator { LLVM_ABI ~ProfileAnnotator(); }; -/// Assign a GUID to functions as metadata. GUID calculation takes linkage into -/// account, which may change especially through and after thinlto. By -/// pre-computing and assigning as metadata, this mechanism is resilient to such -/// changes (as well as name changes e.g. suffix ".llvm." additions). - -// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early in -// the pass pipeline, associate it with any Global Value, and then use it for -// PGO and ThinLTO. -// At that point, this should be moved elsewhere. -class AssignGUIDPass : public PassInfoMixin { -public: - explicit AssignGUIDPass() = default; - - /// Assign a GUID *if* one is not already assign, as a function metadata named - /// `GUIDMetadataName`. - LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - LLVM_ABI static const char *GUIDMetadataName; - // This should become GlobalValue::getGUID - LLVM_ABI static uint64_t getGUID(const Function &F); -}; - } // namespace llvm #endif // LLVM_ANALYSIS_CTXPROFANALYSIS_H diff --git a/llvm/include/llvm/Bitcode/BitcodeReader.h b/llvm/include/llvm/Bitcode/BitcodeReader.h index 772ca82019278..b7cab51857f0b 100644 --- a/llvm/include/llvm/Bitcode/BitcodeReader.h +++ b/llvm/include/llvm/Bitcode/BitcodeReader.h @@ -17,6 +17,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Bitstream/BitCodeEnums.h" #include "llvm/IR/GlobalValue.h" +#include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" @@ -165,7 +166,8 @@ struct ParserCallbacks { /// into CombinedIndex. LLVM_ABI Error readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, - std::function IsPrevailing = nullptr); + std::function IsPrevailing = nullptr, + std::function OnValueInfo = nullptr); }; struct BitcodeFileContents { diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 9162754bbfe1a..2574823877622 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -120,6 +120,9 @@ enum ModuleCodes { // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility] MODULE_CODE_IFUNC = 18, + + // GUIDLIST: [n x i64] + MODULE_CODE_GUIDLIST = 19, }; /// PARAMATTR blocks have code for defining a parameter attribute set. diff --git a/llvm/include/llvm/IR/FixedMetadataKinds.def b/llvm/include/llvm/IR/FixedMetadataKinds.def index 6d74aff4ae250..0e2d928ffbd80 100644 --- a/llvm/include/llvm/IR/FixedMetadataKinds.def +++ b/llvm/include/llvm/IR/FixedMetadataKinds.def @@ -61,3 +61,4 @@ LLVM_FIXED_MD_KIND(MD_implicit_ref, "implicit.ref", 46) LLVM_FIXED_MD_KIND(MD_nofpclass, "nofpclass", 47) LLVM_FIXED_MD_KIND(MD_call_target, "call_target", 48) LLVM_FIXED_MD_KIND(MD_inline_history, "inline_history", 49) +LLVM_FIXED_MD_KIND(MD_unique_id, "guid", 50) diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h index 83e695cdd27d9..acc836e1974d4 100644 --- a/llvm/include/llvm/IR/GlobalValue.h +++ b/llvm/include/llvm/IR/GlobalValue.h @@ -589,17 +589,40 @@ class GlobalValue : public Constant { /// used as the key for a global lookup (e.g. profile or ThinLTO). LLVM_ABI std::string getGlobalIdentifier() const; + /// Assign a GUID to this value based on its current name and linkage. + /// This GUID will remain the same even if those change. This method is + /// idempotent -- if a GUID has already been assigned, calling it again + /// will do nothing. + /// + /// This is private (exposed only to \c AssignGUIDPass), as users don't need + /// to call it. GUIDs are assigned only by \c AssignGUIDPass. The pass + /// pipeline should be set up such that GUIDs are always available when + /// needed. If not, the GUID assignment pass should be moved (or run again) + /// such that they are. + void assignGUID(); + + // assignGUID needs to be accessible from AssignGUIDPass, which is called + // early in the pipeline to make GUIDs available to later passes. But we'd + // rather not expose it publicly, as no-one else should call it. + friend class AssignGUIDPass; + 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. LLVM_ABI static GUID getGUIDAssumingExternalLinkage(StringRef GlobalName); - /// Return a 64-bit global unique ID constructed from global value name - /// (i.e. returned by getGlobalIdentifier()). - GUID getGUID() const { - return getGUIDAssumingExternalLinkage(getGlobalIdentifier()); - } + /// Return a 64-bit global unique ID for this value. It is based on the + /// "original" name and linkage of this value (i.e. whenever its GUID was + /// assigned). This might not match the current name and linkage. + GUID getGUID() const; + + /// Return the GUID for this value if it has been assigned, nullopt + /// otherwise. This should only need to be used in some exceptional + /// situations. If possible whatever code needs access to a GUID should + /// be set up to run after AssignGUIDPass, in which case it will always + /// be available. + std::optional getGUIDIfAssigned() const; /// @name Materialization /// Materialization is used to construct functions only as they're needed. diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h index 7156a83c9f3cc..b4a13128dd9f7 100644 --- a/llvm/include/llvm/IR/Module.h +++ b/llvm/include/llvm/IR/Module.h @@ -32,6 +32,7 @@ #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Debug.h" #include "llvm/TargetParser/Triple.h" #include #include @@ -576,7 +577,22 @@ class LLVM_ABI Module { // Use global_size() to get the total number of global variables. // Use globals() to get the range of all global variables. + std::optional getGUID(const Value* V) const { + const auto It = ValueToGUIDMap.find(V); + if (It == ValueToGUIDMap.end()) { + return {}; + } + + return It->getSecond(); + } + + void insertGUID(const Value* V, GlobalValue::GUID GUID) { + ValueToGUIDMap[V] = GUID; + } + private: + DenseMap ValueToGUIDMap; + /// @} /// @name Direct access to the globals list, functions list, and symbol table /// @{ diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h index 6859b9a2f46e6..be204e8a52aa8 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -29,6 +29,7 @@ #include "llvm/IR/Module.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/InterleavedRange.h" #include "llvm/Support/ScaledNumber.h" #include "llvm/Support/StringSaver.h" @@ -599,8 +600,8 @@ class GlobalValueSummary { bool wasPromoted() const { return Flags.Promoted; } void promote() { - assert(GlobalValue::isLocalLinkage(linkage()) && - "unexpected (re-)promotion of non-local symbol"); + assert(!GlobalValue::isExternalLinkage(linkage()) && + "unexpected (re-)promotion of external symbol"); assert(!Flags.Promoted); Flags.Promoted = true; Flags.Linkage = GlobalValue::LinkageTypes::ExternalLinkage; @@ -1769,14 +1770,19 @@ class ModuleSummaryIndex { return ValueInfo(HaveGVs, VP); } - /// Return a ValueInfo for \p GV and mark it as belonging to GV. - ValueInfo getOrInsertValueInfo(const GlobalValue *GV) { + /// Return a ValueInfo for \p GV with GUID \p GUID and mark it as belonging to GV. + ValueInfo getOrInsertValueInfo(const GlobalValue *GV, GlobalValue::GUID GUID) { assert(HaveGVs); - auto VP = getOrInsertValuePtr(GV->getGUID()); + auto VP = getOrInsertValuePtr(GUID); VP->second.U.GV = GV; return ValueInfo(HaveGVs, VP); } + /// Return a ValueInfo for \p GV and mark it as belonging to GV. + ValueInfo getOrInsertValueInfo(const GlobalValue *GV) { + return getOrInsertValueInfo(GV, GV->getGUID()); + } + /// Return the GUID for \p OriginalId in the OidGuidMap. GlobalValue::GUID getGUIDFromOriginalID(GlobalValue::GUID OriginalID) const { const auto I = OidGuidMap.find(OriginalID); diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h index aba2661e81c47..d3ea76db103b7 100644 --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -590,6 +590,23 @@ class LTO { /// LTO backend. unsigned Partition = Unknown; + // FIXME: make private, and also make GlobalResolution a class, it has been + // becoming more than just a data bag. + GlobalValue::GUID GUID = 0; + + void setGUID(GlobalValue::GUID G) { + assert(G); + assert(!GUID || GUID == G); + GUID = G; + } + + GlobalValue::GUID getGUID() const { + return GUID ? GUID + : GlobalValue::getGUIDAssumingExternalLinkage( + GlobalValue::getGlobalIdentifier( + IRName, GlobalValue::LinkageTypes::ExternalLinkage, + "")); + } /// Special partition numbers. enum : unsigned { /// A partition number has not yet been assigned to this global. diff --git a/llvm/include/llvm/Transforms/Utils/AssignGUID.h b/llvm/include/llvm/Transforms/Utils/AssignGUID.h new file mode 100644 index 0000000000000..0abd450d5a522 --- /dev/null +++ b/llvm/include/llvm/Transforms/Utils/AssignGUID.h @@ -0,0 +1,42 @@ +//===-- AssignGUID.h - Unique identifier assignment pass --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file provides a pass which assigns a a GUID (globally unique identifier) +// to every GlobalValue in the module, according to its current name, linkage, +// and originating file. This way we have a consistent identifier even when +// these inputs to the GUID change (for instance, after externalising a global +// in ThinLTO). +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TRANSFORMS_UTILS_ASSIGNGUID_H +#define LLVM_TRANSFORMS_UTILS_ASSIGNGUID_H + +#include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" +#include "llvm/Support/Debug.h" + +namespace llvm { + +class AssignGUIDPass : public PassInfoMixin { +public: + AssignGUIDPass() = default; + + static void runOnModule(Module &M); + + PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) { + AssignGUIDPass::runOnModule(M); + return PreservedAnalyses::all(); + } + + static bool isRequired() { return true; } +}; + +} // end namespace llvm + +#endif // LLVM_TRANSFORMS_UTILS_ASSIGNGUID_H \ No newline at end of file diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp index c4abec02e765a..d4c00e4090220 100644 --- a/llvm/lib/Analysis/CtxProfAnalysis.cpp +++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp @@ -50,9 +50,7 @@ static cl::opt ForceIsInSpecializedModule( "ctx-profile-force-is-specialized", cl::init(false), cl::desc("Treat the given module as-if it were containing the " "post-thinlink module containing the root")); - -const char *AssignGUIDPass::GUIDMetadataName = "guid"; - + class ProfileAnnotatorImpl final { friend class ProfileAnnotator; class BBInfo; @@ -420,33 +418,6 @@ bool ProfileAnnotator::getOutgoingBranchWeights( return MaxCount > 0; } -PreservedAnalyses AssignGUIDPass::run(Module &M, ModuleAnalysisManager &MAM) { - for (auto &F : M.functions()) { - if (F.isDeclaration()) - continue; - if (F.getMetadata(GUIDMetadataName)) - continue; - const GlobalValue::GUID GUID = F.getGUID(); - F.setMetadata(GUIDMetadataName, - MDNode::get(M.getContext(), - {ConstantAsMetadata::get(ConstantInt::get( - Type::getInt64Ty(M.getContext()), GUID))})); - } - return PreservedAnalyses::none(); -} - -GlobalValue::GUID AssignGUIDPass::getGUID(const Function &F) { - if (F.isDeclaration()) { - assert(GlobalValue::isExternalLinkage(F.getLinkage())); - return F.getGUID(); - } - auto *MD = F.getMetadata(GUIDMetadataName); - assert(MD && "guid not found for defined function"); - return cast(cast(MD->getOperand(0)) - ->getValue() - ->stripPointerCasts()) - ->getZExtValue(); -} AnalysisKey CtxProfAnalysis::Key; CtxProfAnalysis::CtxProfAnalysis(std::optional Profile) @@ -515,7 +486,7 @@ PGOContextualProfile CtxProfAnalysis::run(Module &M, for (const auto &F : M) { if (F.isDeclaration()) continue; - auto GUID = AssignGUIDPass::getGUID(F); + auto GUID = F.getGUID(); assert(GUID && "guid not found for defined function"); const auto &Entry = F.begin(); uint32_t MaxCounters = 0; // we expect at least a counter. @@ -549,13 +520,6 @@ PGOContextualProfile CtxProfAnalysis::run(Module &M, return Result; } -GlobalValue::GUID -PGOContextualProfile::getDefinedFunctionGUID(const Function &F) const { - if (auto It = FuncInfo.find(AssignGUIDPass::getGUID(F)); It != FuncInfo.end()) - return It->first; - return 0; -} - CtxProfAnalysisPrinterPass::CtxProfAnalysisPrinterPass(raw_ostream &OS) : OS(OS), Mode(PrintLevel) {} @@ -671,7 +635,7 @@ bool PGOContextualProfile::isInSpecializedModule() const { void PGOContextualProfile::update(Visitor V, const Function &F) { assert(isFunctionKnown(F)); - GlobalValue::GUID G = getDefinedFunctionGUID(F); + GlobalValue::GUID G = F.getGUID(); for (auto *Node = FuncInfo.find(G)->second.Index.Next; Node; Node = Node->Next) V(*reinterpret_cast(Node)); @@ -682,7 +646,7 @@ void PGOContextualProfile::visit(ConstVisitor V, const Function *F) const { return preorderVisit(Profiles.Contexts, V); assert(isFunctionKnown(*F)); - GlobalValue::GUID G = getDefinedFunctionGUID(*F); + GlobalValue::GUID G = F->getGUID(); for (const auto *Node = FuncInfo.find(G)->second.Index.Next; Node; Node = Node->Next) V(*reinterpret_cast(Node)); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 917aecb47590d..6b4fd41594cb4 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1064,8 +1064,9 @@ bool LLParser::skipModuleSummaryEntry() { // support is in place we will look for the tokens corresponding to the // expected tags. if (Lex.getKind() != lltok::kw_gv && Lex.getKind() != lltok::kw_module && - Lex.getKind() != lltok::kw_typeid && Lex.getKind() != lltok::kw_flags && - Lex.getKind() != lltok::kw_blockcount) + Lex.getKind() != lltok::kw_typeid && + Lex.getKind() != lltok::kw_typeidCompatibleVTable && + Lex.getKind() != lltok::kw_flags && Lex.getKind() != lltok::kw_blockcount) return tokError( "Expected 'gv', 'module', 'typeid', 'flags' or 'blockcount' at the " "start of summary entry"); @@ -9876,7 +9877,12 @@ bool LLParser::addGlobalValueToIndex( if (!GV) return error(Loc, "Reference to undefined global \"" + Name + "\""); - VI = Index->getOrInsertValueInfo(GV); + // Be a little lenient here, to accomodate older files without GUIDs + // already computed and assigned as metadata. + auto MaybeGUID = GV->getGUIDIfAssigned(); + GUID = MaybeGUID ? *MaybeGUID : GlobalValue::getGUIDAssumingExternalLinkage(GV->getName()); + + VI = Index->getOrInsertValueInfo(GV, GUID); } else { assert( (!GlobalValue::isLocalLinkage(Linkage) || !SourceFileName.empty()) && diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp index 911ec7501eb8b..6574ab7a93c58 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp @@ -142,6 +142,7 @@ GetCodeName(unsigned CodeID, unsigned BlockID, STRINGIFY_CODE(MODULE_CODE, METADATA_VALUES_UNUSED) STRINGIFY_CODE(MODULE_CODE, SOURCE_FILENAME) STRINGIFY_CODE(MODULE_CODE, HASH) + STRINGIFY_CODE(MODULE_CODE, GUIDLIST) } case bitc::IDENTIFICATION_BLOCK_ID: switch (CodeID) { diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index e01cf501b8841..f7a64037759cc 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -696,6 +696,9 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer { std::optional ValueTypeCallback; + /// A list of GUIDs defined by this module. Indexed by ValueID. + std::vector GUIDList; + public: BitcodeReader(BitstreamCursor Stream, StringRef Strtab, StringRef ProducerIdentification, LLVMContext &Context); @@ -974,9 +977,10 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// Callback to ask whether a symbol is the prevailing copy when invoked /// during combined index building. - std::function IsPrevailing; + std::function IsPrevailing = nullptr; + std::function OnValueInfo = nullptr; - /// Saves the stack ids from the STACK_IDS record to consult when adding stack + /// Saves the stack ids from the STACK_IDS record to consult when adding /// ids from the lists in the callsite and alloc entries to the index. std::vector StackIds; @@ -989,11 +993,15 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// list and used to avoid repeated hash lookups. std::vector StackIdToIndex; + /// A list of GUIDs defined by this module. Indexed by ValueID. + std::vector DefinedGUIDs; + public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, StringRef ModulePath, - std::function IsPrevailing = nullptr); + std::function IsPrevailing = nullptr, + std::function OnValueInfo = nullptr); Error parseModule(); @@ -4096,6 +4104,14 @@ Error BitcodeReader::globalCleanup() { TheModule->insertGlobalVariable(Pair.second); } + for (size_t ValueID = 0; ValueID < GUIDList.size(); ValueID++) { + const auto GUID = GUIDList[ValueID]; + if (GUID == 0) continue; + + const auto* Value = ValueList[ValueID]; + TheModule->insertGUID(Value, GUID); + } + // Force deallocation of memory for these vectors to favor the client that // want lazy deserialization. std::vector>().swap(GlobalInits); @@ -4899,6 +4915,10 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit, // historically always the start of the regular bitcode header. VSTOffset = Record[0] - 1; break; + // MODULE_CODE_GUIDLIST: [i64 x N] + case bitc::MODULE_CODE_GUIDLIST: + llvm::append_range(GUIDList, Record); + break; /// MODULE_CODE_SOURCE_FILENAME: [namechar x N] case bitc::MODULE_CODE_SOURCE_FILENAME: SmallString<128> ValueName; @@ -4909,6 +4929,7 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit, } Record.clear(); } + this->ValueTypeCallback = std::nullopt; return Error::success(); } @@ -7280,9 +7301,11 @@ std::vector BitcodeReader::getIdentifiedStructTypes() const { ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader( BitstreamCursor Cursor, StringRef Strtab, ModuleSummaryIndex &TheIndex, - StringRef ModulePath, std::function IsPrevailing) + StringRef ModulePath, std::function IsPrevailing, + std::function OnValueInfo) : BitcodeReaderBase(std::move(Cursor), Strtab), TheIndex(TheIndex), - ModulePath(ModulePath), IsPrevailing(IsPrevailing) {} + ModulePath(ModulePath), IsPrevailing(IsPrevailing), + OnValueInfo(OnValueInfo) {} void ModuleSummaryIndexBitcodeReader::addThisModule() { TheIndex.addModule(ModulePath); @@ -7310,23 +7333,27 @@ ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) { void ModuleSummaryIndexBitcodeReader::setValueGUID( uint64_t ValueID, StringRef ValueName, GlobalValue::LinkageTypes Linkage, StringRef SourceFileName) { - std::string GlobalId = - GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName); - auto ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage(GlobalId); + GlobalValue::GUID ValueGUID = 0; + if (ValueID < DefinedGUIDs.size()) + ValueGUID = DefinedGUIDs[ValueID]; + if (ValueGUID == 0) + ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage( + GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName)); + auto OriginalNameID = ValueGUID; if (GlobalValue::isLocalLinkage(Linkage)) OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName); if (PrintSummaryGUIDs) - dbgs() << "GUID " << ValueGUID << "(" << OriginalNameID << ") is " - << ValueName << "\n"; + dbgs() << "GUID " << ValueGUID << "(" << OriginalNameID << ") is " << ValueName << "\n"; // UseStrtab is false for legacy summary formats and value names are // created on stack. In that case we save the name in a string saver in // the index so that the value name can be recorded. - ValueIdToValueInfoMap[ValueID] = std::make_pair( - TheIndex.getOrInsertValueInfo( - ValueGUID, UseStrtab ? ValueName : TheIndex.saveString(ValueName)), - OriginalNameID); + auto VI = TheIndex.getOrInsertValueInfo( + ValueGUID, UseStrtab ? ValueName : TheIndex.saveString(ValueName)); + ValueIdToValueInfoMap[ValueID] = std::make_pair(VI, OriginalNameID); + if (OnValueInfo) + OnValueInfo(VI); } // Specialized value symbol table parser used when reading module index @@ -7535,6 +7562,10 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() { // was historically always the start of the regular bitcode header. VSTOffset = Record[0] - 1; break; + // MODULE_CODE_GUIDLIST: [i64 x N] + case bitc::MODULE_CODE_GUIDLIST: + llvm::append_range(DefinedGUIDs, Record); + break; // v1 GLOBALVAR: [pointer type, isconst, initid, linkage, ...] // v1 FUNCTION: [type, callingconv, isproto, linkage, ...] // v1 ALIAS: [alias type, addrspace, aliasee val#, linkage, ...] @@ -7931,7 +7962,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { // and kept). auto LT = (GlobalValue::LinkageTypes)Flags.Linkage; bool IsPrevailingSym = !IsPrevailing || GlobalValue::isLocalLinkage(LT) || - IsPrevailing(VI.getGUID()); + IsPrevailing(VI.name()); // If this is not the prevailing copy, and the records are in the "old" // order (preceding), clear them now. They should already be empty in @@ -8747,13 +8778,14 @@ BitcodeModule::getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, // regular LTO modules). Error BitcodeModule::readSummary( ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, - std::function IsPrevailing) { + std::function IsPrevailing, + std::function OnValueInfo) { BitstreamCursor Stream(Buffer); if (Error JumpFailed = Stream.JumpToBit(ModuleBit)) return JumpFailed; ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex, - ModulePath, IsPrevailing); + ModulePath, IsPrevailing, OnValueInfo); return R.parseModule(); } diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 71d5a8bc98a4b..c8cd0919cb24a 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -254,6 +254,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1604,6 +1605,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4618,12 +4621,21 @@ void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord( /*WriteContextSizeInfoIndex*/ true, CallStackPos, CallStackCount); } +static GlobalValue::GUID getOrComputeGUID(const GlobalValue& V) { + auto MaybeGUID = V.getGUIDIfAssigned(); + return MaybeGUID ? *MaybeGUID : GlobalValue::getGUIDAssumingExternalLinkage(V.getName()); +} + // Collect the global value references in the given variable's initializer, // and emit them in a summary record. void ModuleBitcodeWriterBase::writeModuleLevelReferences( const GlobalVariable &V, SmallVector &NameVals, unsigned FSModRefsAbbrev, unsigned FSModVTableRefsAbbrev) { - auto VI = Index->getValueInfo(V.getGUID()); + // Be a little lenient here, to accomodate older files without GUIDs + // already computed and assigned as metadata. + GlobalValue::GUID GUID = getOrComputeGUID(V); + + auto VI = Index->getValueInfo(GUID); if (!VI || VI.getSummaryList().empty()) { // Only declarations should not have a summary (a declaration might however // have a summary if the def was in module level asm). @@ -4836,7 +4848,11 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { if (!F.hasName()) report_fatal_error("Unexpected anonymous function when writing summary"); - ValueInfo VI = Index->getValueInfo(F.getGUID()); + // Be a little lenient here, to accomodate older files without GUIDs + // already computed and assigned as metadata. + GlobalValue::GUID GUID = getOrComputeGUID(F); + + ValueInfo VI = Index->getValueInfo(GUID); if (!VI || VI.getSummaryList().empty()) { // Only declarations should not have a summary (a declaration might // however have a summary if the def was in module level asm). @@ -4868,7 +4884,9 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { if (!F.hasName()) report_fatal_error("Unexpected anonymous function when writing summary"); - ValueInfo VI = Index->getValueInfo(F.getGUID()); + GlobalValue::GUID GUID = getOrComputeGUID(F); + + ValueInfo VI = Index->getValueInfo(GUID); if (!VI || VI.getSummaryList().empty()) { // Only declarations should not have a summary (a declaration might // however have a summary if the def was in module level asm). @@ -4920,6 +4938,27 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.ExitBlock(); } +void ModuleBitcodeWriterBase::writeGUIDList() { + const ValueEnumerator::ValueList &Vals = VE.getValues(); + const size_t Max = Vals.size(); + + std::vector GUIDs(Max, 0); + for (const GlobalValue &GV : M.global_values()) { + GlobalValue::GUID GUID; + if (auto MaybeGUID = GV.getGUIDIfAssigned(); MaybeGUID) { + GUID = *MaybeGUID; + } else { + GUID = 0; + } + if (GUID == 0) continue; + + const auto ValueID = VE.getValueID(&GV); + GUIDs[ValueID] = GUID; + } + + Stream.EmitRecord(bitc::MODULE_CODE_GUIDLIST, GUIDs); +} + /// Emit the combined summary section into the combined index file. void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4); @@ -5712,6 +5751,8 @@ void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { // GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage] diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 1bd7e9605ffc7..38263675091ff 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -81,6 +81,48 @@ GlobalValue::getGUIDAssumingExternalLinkage(StringRef GlobalIdentifier) { return MD5Hash(GlobalIdentifier); } +void GlobalValue::assignGUID() { + if (getMetadata(LLVMContext::MD_unique_id) != nullptr) + return; + + const GUID G = + GlobalValue::getGUIDAssumingExternalLinkage(getGlobalIdentifier()); + setMetadata( + LLVMContext::MD_unique_id, + MDNode::get(getContext(), {ConstantAsMetadata::get(ConstantInt::get( + Type::getInt64Ty(getContext()), G))})); +} + +GlobalValue::GUID GlobalValue::getGUID() const { + auto MaybeGUID = getGUIDIfAssigned(); + assert(MaybeGUID.has_value() && + "GUID was not assigned before calling GetGUID()"); + return *MaybeGUID; +} + +std::optional GlobalValue::getGUIDIfAssigned() const { + // First check the metadata. + auto *MD = getMetadata(LLVMContext::MD_unique_id); + if (MD != nullptr) + return cast(cast(MD->getOperand(0)) + ->getValue() + ->stripPointerCasts()) + ->getZExtValue(); + + // Handle a few special cases where we just want to compute it based on the + // current properties. + if (isDeclaration() || isa(this) || getName().starts_with("llvm.")) { + return GlobalValue::getGUIDAssumingExternalLinkage(getGlobalIdentifier()); + } + + // Otherwise we try to look it up in the module, for cases where we've read + // the GUID table but not the metadata. + if (getParent() == nullptr) return {}; + const Module &M = *getParent(); + + return M.getGUID(this); +} + void GlobalValue::removeFromParent() { switch (getValueID()) { #define HANDLE_GLOBAL_VALUE(NAME) \ diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 95faf3484c456..d872f44a1f1a1 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -27,6 +27,7 @@ #include "llvm/Config/llvm-config.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/DiagnosticPrinter.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMRemarkStreamer.h" #include "llvm/IR/LegacyPassManager.h" @@ -758,6 +759,7 @@ void LTO::addModuleToGlobalRes(ArrayRef Syms, // FIXME: instead of this check, it would be desirable to compute GUIDs // based on mangled name, but this requires an access to the Target Triple // and would be relatively invasive on the codebase. + // FIXME: use the GUID member of GlobalRes. if (GlobalRes.IRName != Sym.getIRName()) { GlobalRes.Partition = GlobalResolution::External; GlobalRes.VisibleOutsideSummary = true; @@ -1175,21 +1177,27 @@ LTO::addThinLTO(BitcodeModule BM, ArrayRef Syms, llvm::TimeTraceScope timeScope("LTO add thin LTO"); const auto BMID = BM.getModuleIdentifier(); ArrayRef ResTmp = Res; + DenseSet Prevailing; for (const InputFile::Symbol &Sym : Syms) { assert(!ResTmp.empty()); const SymbolResolution &R = ResTmp.consume_front(); - - if (!Sym.getIRName().empty() && R.Prevailing) { - auto GUID = GlobalValue::getGUIDAssumingExternalLinkage( - GlobalValue::getGlobalIdentifier(Sym.getIRName(), - GlobalValue::ExternalLinkage, "")); - ThinLTO.setPrevailingModuleForGUID(GUID, BMID); - } + if (!Sym.getIRName().empty() && R.Prevailing) + Prevailing.insert(Sym.getIRName()); } + StringMap IRSpecifiedGUIDs; if (Error Err = BM.readSummary( - ThinLTO.CombinedIndex, BMID, [&](GlobalValue::GUID GUID) { - return ThinLTO.isPrevailingModuleForGUID(GUID, BMID); + ThinLTO.CombinedIndex, BMID, + [&](StringRef Name) { return (Prevailing.count(Name) > 0); }, + [&](ValueInfo VI) { + auto IT = IRSpecifiedGUIDs.insert({VI.name(), VI.getGUID()}); + (void)IT; + assert(IT.second); + if (auto GRIt = GlobalResolutions->find(VI.name()); + GRIt != GlobalResolutions->end() && + Prevailing.count(VI.name())) { + GRIt->second.setGUID(VI.getGUID()); + } })) return Err; LLVM_DEBUG(dbgs() << "Module " << BMID << "\n"); @@ -1197,28 +1205,31 @@ LTO::addThinLTO(BitcodeModule BM, ArrayRef Syms, for (const InputFile::Symbol &Sym : Syms) { assert(!Res.empty()); const SymbolResolution &R = Res.consume_front(); - + auto GUIDIter = IRSpecifiedGUIDs.find(Sym.getIRName()); + auto GUID = + GUIDIter == IRSpecifiedGUIDs.end() + ? GlobalValue::getGUIDAssumingExternalLinkage( + GlobalValue::getGlobalIdentifier( + Sym.getIRName(), GlobalValue::ExternalLinkage, "")) + : GUIDIter->second; if (!Sym.getIRName().empty() && (R.Prevailing || R.FinalDefinitionInLinkageUnit)) { - auto GUID = GlobalValue::getGUIDAssumingExternalLinkage( - GlobalValue::getGlobalIdentifier(Sym.getIRName(), - GlobalValue::ExternalLinkage, "")); if (R.Prevailing) { - assert(ThinLTO.isPrevailingModuleForGUID(GUID, BMID)); - + ThinLTO.setPrevailingModuleForGUID(GUID, BMID); // For linker redefined symbols (via --wrap or --defsym) we want to // switch the linkage to `weak` to prevent IPOs from happening. // Find the summary in the module for this very GV and record the new // linkage so that we can switch it when we import the GV. if (R.LinkerRedefined) - if (auto S = ThinLTO.CombinedIndex.findSummaryInModule(GUID, BMID)) + if (auto *S = ThinLTO.CombinedIndex.findSummaryInModule( + GUID, BMID)) S->setLinkage(GlobalValue::WeakAnyLinkage); } // If the linker resolved the symbol to a local definition then mark it // as local in the summary for the module we are adding. if (R.FinalDefinitionInLinkageUnit) { - if (auto S = ThinLTO.CombinedIndex.findSummaryInModule(GUID, BMID)) { + if (auto *S = ThinLTO.CombinedIndex.findSummaryInModule(GUID, BMID)) { S->setDSOLocal(true); } } @@ -1313,8 +1324,7 @@ Error LTO::run(AddStreamFn AddStream, FileCache Cache) { if (Res.second.IRName.empty()) continue; - GlobalValue::GUID GUID = GlobalValue::getGUIDAssumingExternalLinkage( - GlobalValue::dropLLVMManglingEscape(Res.second.IRName)); + GlobalValue::GUID GUID = Res.second.getGUID(); if (Res.second.VisibleOutsideSummary && Res.second.Prevailing) GUIDPreservedSymbols.insert(GUID); @@ -2136,8 +2146,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, if (Res.second.Partition != GlobalResolution::External || !Res.second.isPrevailingIRSymbol()) continue; - auto GUID = GlobalValue::getGUIDAssumingExternalLinkage( - GlobalValue::dropLLVMManglingEscape(Res.second.IRName)); + auto GUID = Res.second.getGUID(); // Mark exported unless index-based analysis determined it to be dead. if (ThinLTO.CombinedIndex.isGUIDLive(GUID)) ExportedGUIDs.insert(GUID); diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 16a42e526eb8a..6ff723ed6945d 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -625,12 +625,17 @@ static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals, const ModuleSummaryIndex &Index) { llvm::TimeTraceScope timeScope("Drop dead symbols"); std::vector DeadGVs; - for (auto &GV : Mod.global_values()) - if (GlobalValueSummary *GVS = DefinedGlobals.lookup(GV.getGUID())) + + for (auto &GV : Mod.global_values()) { + auto GUID = Mod.getGUID(&GV); + if (!GUID) continue; + + if (GlobalValueSummary *GVS = DefinedGlobals.lookup(*GUID)) if (!Index.isGlobalValueLive(GVS)) { DeadGVs.push_back(&GV); convertToDeclaration(GV); } + } // Now that all dead bodies have been dropped, delete the actual objects // themselves when possible. diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 2751961e684d2..a5365dc554bf8 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -346,6 +346,7 @@ #include "llvm/Transforms/Scalar/TailRecursionElimination.h" #include "llvm/Transforms/Scalar/WarnMissedTransforms.h" #include "llvm/Transforms/Utils/AddDiscriminators.h" +#include "llvm/Transforms/Utils/AssignGUID.h" #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" #include "llvm/Transforms/Utils/BreakCriticalEdges.h" #include "llvm/Transforms/Utils/CanonicalizeAliases.h" diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index f017419791a85..11c171f51de74 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -137,6 +137,7 @@ #include "llvm/Transforms/Scalar/TailRecursionElimination.h" #include "llvm/Transforms/Scalar/WarnMissedTransforms.h" #include "llvm/Transforms/Utils/AddDiscriminators.h" +#include "llvm/Transforms/Utils/AssignGUID.h" #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" #include "llvm/Transforms/Utils/CanonicalizeAliases.h" #include "llvm/Transforms/Utils/CountVisits.h" @@ -808,6 +809,7 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level, void PassBuilder::addRequiredLTOPreLinkPasses(ModulePassManager &MPM) { MPM.addPass(CanonicalizeAliasesPass()); MPM.addPass(NameAnonGlobalPass()); + MPM.addPass(AssignGUIDPass()); } void PassBuilder::addPreInlinerPasses(ModulePassManager &MPM, @@ -1065,6 +1067,7 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel Level, if (!UseCtxProfile.empty() && Phase == ThinOrFullLTOPhase::ThinLTOPostLink) { MPM.addPass(GlobalOptPass()); MPM.addPass(GlobalDCEPass()); + MPM.addPass(AssignGUIDPass()); MPM.addPass(PGOCtxProfFlatteningPass(/*IsPreThinlink=*/false)); } @@ -1254,10 +1257,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, // In pre-link, we just want the instrumented IR. We use the contextual // profile in the post-thinlink phase. // The instrumentation will be removed in post-thinlink after IPO. - // FIXME(mtrofin): move AssignGUIDPass if there is agreement to use this - // mechanism for GUIDs. - MPM.addPass(AssignGUIDPass()); if (IsCtxProfUse) { + MPM.addPass(AssignGUIDPass()); MPM.addPass(PGOCtxProfFlatteningPass(/*IsPreThinlink=*/true)); return MPM; } @@ -1683,6 +1684,8 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level, if (PTO.DevirtualizeSpeculatively && LTOPhase == ThinOrFullLTOPhase::None) { // TODO: explore a better pipeline configuration that can improve // compilation time overhead. + // FIXME: move this earlier (lots of pass ordering tests will need fixing) + MPM.addPass(AssignGUIDPass()); MPM.addPass(WholeProgramDevirtPass( /*ExportSummary*/ nullptr, /*ImportSummary*/ nullptr, diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index 82fbab5e1857f..bd11b335cfc34 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -12,6 +12,7 @@ #include "llvm/Transforms/IPO/FunctionImport.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" @@ -1877,6 +1878,21 @@ static void internalizeGVsAfterImport(Module &M) { } } +static GlobalValue::GUID getGUIDOrFallback(const GlobalValue& GV) { + // Modules compiled against the current version should have a GUID table + // and hence have the GUID available simply by calling getGUID(). But we + // want to support running on old bitcode files which have no embedded + // GUIDs. So if it's missing we fall back to computing the GUID with its + // current name / linkage type. + const auto MaybeGUID = GV.getGUIDIfAssigned(); + return MaybeGUID ? *MaybeGUID + : GlobalValue::getGUIDAssumingExternalLinkage( + GlobalValue::getGlobalIdentifier( + GV.getName(), + GV.getLinkage(), + GV.getParent()->getSourceFileName())); +} + // Automatically import functions in Module \p DestModule based on the summaries // index. Expected FunctionImporter::importFunctions( @@ -1891,7 +1907,7 @@ Expected FunctionImporter::importFunctions( DenseSet MoveSymbolGUIDSet; MoveSymbolGUIDSet.insert_range(MoveSymbolGUID); for (auto &F : DestModule) - if (!F.isDeclaration() && MoveSymbolGUIDSet.contains(F.getGUID())) + if (!F.isDeclaration() && MoveSymbolGUIDSet.contains(getGUIDOrFallback(F))) F.deleteBody(); IRMover Mover(DestModule); @@ -1919,7 +1935,7 @@ Expected FunctionImporter::importFunctions( for (Function &F : *SrcModule) { if (!F.hasName()) continue; - auto GUID = F.getGUID(); + auto GUID = getGUIDOrFallback(F); auto MaybeImportType = ImportList.getImportType(ModName, GUID); bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition; @@ -1959,7 +1975,7 @@ Expected FunctionImporter::importFunctions( for (GlobalVariable &GV : SrcModule->globals()) { if (!GV.hasName()) continue; - auto GUID = GV.getGUID(); + auto GUID = getGUIDOrFallback(GV); auto MaybeImportType = ImportList.getImportType(ModName, GUID); bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition; @@ -1983,29 +1999,31 @@ Expected FunctionImporter::importFunctions( for (GlobalAlias &GA : SrcModule->aliases()) { if (!GA.hasName() || isa(GA.getAliaseeObject())) continue; - auto GUID = GA.getGUID(); + auto GUID = getGUIDOrFallback(GA); auto MaybeImportType = ImportList.getImportType(ModName, GUID); bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition; - LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not") - << " importing alias" - << (ImportDefinition - ? " definition " - : (MaybeImportType ? " declaration " : " ")) - << GUID << " " << GA.getName() << " from " + LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not") + << " importing alias" + << (ImportDefinition + ? " definition " + : (MaybeImportType ? " declaration " : " ")) + << GUID << " " << GA.getName() << " from " + << SrcModule->getSourceFileName() << "\n"); + if (ImportDefinition) { + if (Error Err = GA.materialize()) + return std::move(Err); + // Import alias as a copy of its aliasee. + GlobalObject *GO = GA.getAliaseeObject(); + if (Error Err = GO->materialize()) + return std::move(Err); + auto *Fn = replaceAliasWithAliasee(SrcModule.get(), &GA); + assert(Fn); + (void)Fn; + LLVM_DEBUG(dbgs() << "Is importing aliasee fn " << getGUIDOrFallback(*GO) << " " + << GO->getName() << " from " << SrcModule->getSourceFileName() << "\n"); - if (ImportDefinition) { - if (Error Err = GA.materialize()) - return std::move(Err); - // Import alias as a copy of its aliasee. - GlobalObject *GO = GA.getAliaseeObject(); - if (Error Err = GO->materialize()) - return std::move(Err); - auto *Fn = replaceAliasWithAliasee(SrcModule.get(), &GA); - LLVM_DEBUG(dbgs() << "Is importing aliasee fn " << GO->getGUID() - << " " << GO->getName() << " from " - << SrcModule->getSourceFileName() << "\n"); if (EnableImportMetadata || EnableMemProfContextDisambiguation) { // Add 'thinlto_src_module' and 'thinlto_src_file' metadata for // statistics and debugging. diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp index fb9969620f7f8..9bb93d7c160f5 100644 --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -198,6 +198,8 @@ void simplifyExternals(Module &M) { AttributeList::FunctionIndex, F.getAttributes().getFnAttrs())); NewF->takeName(&F); + NewF->setMetadata(LLVMContext::MD_unique_id, + F.getMetadata(LLVMContext::MD_unique_id)); F.replaceAllUsesWith(NewF); F.eraseFromParent(); } diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp index 5b2391a6a7b67..23e5c69ee7e37 100644 --- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -108,6 +108,7 @@ #include "llvm/TargetParser/Triple.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/FunctionAttrs.h" +#include "llvm/Transforms/Utils/AssignGUID.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/CallPromotionUtils.h" #include "llvm/Transforms/Utils/Evaluator.h" @@ -886,6 +887,12 @@ void llvm::updateVCallVisibilityInModule( function_ref IsVisibleToRegularObj) { if (!hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO)) return; + + // Manually assign GUIDs -- updateVCallVisibilityInModule accesses GUIDs, and + // there's no way to specify it in the pass pipeline since this runs before + // any pass given on the command line. + AssignGUIDPass::runOnModule(M); + for (GlobalVariable &GV : M.globals()) { // Add linkage unit visibility to any variable with type metadata, which are // the vtable definitions. We won't have an existing vcall_visibility diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp index 32ae14b45764b..42609f29df625 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp @@ -126,7 +126,7 @@ void annotateIndirectCalls(Module &M, const CtxProfAnalysis::Result &CtxProf) { for (auto &F : M) { if (F.isDeclaration()) continue; - auto FlatProfIter = FlatIndCalls.find(AssignGUIDPass::getGUID(F)); + auto FlatProfIter = FlatIndCalls.find(F.getGUID()); if (FlatProfIter == FlatIndCalls.end()) continue; const auto &FlatProf = FlatProfIter->second; @@ -179,7 +179,7 @@ PreservedAnalyses PGOCtxProfFlatteningPass::run(Module &M, "Function has unreachable basic blocks. The expectation was that " "DCE was run before."); - auto It = FlattenedProfile.find(AssignGUIDPass::getGUID(F)); + auto It = FlattenedProfile.find(F.getGUID()); // If this function didn't appear in the contextual profile, it's cold. if (It == FlattenedProfile.end()) clearColdFunctionProfile(F); diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp index de7c1696078db..6a9d10ef5cca0 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp @@ -280,8 +280,7 @@ bool CtxInstrumentationLowerer::lowerFunction(Function &F) { assert(Mark->getIndex()->isZero()); IRBuilder<> Builder(Mark); - Guid = Builder.getInt64( - AssignGUIDPass::getGUID(cast(*Mark->getNameValue()))); + Guid = Builder.getInt64(cast(*Mark->getNameValue()).getGUID()); // The type of the context of this function is now knowable since we have // NumCallsites and NumCounters. We declare it here because it's more // convenient - we have the Builder. diff --git a/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp b/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp index a3e3b9a207ca1..272320a8b27cc 100644 --- a/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp +++ b/llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp @@ -12,7 +12,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/ConstantFolding.h" -#include "llvm/Analysis/CtxProfAnalysis.h" #include "llvm/Analysis/DomTreeUpdater.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/PostDominators.h" @@ -212,8 +211,8 @@ PreservedAnalyses JumpTableToSwitchPass::run(Function &F, DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy); bool Changed = false; auto FuncToGuid = [&](const Function &Fct) { - if (Fct.getMetadata(AssignGUIDPass::GUIDMetadataName)) - return AssignGUIDPass::getGUID(Fct); + if (const auto MaybeGUID = Fct.getGUIDIfAssigned(); MaybeGUID) + return *MaybeGUID; return Function::getGUIDAssumingExternalLinkage(getIRPGOFuncName(F, InLTO)); }; diff --git a/llvm/lib/Transforms/Utils/AssignGUID.cpp b/llvm/lib/Transforms/Utils/AssignGUID.cpp new file mode 100644 index 0000000000000..7a7dba15c64fb --- /dev/null +++ b/llvm/lib/Transforms/Utils/AssignGUID.cpp @@ -0,0 +1,31 @@ +//===-- AssignGUID.cpp - Unique identifier assignment pass ------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file provides a pass which assigns a a GUID (globally unique identifier) +// to every GlobalValue in the module, according to its current name, linkage, +// and originating file. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Transforms/Utils/AssignGUID.h" +#include "llvm/Support/Debug.h" + +using namespace llvm; + +void AssignGUIDPass::runOnModule(Module &M) { + for (auto &GV : M.globals()) { + if (GV.isDeclaration()) + continue; + GV.assignGUID(); + } + for (auto &F : M.functions()) { + if (F.isDeclaration()) + continue; + F.assignGUID(); + } +} \ No newline at end of file diff --git a/llvm/lib/Transforms/Utils/CMakeLists.txt b/llvm/lib/Transforms/Utils/CMakeLists.txt index 2b5f5cf344e60..3541af676fc31 100644 --- a/llvm/lib/Transforms/Utils/CMakeLists.txt +++ b/llvm/lib/Transforms/Utils/CMakeLists.txt @@ -2,6 +2,7 @@ add_llvm_component_library(LLVMTransformUtils AddDiscriminators.cpp AMDGPUEmitPrintf.cpp ASanStackFrameLayout.cpp + AssignGUID.cpp AssumeBundleBuilder.cpp BasicBlockUtils.cpp BreakCriticalEdges.cpp diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp index f0f9add09bf82..6912338ce5ffd 100644 --- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp +++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp @@ -616,11 +616,11 @@ CallBase *llvm::promoteCallWithIfThenElse(CallBase &CB, Function &Callee, IndirectBBIns->setIndex(IndirectID); IndirectBBIns->insertInto(&IndirectBB, IndirectBB.getFirstInsertionPt()); - const GlobalValue::GUID CalleeGUID = AssignGUIDPass::getGUID(Callee); + const GlobalValue::GUID CalleeGUID = Callee.getGUID(); const uint32_t NewCountersSize = IndirectID + 1; auto ProfileUpdater = [&](PGOCtxProfContext &Ctx) { - assert(Ctx.guid() == AssignGUIDPass::getGUID(Caller)); + assert(Ctx.guid() == Caller.getGUID()); assert(NewCountersSize - 2 == Ctx.counters().size()); // All the ctx-es belonging to a function must have the same size counters. Ctx.resizeCounters(NewCountersSize); @@ -655,7 +655,6 @@ CallBase *llvm::promoteCallWithIfThenElse(CallBase &CB, Function &Callee, // times, and the indirect BB, IndirectCount times Ctx.counters()[DirectID] = DirectCount; Ctx.counters()[IndirectID] = IndirectCount; - }; CtxProf.update(ProfileUpdater, Caller); return &DirectCall; diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp index bb638f180bfbf..6768f6fff580a 100644 --- a/llvm/lib/Transforms/Utils/CloneModule.cpp +++ b/llvm/lib/Transforms/Utils/CloneModule.cpp @@ -129,17 +129,21 @@ std::unique_ptr llvm::CloneModule( for (const Function &I : M) { Function *F = cast(VMap[&I]); - if (I.isDeclaration()) { + auto CopyMD = [&]() { // Copy over metadata for declarations since we're not doing it below in // CloneFunctionInto(). SmallVector, 1> MDs; I.getAllMetadata(MDs); for (auto MD : MDs) F->addMetadata(MD.first, *MapMetadata(MD.second, VMap)); + }; + if (I.isDeclaration()) { + CopyMD(); continue; } if (!ShouldCloneDefinition(&I)) { + CopyMD(); // Skip after setting the correct linkage for an external reference. F->setLinkage(GlobalValue::ExternalLinkage); // Personality function is not valid on a declaration. diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp index 475699c42b21e..72f9b7be7f432 100644 --- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -166,6 +166,21 @@ FunctionImportGlobalProcessing::getPromotedName(const GlobalValue *SGV) { ImportIndex.getModuleHash(SGV->getParent()->getModuleIdentifier())); } +static GlobalValue::GUID getGUIDOrFallback(const GlobalValue& GV) { + // Modules compiled against the current version should have a GUID table + // and hence have the GUID available simply by calling getGUID(). But we + // want to support running on old bitcode files which have no embedded + // GUIDs. So if it's missing we fall back to computing the GUID with its + // current name / linkage type. + const auto MaybeGUID = GV.getGUIDIfAssigned(); + return MaybeGUID ? *MaybeGUID + : GlobalValue::getGUIDAssumingExternalLinkage( + GlobalValue::getGlobalIdentifier( + GV.getName(), + GV.getLinkage(), + GV.getParent()->getSourceFileName())); +} + GlobalValue::LinkageTypes FunctionImportGlobalProcessing::getLinkage(const GlobalValue *SGV, bool DoPromote) { @@ -191,7 +206,7 @@ FunctionImportGlobalProcessing::getLinkage(const GlobalValue *SGV, // and/or optimization, but are turned into declarations later // during the EliminateAvailableExternally pass. if (doImportAsDefinition(SGV) && !isa(SGV)) - return SymbolsToMove.contains(SGV->getGUID()) + return SymbolsToMove.contains(getGUIDOrFallback(*SGV)) ? GlobalValue::ExternalLinkage : GlobalValue::AvailableExternallyLinkage; // An imported external declaration stays external. @@ -267,7 +282,7 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) { ValueInfo VI; if (GV.hasName()) - VI = ImportIndex.getValueInfo(GV.getGUID()); + VI = ImportIndex.getValueInfo(getGUIDOrFallback(GV)); // We should always have a ValueInfo (i.e. GV in index) for definitions when // we are exporting, and also when importing that value. diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index c398a6ae4f0f9..1dd3aebc94b3d 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -2435,7 +2435,7 @@ llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, // Get some preliminary data about the callsite before it might get inlined. // Inlining shouldn't delete the callee, but it's cleaner (and low-cost) to // get this data upfront and rely less on InlineFunction's behavior. - const auto CalleeGUID = AssignGUIDPass::getGUID(Callee); + const auto CalleeGUID = Callee.getGUID(); auto *CallsiteIDIns = CtxProfAnalysis::getCallsiteInstrumentation(CB); const auto CallsiteID = static_cast(CallsiteIDIns->getIndex()->getZExtValue()); @@ -2460,7 +2460,7 @@ llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, const uint32_t NewCountersSize = CtxProf.getNumCounters(Caller); auto Updater = [&](PGOCtxProfContext &Ctx) { - assert(Ctx.guid() == AssignGUIDPass::getGUID(Caller)); + assert(Ctx.guid() == Caller.getGUID()); const auto &[CalleeCounterMap, CalleeCallsiteMap] = IndicesMaps; assert( (Ctx.counters().size() + diff --git a/llvm/test/Assembler/index-value-order.ll b/llvm/test/Assembler/index-value-order.ll index 9df6d4a46fef2..15ace18647de6 100644 --- a/llvm/test/Assembler/index-value-order.ll +++ b/llvm/test/Assembler/index-value-order.ll @@ -11,13 +11,16 @@ target triple = "x86_64-unknown-linux-gnu" $_ZTSN3FooE = comdat any -@_ZTSN3FooE = linkonce_odr constant [7 x i8] c"N3FooE\00", comdat, align 1 -@"_ZTVN3FooE" = internal unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr null, ptr @"_Z3barv"] }, align 8 +@_ZTSN3FooE = linkonce_odr constant [7 x i8] c"N3FooE\00", comdat, align 1, !guid !0 +@"_ZTVN3FooE" = internal unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr null, ptr @"_Z3barv"] }, align 8, !guid !1 -define internal i32 @"_Z3barv"() { +define internal i32 @"_Z3barv"() !guid !2 { ret i32 0 } +!0 = !{i64 0} +!1 = !{i64 1} +!2 = !{i64 2} ^0 = module: (path: "index-value-order.ll", hash: (0, 0, 0, 0, 0)) ^9 = gv: (name: "_ZTVN3FooE", summaries: (variable: (module: ^0, flags: (linkage: internal, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0), varFlags: (readonly: 1, writeonly: 0, constant: 1, vcall_visibility: 0), vTableFuncs: ((virtFunc: ^3, offset: 16))))) ^4 = gv: (name: "_ZTSN3FooE", summaries: (variable: (module: ^0, flags: (linkage: linkonce_odr, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), varFlags: (readonly: 0, writeonly: 0, constant: 1)))) diff --git a/llvm/test/Bitcode/thinlto-alias.ll b/llvm/test/Bitcode/thinlto-alias.ll index 4191983055b2c..e6213f61ca8ed 100644 --- a/llvm/test/Bitcode/thinlto-alias.ll +++ b/llvm/test/Bitcode/thinlto-alias.ll @@ -13,6 +13,7 @@ ; CHECK: +; CHECK-NEXT: ; op4=none1 op6=hot1 op8=cold1 op10=none2 op12=hot2 op14=cold2 op16=none3 op18=hot3 op20=cold3 op22=123 -; CHECK-NEXT: +; CHECK-NEXT: ; CHECK-NEXT: ; CHECK-NEXT: diff --git a/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll b/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll index ed3c716288d6f..7f5f5ca39c544 100644 --- a/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll @@ -11,6 +11,7 @@ ; RUN: llvm-lto -thinlto-index-stats %p/Inputs/thinlto-function-summary-callgraph-pgo-combined.1.bc | FileCheck %s --check-prefix=OLD-COMBINED ; CHECK: +; CHECK-NEXT: ; op4=hot1 op6=cold op8=hot2 op10=hot4 op12=none1 op14=hot3 op16=none2 op18=none3 op20=123 -; CHECK-NEXT: +; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: +; CHECK-NEXT: ; op4=none1 op6=hot1 op8=cold1 op10=none2 op12=hot2 op14=cold2 op16=none3 op18=hot3 op20=cold3 op22=123 -; CHECK-NEXT: +; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: