Skip to content

Reverting PR #184065 and #200323 to address some interplay with CFI#201194

Merged
mtrofin merged 3 commits into
llvm:mainfrom
mtrofin:revert
Jun 2, 2026
Merged

Reverting PR #184065 and #200323 to address some interplay with CFI#201194
mtrofin merged 3 commits into
llvm:mainfrom
mtrofin:revert

Conversation

@mtrofin

@mtrofin mtrofin commented Jun 2, 2026

Copy link
Copy Markdown
Member

There is a relation between CFI and ThinLTO GUIDs that still needs to be disentangled first. Note that we leave the MD_unique_id in FixedMetadataKinds.def to avoid needing to re-number it later. Plus the metadata string ("guid") itself is used by ctxprof. PR #184065 is the main revert, PR #200323 is a small add-on to the former and easier to revert/reland together.

@llvmorg-github-actions llvmorg-github-actions Bot added lld backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. llvm:codegen lld:ELF PGO Profile Guided Optimizations LTO Link time optimization (regular/full LTO or ThinLTO) llvm:ir llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Jun 2, 2026
@llvmorg-github-actions

llvmorg-github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-lld-elf
@llvm/pr-subscribers-pgo
@llvm/pr-subscribers-lto
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-lld
@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-clang-codegen

Author: Mircea Trofin (mtrofin)

Changes

There is a relation between CFI and ThinLTO GUIDs that still needs to be disentangled first. Note that we leave the MD_unique_id in FixedMetadataKinds.def to avoid needing to re-number it later. Plus the metadata string ("guid") itself is used by ctxprof.


Patch is 161.28 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/201194.diff

120 Files Affected:

  • (modified) clang/lib/CodeGen/CGCUDANV.cpp (+1-5)
  • (modified) clang/test/CodeGen/cfi-icall-trap-recover-runtime.c (+12-12)
  • (modified) clang/test/CodeGen/lto-newpm-pipeline.c (-3)
  • (modified) clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp (+6-6)
  • (modified) lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll (+6-6)
  • (modified) lld/test/ELF/lto/devirt_vcall_vis_public.ll (+3-3)
  • (modified) lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll (+6-6)
  • (modified) llvm/include/llvm/Analysis/CtxProfAnalysis.h (+31-5)
  • (modified) llvm/include/llvm/Bitcode/BitcodeReader.h (+1-3)
  • (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (-3)
  • (modified) llvm/include/llvm/IR/GlobalObject.h (+1-1)
  • (modified) llvm/include/llvm/IR/GlobalValue.h (+5-42)
  • (modified) llvm/include/llvm/IR/Module.h (+3-28)
  • (modified) llvm/include/llvm/IR/ModuleSummaryIndex.h (+3-11)
  • (modified) llvm/include/llvm/LTO/LTO.h (-20)
  • (removed) llvm/include/llvm/Transforms/Utils/AssignGUID.h (-49)
  • (modified) llvm/lib/Analysis/CtxProfAnalysis.cpp (+39-3)
  • (modified) llvm/lib/AsmParser/LLParser.cpp (+1-5)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp (-1)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+17-61)
  • (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+3-49)
  • (modified) llvm/lib/CodeGen/GlobalMerge.cpp (+8-12)
  • (modified) llvm/lib/IR/Globals.cpp (+2-57)
  • (modified) llvm/lib/LTO/LTO.cpp (+30-45)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (+2-8)
  • (modified) llvm/lib/Passes/PassBuilder.cpp (-1)
  • (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+3-7)
  • (modified) llvm/lib/Transforms/IPO/ConstantMerge.cpp (+4-4)
  • (modified) llvm/lib/Transforms/IPO/FunctionImport.cpp (+9-21)
  • (modified) llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp (-2)
  • (modified) llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp (-1)
  • (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp (+2-1)
  • (modified) llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp (+4-3)
  • (removed) llvm/lib/Transforms/Utils/AssignGUID.cpp (-41)
  • (modified) llvm/lib/Transforms/Utils/CMakeLists.txt (-1)
  • (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+3-2)
  • (modified) llvm/lib/Transforms/Utils/CloneModule.cpp (+1-5)
  • (modified) llvm/lib/Transforms/Utils/FunctionImportUtils.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+2-2)
  • (modified) llvm/test/Assembler/index-value-order.ll (+3-6)
  • (modified) llvm/test/Bitcode/thinlto-alias.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll (+2-3)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-profile-summary.ll (+2-3)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-sample-profile-summary.ll (+2-3)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-refgraph.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary.ll (-1)
  • (modified) llvm/test/CodeGen/X86/fat-lto-section.ll (+1-1)
  • (modified) llvm/test/LTO/Resolution/X86/not-prevailing-alias.ll (+1-1)
  • (modified) llvm/test/LTO/Resolution/X86/not-prevailing-weak-aliasee.ll (+1-1)
  • (modified) llvm/test/Linker/funcimport2.ll (+1-1)
  • (modified) llvm/test/Other/new-pm-O0-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll (-1)
  • (modified) llvm/test/ThinLTO/AArch64/aarch64_inline.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/Inputs/cache-typeid-resolutions1.ll (+1-2)
  • (modified) llvm/test/ThinLTO/X86/Inputs/cache-typeid-resolutions2.ll (+2-4)
  • (modified) llvm/test/ThinLTO/X86/Inputs/cache-typeid-resolutions3.ll (+4-8)
  • (modified) llvm/test/ThinLTO/X86/ctor-dtor-alias.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/ctor-dtor-alias2.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/deadstrip.ll (+4-4)
  • (modified) llvm/test/ThinLTO/X86/devirt_function_alias.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/devirt_function_alias2.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/devirt_pure_virtual_base.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/distributed_import.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/funcattrs-prop-exported-internal.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/funcattrs-prop-weak.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/globals-import.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/hidden-escaped-symbols-alt.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/hidden-escaped-symbols.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/import-ro-constant.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/index-const-prop-alias.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/index-const-prop.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll (+8-8)
  • (modified) llvm/test/ThinLTO/X86/memprof-dups.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/memprof_callee_type_mismatch.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/memprof_imported_internal.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/memprof_imported_internal2.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/prevailing_weak_globals_import.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/visibility-elf.ll (+6-6)
  • (modified) llvm/test/ThinLTO/X86/visibility-macho.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/weak_resolution.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/windows-vftable.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/writeonly.ll (+2-2)
  • (removed) llvm/test/Transforms/AssignGUID/assign_guid.ll (-18)
  • (modified) llvm/test/Transforms/ConstantMerge/merge-dbg.ll (-1)
  • (modified) llvm/test/Transforms/EmbedBitcode/embed-wpd.ll (+1-1)
  • (modified) llvm/test/Transforms/EmbedBitcode/embed.ll (+6-7)
  • (modified) llvm/test/Transforms/FunctionImport/funcimport-debug-retained-nodes.ll (+1-2)
  • (modified) llvm/test/Transforms/FunctionImport/funcimport.ll (+12-12)
  • (removed) llvm/test/Transforms/GlobalMerge/guid.ll (-38)
  • (modified) llvm/test/Transforms/LowerTypeTests/cfi-icall-alias.ll (+1-1)
  • (modified) llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll (+2-2)
  • (modified) llvm/test/Transforms/PhaseOrdering/speculative-devirt-then-inliner.ll (+1-1)
  • (modified) llvm/test/Transforms/SampleProfile/ctxsplit.ll (+4-4)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal-typeid.ll (+1-1)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal1.ll (+1-1)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll (+4-5)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll (+1-1)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc.ll (+8-8)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split.ll (+2-2)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll (+1-1)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/branch-funnel-profile.ll (+22-22)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll (+2-2)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll (+3-3)
  • (modified) llvm/test/tools/gold/X86/devirt_vcall_vis_export_dynamic.ll (+2-2)
  • (modified) llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll (+1-1)
  • (modified) llvm/test/tools/gold/X86/devirt_vcall_vis_shared_def.ll (+2-2)
  • (modified) llvm/test/tools/gold/X86/thinlto_weak_library.ll (+1-1)
  • (modified) llvm/test/tools/gold/X86/thinlto_weak_resolution.ll (+2-2)
  • (modified) llvm/test/tools/gold/X86/v1.16/devirt_vcall_vis_export_dynamic.ll (+1-1)
  • (modified) llvm/tools/llvm-link/llvm-link.cpp (+1-2)
  • (modified) llvm/tools/opt/NewPMDriver.cpp (-8)
  • (modified) llvm/tools/opt/optdriver.cpp (-7)
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index a727a006969d8..b74de7e064c35 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -25,7 +25,6 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/ReplaceConstant.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -1015,10 +1014,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
     // Generate a unique module ID.
     SmallString<64> ModuleID;
     llvm::raw_svector_ostream OS(ModuleID);
