Skip to content

Commit 87d6941

Browse files
authored
Reverting PR #184065 and #200323 to address some interplay with CFI (#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.
1 parent f2a780b commit 87d6941

120 files changed

Lines changed: 385 additions & 811 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "llvm/IR/BasicBlock.h"
2626
#include "llvm/IR/Constants.h"
2727
#include "llvm/IR/DerivedTypes.h"
28-
#include "llvm/IR/GlobalValue.h"
2928
#include "llvm/IR/ReplaceConstant.h"
3029
#include "llvm/Support/Format.h"
3130
#include "llvm/Support/VirtualFileSystem.h"
@@ -1015,10 +1014,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
10151014
// Generate a unique module ID.
10161015
SmallString<64> ModuleID;
10171016
llvm::raw_svector_ostream OS(ModuleID);
1018-
OS << ModuleIDPrefix
1019-
<< llvm::format("%" PRIx64,
1020-
llvm::GlobalValue::getGUIDAssumingExternalLinkage(
1021-
FatbinWrapper->getName()));
1017+
OS << ModuleIDPrefix << llvm::format("%" PRIx64, FatbinWrapper->getGUID());
10221018
llvm::Constant *ModuleIDConstant = makeConstantArray(
10231019
std::string(ModuleID), "", ModuleIDSectionName, 32, /*AddNull=*/true);
10241020

clang/test/CodeGen/cfi-icall-trap-recover-runtime.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,32 @@
1515

1616

