[llvm] Store GUIDs in metadata (PR #133682)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 10:34:47 PDT 2025
================
@@ -78,6 +78,46 @@ GlobalValue::getGUIDAssumingExternalLinkage(StringRef GlobalIdentifier) {
return MD5Hash(GlobalIdentifier);
}
+void GlobalValue::assignGUID() {
+ if (isDeclaration()) {
+ // Declarations don't get an assigned GUID. Their definition is in another
+ // module, and it may have been promoted from local to external linkage
+ // during LTO. Because of this, we can only determine their GUID once the
+ // definition is available.
+ return;
+ }
+ 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 {
+ if (isa<GlobalAlias>(this)) {
+ return GlobalValue::getGUIDAssumingExternalLinkage(getGlobalIdentifier());
+ }
+
+ if (isDeclaration()) {
----------------
mtrofin wrote:
They can have a GUID tho, because the linkage won't be private or internal. So the GUID won't depend on the module defining them.
https://github.com/llvm/llvm-project/pull/133682
More information about the llvm-commits
mailing list