-    OS << ModuleIDPrefix
-       << llvm::format("%" PRIx64,
-                       llvm::GlobalValue::getGUIDAssumingExternalLinkage(
-                           FatbinWrapper->getName()));
+    OS << ModuleIDPrefix << llvm::format("%" PRIx64, FatbinWrapper->getGUID());
     llvm::Constant *ModuleIDConstant = makeConstantArray(
         std::string(ModuleID), "", ModuleIDSectionName, 32, /*AddNull=*/true);
 
diff --git a/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c b/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
index 5717fc66488af..2c44842f9d28e 100644
--- a/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
+++ b/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
@@ -15,32 +15,32 @@
 
 
 // TRAP-LABEL: define hidden void @f(
-// TRAP-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// TRAP-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // TRAP-NEXT:  [[ENTRY:.*:]]
 // TRAP-NEXT:    ret void
 //
 // ABORT-LABEL: define hidden void @f(
-// ABORT-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// ABORT-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // ABORT-NEXT:  [[ENTRY:.*:]]
 // ABORT-NEXT:    ret void
 //
 // RECOVER-LABEL: define hidden void @f(
-// RECOVER-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// RECOVER-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // RECOVER-NEXT:  [[ENTRY:.*:]]
 // RECOVER-NEXT:    ret void
 //
 // ABORT_MIN-LABEL: define hidden void @f(
-// ABORT_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// ABORT_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // ABORT_MIN-NEXT:  [[ENTRY:.*:]]
 // ABORT_MIN-NEXT:    ret void
 //
 // RECOVER_MIN-LABEL: define hidden void @f(
-// RECOVER_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// RECOVER_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // RECOVER_MIN-NEXT:  [[ENTRY:.*:]]
 // RECOVER_MIN-NEXT:    ret void
 //
 // PRESERVE_MIN-LABEL: define hidden void @f(
-// PRESERVE_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// PRESERVE_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // PRESERVE_MIN-NEXT:  [[ENTRY:.*:]]
 // PRESERVE_MIN-NEXT:    ret void
 //
