Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 4 additions & 1 deletion llvm/lib/LTO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ std::string llvm::computeLTOCacheKey(

// Include the hash for the linkage type to reflect internalization and weak
// resolution, and collect any used type identifier resolutions.
for (auto &GS : DefinedGlobals) {
SmallVector<std::pair<GlobalValue::GUID, GlobalValueSummary *>>

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.

Add a comment above this about why it is needed.

SortedDefinedGlobals(DefinedGlobals.begin(), DefinedGlobals.end());
llvm::sort(SortedDefinedGlobals, llvm::less_first());
for (auto &GS : SortedDefinedGlobals) {
GlobalValue::LinkageTypes Linkage = GS.second->linkage();
Hasher.update(
ArrayRef<uint8_t>((const uint8_t *)&Linkage, sizeof(Linkage)));
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/ThinLTO/X86/Inputs/cache-defined-globals-order.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define linkonce_odr void @shared29() {
ret void
}
27 changes: 27 additions & 0 deletions llvm/test/ThinLTO/X86/cache-defined-globals-order.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; RUN: rm -rf %t && mkdir -p %t
; RUN: opt -module-hash -module-summary %s -o %t/t.bc
; RUN: opt -module-hash -module-summary %S/Inputs/cache-defined-globals-order.ll -o %t/a.bc

; Tests that the LTO cache key is insensitive to the order of the modules.
; The linkonce_odr function @shared29 is defined in both t.bc and a.bc, so
; it gets a different position in the combined index depending on which
; module is processed first, which results in a different insertion order
; for DefinedGlobals.

; RUN: llvm-lto2 run -cache-dir %t/cache -o %t.o %t/t.bc %t/a.bc -r=%t/t.bc,main,plx -r=%t/t.bc,shared29,plx -r=%t/a.bc,shared29,lx
; RUN: ls %t/cache | count 2

; RUN: llvm-lto2 run -cache-dir %t/cache -o %t.o %t/a.bc %t/t.bc -r=%t/t.bc,main,plx -r=%t/t.bc,shared29,plx -r=%t/a.bc,shared29,lx
; RUN: ls %t/cache | count 2

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @main() {
call void @shared29()
ret void
}

define linkonce_odr void @shared29() {
ret void
}
Loading