1717
// TRAP-LABEL: define hidden void @f(
18-
// TRAP-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
18+
// TRAP-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
1919
// TRAP-NEXT: [[ENTRY:.*:]]
2020
// TRAP-NEXT: ret void
2121
//
2222
// ABORT-LABEL: define hidden void @f(
23-
// ABORT-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
23+
// ABORT-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
2424
// ABORT-NEXT: [[ENTRY:.*:]]
2525
// ABORT-NEXT: ret void
2626
//
2727
// RECOVER-LABEL: define hidden void @f(
28-
// RECOVER-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
28+
// RECOVER-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
2929
// RECOVER-NEXT: [[ENTRY:.*:]]
3030
// RECOVER-NEXT: ret void
3131
//
3232
// ABORT_MIN-LABEL: define hidden void @f(
33-
// ABORT_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
33+
// ABORT_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
3434
// ABORT_MIN-NEXT: [[ENTRY:.*:]]
3535
// ABORT_MIN-NEXT: ret void
3636
//
3737
// RECOVER_MIN-LABEL: define hidden void @f(
38-
// RECOVER_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
38+
// RECOVER_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
3939
// RECOVER_MIN-NEXT: [[ENTRY:.*:]]
4040
// RECOVER_MIN-NEXT: ret void
4141
//
4242
// PRESERVE_MIN-LABEL: define hidden void @f(
43-
// PRESERVE_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]]
43+
// PRESERVE_MIN-SAME: ) #[[ATTR0:[0-9]+]] !type [[META6:![0-9]+]] !type [[META7:![0-9]+]] {
4444
// PRESERVE_MIN-NEXT: [[ENTRY:.*:]]
4545
// PRESERVE_MIN-NEXT: ret void
4646
//
@@ -50,7 +50,7 @@ void f() {
5050
void xf();
5151

5252
// TRAP-LABEL: define hidden void @g(
53-
// TRAP-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
53+
// TRAP-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
5454
// TRAP-NEXT: [[ENTRY:.*:]]
5555
// TRAP-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
5656
// TRAP-NEXT: [[FP:%.*]] = alloca ptr, align 8
@@ -71,7 +71,7 @@ void xf();
7171
// TRAP-NEXT: ret void
7272
//
7373
// ABORT-LABEL: define hidden void @g(
74-
// ABORT-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
74+
// ABORT-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
7575
// ABORT-NEXT: [[ENTRY:.*:]]
7676
// ABORT-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
7777
// ABORT-NEXT: [[FP:%.*]] = alloca ptr, align 8
@@ -93,7 +93,7 @@ void xf();
9393
// ABORT-NEXT: ret void
9494
//
9595
// RECOVER-LABEL: define hidden void @g(
96-
// RECOVER-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
96+
// RECOVER-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
9797
// RECOVER-NEXT: [[ENTRY:.*:]]
9898
// RECOVER-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
9999
// RECOVER-NEXT: [[FP:%.*]] = alloca ptr, align 8
@@ -115,7 +115,7 @@ void xf();
115115
// RECOVER-NEXT: ret void
116116
//
117117
// ABORT_MIN-LABEL: define hidden void @g(
118-
// ABORT_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
118+
// ABORT_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
119119
// ABORT_MIN-NEXT: [[ENTRY:.*:]]
120120
// ABORT_MIN-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
121121
// ABORT_MIN-NEXT: [[FP:%.*]] = alloca ptr, align 8
@@ -136,7 +136,7 @@ void xf();
136136
// ABORT_MIN-NEXT: ret void
137137
//
138138
// RECOVER_MIN-LABEL: define hidden void @g(
139-
// RECOVER_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
139+
// RECOVER_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
140140
// RECOVER_MIN-NEXT: [[ENTRY:.*:]]
141141
// RECOVER_MIN-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
142142
// RECOVER_MIN-NEXT: [[FP:%.*]] = alloca ptr, align 8
@@ -157,7 +157,7 @@ void xf();
157157
// RECOVER_MIN-NEXT: ret void
158158
//
159159
// PRESERVE_MIN-LABEL: define hidden void @g(
160-
// PRESERVE_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]]
160+
// PRESERVE_MIN-SAME: i32 noundef [[B:%.*]]) #[[ATTR0]] !type [[META8:![0-9]+]] !type [[META9:![0-9]+]] {
161161
// PRESERVE_MIN-NEXT: [[ENTRY:.*:]]
162162
// PRESERVE_MIN-NEXT: [[B_ADDR:%.*]] = alloca i32, align 4
163163
// PRESERVE_MIN-NEXT: [[FP:%.*]] = alloca ptr, align 8

clang/test/CodeGen/lto-newpm-pipeline.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
// CHECK-FULL-O0-NEXT: Running pass: CoroConditionalWrapper
3535
// CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass
3636
// CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass
37-
// CHECK-FULL-O0-NEXT: Running pass: AssignGUIDPass
3837
// CHECK-FULL-O0-NEXT: Running pass: AnnotationRemarksPass
3938
// CHECK-FULL-O0-NEXT: Running analysis: TargetLibraryAnalysis
4039
// CHECK-FULL-O0-NEXT: Running pass: VerifierPass
@@ -49,7 +48,6 @@
4948
// CHECK-THIN-O0-NEXT: Running pass: CoroConditionalWrapper
5049
// CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass
5150
// CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass
52-
// CHECK-THIN-O0-NEXT: Running pass: AssignGUIDPass
5351
// CHECK-THIN-O0-NEXT: Running pass: AnnotationRemarksPass
5452
// CHECK-THIN-O0-NEXT: Running analysis: TargetLibraryAnalysis
5553
// CHECK-THIN-O0-NEXT: Running pass: VerifierPass
@@ -66,7 +64,6 @@
6664
// CHECK-THIN-OPTIMIZED-NOT: Running pass: LoopVectorizePass
6765
// CHECK-THIN-OPTIMIZED: Running pass: CanonicalizeAliasesPass
6866
// CHECK-THIN-OPTIMIZED: Running pass: NameAnonGlobalPass
69-
// CHECK-THIN-OPTIMIZED: Running pass: AssignGUIDPass
7067
// CHECK-THIN-OPTIMIZED: Running pass: ThinLTOBitcodeWriterPass
7168

7269
void Foo(void) {}

clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct S1 {
1919
};
2020

2121
// TRAP-LABEL: define hidden void @_Z3s1fP2S1(
22-
// TRAP-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
22+
// TRAP-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
2323
// TRAP-NEXT: [[ENTRY:.*:]]
2424
// TRAP-NEXT: [[S1_ADDR:%.*]] = alloca ptr, align 8
2525
// TRAP-NEXT: store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -37,7 +37,7 @@ struct S1 {
3737
// TRAP-NEXT: ret void
3838
//
3939
// ABORT-LABEL: define hidden void @_Z3s1fP2S1(
40-
// ABORT-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
40+
// ABORT-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
4141
// ABORT-NEXT: [[ENTRY:.*:]]
4242
// ABORT-NEXT: [[S1_ADDR:%.*]] = alloca ptr, align 8
4343
// ABORT-NEXT: store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -58,7 +58,7 @@ struct S1 {
5858
// ABORT-NEXT: ret void
5959
//
6060
// RECOVER-LABEL: define hidden void @_Z3s1fP2S1(
61-
// RECOVER-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
61+
// RECOVER-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
6262
// RECOVER-NEXT: [[ENTRY:.*:]]
6363
// RECOVER-NEXT: [[S1_ADDR:%.*]] = alloca ptr, align 8
6464
// RECOVER-NEXT: store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -79,7 +79,7 @@ struct S1 {
7979
// RECOVER-NEXT: ret void
8080
//
8181
// ABORT_MIN-LABEL: define hidden void @_Z3s1fP2S1(
82-
// ABORT_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
82+
// ABORT_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
8383
// ABORT_MIN-NEXT: [[ENTRY:.*:]]
8484
// ABORT_MIN-NEXT: [[S1_ADDR:%.*]] = alloca ptr, align 8
8585
// ABORT_MIN-NEXT: store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -98,7 +98,7 @@ struct S1 {
9898
// ABORT_MIN-NEXT: ret void
9999
//
100100
// RECOVER_MIN-LABEL: define hidden void @_Z3s1fP2S1(
101-
// RECOVER_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
101+
// RECOVER_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
102102
// RECOVER_MIN-NEXT: [[ENTRY:.*:]]
103103
// RECOVER_MIN-NEXT: [[S1_ADDR:%.*]] = alloca ptr, align 8
104104
// RECOVER_MIN-NEXT: store ptr [[S1]], ptr [[S1_ADDR]], align 8
@@ -117,7 +117,7 @@ struct S1 {
117117
// RECOVER_MIN-NEXT: ret void
118118
//
119119
// PRESERVE_MIN-LABEL: define hidden void @_Z3s1fP2S1(
120-
// PRESERVE_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]]
120+
// PRESERVE_MIN-SAME: ptr noundef [[S1:%.*]]) #[[ATTR0:[0-9]+]] {
121121
// PRESERVE_MIN-NEXT: [[ENTRY:.*:]]
122122
// PRESERVE_MIN-NEXT: [[S1_ADDR:%.*]] = alloca ptr, align 8
123123
// PRESERVE_MIN-NEXT: store ptr [[S1]], ptr [[S1_ADDR]], align 8

lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
;; Index based WPD
77
;; Generate unsplit module with summary for ThinLTO index-based WPD.
8-
; RUN: opt --passes=assign-guid --thinlto-bc -o %t2.o %s
8+
; RUN: opt --thinlto-bc -o %t2.o %s
99
; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
1010
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
1111
; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
@@ -16,13 +16,13 @@
1616

1717
;; Hybrid WPD
1818
;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
19-
; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
19+
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
2020
; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
2121
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
2222
; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
2323

2424
;; Regular LTO WPD
25-
; RUN: opt --passes=assign-guid -o %t4.o %s
25+
; RUN: opt -o %t4.o %s
2626
; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
2727
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
2828
; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
@@ -107,19 +107,19 @@
107107
;; preemption, even without any options.
108108

109109
;; Index based WPD
110-
; RUN: opt --passes=assign-guid -relocation-model=pic --thinlto-bc -o %t5.o %s
110+
; RUN: opt -relocation-model=pic --thinlto-bc -o %t5.o %s
111111
; RUN: ld.lld %t5.o -o %t5.so -shared
112112
; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
113113
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
114114

115115
;; Hybrid WPD
116-
; RUN: opt --passes=assign-guid -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
116+
; RUN: opt -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s
117117
; RUN: ld.lld %t5.o -o %t5.so -shared
118118
; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
119119
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
120120

121121
;; Regular LTO WPD
122-
; RUN: opt --passes=assign-guid -relocation-model=pic -o %t5.o %s
122+
; RUN: opt -relocation-model=pic -o %t5.o %s
123123
; RUN: ld.lld %t5.o -o %t5.so -shared
124124
; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \
125125
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty

lld/test/ELF/lto/devirt_vcall_vis_public.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
;; Index based WPD
55
;; Generate unsplit module with summary for ThinLTO index-based WPD.
6-
; RUN: opt --passes=assign-guid --thinlto-bc -o %t2.o %s
6+
; RUN: opt --thinlto-bc -o %t2.o %s
77
; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
88
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
99
; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
1010

1111
;; Hybrid WPD
1212
;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
13-
; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
13+
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s
1414
; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
1515
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
1616
; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
1717

1818
;; Regular LTO WPD
19-
; RUN: opt --passes=assign-guid -o %t4.o %s
19+
; RUN: opt -o %t4.o %s
2020
; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
2121
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
2222
; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR

lld/test/ELF/lto/devirt_vcall_vis_shared_def.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77
;; Index based WPD
88
;; Generate unsplit module with summary for ThinLTO index-based WPD.
9-
; RUN: opt --passes=assign-guid --thinlto-bc -o %t1a.o %s
10-
; RUN: opt --passes=assign-guid --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
9+
; RUN: opt --thinlto-bc -o %t1a.o %s
10+
; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
1111
; RUN: ld.lld %t1a.o %t2a.o -o %t3a -save-temps --lto-whole-program-visibility \
1212
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
1313
; RUN: llvm-dis %t1a.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
1414

1515
;; Hybrid WPD
1616
;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
17-
; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s
18-
; RUN: opt --passes=assign-guid --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll
17+
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s
18+
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll
1919
; RUN: ld.lld %t1b.o %t2b.o -o %t3b -save-temps --lto-whole-program-visibility \
2020
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
2121
; RUN: llvm-dis %t1b.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
2222

2323
;; Regular LTO WPD
24-
; RUN: opt --passes=assign-guid -o %t1c.o %s
25-
; RUN: opt --passes=assign-guid -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
24+
; RUN: opt -o %t1c.o %s
25+
; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
2626
; RUN: ld.lld %t1c.o %t2c.o -o %t3c -save-temps --lto-whole-program-visibility \
2727
; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
2828
; RUN: llvm-dis %t3c.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR

llvm/include/llvm/Analysis/CtxProfAnalysis.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class PGOContextualProfile {
4747
// we'll need when we maintain the profiles during IPO transformations.
4848
std::map<GlobalValue::GUID, FunctionInfo> FuncInfo;
4949

50+
/// Get the GUID of this Function if it's defined in this module.
51+
LLVM_ABI GlobalValue::GUID getDefinedFunctionGUID(const Function &F) const;
52+
5053
// This is meant to be constructed from CtxProfAnalysis, which will also set
5154
// its state piecemeal.
5255
PGOContextualProfile() = default;
@@ -65,7 +68,9 @@ class PGOContextualProfile {
6568

6669
LLVM_ABI bool isInSpecializedModule() const;
6770

68-
bool isFunctionKnown(const Function &F) const { return !F.isDeclaration(); }
71+
bool isFunctionKnown(const Function &F) const {
72+
return getDefinedFunctionGUID(F) != 0;
73+
}
6974

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

7782
uint32_t getNumCounters(const Function &F) const {
7883
assert(isFunctionKnown(F));
79-
return FuncInfo.find(F.getGUID())->second.NextCounterIndex;
84+
return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCounterIndex;
8085
}
8186

8287
uint32_t getNumCallsites(const Function &F) const {
8388
assert(isFunctionKnown(F));
84-
return FuncInfo.find(F.getGUID())->second.NextCallsiteIndex;
89+
return FuncInfo.find(getDefinedFunctionGUID(F))->second.NextCallsiteIndex;
8590
}
8691

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

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

97102
using ConstVisitor = function_ref<void(const PGOCtxProfContext &)>;
@@ -182,5 +187,26 @@ class ProfileAnnotator {
182187
LLVM_ABI ~ProfileAnnotator();
183188
};
184189

190+
/// Assign a GUID to functions as metadata. GUID calculation takes linkage into
191+
/// account, which may change especially through and after thinlto. By
192+
/// pre-computing and assigning as metadata, this mechanism is resilient to such
193+
/// changes (as well as name changes e.g. suffix ".llvm." additions).
194+
195+
// FIXME(mtrofin): we can generalize this mechanism to calculate a GUID early in
196+
// the pass pipeline, associate it with any Global Value, and then use it for
197+
// PGO and ThinLTO.
198+
// At that point, this should be moved elsewhere.
199+
class AssignGUIDPass : public OptionalPassInfoMixin<AssignGUIDPass> {
200+
public:
201+
explicit AssignGUIDPass() = default;
202+
203+
/// Assign a GUID *if* one is not already assign, as a function metadata named
204+
/// `GUIDMetadataName`.
205+
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
206+
LLVM_ABI static const char *GUIDMetadataName;
207+
// This should become GlobalValue::getGUID
208+
LLVM_ABI static uint64_t getGUID(const Function &F);
209+
};
210+
185211
} // namespace llvm
186212
#endif // LLVM_ANALYSIS_CTXPROFANALYSIS_H

llvm/include/llvm/Bitcode/BitcodeReader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "llvm/ADT/StringRef.h"
1818
#include "llvm/Bitstream/BitCodeEnums.h"
1919
#include "llvm/IR/GlobalValue.h"
20-
#include "llvm/IR/ModuleSummaryIndex.h"
2120
#include "llvm/Support/Compiler.h"
2221
#include "llvm/Support/Endian.h"
2322
#include "llvm/Support/Error.h"
@@ -166,8 +165,7 @@ struct ParserCallbacks {
166165
/// into CombinedIndex.
167166
LLVM_ABI Error
168167
readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath,
169-
std::function<bool(StringRef)> IsPrevailing = nullptr,
170-
std::function<void(ValueInfo)> OnValueInfo = nullptr);
168+
std::function<bool(GlobalValue::GUID)> IsPrevailing = nullptr);
171169
};
172170

173171
struct BitcodeFileContents {

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ enum ModuleCodes {
120120

121121
// IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
122122
MODULE_CODE_IFUNC = 18,
123-
124-
// GUIDLIST: [n x i64]
125-
MODULE_CODE_GUIDLIST = 19,
126123
};
127124

128125
/// PARAMATTR blocks have code for defining a parameter attribute set.

0 commit comments

Comments
 (0)