22 "use-source-filename-for-promoted-locals",
cl::Hidden,
23 cl::desc(
"Uses the source file name instead of the Module hash. "
24 "This requires that the source filename has a unique name / "
25 "path to avoid name collisions."));
28 "thinlto-move-symbols",
30 "Move the symbols with the given name. This will delete these symbols "
31 "wherever they are originally defined, and make sure their "
32 "linkage is External where they are imported. It is meant to be "
33 "used with the name of contextual profiling roots."),
39 : M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport),
40 ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {
61bool FunctionImportGlobalProcessing::doImportAsDefinition(
63 if (!isPerformingImport())
67 if (!GlobalsToImport->count(
const_cast<GlobalValue *
>(SGV)))
70 assert(!isa<GlobalAlias>(SGV) &&
71 "Unexpected global alias in the import list.");
77bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
82 if (isa<GlobalIFunc>(SGV) ||
83 (isa<GlobalAlias>(SGV) &&
84 isa<GlobalIFunc>(cast<GlobalAlias>(SGV)->getAliaseeObject())))
89 if (!isPerformingImport() && !isModuleExporting())
92 if (isPerformingImport()) {
94 !isNonRenamableLocal(*SGV)) &&
95 "Attempting to promote non-renamable local");
111 assert(Summary &&
"Missing summary for global value when exporting");
114 assert(!isNonRenamableLocal(*SGV) &&
115 "Attempting to promote non-renamable local");
123bool FunctionImportGlobalProcessing::isNonRenamableLocal(
137FunctionImportGlobalProcessing::getPromotedName(
const GlobalValue *SGV) {
146 std::replace_if(std::begin(Suffix), std::end(Suffix),
147 [&](
char ch) {
return !isAlnum(ch); },
'_');
158FunctionImportGlobalProcessing::getLinkage(
const GlobalValue *SGV,
164 if (isModuleExporting()) {
171 if (!isPerformingImport())
181 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
182 return SymbolsToMove.contains(SGV->
getGUID())
191 if (!doImportAsDefinition(SGV))
203 assert(!doImportAsDefinition(SGV));
212 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
230 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
241 assert(!doImportAsDefinition(SGV));
254void FunctionImportGlobalProcessing::processGlobalForThinLTO(
GlobalValue &GV) {
263 (isPerformingImport() && !doImportAsDefinition(&GV)));
285 auto *GVS = dyn_cast_or_null<GlobalVarSummary>(
289 V->addAttribute(
"thinlto-internalize");
306 GV.
setName(getPromotedName(&GV));
314 if (
C->getName() ==
Name)
322 if (ClearDSOLocalOnDeclarations &&
324 (isPerformingImport() && !doImportAsDefinition(&GV))) &&
338 auto *GO = dyn_cast<GlobalObject>(&GV);
339 if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
343 assert(GO->hasAvailableExternallyLinkage() &&
344 "Expected comdat on definition (possibly available external)");
345 GO->setComdat(
nullptr);
349void FunctionImportGlobalProcessing::processGlobalsForThinLTO() {
351 processGlobalForThinLTO(GV);
353 processGlobalForThinLTO(SF);
355 processGlobalForThinLTO(GA);
359 if (!RenamedComdats.empty())
360 for (
auto &GO :
M.global_objects())
361 if (
auto *
C = GO.getComdat()) {
362 auto Replacement = RenamedComdats.find(
C);
363 if (Replacement != RenamedComdats.end())
364 GO.setComdat(Replacement->second);
371 bool ClearDSOLocalOnDeclarations,
374 ClearDSOLocalOnDeclarations);
375 ThinLTOProcessing.
run();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > UseSourceFilenameForPromotedLocals("use-source-filename-for-promoted-locals", cl::Hidden, cl::desc("Uses the source file name instead of the Module hash. " "This requires that the source filename has a unique name / " "path to avoid name collisions."))
Uses the "source_filename" instead of a Module hash ID for the suffix of promoted locals during LTO.
cl::list< GlobalValue::GUID > MoveSymbolGUID("thinlto-move-symbols", cl::desc("Move the symbols with the given name. This will delete these symbols " "wherever they are originally defined, and make sure their " "linkage is External where they are imported. It is meant to be " "used with the name of contextual profiling roots."), cl::Hidden)
cl::list< GlobalValue::GUID > MoveSymbolGUID
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Class to handle necessary GlobalValue changes required by ThinLTO function importing,...
LLVM_ABI FunctionImportGlobalProcessing(Module &M, const ModuleSummaryIndex &Index, SetVector< GlobalValue * > *GlobalsToImport, bool ClearDSOLocalOnDeclarations)
bool isImplicitDSOLocal() const
static bool isLocalLinkage(LinkageTypes Linkage)
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
LinkageTypes getLinkage() const
bool hasLocalLinkage() const
void setDLLStorageClass(DLLStorageClassTypes C)
LLVM_ABI const Comdat * getComdat() const
bool hasDLLImportStorageClass() const
void setLinkage(LinkageTypes LT)
bool isDeclarationForLinker() const
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Module * getParent()
Get the module that this global value is contained inside of...
void setDSOLocal(bool Local)
@ HiddenVisibility
The GV is hidden.
void setVisibility(VisibilityTypes V)
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
bool withAttributePropagation() const
bool isReadOnly(const GlobalVarSummary *GVS) const
bool isWriteOnly(const GlobalVarSummary *GVS) const
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
bool hasExportedFunctions(const Module &M) const
Check if the given Module has any functions available for exporting in the index.
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local,...
bool withDSOLocalPropagation() const
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
A Module instance is used to store all the information related to an LLVM module.
const std::string & getSourceFileName() const
Get the module's original source file name.
iterator_range< global_iterator > globals()
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
A vector that has set insertion semantics.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
std::string str() const
str - Get the contents as an std::string.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
This is an optimization pass for GlobalISel generic memory operations.
constexpr from_range_t from_range
LLVM_ABI void renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, bool ClearDSOLocalOnDeclarations, SetVector< GlobalValue * > *GlobalsToImport=nullptr)
Perform in-place global value handling on the given Module for exported local functions renamed and p...
LLVM_ABI GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Struct that holds a reference to a particular GUID in a global value summary.