@@ -50,7 +50,7 @@ void f() {
 void xf();
 
 // TRAP-LABEL: define hidden void @g(
-// TRAP-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// TRAP-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // TRAP-NEXT:  [[ENTRY:.*:]]
 // TRAP-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // TRAP-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -71,7 +71,7 @@ void xf();
 // TRAP-NEXT:    ret void
 //
 // ABORT-LABEL: define hidden void @g(
-// ABORT-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// ABORT-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // ABORT-NEXT:  [[ENTRY:.*:]]
 // ABORT-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // ABORT-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -93,7 +93,7 @@ void xf();
 // ABORT-NEXT:    ret void
 //
 // RECOVER-LABEL: define hidden void @g(
-// RECOVER-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// RECOVER-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // RECOVER-NEXT:  [[ENTRY:.*:]]
 // RECOVER-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // RECOVER-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -115,7 +115,7 @@ void xf();
 // RECOVER-NEXT:    ret void
 //
 // ABORT_MIN-LABEL: define hidden void @g(
-// ABORT_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// ABORT_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // ABORT_MIN-NEXT:  [[ENTRY:.*:]]
 // ABORT_MIN-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // ABORT_MIN-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -136,7 +136,7 @@ void xf();
 // ABORT_MIN-NEXT:    ret void
 //
 // RECOVER_MIN-LABEL: define hidden void @g(
-// RECOVER_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// RECOVER_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // RECOVER_MIN-NEXT:  [[ENTRY:.*:]]
 // RECOVER_MIN-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // RECOVER_MIN-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -157,7 +157,7 @@ void xf();
 // RECOVER_MIN-NEXT:    ret void
 //
 // PRESERVE_MIN-LABEL: define hidden void @g(
-// PRESERVE_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// PRESERVE_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // PRESERVE_MIN-NEXT:  [[ENTRY:.*:]]
 // PRESERVE_MIN-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // PRESERVE_MIN-NEXT:    [[FP:%.*]] = alloca ptr, align 8
diff --git a/clang/test/CodeGen/lto-newpm-pipeline.c b/clang/test/CodeGen/lto-newpm-pipeline.c
index c8ee5e949ae87..ea9784a76f923 100644
--- a/clang/test/CodeGen/lto-newpm-pipeline.c
+++ b/clang/test/CodeGen/lto-newpm-pipeline.c
@@ -34,7 +34,6 @@
 // CHECK-FULL-O0-NEXT: Running pass: CoroConditionalWrapper
 // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass
-// CHECK-FULL-O0-NEXT: Running pass: AssignGUIDPass
 // CHECK-FULL-O0-NEXT: Running pass: AnnotationRemarksPass
 // CHECK-FULL-O0-NEXT: Running analysis: TargetLibraryAnalysis
 // CHECK-FULL-O0-NEXT: Running pass: VerifierPass
@@ -49,7 +48,6 @@
 // CHECK-THIN-O0-NEXT: Running pass: CoroConditionalWrapper
 // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass
-// CHECK-THIN-O0-NEXT: Running pass: AssignGUIDPass
 // CHECK-THIN-O0-NEXT: Running pass: AnnotationRemarksPass
 // CHECK-THIN-O0-NEXT: Running analysis: TargetLibraryAnalysis
 // CHECK-THIN-O0-NEXT: Running pass: VerifierPass
@@ -66,7 +64,6 @@
 // CHECK-THIN-OPTIMIZED-NOT: Running pass: LoopVectorizePass
 // CHECK-THIN-OPTIMIZED: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-OPTIMIZED: Running pass: NameAnonGlobalPass
-// CHECK-THIN-OPTIMIZED: Running pass: AssignGUIDPass
 // CHECK-THIN-OPTIMIZED: Running pass: ThinLTOBitcodeWriterPass
 
 void Foo(void) {}
diff --git a/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp b/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
index a1e1563a4f38d..2451d31e9a489 100644
--- a/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
+++ b/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
@@ -19,7 +19,7 @@ struct S1 {
 };
 
 // TRAP-LABEL: define hidden void @_Z3s1fP2S1(
-// TRAP-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// TRAP-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // TRAP-NEXT:  [[ENTRY:.*:]]
 // TRAP-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // TRAP-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -37,7 +37,7 @@ struct S1 {
 // TRAP-NEXT:    ret void
 //
 // ABORT-LABEL: define hidden void @_Z3s1fP2S1(
-// ABORT-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// ABORT-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // ABORT-NEXT:  [[ENTRY:.*:]]
 // ABORT-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // ABORT-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -58,7 +58,7 @@ struct S1 {
 // ABORT-NEXT:    ret void
 //
 // RECOVER-LABEL: define hidden void @_Z3s1fP2S1(
-// RECOVER-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// RECOVER-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // RECOVER-NEXT:  [[ENTRY:.*:]]
 // RECOVER-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // RECOVER-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -79,7 +79,7 @@ struct S1 {
 // RECOVER-NEXT:    ret void
 //
 // ABORT_MIN-LABEL: define hidden void @_Z3s1fP2S1(
-// ABORT_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// ABORT_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // ABORT_MIN-NEXT:  [[ENTRY:.*:]]
 // ABORT_MIN-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // ABORT_MIN-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -98,7 +98,7 @@ struct S1 {
 // ABORT_MIN-NEXT:    ret void
 //
 // RECOVER_MIN-LABEL: define hidden void @_Z3s1fP2S1(
-// RECOVER_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// RECOVER_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // RECOVER_MIN-NEXT:  [[ENTRY:.*:]]
 // RECOVER_MIN-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // RECOVER_MIN-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -117,7 +117,7 @@ struct S1 {
 // RECOVER_MIN-NEXT:    ret void
 //
 // PRESERVE_MIN-LABEL: define hidden void @_Z3s1fP2S1(
-// PRESERVE_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// PRESERVE_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // PRESERVE_MIN-NEXT:  [[ENTRY:.*:]]
 // PRESERVE_MIN-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // PRESERVE_MIN-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
diff --git a/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll b/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
index 9b9c7891a6da6..bcb92a1beb17b 100644
--- a/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
+++ b/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
@@ -5,7 +5,7 @@
 
 ;; Index based WPD
 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t2.o %s
+; RUN: opt --thinlto-bc -o %t2.o %s
 ; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
@@ -16,13 +16,13 @@
 
 ;; Hybrid WPD
 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
 ; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -o %t4.o %s
+; RUN: opt -o %t4.o %s
 ; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
@@ -107,19 +107,19 @@
 ;; preemption, even without any options.
 
 ;; Index based WPD
-; RUN: opt --passes=assign-guid -relocation-model=pic --thinlto-bc -o %t5.o %s
+; RUN: opt -relocation-model=pic --thinlto-bc -o %t5.o %s
 ; RUN: ld.lld %t5.o -o %t5.so -shared
 ; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
 
 ;; Hybrid WPD
-; RUN: opt --passes=assign-guid -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
+; RUN: opt -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
 ; RUN: ld.lld %t5.o -o %t5.so -shared
 ; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -relocation-model=pic -o %t5.o %s
+; RUN: opt -relocation-model=pic -o %t5.o %s
 ; RUN: ld.lld %t5.o -o %t5.so -shared
 ; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
diff --git a/lld/test/ELF/lto/devirt_vcall_vis_public.ll b/lld/test/ELF/lto/devirt_vcall_vis_public.ll
index 0030e5804af81..a827fea465fd7 100644
--- a/lld/test/ELF/lto/devirt_vcall_vis_public.ll
+++ b/lld/test/ELF/lto/devirt_vcall_vis_public.ll
@@ -3,20 +3,20 @@
 
 ;; Index based WPD
 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t2.o %s
+; RUN: opt --thinlto-bc -o %t2.o %s
 ; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Hybrid WPD
 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
 ; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -o %t4.o %s
+; RUN: opt -o %t4.o %s
 ; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
diff --git a/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll b/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll
index b77dde97a2c05..a61e290bb0eb1 100644
--- a/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll
+++ b/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll
@@ -6,23 +6,23 @@
 
 ;; Index based WPD
 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t1a.o %s
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
+; RUN: opt --thinlto-bc -o %t1a.o %s
+; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
 ; RUN: ld.lld %t1a.o %t2a.o -o %t3a -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t1a.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Hybrid WPD
 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll
 ; RUN: ld.lld %t1b.o %t2b.o -o %t3b -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t1b.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -o %t1c.o %s
-; RUN: opt --passes=assign-guid -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
+; RUN: opt -o %t1c.o %s
+; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
 ; RUN: ld.lld %t1c.o %t2c.o -o %t3c -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t3c.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index d2a1c07bd58e4..8260b95026ad2 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -47,6 +47,9 @@ class PGOContextualProfile {
   // we'll need when we maintain the profiles during IPO transformations.
   std::map<GlobalValue::GUID, FunctionInfo> 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;
@@ -65,7 +68,9 @@ class PGOContextualProfile {
 
   LLVM_ABI bool isInSpecializedModule() const;
 
-  bool isFunctionKnown(const Function &F) const { return !F.isDeclaration(); }
+  bool isFunctionKnown(const Function &F) const {
+    return getDefinedFunctionGUID(F) != 0;
+  }
 
   StringRef getFunctionName(GlobalValue::GUID GUID) const {
     auto It = FuncInfo.find(GUID);
@@ -76,22 +81,22 @@ class PGOContextualProfile {
 
   uint32_t getNumCounters(const Function &F) const {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
   }
 
   uint32_t getNumCallsites(const Function &F) const {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
   }
 
   uint32_t allocateNextCounterIndex(const Function &F) {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
   }
 
   uint32_t allocateNextCallsiteIndex(const Function &F) {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
   }
 
   using ConstVisitor = function_ref<void(const PGOCtxProfContext &)>;
@@ -182,5 +187,26 @@ 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 OptionalPassInfoMixin<AssignGUIDPass> {
+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 b7cab51857f0b..772ca82019278 100644
--- a/llvm/include/llvm/Bitcode/BitcodeReader.h
+++ b/llvm/include/llvm/Bitcode/BitcodeReader.h
@@ -17,7 +17,6 @@
 #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"
@@ -166,8 +165,7 @@ struct ParserCallbacks {
     /// into CombinedIndex.
     LLVM_ABI Error
     readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,
-                std::function<bool(StringRef)> IsPrevailing = nullptr,
-                std::function<void(ValueInfo)> OnValueInfo = nullptr);
+                std::function<bool(GlobalValue::GUID)> IsPrevailing = nullptr);
   };
 
   struct BitcodeFileContents {
diff --git a/llvm/include/llvm/Bitcode/LL...
[truncated]

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-x86

Author: Mircea Trofin (mtrofin)

Changes

There is a relation between CFI and ThinLTO GUIDs that still needs to be disentangled first. Note that we leave the MD_unique_id in FixedMetadataKinds.def to avoid needing to re-number it later. Plus the metadata string ("guid") itself is used by ctxprof.


Patch is 161.28 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/201194.diff

120 Files Affected:

  • (modified) clang/lib/CodeGen/CGCUDANV.cpp (+1-5)
  • (modified) clang/test/CodeGen/cfi-icall-trap-recover-runtime.c (+12-12)
  • (modified) clang/test/CodeGen/lto-newpm-pipeline.c (-3)
  • (modified) clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp (+6-6)
  • (modified) lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll (+6-6)
  • (modified) lld/test/ELF/lto/devirt_vcall_vis_public.ll (+3-3)
  • (modified) lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll (+6-6)
  • (modified) llvm/include/llvm/Analysis/CtxProfAnalysis.h (+31-5)
  • (modified) llvm/include/llvm/Bitcode/BitcodeReader.h (+1-3)
  • (modified) llvm/include/llvm/Bitcode/LLVMBitCodes.h (-3)
  • (modified) llvm/include/llvm/IR/GlobalObject.h (+1-1)
  • (modified) llvm/include/llvm/IR/GlobalValue.h (+5-42)
  • (modified) llvm/include/llvm/IR/Module.h (+3-28)
  • (modified) llvm/include/llvm/IR/ModuleSummaryIndex.h (+3-11)
  • (modified) llvm/include/llvm/LTO/LTO.h (-20)
  • (removed) llvm/include/llvm/Transforms/Utils/AssignGUID.h (-49)
  • (modified) llvm/lib/Analysis/CtxProfAnalysis.cpp (+39-3)
  • (modified) llvm/lib/AsmParser/LLParser.cpp (+1-5)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp (-1)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+17-61)
  • (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+3-49)
  • (modified) llvm/lib/CodeGen/GlobalMerge.cpp (+8-12)
  • (modified) llvm/lib/IR/Globals.cpp (+2-57)
  • (modified) llvm/lib/LTO/LTO.cpp (+30-45)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (+2-8)
  • (modified) llvm/lib/Passes/PassBuilder.cpp (-1)
  • (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+3-7)
  • (modified) llvm/lib/Transforms/IPO/ConstantMerge.cpp (+4-4)
  • (modified) llvm/lib/Transforms/IPO/FunctionImport.cpp (+9-21)
  • (modified) llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp (-2)
  • (modified) llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp (-1)
  • (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp (+2-1)
  • (modified) llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp (+4-3)
  • (removed) llvm/lib/Transforms/Utils/AssignGUID.cpp (-41)
  • (modified) llvm/lib/Transforms/Utils/CMakeLists.txt (-1)
  • (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+3-2)
  • (modified) llvm/lib/Transforms/Utils/CloneModule.cpp (+1-5)
  • (modified) llvm/lib/Transforms/Utils/FunctionImportUtils.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+2-2)
  • (modified) llvm/test/Assembler/index-value-order.ll (+3-6)
  • (modified) llvm/test/Bitcode/thinlto-alias.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll (+2-3)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-profile-summary.ll (+2-3)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph-sample-profile-summary.ll (+2-3)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-callgraph.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary-refgraph.ll (-1)
  • (modified) llvm/test/Bitcode/thinlto-function-summary.ll (-1)
  • (modified) llvm/test/CodeGen/X86/fat-lto-section.ll (+1-1)
  • (modified) llvm/test/LTO/Resolution/X86/not-prevailing-alias.ll (+1-1)
  • (modified) llvm/test/LTO/Resolution/X86/not-prevailing-weak-aliasee.ll (+1-1)
  • (modified) llvm/test/Linker/funcimport2.ll (+1-1)
  • (modified) llvm/test/Other/new-pm-O0-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll (+1-2)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll (-1)
  • (modified) llvm/test/ThinLTO/AArch64/aarch64_inline.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/Inputs/cache-typeid-resolutions1.ll (+1-2)
  • (modified) llvm/test/ThinLTO/X86/Inputs/cache-typeid-resolutions2.ll (+2-4)
  • (modified) llvm/test/ThinLTO/X86/Inputs/cache-typeid-resolutions3.ll (+4-8)
  • (modified) llvm/test/ThinLTO/X86/ctor-dtor-alias.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/ctor-dtor-alias2.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/deadstrip.ll (+4-4)
  • (modified) llvm/test/ThinLTO/X86/devirt_function_alias.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/devirt_function_alias2.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/devirt_pure_virtual_base.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/distributed_import.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/funcattrs-prop-exported-internal.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/funcattrs-prop-weak.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/globals-import.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/hidden-escaped-symbols-alt.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/hidden-escaped-symbols.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/import-ro-constant.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/index-const-prop-alias.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/index-const-prop.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll (+8-8)
  • (modified) llvm/test/ThinLTO/X86/memprof-dups.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/memprof_callee_type_mismatch.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/memprof_imported_internal.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/memprof_imported_internal2.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/prevailing_weak_globals_import.ll (+1-1)
  • (modified) llvm/test/ThinLTO/X86/visibility-elf.ll (+6-6)
  • (modified) llvm/test/ThinLTO/X86/visibility-macho.ll (+3-3)
  • (modified) llvm/test/ThinLTO/X86/weak_resolution.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/windows-vftable.ll (+2-2)
  • (modified) llvm/test/ThinLTO/X86/writeonly.ll (+2-2)
  • (removed) llvm/test/Transforms/AssignGUID/assign_guid.ll (-18)
  • (modified) llvm/test/Transforms/ConstantMerge/merge-dbg.ll (-1)
  • (modified) llvm/test/Transforms/EmbedBitcode/embed-wpd.ll (+1-1)
  • (modified) llvm/test/Transforms/EmbedBitcode/embed.ll (+6-7)
  • (modified) llvm/test/Transforms/FunctionImport/funcimport-debug-retained-nodes.ll (+1-2)
  • (modified) llvm/test/Transforms/FunctionImport/funcimport.ll (+12-12)
  • (removed) llvm/test/Transforms/GlobalMerge/guid.ll (-38)
  • (modified) llvm/test/Transforms/LowerTypeTests/cfi-icall-alias.ll (+1-1)
  • (modified) llvm/test/Transforms/PGOProfile/thinlto_indirect_call_promotion.ll (+2-2)
  • (modified) llvm/test/Transforms/PhaseOrdering/speculative-devirt-then-inliner.ll (+1-1)
  • (modified) llvm/test/Transforms/SampleProfile/ctxsplit.ll (+4-4)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal-typeid.ll (+1-1)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal1.ll (+1-1)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal2.ll (+4-5)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc-internal.ll (+1-1)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split-vfunc.ll (+8-8)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/split.ll (+2-2)
  • (modified) llvm/test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll (+1-1)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/branch-funnel-profile.ll (+22-22)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll (+2-2)
  • (modified) llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll (+3-3)
  • (modified) llvm/test/tools/gold/X86/devirt_vcall_vis_export_dynamic.ll (+2-2)
  • (modified) llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll (+1-1)
  • (modified) llvm/test/tools/gold/X86/devirt_vcall_vis_shared_def.ll (+2-2)
  • (modified) llvm/test/tools/gold/X86/thinlto_weak_library.ll (+1-1)
  • (modified) llvm/test/tools/gold/X86/thinlto_weak_resolution.ll (+2-2)
  • (modified) llvm/test/tools/gold/X86/v1.16/devirt_vcall_vis_export_dynamic.ll (+1-1)
  • (modified) llvm/tools/llvm-link/llvm-link.cpp (+1-2)
  • (modified) llvm/tools/opt/NewPMDriver.cpp (-8)
  • (modified) llvm/tools/opt/optdriver.cpp (-7)
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index a727a006969d8..b74de7e064c35 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -25,7 +25,6 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/ReplaceConstant.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -1015,10 +1014,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
     // Generate a unique module ID.
     SmallString<64> ModuleID;
     llvm::raw_svector_ostream OS(ModuleID);
-    OS << ModuleIDPrefix
-       << llvm::format("%" PRIx64,
-                       llvm::GlobalValue::getGUIDAssumingExternalLinkage(
-                           FatbinWrapper->getName()));
+    OS << ModuleIDPrefix << llvm::format("%" PRIx64, FatbinWrapper->getGUID());
     llvm::Constant *ModuleIDConstant = makeConstantArray(
         std::string(ModuleID), "", ModuleIDSectionName, 32, /*AddNull=*/true);
 
diff --git a/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c b/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
index 5717fc66488af..2c44842f9d28e 100644
--- a/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
+++ b/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
@@ -15,32 +15,32 @@
 
 
 // TRAP-LABEL: define hidden void @f(
-// TRAP-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// TRAP-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // TRAP-NEXT:  [[ENTRY:.*:]]
 // TRAP-NEXT:    ret void
 //
 // ABORT-LABEL: define hidden void @f(
-// ABORT-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// ABORT-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // ABORT-NEXT:  [[ENTRY:.*:]]
 // ABORT-NEXT:    ret void
 //
 // RECOVER-LABEL: define hidden void @f(
-// RECOVER-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// RECOVER-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // RECOVER-NEXT:  [[ENTRY:.*:]]
 // RECOVER-NEXT:    ret void
 //
 // ABORT_MIN-LABEL: define hidden void @f(
-// ABORT_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// ABORT_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // ABORT_MIN-NEXT:  [[ENTRY:.*:]]
 // ABORT_MIN-NEXT:    ret void
 //
 // RECOVER_MIN-LABEL: define hidden void @f(
-// RECOVER_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// RECOVER_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // RECOVER_MIN-NEXT:  [[ENTRY:.*:]]
 // RECOVER_MIN-NEXT:    ret void
 //
 // PRESERVE_MIN-LABEL: define hidden void @f(
-// PRESERVE_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
+// PRESERVE_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
 // PRESERVE_MIN-NEXT:  [[ENTRY:.*:]]
 // PRESERVE_MIN-NEXT:    ret void
 //
@@ -50,7 +50,7 @@ void f() {
 void xf();
 
 // TRAP-LABEL: define hidden void @g(
-// TRAP-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// TRAP-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // TRAP-NEXT:  [[ENTRY:.*:]]
 // TRAP-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // TRAP-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -71,7 +71,7 @@ void xf();
 // TRAP-NEXT:    ret void
 //
 // ABORT-LABEL: define hidden void @g(
-// ABORT-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// ABORT-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // ABORT-NEXT:  [[ENTRY:.*:]]
 // ABORT-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // ABORT-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -93,7 +93,7 @@ void xf();
 // ABORT-NEXT:    ret void
 //
 // RECOVER-LABEL: define hidden void @g(
-// RECOVER-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// RECOVER-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // RECOVER-NEXT:  [[ENTRY:.*:]]
 // RECOVER-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // RECOVER-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -115,7 +115,7 @@ void xf();
 // RECOVER-NEXT:    ret void
 //
 // ABORT_MIN-LABEL: define hidden void @g(
-// ABORT_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// ABORT_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // ABORT_MIN-NEXT:  [[ENTRY:.*:]]
 // ABORT_MIN-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // ABORT_MIN-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -136,7 +136,7 @@ void xf();
 // ABORT_MIN-NEXT:    ret void
 //
 // RECOVER_MIN-LABEL: define hidden void @g(
-// RECOVER_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// RECOVER_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // RECOVER_MIN-NEXT:  [[ENTRY:.*:]]
 // RECOVER_MIN-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // RECOVER_MIN-NEXT:    [[FP:%.*]] = alloca ptr, align 8
@@ -157,7 +157,7 @@ void xf();
 // RECOVER_MIN-NEXT:    ret void
 //
 // PRESERVE_MIN-LABEL: define hidden void @g(
-// PRESERVE_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
+// PRESERVE_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
 // PRESERVE_MIN-NEXT:  [[ENTRY:.*:]]
 // PRESERVE_MIN-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
 // PRESERVE_MIN-NEXT:    [[FP:%.*]] = alloca ptr, align 8
diff --git a/clang/test/CodeGen/lto-newpm-pipeline.c b/clang/test/CodeGen/lto-newpm-pipeline.c
index c8ee5e949ae87..ea9784a76f923 100644
--- a/clang/test/CodeGen/lto-newpm-pipeline.c
+++ b/clang/test/CodeGen/lto-newpm-pipeline.c
@@ -34,7 +34,6 @@
 // CHECK-FULL-O0-NEXT: Running pass: CoroConditionalWrapper
 // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass
-// CHECK-FULL-O0-NEXT: Running pass: AssignGUIDPass
 // CHECK-FULL-O0-NEXT: Running pass: AnnotationRemarksPass
 // CHECK-FULL-O0-NEXT: Running analysis: TargetLibraryAnalysis
 // CHECK-FULL-O0-NEXT: Running pass: VerifierPass
@@ -49,7 +48,6 @@
 // CHECK-THIN-O0-NEXT: Running pass: CoroConditionalWrapper
 // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass
-// CHECK-THIN-O0-NEXT: Running pass: AssignGUIDPass
 // CHECK-THIN-O0-NEXT: Running pass: AnnotationRemarksPass
 // CHECK-THIN-O0-NEXT: Running analysis: TargetLibraryAnalysis
 // CHECK-THIN-O0-NEXT: Running pass: VerifierPass
@@ -66,7 +64,6 @@
 // CHECK-THIN-OPTIMIZED-NOT: Running pass: LoopVectorizePass
 // CHECK-THIN-OPTIMIZED: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-OPTIMIZED: Running pass: NameAnonGlobalPass
-// CHECK-THIN-OPTIMIZED: Running pass: AssignGUIDPass
 // CHECK-THIN-OPTIMIZED: Running pass: ThinLTOBitcodeWriterPass
 
 void Foo(void) {}
diff --git a/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp b/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
index a1e1563a4f38d..2451d31e9a489 100644
--- a/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
+++ b/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
@@ -19,7 +19,7 @@ struct S1 {
 };
 
 // TRAP-LABEL: define hidden void @_Z3s1fP2S1(
-// TRAP-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// TRAP-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // TRAP-NEXT:  [[ENTRY:.*:]]
 // TRAP-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // TRAP-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -37,7 +37,7 @@ struct S1 {
 // TRAP-NEXT:    ret void
 //
 // ABORT-LABEL: define hidden void @_Z3s1fP2S1(
-// ABORT-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// ABORT-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // ABORT-NEXT:  [[ENTRY:.*:]]
 // ABORT-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // ABORT-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -58,7 +58,7 @@ struct S1 {
 // ABORT-NEXT:    ret void
 //
 // RECOVER-LABEL: define hidden void @_Z3s1fP2S1(
-// RECOVER-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// RECOVER-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // RECOVER-NEXT:  [[ENTRY:.*:]]
 // RECOVER-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // RECOVER-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -79,7 +79,7 @@ struct S1 {
 // RECOVER-NEXT:    ret void
 //
 // ABORT_MIN-LABEL: define hidden void @_Z3s1fP2S1(
-// ABORT_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// ABORT_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // ABORT_MIN-NEXT:  [[ENTRY:.*:]]
 // ABORT_MIN-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // ABORT_MIN-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -98,7 +98,7 @@ struct S1 {
 // ABORT_MIN-NEXT:    ret void
 //
 // RECOVER_MIN-LABEL: define hidden void @_Z3s1fP2S1(
-// RECOVER_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// RECOVER_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // RECOVER_MIN-NEXT:  [[ENTRY:.*:]]
 // RECOVER_MIN-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // RECOVER_MIN-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -117,7 +117,7 @@ struct S1 {
 // RECOVER_MIN-NEXT:    ret void
 //
 // PRESERVE_MIN-LABEL: define hidden void @_Z3s1fP2S1(
-// PRESERVE_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
+// PRESERVE_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
 // PRESERVE_MIN-NEXT:  [[ENTRY:.*:]]
 // PRESERVE_MIN-NEXT:    [[S1_ADDR:%.*]] = alloca ptr, align 8
 // PRESERVE_MIN-NEXT:    store ptr [[S1]], ptr [[S1_ADDR]], align 8
diff --git a/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll b/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
index 9b9c7891a6da6..bcb92a1beb17b 100644
--- a/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
+++ b/lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
@@ -5,7 +5,7 @@
 
 ;; Index based WPD
 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t2.o %s
+; RUN: opt --thinlto-bc -o %t2.o %s
 ; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
@@ -16,13 +16,13 @@
 
 ;; Hybrid WPD
 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
 ; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -o %t4.o %s
+; RUN: opt -o %t4.o %s
 ; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
@@ -107,19 +107,19 @@
 ;; preemption, even without any options.
 
 ;; Index based WPD
-; RUN: opt --passes=assign-guid -relocation-model=pic --thinlto-bc -o %t5.o %s
+; RUN: opt -relocation-model=pic --thinlto-bc -o %t5.o %s
 ; RUN: ld.lld %t5.o -o %t5.so -shared
 ; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
 
 ;; Hybrid WPD
-; RUN: opt --passes=assign-guid -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
+; RUN: opt -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
 ; RUN: ld.lld %t5.o -o %t5.so -shared
 ; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -relocation-model=pic -o %t5.o %s
+; RUN: opt -relocation-model=pic -o %t5.o %s
 ; RUN: ld.lld %t5.o -o %t5.so -shared
 ; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
diff --git a/lld/test/ELF/lto/devirt_vcall_vis_public.ll b/lld/test/ELF/lto/devirt_vcall_vis_public.ll
index 0030e5804af81..a827fea465fd7 100644
--- a/lld/test/ELF/lto/devirt_vcall_vis_public.ll
+++ b/lld/test/ELF/lto/devirt_vcall_vis_public.ll
@@ -3,20 +3,20 @@
 
 ;; Index based WPD
 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t2.o %s
+; RUN: opt --thinlto-bc -o %t2.o %s
 ; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Hybrid WPD
 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
 ; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -o %t4.o %s
+; RUN: opt -o %t4.o %s
 ; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
diff --git a/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll b/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll
index b77dde97a2c05..a61e290bb0eb1 100644
--- a/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll
+++ b/lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll
@@ -6,23 +6,23 @@
 
 ;; Index based WPD
 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t1a.o %s
-; RUN: opt --passes=assign-guid --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
+; RUN: opt --thinlto-bc -o %t1a.o %s
+; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
 ; RUN: ld.lld %t1a.o %t2a.o -o %t3a -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t1a.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Hybrid WPD
 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s
-; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll
 ; RUN: ld.lld %t1b.o %t2b.o -o %t3b -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t1b.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ;; Regular LTO WPD
-; RUN: opt --passes=assign-guid -o %t1c.o %s
-; RUN: opt --passes=assign-guid -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
+; RUN: opt -o %t1c.o %s
+; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
 ; RUN: ld.lld %t1c.o %t2c.o -o %t3c -save-temps --lto-whole-program-visibility \
 ; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
 ; RUN: llvm-dis %t3c.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index d2a1c07bd58e4..8260b95026ad2 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -47,6 +47,9 @@ class PGOContextualProfile {
   // we'll need when we maintain the profiles during IPO transformations.
   std::map<GlobalValue::GUID, FunctionInfo> 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;
@@ -65,7 +68,9 @@ class PGOContextualProfile {
 
   LLVM_ABI bool isInSpecializedModule() const;
 
-  bool isFunctionKnown(const Function &F) const { return !F.isDeclaration(); }
+  bool isFunctionKnown(const Function &F) const {
+    return getDefinedFunctionGUID(F) != 0;
+  }
 
   StringRef getFunctionName(GlobalValue::GUID GUID) const {
     auto It = FuncInfo.find(GUID);
@@ -76,22 +81,22 @@ class PGOContextualProfile {
 
   uint32_t getNumCounters(const Function &F) const {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
   }
 
   uint32_t getNumCallsites(const Function &F) const {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
   }
 
   uint32_t allocateNextCounterIndex(const Function &F) {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
   }
 
   uint32_t allocateNextCallsiteIndex(const Function &F) {
     assert(isFunctionKnown(F));
-    return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
+    return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
   }
 
   using ConstVisitor = function_ref<void(const PGOCtxProfContext &)>;
@@ -182,5 +187,26 @@ 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 OptionalPassInfoMixin<AssignGUIDPass> {
+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 b7cab51857f0b..772ca82019278 100644
--- a/llvm/include/llvm/Bitcode/BitcodeReader.h
+++ b/llvm/include/llvm/Bitcode/BitcodeReader.h
@@ -17,7 +17,6 @@
 #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"
@@ -166,8 +165,7 @@ struct ParserCallbacks {
     /// into CombinedIndex.
     LLVM_ABI Error
     readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,
-                std::function<bool(StringRef)> IsPrevailing = nullptr,
-                std::function<void(ValueInfo)> OnValueInfo = nullptr);
+                std::function<bool(GlobalValue::GUID)> IsPrevailing = nullptr);
   };
 
   struct BitcodeFileContents {
diff --git a/llvm/include/llvm/Bitcode/LL...
[truncated]

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions c,h,cpp -- clang/lib/CodeGen/CGCUDANV.cpp clang/test/CodeGen/cfi-icall-trap-recover-runtime.c clang/test/CodeGen/lto-newpm-pipeline.c clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp llvm/include/llvm/Analysis/CtxProfAnalysis.h llvm/include/llvm/Bitcode/BitcodeReader.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/GlobalObject.h llvm/include/llvm/IR/GlobalValue.h llvm/include/llvm/IR/Module.h llvm/include/llvm/IR/ModuleSummaryIndex.h llvm/include/llvm/LTO/LTO.h llvm/lib/Analysis/CtxProfAnalysis.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalMerge.cpp llvm/lib/IR/Globals.cpp llvm/lib/LTO/LTO.cpp llvm/lib/LTO/LTOBackend.cpp llvm/lib/Passes/PassBuilder.cpp llvm/lib/Passes/PassBuilderPipelines.cpp llvm/lib/Transforms/IPO/ConstantMerge.cpp llvm/lib/Transforms/IPO/FunctionImport.cpp llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp llvm/lib/Transforms/Utils/CallPromotionUtils.cpp llvm/lib/Transforms/Utils/CloneModule.cpp llvm/lib/Transforms/Utils/FunctionImportUtils.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/tools/llvm-link/llvm-link.cpp llvm/tools/opt/NewPMDriver.cpp llvm/tools/opt/optdriver.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 2032c0ceb..f289eb7d6 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -579,9 +579,9 @@ public:
   // Use globals() to get the range of all global variables.
 
 private:
-/// @}
-/// @name Direct access to the globals list, functions list, and symbol table
-/// @{
+  /// @}
+  /// @name Direct access to the globals list, functions list, and symbol table
+  /// @{
 
   /// Get the Module's list of global variables (constant).
   const GlobalListType   &getGlobalList() const       { return GlobalList; }
diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
index 1bfeea3b7..a7131b647 100644
--- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -676,7 +676,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;

@mtrofin mtrofin enabled auto-merge (squash) June 2, 2026 20:57

@boomanaiden154 boomanaiden154 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@mtrofin mtrofin merged commit 87d6941 into llvm:main Jun 2, 2026
8 of 10 checks passed
@mtrofin mtrofin deleted the revert branch June 2, 2026 21:46
yingopq pushed a commit to yingopq/llvm-project that referenced this pull request Jun 5, 2026
…th CFI (llvm#201194)

There is a relation between CFI and ThinLTO GUIDs that still needs to be
disentangled first. Note that we leave the `MD_unique_id` in
`FixedMetadataKinds.def` to avoid needing to re-number it later. Plus
the metadata string ("guid") itself is used by ctxprof.
mtrofin added a commit that referenced this pull request Jul 7, 2026
This reverts #201194, thus relanding @orodley's PR #184065 (and
#200323):

> 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

The CFI issues that triggered the original revert are fixed by #201370,
together with the addressing of the TODOs in `LowerTypeTests.cpp` left
in the latter. The [graphite
diff](https://app.graphite.com/github/pr/llvm/llvm-project/201849/Reland-%23184065)
between this change's V1 and V2 shows what's been added:

- the `TODO`s from #201370 are done
- in LowerTypeTests.cpp, passing `!guid` when creating a new declaration
and when converting a definition to a declaration.
- `llvm/test/Transforms/LowerTypeTests/export-icall.ll` tests also the
above def->decl conversion
- removed
`test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll`
introduced in #194383 (this was between the revert and this PR), as now
the general expectation is that GUID assignment happens appropriately
and all passes use `getGUID`, so there's no reason for `CtxProfAnalysis`
to do something different.

Currently, we reassign GUIDs when CFI promotes internal linkage symbols,
which is counter to the goal of the RFC. This is addressed in PR
#203171. The reason for this split fix can be explained on
`compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c`. Here, a module
with the exact same source path is compiled twice, under different
conditional compilation, to produce 2 objects. Each object defines an
internal linkage symbol with the same name (this is
`install_trap_loop_detection` from
`compiler-rt/test/cfi/trap_loop_signal_handler.inc` which is
`-include`\-d by both - see how `%clang_cfi` is defined). The ThinLTO
GUID of this symbol will be the same. Its name won't be - because CFI
promotes it and renames it using a hash that is based on the IR Module
content (rather than the source path). During thinlink,
`LTO::addThinLTO`will mark each of the 2 exported symbols as prevailing
in their corresponding modules. But that is done by associating their
GUID to the module. So whichever comes last wins. The other symbol will
be marked available externally and its body DCEd later in backend. But
each module will refer to its copy of `install_trap_loop_detection`, and
so we end up with a linker error.

As mentioned, the fix is in PR #203171, and this relanding PR just
maintains the existing ThinLTO behavior by rewriting the GUIDs. Since we
haven't yet leveraged the GUID mechanics for e.g. simplifying PGO, this
aspect of this change is essentially NFC.

Co-authored-by: Owen Rodley <orodley@google.com>
gandhi56 pushed a commit that referenced this pull request Jul 9, 2026
This reverts #201194, thus relanding @orodley's PR #184065 (and
#200323):

> 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

The CFI issues that triggered the original revert are fixed by #201370,
together with the addressing of the TODOs in `LowerTypeTests.cpp` left
in the latter. The [graphite
diff](https://app.graphite.com/github/pr/llvm/llvm-project/201849/Reland-%23184065)
between this change's V1 and V2 shows what's been added:

- the `TODO`s from #201370 are done
- in LowerTypeTests.cpp, passing `!guid` when creating a new declaration
and when converting a definition to a declaration.
- `llvm/test/Transforms/LowerTypeTests/export-icall.ll` tests also the
above def->decl conversion
- removed
`test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll`
introduced in #194383 (this was between the revert and this PR), as now
the general expectation is that GUID assignment happens appropriately
and all passes use `getGUID`, so there's no reason for `CtxProfAnalysis`
to do something different.

Currently, we reassign GUIDs when CFI promotes internal linkage symbols,
which is counter to the goal of the RFC. This is addressed in PR
#203171. The reason for this split fix can be explained on
`compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c`. Here, a module
with the exact same source path is compiled twice, under different
conditional compilation, to produce 2 objects. Each object defines an
internal linkage symbol with the same name (this is
`install_trap_loop_detection` from
`compiler-rt/test/cfi/trap_loop_signal_handler.inc` which is
`-include`\-d by both - see how `%clang_cfi` is defined). The ThinLTO
GUID of this symbol will be the same. Its name won't be - because CFI
promotes it and renames it using a hash that is based on the IR Module
content (rather than the source path). During thinlink,
`LTO::addThinLTO`will mark each of the 2 exported symbols as prevailing
in their corresponding modules. But that is done by associating their
GUID to the module. So whichever comes last wins. The other symbol will
be marked available externally and its body DCEd later in backend. But
each module will refer to its copy of `install_trap_loop_detection`, and
so we end up with a linker error.

As mentioned, the fix is in PR #203171, and this relanding PR just
maintains the existing ThinLTO behavior by rewriting the GUIDs. Since we
haven't yet leveraged the GUID mechanics for e.g. simplifying PGO, this
aspect of this change is essentially NFC.

Co-authored-by: Owen Rodley <orodley@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. lld:ELF lld llvm:analysis Includes value tracking, cost tables and constant folding llvm:codegen llvm:ir llvm:transforms LTO Link time optimization (regular/full LTO or ThinLTO) PGO Profile Guided Optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants