diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h --- a/llvm/include/llvm/IR/Module.h +++ b/llvm/include/llvm/IR/Module.h @@ -893,9 +893,6 @@ GlobalVariable *collectUsedGlobalVariables(const Module &M, SmallVectorImpl &Set, bool CompilerUsed); -GlobalVariable *collectUsedGlobalVariables(const Module &M, - SmallPtrSetImpl &Set, - bool CompilerUsed); /// An raw_ostream inserter for modules. inline raw_ostream &operator<<(raw_ostream &O, const Module &M) { diff --git a/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h b/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h --- a/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h +++ b/llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h @@ -111,10 +111,13 @@ HasExportedFunctions = ImportIndex.hasExportedFunctions(M); #ifndef NDEBUG + SmallVector Vec; // First collect those in the llvm.used set. - collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false); + collectUsedGlobalVariables(M, Vec, /*CompilerUsed=*/false); // Next collect those in the llvm.compiler.used set. - collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true); + collectUsedGlobalVariables(M, Vec, /*CompilerUsed=*/true); + for (GlobalValue *V : Vec) + Used.insert(V); #endif } diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -665,11 +665,11 @@ // here because we use this information to mark functions containing inline // assembly calls as not importable. SmallPtrSet LocalsUsed; - SmallPtrSet Used; + SmallVector Used; // First collect those in the llvm.used set. - collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false); + collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/false); // Next collect those in the llvm.compiler.used set. - collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ true); + collectUsedGlobalVariables(M, Used, /*CompilerUsed=*/true); DenseSet CantBePromoted; for (auto *V : Used) { if (V->hasLocalLinkage()) { diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -673,21 +673,6 @@ return GV; } -GlobalVariable *llvm::collectUsedGlobalVariables( - const Module &M, SmallPtrSetImpl &Set, 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(GV->getInitializer()); - for (Value *Op : Init->operands()) { - GlobalValue *G = cast(Op->stripPointerCasts()); - Set.insert(G); - } - return GV; -} - void Module::setPartialSampleProfileRatio(const ModuleSummaryIndex &Index) { if (auto *SummaryMD = getProfileSummary(/*IsCS*/ false)) { std::unique_ptr ProfileSummary( diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -119,8 +119,11 @@ return make_error("input module has no datalayout", inconvertibleErrorCode()); + SmallVector UsedV; SmallPtrSet Used; - collectUsedGlobalVariables(*M, Used, /*CompilerUsed*/ false); + collectUsedGlobalVariables(*M, UsedV, /*CompilerUsed=*/false); + for (GlobalValue *V : UsedV) + Used.insert(V); ModuleSymbolTable Msymtab; Msymtab.addModule(M); diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -2795,8 +2795,14 @@ public: LLVMUsed(Module &M) { - UsedV = collectUsedGlobalVariables(M, Used, false); - CompilerUsedV = collectUsedGlobalVariables(M, CompilerUsed, true); + SmallVector Vec; + UsedV = collectUsedGlobalVariables(M, Vec, false); + for (GlobalValue *V : Vec) + Used.insert(V); + Vec.clear(); + CompilerUsedV = collectUsedGlobalVariables(M, Vec, true); + for (GlobalValue *V : Vec) + CompilerUsed.insert(V); } using iterator = SmallPtrSet::iterator; diff --git a/llvm/lib/Transforms/IPO/Internalize.cpp b/llvm/lib/Transforms/IPO/Internalize.cpp --- a/llvm/lib/Transforms/IPO/Internalize.cpp +++ b/llvm/lib/Transforms/IPO/Internalize.cpp @@ -151,7 +151,7 @@ bool Changed = false; CallGraphNode *ExternalNode = CG ? CG->getExternalCallingNode() : nullptr; - SmallPtrSet Used; + SmallVector Used; collectUsedGlobalVariables(M, Used, false); // Collect comdat visiblity information for the module.