Reland "Compute GUIDs once and store in metadata" (#184065) #201849
Reland "Compute GUIDs once and store in metadata" (#184065) #201849mtrofin wants to merge 1 commit into
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ad94f68 to
a1a789e
Compare
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
8cd8eb5 to
f053482
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
f053482 to
9926393
Compare
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
13d3ad0 to
f8a1ec9
Compare
854a6f9 to
6dc97cf
Compare
|
✅ With the latest revision this PR passed the LLVM ABI annotation checker. |
6f02138 to
c7ff207
Compare
c7ff207 to
525046e
Compare
|
@llvm/pr-subscribers-clang-codegen Author: Mircea Trofin (mtrofin) ChangesThis reverts #201194, thus relanding PR #184065 (and #200323). The CFI issues are fixed by #201370, together with the addressing of the TODOs in
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 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. Patch is 166.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/201849.diff 122 Files Affected:
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 17b1963684428..23856c98d36ab 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -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/ProfileData/InstrProf.h"
#include "llvm/Support/Format.h"
@@ -1044,7 +1045,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);
diff --git a/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c b/clang/test/CodeGen/cfi-icall-trap-recover-runtime.c
index 2c44842f9d28e..5717fc66488af 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 ea9784a76f923..c8ee5e949ae87 100644
--- a/clang/test/CodeGen/lto-newpm-pipeline.c
+++ b/clang/test/CodeGen/lto-newpm-pipeline.c
@@ -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
@@ -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
@@ -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) {}
diff --git a/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp b/clang/test/CodeGenCXX/cfi-vcall-trap-recover-runtime.cpp
index 2451d31e9a489..a1e1563a4f38d 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 bcb92a1beb17b..9b9c7891a6da6 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 --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
@@ -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
@@ -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
diff --git a/lld/test/ELF/lto/devirt_vcall_vis_public.ll b/lld/test/ELF/lto/devirt_vcall_vis_public.ll
index a827fea465fd7..0030e5804af81 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 --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
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 a61e290bb0eb1..b77dde97a2c05 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 --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
diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index 8260b95026ad2..d2a1c07bd58e4 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -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;
@@ -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);
@@ -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 &)>;
@@ -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
diff --git a/llvm/include/llvm/Bitcode/BitcodeReader.h b/llvm/include/llvm/Bitcode/BitcodeReader.h
index 772ca82019278..b7cab51857f0b 100644
--- a/llvm/include/llvm/Bitcode/BitcodeReader.h
+++ b/llvm/include/llvm/Bitcode/BitcodeReader.h
@@ -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"
@@ -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 {
diff --git a/llvm/include/llvm/Bitcode/LLVMBi...
[truncated]
|
|
Please fix the title of the PR: it should explain what the change is doing for anyone who doesn't know what "#184065" is off the top of their head. |
525046e to
fa7961a
Compare
7834ddf to
8cce117
Compare
fa7961a to
1817d11
Compare
1817d11 to
2829ab3
Compare
|
Does this also address the compile-time regressions from the previous implementation? |
| } | ||
|
|
||
| if (!ShouldCloneDefinition(&I)) { | ||
| CopyMD(); |
There was a problem hiding this comment.
Doesn't this line create a blowup of unnecessary copies?
There was a problem hiding this comment.
good catch - fixed. Thanks!
|
I looked more into it but didn't update the other thread. IIRC the remaining surprise was the clang build regressing by 0.15%, because for the single-TU compilations, the regression was attributable to modules with lots of global values but not so much IR, where the bitcode serialization of the extra GUID table would start showing up. I'm actually not able to repro the clang build - I figured in the meantime that the "instructions" link in the clang-build part of the report gives me a per-module compilation change, and I found a module ( What's the cmake you use for building the host clang, and what's the cmake for the build target? |
a6fdde1 to
4da2c32
Compare
|
Turns out the clang build regression was in large due to some Fixed and re-ran the compile time tracker, the largest clang-build regression is now 1%. |
4da2c32 to
4bf5379
Compare
|
The stage1-ReleaseThinLTO results still don't look great and it seems like the geomean for the clang build is about the same? |
4bf5379 to
1cbfe8b
Compare
Note that some compile time performance effect in thinlto builds should be expected: we serialize/deserialize more. I think the main concern was "is there something else". re. stage1 - yes, see my earlier response ("for the single-TU compilations, the regression was attributable to modules with lots of global values but not so much IR, where the bitcode serialization of the extra GUID table would start showing up.") Re. clang-build, there's little change in the overall build timing (I don't think it's a geomean) because the individual compilation outliers like ModuleLinker were few and their negative contribution likely lost, before, in the overall parallel compilation part of the build. The rest is very likely for the same reason (more serialization) seen in the benchmarks builds, as at most we see compilation regressions within the same relative ranges for individual modules. |
|
To clarify, the regression I was concerned about is the one on bin/clang-23, i.e. the one during thin linking, not the one on individual files (pre-link). |
|
Ah, ok. About that one: Looking at the profile itself, ( Before: After: This lines up with the "we serialize more" (and so we deserialize during linking). Not sure what to make of the |
1cbfe8b to
55df97c
Compare

This reverts #201194, thus relanding @orodley's PR #184065 (and #200323):
The CFI issues that triggered the original revert are fixed by #201370, together with the addressing of the TODOs in
LowerTypeTests.cppleft in the latter. The graphite diff between this change's V1 and V2 shows what's been added:TODOs from [CFI][ThinLTO] Remove the need for CFI calculating ThinLTO GUIDs #201370 are done!guidwhen creating a new declaration and when converting a definition to a declaration.llvm/test/Transforms/LowerTypeTests/export-icall.lltests also the above def->decl conversiontest/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.llintroduced in [CtxProf] emit fatal usage error when flatten-prethinlink runs without guid metadata #194383 (this was between the revert and this PR), as now the general expectation is that GUID assignment happens appropriately and all passes usegetGUID, so there's no reason forCtxProfAnalysisto 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 isinstall_trap_loop_detectionfromcompiler-rt/test/cfi/trap_loop_signal_handler.incwhich is-include-d by both - see how%clang_cfiis 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::addThinLTOwill 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 ofinstall_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: @orodley