24 "use-source-filename-for-promoted-locals",
cl::Hidden,
25 cl::desc(
"Uses the source file name instead of the Module hash. "
26 "This requires that the source filename has a unique name / "
27 "path to avoid name collisions."));
30 "thinlto-move-symbols",
32 "Move the symbols with the given name. This will delete these symbols "
33 "wherever they are originally defined, and make sure their "
34 "linkage is External where they are imported. It is meant to be "
35 "used with the name of contextual profiling roots."),
41 : M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport),
42 ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {
48 HasExportedFunctions = ImportIndex.hasExportedFunctions(M);
63bool FunctionImportGlobalProcessing::doImportAsDefinition(
65 if (!isPerformingImport())
69 if (!GlobalsToImport->count(
const_cast<GlobalValue *
>(SGV)))
73 "Unexpected global alias in the import list.");
79bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
91 if (!isPerformingImport() && !isModuleExporting())
94 if (isPerformingImport()) {
97 "Attempting to promote non-renamable local");
111 auto Summary = ImportIndex.findSummaryInModule(
113 assert(Summary &&
"Missing summary for global value when exporting");
116 assert(!isNonRenamableLocal(*SGV) &&
117 "Attempting to promote non-renamable local");
125bool FunctionImportGlobalProcessing::isNonRenamableLocal(
132 if (Used.count(
const_cast<GlobalValue *
>(&GV)))
139FunctionImportGlobalProcessing::getPromotedName(
const GlobalValue *SGV) {
148 std::replace_if(std::begin(Suffix), std::end(Suffix),
149 [&](
char ch) {
return !
isAlnum(ch); },
'_');
160FunctionImportGlobalProcessing::getLinkage(
const GlobalValue *SGV,
166 if (isModuleExporting()) {
173 if (!isPerformingImport())
184 return SymbolsToMove.contains(SGV->
getGUID())
193 if (!doImportAsDefinition(SGV))
205 assert(!doImportAsDefinition(SGV));
243 assert(!doImportAsDefinition(SGV));
256void FunctionImportGlobalProcessing::processGlobalForThinLTO(
GlobalValue &GV) {
260 VI = ImportIndex.getValueInfo(GV.
getGUID());
265 (isPerformingImport() && !doImportAsDefinition(&GV)));
276 if (!GV.
isDeclaration() && VI && ImportIndex.withAttributePropagation()) {
288 ImportIndex.findSummaryInModule(VI, M.getModuleIdentifier()));
290 (ImportIndex.isReadOnly(GVS) || ImportIndex.isWriteOnly(GVS))) {
291 V->addAttribute(
"thinlto-internalize");
299 if (ImportIndex.isWriteOnly(GVS))
308 GV.
setName(getPromotedName(&GV));
316 if (
C->getName() == Name)
317 RenamedComdats.try_emplace(
C, M.getOrInsertComdat(GV.
getName()));
324 if (ClearDSOLocalOnDeclarations &&
326 (isPerformingImport() && !doImportAsDefinition(&GV))) &&
329 }
else if (VI &&
VI.isDSOLocal(ImportIndex.withDSOLocalPropagation())) {
341 if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
345 assert(GO->hasAvailableExternallyLinkage() &&
346 "Expected comdat on definition (possibly available external)");
347 GO->setComdat(
nullptr);
351void FunctionImportGlobalProcessing::processGlobalsForThinLTO() {
352 for (GlobalVariable &GV : M.globals())
353 processGlobalForThinLTO(GV);
354 for (Function &SF : M)
355 processGlobalForThinLTO(SF);
356 for (GlobalAlias &GA : M.aliases())
357 processGlobalForThinLTO(GA);
361 if (!RenamedComdats.empty())
362 for (
auto &GO : M.global_objects())
363 if (
auto *
C = GO.getComdat()) {
364 auto Replacement = RenamedComdats.find(
C);
365 if (Replacement != RenamedComdats.end())
366 GO.setComdat(Replacement->second);
373 bool ClearDSOLocalOnDeclarations,
377 ClearDSOLocalOnDeclarations);
378 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 bool isNonRenamableLocal(const GlobalValue &GV)
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...
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local,...
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.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
A vector that has set insertion semantics.
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.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
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.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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...
auto dyn_cast_or_null(const Y &Val)
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
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.