[PATCH] D97128: [ThinLTO] Make cloneUsedGlobalVariables deterministic
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 20 15:28:49 PST 2021
MaskRay created this revision.
MaskRay added a reviewer: tejohnson.
Herald added subscribers: steven_wu, mgrang, hiraditya, inglorion.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Iterating on `SmallPtrSet<GlobalValue *, 8>` with more than 8 elements
is not deterministic. Use a SmallVector instead because `Used` is guaranteed to contain unique elements.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97128
Files:
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
===================================================================
--- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -200,22 +200,20 @@
static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
bool CompilerUsed) {
SmallPtrSet<GlobalValue *, 8> Used;
- SmallPtrSet<GlobalValue *, 8> NewUsed;
+ SmallVector<GlobalValue *, 8> NewUsed;
// First collect those in the llvm[.compiler].used set.
collectUsedGlobalVariables(SrcM, Used, CompilerUsed);
// Next build a set of the equivalent values defined in DestM.
for (auto *V : Used) {
auto *GV = DestM.getNamedValue(V->getName());
if (GV && !GV->isDeclaration())
- NewUsed.insert(GV);
+ NewUsed.push_back(GV);
}
// Finally, add them to a llvm[.compiler].used variable in DestM.
if (CompilerUsed)
- appendToCompilerUsed(
- DestM, std::vector<GlobalValue *>(NewUsed.begin(), NewUsed.end()));
+ appendToCompilerUsed(DestM, NewUsed);
else
- appendToUsed(DestM,
- std::vector<GlobalValue *>(NewUsed.begin(), NewUsed.end()));
+ appendToUsed(DestM, NewUsed);
}
// If it's possible to split M into regular and thin LTO parts, do so and write
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97128.325253.patch
Type: text/x-patch
Size: 1335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210220/f54e4e65/attachment.bin>
More information about the llvm-commits
mailing list