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."));
29bool FunctionImportGlobalProcessing::doImportAsDefinition(
31 if (!isPerformingImport())
35 if (!GlobalsToImport->count(
const_cast<GlobalValue *
>(SGV)))
38 assert(!isa<GlobalAlias>(SGV) &&
39 "Unexpected global alias in the import list.");
45bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
50 if (isa<GlobalIFunc>(SGV) ||
51 (isa<GlobalAlias>(SGV) &&
52 isa<GlobalIFunc>(cast<GlobalAlias>(SGV)->getAliaseeObject())))
57 if (!isPerformingImport() && !isModuleExporting())
60 if (isPerformingImport()) {
62 !isNonRenamableLocal(*SGV)) &&
63 "Attempting to promote non-renamable local");
79 assert(Summary &&
"Missing summary for global value when exporting");
82 assert(!isNonRenamableLocal(*SGV) &&
83 "Attempting to promote non-renamable local");
91bool FunctionImportGlobalProcessing::isNonRenamableLocal(
105FunctionImportGlobalProcessing::getPromotedName(
const GlobalValue *SGV) {
114 std::replace_if(std::begin(Suffix), std::end(Suffix),
115 [&](
char ch) {
return !isAlnum(ch); },
'_');
126FunctionImportGlobalProcessing::getLinkage(
const GlobalValue *SGV,
132 if (isModuleExporting()) {
139 if (!isPerformingImport())
149 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
157 if (!doImportAsDefinition(SGV))
169 assert(!doImportAsDefinition(SGV));
178 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
196 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
207 assert(!doImportAsDefinition(SGV));
220void FunctionImportGlobalProcessing::processGlobalForThinLTO(
GlobalValue &GV) {
229 (isPerformingImport() && !doImportAsDefinition(&GV)));
251 auto *GVS = dyn_cast_or_null<GlobalVarSummary>(
255 V->addAttribute(
"thinlto-internalize");
272 GV.
setName(getPromotedName(&GV));
280 if (
C->getName() ==
Name)
288 if (ClearDSOLocalOnDeclarations &&
290 (isPerformingImport() && !doImportAsDefinition(&GV))) &&
304 auto *GO = dyn_cast<GlobalObject>(&GV);
305 if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
309 assert(GO->hasAvailableExternallyLinkage() &&
310 "Expected comdat on definition (possibly available external)");
311 GO->setComdat(
nullptr);
315void FunctionImportGlobalProcessing::processGlobalsForThinLTO() {
317 processGlobalForThinLTO(GV);
319 processGlobalForThinLTO(SF);
321 processGlobalForThinLTO(GA);
325 if (!RenamedComdats.empty())
326 for (
auto &GO :
M.global_objects())
327 if (
auto *
C = GO.getComdat()) {
328 auto Replacement = RenamedComdats.find(
C);
329 if (Replacement != RenamedComdats.end())
330 GO.setComdat(Replacement->second);
335 processGlobalsForThinLTO();
340 bool ClearDSOLocalOnDeclarations,
343 ClearDSOLocalOnDeclarations);
344 return ThinLTOProcessing.
run();
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Class to handle necessary GlobalValue changes required by ThinLTO function importing,...
bool isImplicitDSOLocal() const
static bool isLocalLinkage(LinkageTypes Linkage)
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)
const Comdat * getComdat() const
bool hasDLLImportStorageClass() const
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
void setLinkage(LinkageTypes LT)
bool isDeclarationForLinker() const
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.
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...
std::string str() const
str - Get the contents as an std::string.
void setName(const Twine &Name)
Change the name of the value.
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.
bool 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...
Struct that holds a reference to a particular GUID in a global value summary.