Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5e27552
Compute GUIDs once and store in metadata
orodley Sep 2, 2025
b5115c1
Address review comments and formatting issues
orodley Mar 12, 2026
f8b5be2
More formatting fixes
orodley Mar 13, 2026
64360a8
Ditto
orodley Mar 13, 2026
07ae242
And again
orodley Mar 13, 2026
ac31c29
Fix lld tests
orodley Mar 23, 2026
e776664
Fix clang tests
orodley Mar 30, 2026
a5942aa
First round of review changes, plus handle removal of Value::getMetadata
orodley Apr 15, 2026
7c9269f
Use an abbreviation for the GUID list in bitcode
orodley Apr 24, 2026
058159c
Move getGUIDOrFallback into GlobalValue
orodley Apr 24, 2026
bec5eb7
Revert accidental change
orodley Apr 28, 2026
45e8e97
Add comment
orodley Apr 28, 2026
a3911e0
Another comment
orodley Apr 28, 2026
34f29e6
Move the AssignGUIDPass::runOnModule call up out of WholeProgramDevir…
orodley May 11, 2026
c623861
Restructure control flow
orodley May 11, 2026
2d99e14
Remove blank line
orodley May 11, 2026
6cd6aef
Call getGUIDIfAssigned on the GlobalValue directly
orodley May 11, 2026
60a5412
Remove `Instruction` case in `getGUIDMetadata`
orodley May 11, 2026
6bfff71
Drop the check for a null getParent()
orodley May 11, 2026
6709db8
Add comment on ValueToGUIDMap
orodley May 11, 2026
e95d8b7
Merge to HEAD
orodley May 12, 2026
f24bfd3
Reformat
orodley May 12, 2026
e128e05
Merge to HEAD
orodley May 14, 2026
671486c
Formatting fixes
orodley May 15, 2026
4f6583e
Fix an incorrect GUID calculation
orodley May 25, 2026
99fc975
Fix gold tests
orodley May 26, 2026
f0cfcc3
Merge to HEAD
orodley May 26, 2026
85e9009
Fix split-internal2.ll test
orodley May 26, 2026
d407ee9
Propagate GUID metadata when converting to declarations
orodley May 26, 2026
81bb4a8
Run AssignGUIDPass under ctx prof gen as well
orodley May 26, 2026
5a803e0
More test fixes...
orodley May 26, 2026
6dcad4a
fyet more test fixes
orodley May 26, 2026
db0dd4f
Remove config file
orodley May 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/CodeGen/CGCUDANV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#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"
Expand Down Expand Up @@ -975,7 +976,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
// Generate a unique module ID.
SmallString<64> ModuleID;
llvm::raw_svector_ostream OS(ModuleID);
OS << ModuleIDPrefix << llvm::format("%" PRIx64, FatbinWrapper->getGUID());
OS << ModuleIDPrefix
<< llvm::format("%" PRIx64,
llvm::GlobalValue::getGUIDAssumingExternalLinkage(
FatbinWrapper->getName()));
llvm::Constant *ModuleIDConstant = makeConstantArray(
std::string(ModuleID), "", ModuleIDSectionName, 32, /*AddNull=*/true);

Expand Down
24 changes: 12 additions & 12 deletions clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGen/lto-newpm-pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// 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
Expand All @@ -48,6 +49,7 @@
// 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
Expand All @@ -64,6 +66,7 @@
// 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) {}
12 changes: 6 additions & 6 deletions clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

;; Index based WPD
;; Generate unsplit module with summary for ThinLTO index-based WPD.
; RUN: opt --thinlto-bc -o %t2.o %s
; RUN: opt --passes=assign-guid --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
Expand All @@ -16,13 +16,13 @@

;; Hybrid WPD
;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
; RUN: opt --passes=assign-guid --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 -o %t4.o %s
; RUN: opt --passes=assign-guid -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
Expand Down Expand Up @@ -107,19 +107,19 @@
;; preemption, even without any options.

;; Index based WPD
; RUN: opt -relocation-model=pic --thinlto-bc -o %t5.o %s
; RUN: opt --passes=assign-guid -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 -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
; RUN: opt --passes=assign-guid -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 -relocation-model=pic -o %t5.o %s
; RUN: opt --passes=assign-guid -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
Expand Down
6 changes: 3 additions & 3 deletions lld/test/ELF/lto/devirt_vcall_vis_public.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

;; Index based WPD
;; Generate unsplit module with summary for ThinLTO index-based WPD.
; RUN: opt --thinlto-bc -o %t2.o %s
; RUN: opt --passes=assign-guid --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 --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
; RUN: opt --passes=assign-guid --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 -o %t4.o %s
; RUN: opt --passes=assign-guid -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
Expand Down
12 changes: 6 additions & 6 deletions lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

;; Index based WPD
;; Generate unsplit module with summary for ThinLTO index-based WPD.
; RUN: opt --thinlto-bc -o %t1a.o %s
; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
; 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: 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 --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: 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: 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 -o %t1c.o %s
; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
; 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: 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
Expand Down
36 changes: 5 additions & 31 deletions llvm/include/llvm/Analysis/CtxProfAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ 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;
Expand All @@ -68,9 +65,7 @@ class PGOContextualProfile {

LLVM_ABI bool isInSpecializedModule() const;

bool isFunctionKnown(const Function &F) const {
return getDefinedFunctionGUID(F) != 0;
}
bool isFunctionKnown(const Function &F) const { return !F.isDeclaration(); }

StringRef getFunctionName(GlobalValue::GUID GUID) const {
auto It = FuncInfo.find(GUID);
Expand All @@ -81,22 +76,22 @@ class PGOContextualProfile {

uint32_t getNumCounters(const Function &F) const {
assert(isFunctionKnown(F));
return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
}

uint32_t getNumCallsites(const Function &F) const {
assert(isFunctionKnown(F));
return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
}

uint32_t allocateNextCounterIndex(const Function &F) {
assert(isFunctionKnown(F));
return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex++;
return FuncInfo.find(F.getGUID())->second.NextCounterIndex++;
}

uint32_t allocateNextCallsiteIndex(const Function &F) {
assert(isFunctionKnown(F));
return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex++;
return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex++;
}

using ConstVisitor = function_ref<void(const PGOCtxProfContext &)>;
Expand Down Expand Up @@ -187,26 +182,5 @@ class ProfileAnnotator {
LLVM_ABI ~ProfileAnnotator();
};

/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
/// account, which may change especially through and after thinlto. By
/// pre-computing and assigning as metadata, this mechanism is resilient to such
/// changes (as well as name changes e.g. suffix ".llvm." additions).

// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early in
// the pass pipeline, associate it with any Global Value, and then use it for
// PGO and ThinLTO.
// At that point, this should be moved elsewhere.
class AssignGUIDPass : public 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
4 changes: 3 additions & 1 deletion llvm/include/llvm/Bitcode/BitcodeReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitstream/BitCodeEnums.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
Expand Down Expand Up @@ -165,7 +166,8 @@ struct ParserCallbacks {
/// into CombinedIndex.
LLVM_ABI Error
readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,
std::function<bool(GlobalValue::GUID)> IsPrevailing = nullptr);
std::function<bool(StringRef)> IsPrevailing = nullptr,
std::function<void(ValueInfo)> OnValueInfo = nullptr);
};

struct BitcodeFileContents {
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/Bitcode/LLVMBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading