[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/133682 >From 67d512e2d2055c73d3e6121d3972b23932342d5d Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata See https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801 for context. This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 38 - llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 6 +-- .../llvm/Transforms/Utils/AssignGUID.h| 34 +++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 42 ++- llvm/lib/IR/Globals.cpp | 34 +++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 +++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 131 insertions(+), 83 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index 6f1c3696ca78c..2ca21fc154f9a 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -46,9 +46,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -67,9 +64,9 @@ class PGOContextualProfile { bool isInSpecializedModule() const; - bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; - } + bool isInSpecializedModule() const; + + bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -80,22 +77,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; @@ -157,26 +154,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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`. - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - static const char *GUIDMetadataName; - // This should become GlobalValue:
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/133682 >From 9d34fae78840876402a1b049d345b73285ffe4e5 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 38 - llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 6 +-- .../llvm/Transforms/Utils/AssignGUID.h| 34 +++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 42 ++- llvm/lib/IR/Globals.cpp | 34 +++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 +++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 131 insertions(+), 83 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index 6f1c3696ca78c..2ca21fc154f9a 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -46,9 +46,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -67,9 +64,9 @@ class PGOContextualProfile { bool isInSpecializedModule() const; - bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; - } + bool isInSpecializedModule() const; + + bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -80,22 +77,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; @@ -157,26 +154,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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`. - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - static const char *GUIDMetadataName; - // This should become GlobalValue::getGUID - static uint64_t getGUID(const Function &F); -}; - } // namespace llvm #en
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/133682 >From 59631d43b44c8db12520c26fe4813c02a85c319c Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 36 +++ llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 6 +-- .../llvm/Transforms/Utils/AssignGUID.h| 34 ++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 44 ++- llvm/lib/IR/Globals.cpp | 34 ++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 ++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 130 insertions(+), 84 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index ede8bd2fe5001..2e0b97b3844d9 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -37,9 +37,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -56,9 +53,7 @@ class PGOContextualProfile { const PGOCtxProfile &profiles() const { return Profiles; } - bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; - } + bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -69,22 +64,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; @@ -145,26 +140,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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`. - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - static const char *GUIDMetadataName; - // This should become GlobalValue::getGUID - static uint64_t getGUID(const Function &F); -}; - } // namespace llvm #endif // LLVM_ANALYSIS_CT
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/133682 >From 59631d43b44c8db12520c26fe4813c02a85c319c Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 36 +++ llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 6 +-- .../llvm/Transforms/Utils/AssignGUID.h| 34 ++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 44 ++- llvm/lib/IR/Globals.cpp | 34 ++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 ++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 130 insertions(+), 84 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index ede8bd2fe5001..2e0b97b3844d9 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -37,9 +37,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -56,9 +53,7 @@ class PGOContextualProfile { const PGOCtxProfile &profiles() const { return Profiles; } - bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; - } + bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -69,22 +64,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; @@ -145,26 +140,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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`. - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - static const char *GUIDMetadataName; - // This should become GlobalValue::getGUID - static uint64_t getGUID(const Function &F); -}; - } // namespace llvm #endif // LLVM_ANALYSIS_CT
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/133682 >From c7c5b411e4b22efd9a1b37cd5c71f2fa98069dc8 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata See https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801 for context. This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 36 +++- llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 6 +-- .../llvm/Transforms/Utils/AssignGUID.h| 34 +++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 42 ++- llvm/lib/IR/Globals.cpp | 34 +++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 +++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 129 insertions(+), 83 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index 6f1c3696ca78c..b18b04e133f8f 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -46,9 +46,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -67,9 +64,7 @@ class PGOContextualProfile { bool isInSpecializedModule() const; - bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; - } + bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -80,22 +75,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; @@ -157,26 +152,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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`. - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - static const char *GUIDMetadataName; - // This should become GlobalValue::getGUID - static uint64_t getGUID(const
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/133682 >From 9d34fae78840876402a1b049d345b73285ffe4e5 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 38 - llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 6 +-- .../llvm/Transforms/Utils/AssignGUID.h| 34 +++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 42 ++- llvm/lib/IR/Globals.cpp | 34 +++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 +++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 131 insertions(+), 83 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index 6f1c3696ca78c..2ca21fc154f9a 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -46,9 +46,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -67,9 +64,9 @@ class PGOContextualProfile { bool isInSpecializedModule() const; - bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; - } + bool isInSpecializedModule() const; + + bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -80,22 +77,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; @@ -157,26 +154,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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`. - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - static const char *GUIDMetadataName; - // This should become GlobalValue::getGUID - static uint64_t getGUID(const Function &F); -}; - } // namespace llvm #en
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley created https://github.com/llvm/llvm-project/pull/133682 This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. >From 1379952ca664e04c4aa6806a724bcda1b0fc1a48 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 34 +++--- llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 4 +- .../llvm/Transforms/Utils/AssignGUID.h| 34 ++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 44 ++- llvm/lib/IR/Globals.cpp | 33 ++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 ++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 4 +- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 129 insertions(+), 79 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index ede8bd2fe5001..484cc638a2d53 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -37,9 +37,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -57,7 +54,7 @@ class PGOContextualProfile { const PGOCtxProfile &profiles() const { return Profiles; } bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; +return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { @@ -69,22 +66,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; @@ -145,26 +142,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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:
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/133682 >From dd0751618d4eac29a6af13b2e747ed505ec9b321 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 31 Mar 2025 16:16:35 +1100 Subject: [PATCH] Store GUIDs in metadata This takes the existing AssignGUID pass from CtxProfAnalysis, and runs it by default, at the appropriate stages of the LTO pipeline. It also changes GlobalValue::getGUID() to retrieve the GUID from the metadata instead of computing it. We don't yet have the supporting downstream changes to make a dedicated GUID table in bitcode, nor do we use the metadata as part of ThinLTO -- it retains its existing mechanisms of recomputing GUIDs from separately saved data. That will be changed later. --- llvm/include/llvm/Analysis/CtxProfAnalysis.h | 36 +++ llvm/include/llvm/IR/FixedMetadataKinds.def | 1 + llvm/include/llvm/IR/GlobalValue.h| 4 +- .../llvm/Transforms/Utils/AssignGUID.h| 34 ++ llvm/lib/Analysis/CtxProfAnalysis.cpp | 44 ++- llvm/lib/IR/Globals.cpp | 33 ++ llvm/lib/Passes/PassBuilder.cpp | 1 + llvm/lib/Passes/PassBuilderPipelines.cpp | 9 +++- .../Instrumentation/PGOCtxProfFlattening.cpp | 2 +- .../Instrumentation/PGOCtxProfLowering.cpp| 3 +- llvm/lib/Transforms/Utils/AssignGUID.cpp | 34 ++ llvm/lib/Transforms/Utils/CMakeLists.txt | 1 + .../Transforms/Utils/CallPromotionUtils.cpp | 5 +-- llvm/lib/Transforms/Utils/InlineFunction.cpp | 4 +- 14 files changed, 129 insertions(+), 82 deletions(-) create mode 100644 llvm/include/llvm/Transforms/Utils/AssignGUID.h create mode 100644 llvm/lib/Transforms/Utils/AssignGUID.cpp diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h index ede8bd2fe5001..2e0b97b3844d9 100644 --- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h +++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h @@ -37,9 +37,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. - GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const; - // This is meant to be constructed from CtxProfAnalysis, which will also set // its state piecemeal. PGOContextualProfile() = default; @@ -56,9 +53,7 @@ class PGOContextualProfile { const PGOCtxProfile &profiles() const { return Profiles; } - bool isFunctionKnown(const Function &F) const { -return getDefinedFunctionGUID(F) != 0; - } + bool isFunctionKnown(const Function &F) const { return F.getGUID() != 0; } StringRef getFunctionName(GlobalValue::GUID GUID) const { auto It = FuncInfo.find(GUID); @@ -69,22 +64,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; @@ -145,26 +140,5 @@ class CtxProfAnalysisPrinterPass const PrintMode Mode; }; -/// 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`. - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); - static const char *GUIDMetadataName; - // This should become GlobalValue::getGUID - static uint64_t getGUID(const Function &F); -}; - } // namespace llvm #endif // LLVM_ANALYSIS_CTX
[llvm-branch-commits] [llvm] Store GUIDs in metadata (PR #133682)
orodley wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/133682?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#133682** https://app.graphite.dev/github/pr/llvm/llvm-project/133682?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/133682?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#129644** https://app.graphite.dev/github/pr/llvm/llvm-project/129644?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/133682 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
https://github.com/orodley edited https://github.com/llvm/llvm-project/pull/139497 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
https://github.com/orodley created https://github.com/llvm/llvm-project/pull/139497 None >From bfb6cb21243f043ea1edf6f00cf27d08549066dc Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 12 May 2025 15:50:22 +1000 Subject: [PATCH] Add a GUIDLIST table to bitcode --- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 92b6e68d9d0a7..8acba6477c4a1 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/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d7aa189026a5..6d36b007956a0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -980,6 +980,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format. std::vector RadixArray; + // A table which maps ValueID to the GUID for that value. + std::vector DefinedGUIDs; + public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, @@ -7164,9 +7167,7 @@ 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); + auto ValueGUID = DefinedGUIDs[ValueID]; auto OriginalNameID = ValueGUID; if (GlobalValue::isLocalLinkage(Linkage)) OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName); @@ -7389,6 +7390,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, ...] diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 73bed85c65b3d..3e19220d1bde7 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -227,6 +227,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1560,6 +1561,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4755,6 +4758,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.ExitBlock(); } +void ModuleBitcodeWriterBase::writeGUIDList() { + std::vector GUIDs; + GUIDs.reserve(M.global_size() + M.size() + M.alias_size()); + + for (const GlobalValue &GV : M.global_objects()) { +if (GV.isDeclaration()) { + GUIDs.push_back( + GlobalValue::getGUIDAssumingExternalLinkage(GV.getName())); +} else { + GUIDs.push_back(GV.getGUID()); +} + } + for (const GlobalAlias &GA : M.aliases()) { +// Equivalent to the above loop, as GlobalAliases are always definitions. +GUIDs.push_back(GA.getGUID()); + } + + 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); @@ -5538,6 +5561,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] ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
orodley wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/139497?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#139497** https://app.graphite.dev/github/pr/llvm/llvm-project/139497?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/139497?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#133682** https://app.graphite.dev/github/pr/llvm/llvm-project/133682?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#129644** https://app.graphite.dev/github/pr/llvm/llvm-project/129644?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/139497 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
https://github.com/orodley edited https://github.com/llvm/llvm-project/pull/139497 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/139497 >From 553845ef071219713cd6abe74310e33603c20ef1 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 12 May 2025 15:50:22 +1000 Subject: [PATCH] Add a GUIDLIST table to bitcode --- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 92b6e68d9d0a7..8acba6477c4a1 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/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d7aa189026a5..6d36b007956a0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -980,6 +980,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format. std::vector RadixArray; + // A table which maps ValueID to the GUID for that value. + std::vector DefinedGUIDs; + public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, @@ -7164,9 +7167,7 @@ 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); + auto ValueGUID = DefinedGUIDs[ValueID]; auto OriginalNameID = ValueGUID; if (GlobalValue::isLocalLinkage(Linkage)) OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName); @@ -7389,6 +7390,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, ...] diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 73bed85c65b3d..3e19220d1bde7 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -227,6 +227,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1560,6 +1561,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4755,6 +4758,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.ExitBlock(); } +void ModuleBitcodeWriterBase::writeGUIDList() { + std::vector GUIDs; + GUIDs.reserve(M.global_size() + M.size() + M.alias_size()); + + for (const GlobalValue &GV : M.global_objects()) { +if (GV.isDeclaration()) { + GUIDs.push_back( + GlobalValue::getGUIDAssumingExternalLinkage(GV.getName())); +} else { + GUIDs.push_back(GV.getGUID()); +} + } + for (const GlobalAlias &GA : M.aliases()) { +// Equivalent to the above loop, as GlobalAliases are always definitions. +GUIDs.push_back(GA.getGUID()); + } + + 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); @@ -5538,6 +5561,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] ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailm
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/139497 >From 553845ef071219713cd6abe74310e33603c20ef1 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 12 May 2025 15:50:22 +1000 Subject: [PATCH] Add a GUIDLIST table to bitcode --- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 92b6e68d9d0a7..8acba6477c4a1 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/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1d7aa189026a5..6d36b007956a0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -980,6 +980,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format. std::vector RadixArray; + // A table which maps ValueID to the GUID for that value. + std::vector DefinedGUIDs; + public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, @@ -7164,9 +7167,7 @@ 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); + auto ValueGUID = DefinedGUIDs[ValueID]; auto OriginalNameID = ValueGUID; if (GlobalValue::isLocalLinkage(Linkage)) OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName); @@ -7389,6 +7390,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, ...] diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 73bed85c65b3d..3e19220d1bde7 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -227,6 +227,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1560,6 +1561,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4755,6 +4758,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.ExitBlock(); } +void ModuleBitcodeWriterBase::writeGUIDList() { + std::vector GUIDs; + GUIDs.reserve(M.global_size() + M.size() + M.alias_size()); + + for (const GlobalValue &GV : M.global_objects()) { +if (GV.isDeclaration()) { + GUIDs.push_back( + GlobalValue::getGUIDAssumingExternalLinkage(GV.getName())); +} else { + GUIDs.push_back(GV.getGUID()); +} + } + for (const GlobalAlias &GA : M.aliases()) { +// Equivalent to the above loop, as GlobalAliases are always definitions. +GUIDs.push_back(GA.getGUID()); + } + + 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); @@ -5538,6 +5561,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] ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailm
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/139497 >From bf53f8766fe4e5d4421dea919bf2abb8d4b13004 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 12 May 2025 15:50:22 +1000 Subject: [PATCH] Add a GUIDLIST table to bitcode --- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index b362a88963f6c..8fa3a89536d75 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/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index fde934fbb3cf1..3994f8469078b 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -976,6 +976,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format. std::vector RadixArray; + // A table which maps ValueID to the GUID for that value. + std::vector DefinedGUIDs; + public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, @@ -7162,9 +7165,7 @@ 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); + auto ValueGUID = DefinedGUIDs[ValueID]; auto OriginalNameID = ValueGUID; if (GlobalValue::isLocalLinkage(Linkage)) OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName); @@ -7387,6 +7388,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, ...] diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 628b939af19ce..a72f55bd7d0d1 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -244,6 +244,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1583,6 +1584,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4790,6 +4793,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.ExitBlock(); } +void ModuleBitcodeWriterBase::writeGUIDList() { + std::vector GUIDs; + GUIDs.reserve(M.global_size() + M.size() + M.alias_size()); + + for (const GlobalValue &GV : M.global_objects()) { +if (GV.isDeclaration()) { + GUIDs.push_back( + GlobalValue::getGUIDAssumingExternalLinkage(GV.getName())); +} else { + GUIDs.push_back(GV.getGUID()); +} + } + for (const GlobalAlias &GA : M.aliases()) { +// Equivalent to the above loop, as GlobalAliases are always definitions. +GUIDs.push_back(GA.getGUID()); + } + + 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); @@ -5578,6 +5601,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] ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailm
[llvm-branch-commits] [llvm] Add a GUIDLIST table to bitcode (PR #139497)
https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/139497 >From bf53f8766fe4e5d4421dea919bf2abb8d4b13004 Mon Sep 17 00:00:00 2001 From: Owen Rodley Date: Mon, 12 May 2025 15:50:22 +1000 Subject: [PATCH] Add a GUIDLIST table to bitcode --- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index b362a88963f6c..8fa3a89536d75 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/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index fde934fbb3cf1..3994f8469078b 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -976,6 +976,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format. std::vector RadixArray; + // A table which maps ValueID to the GUID for that value. + std::vector DefinedGUIDs; + public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, @@ -7162,9 +7165,7 @@ 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); + auto ValueGUID = DefinedGUIDs[ValueID]; auto OriginalNameID = ValueGUID; if (GlobalValue::isLocalLinkage(Linkage)) OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName); @@ -7387,6 +7388,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, ...] diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 628b939af19ce..a72f55bd7d0d1 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -244,6 +244,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1583,6 +1584,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4790,6 +4793,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.ExitBlock(); } +void ModuleBitcodeWriterBase::writeGUIDList() { + std::vector GUIDs; + GUIDs.reserve(M.global_size() + M.size() + M.alias_size()); + + for (const GlobalValue &GV : M.global_objects()) { +if (GV.isDeclaration()) { + GUIDs.push_back( + GlobalValue::getGUIDAssumingExternalLinkage(GV.getName())); +} else { + GUIDs.push_back(GV.getGUID()); +} + } + for (const GlobalAlias &GA : M.aliases()) { +// Equivalent to the above loop, as GlobalAliases are always definitions. +GUIDs.push_back(GA.getGUID()); + } + + 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); @@ -5578,6 +5601,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] ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailm