aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Module.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2021-02-23 15:50:45 -0800
committerFangrui Song <i@maskray.me>2021-02-23 16:09:05 -0800
commit3adb89bb9f8e73c82787babb2f877fece7394770 (patch)
tree1d49b99ee5228ce78a585b1b7efeca1827c9ecf7 /llvm/lib/IR/Module.cpp
parent0a5949dcfa31d599353fb4ccf4d207bdae7c7281 (diff)
downloadllvm-3adb89bb9f8e73c82787babb2f877fece7394770.zip
llvm-3adb89bb9f8e73c82787babb2f877fece7394770.tar.gz
llvm-3adb89bb9f8e73c82787babb2f877fece7394770.tar.bz2
[ThinLTO] Make cloneUsedGlobalVariables deterministic
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. While here, decrease inline element counts from 8 to 4. The number of `llvm.used`/`llvm.compiler.used` elements is usually 0 or 1. For full LTO/hybrid LTO, the number may be large, so we need to be careful. According to tejohnson's analysis https://reviews.llvm.org/D97128#2582399 , 4 is good for a large project with WholeProgramDevirt, when available_externally vtables are placed in the llvm.compiler.used set. Differential Revision: https://reviews.llvm.org/D97128
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r--llvm/lib/IR/Module.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 9395b2b..4c24461 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -659,6 +659,21 @@ VersionTuple Module::getSDKVersion() const {
}
GlobalVariable *llvm::collectUsedGlobalVariables(
+ const Module &M, SmallVectorImpl<GlobalValue *> &Vec, bool CompilerUsed) {
+ const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
+ GlobalVariable *GV = M.getGlobalVariable(Name);
+ if (!GV || !GV->hasInitializer())
+ return GV;
+
+ const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
+ for (Value *Op : Init->operands()) {
+ GlobalValue *G = cast<GlobalValue>(Op->stripPointerCasts());
+ Vec.push_back(G);
+ }
+ return GV;
+}
+
+GlobalVariable *llvm::collectUsedGlobalVariables(
const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) {
const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
GlobalVariable *GV = M.getGlobalVariable(Name);