21 bool FunctionImportGlobalProcessing::doImportAsDefinition(
23 if (!isPerformingImport())
27 if (!GlobalsToImport->count(const_cast<GlobalValue *>(SGV)))
30 assert(!isa<GlobalAlias>(SGV) &&
31 "Unexpected global alias in the import list.");
37 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
42 if (!isPerformingImport() && !isModuleExporting())
45 if (isPerformingImport()) {
46 assert((!GlobalsToImport->count(const_cast<GlobalValue *>(SGV)) ||
47 !isNonRenamableLocal(*SGV)) &&
48 "Attempting to promote non-renamable local");
64 assert(Summary &&
"Missing summary for global value when exporting");
65 auto Linkage = Summary->linkage();
67 assert(!isNonRenamableLocal(*SGV) &&
68 "Attempting to promote non-renamable local");
76 bool FunctionImportGlobalProcessing::isNonRenamableLocal(
83 if (Used.count(const_cast<GlobalValue *>(&GV)))
90 FunctionImportGlobalProcessing::getPromotedName(
const GlobalValue *SGV) {
101 FunctionImportGlobalProcessing::getLinkage(
const GlobalValue *SGV,
107 if (isModuleExporting()) {
114 if (!isPerformingImport())
124 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
132 if (!doImportAsDefinition(SGV))
144 assert(!doImportAsDefinition(SGV));
153 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
171 if (doImportAsDefinition(SGV) && !isa<GlobalAlias>(SGV))
182 assert(!doImportAsDefinition(SGV));
195 void FunctionImportGlobalProcessing::processGlobalForThinLTO(
GlobalValue &GV) {
202 if (
Function *
F = dyn_cast<Function>(&GV)) {
203 if (!
F->isDeclaration()) {
205 auto *
FS = cast<FunctionSummary>(S->getBaseObject());
227 (isPerformingImport() && !doImportAsDefinition(&GV)));
249 auto *GVS = dyn_cast_or_null<GlobalVarSummary>(
253 V->addAttribute(
"thinlto-internalize");
270 GV.
setName(getPromotedName(&GV));
287 if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
291 assert(GO->hasAvailableExternallyLinkage() &&
292 "Expected comdat on definition (possibly available external)");
293 GO->setComdat(
nullptr);
297 void FunctionImportGlobalProcessing::processGlobalsForThinLTO() {
299 processGlobalForThinLTO(GV);
301 processGlobalForThinLTO(SF);
303 processGlobalForThinLTO(GA);
307 if (!RenamedComdats.empty())
308 for (
auto &GO : M.global_objects())
309 if (
auto *
C = GO.getComdat()) {
310 auto Replacement = RenamedComdats.find(
C);
311 if (Replacement != RenamedComdats.end())
312 GO.setComdat(Replacement->second);
317 processGlobalsForThinLTO();
324 return ThinLTOProcessing.
run();
void setVisibility(VisibilityTypes V)
bool hasLocalLinkage() const
Special purpose, only applies to global arrays.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
Same, but only replaced by something equivalent.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Available for inspection, not emission.
bool withAttributePropagation() const
Like Internal, but omit from symbol table.
Externally visible function.
Class to handle necessary GlobalValue changes required by ThinLTO function importing, including linkage changes and any necessary renaming.
bool hasDLLImportStorageClass() const
bool isReadOnly(const GlobalVarSummary *GVS) const
static bool isLocalLinkage(LinkageTypes Linkage)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local...
void setName(const Twine &Name)
Change the name of the value.
void setDLLStorageClass(DLLStorageClassTypes C)
LinkageTypes getLinkage() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
ExternalWeak linkage description.
Same, but only replaced by something equivalent.
bool renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, SetVector< GlobalValue *> *GlobalsToImport=nullptr)
Perform in-place global value handling on the given Module for exported local functions renamed and p...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Class to represent profile counts.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Struct that holds a reference to a particular GUID in a global value summary.
bool isWriteOnly(const GlobalVarSummary *GVS) const
Keep one copy of function when linking (inline)
void setLinkage(LinkageTypes LT)
const Comdat * getComdat() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
bool hasSyntheticEntryCounts() const
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
Linkage
Describes symbol linkage.
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
A vector that has set insertion semantics.
iterator_range< global_iterator > globals()
void setDSOLocal(bool Local)