21 bool FunctionImportGlobalProcessing::doImportAsDefinition(
25 if (!GlobalsToImport->
count(const_cast<GlobalValue *>(SGV)))
28 assert(!isa<GlobalAlias>(SGV) &&
29 "Unexpected global alias in the import list.");
35 bool FunctionImportGlobalProcessing::doImportAsDefinition(
37 if (!isPerformingImport())
39 return FunctionImportGlobalProcessing::doImportAsDefinition(SGV,
43 bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
48 if (!isPerformingImport() && !isModuleExporting())
51 if (isPerformingImport()) {
52 assert((!GlobalsToImport->count(const_cast<GlobalValue *>(SGV)) ||
53 !isNonRenamableLocal(*SGV)) &&
54 "Attempting to promote non-renamable local");
70 assert(Summary &&
"Missing summary for global value when exporting");
71 auto Linkage = Summary->linkage();
73 assert(!isNonRenamableLocal(*SGV) &&
74 "Attempting to promote non-renamable local");
82 bool FunctionImportGlobalProcessing::isNonRenamableLocal(
89 if (Used.count(const_cast<GlobalValue *>(&GV)))
95 std::string FunctionImportGlobalProcessing::getName(
const GlobalValue *SGV,
110 FunctionImportGlobalProcessing::getLinkage(
const GlobalValue *SGV,
116 if (isModuleExporting()) {
123 if (!isPerformingImport())
141 if (!doImportAsDefinition(SGV))
153 assert(!doImportAsDefinition(SGV));
162 if (doImportAsDefinition(SGV) && !dyn_cast<GlobalAlias>(SGV))
180 if (doImportAsDefinition(SGV) && !dyn_cast<GlobalAlias>(SGV))
191 assert(!doImportAsDefinition(SGV));
204 void FunctionImportGlobalProcessing::processGlobalForThinLTO(
GlobalValue &GV) {
211 if (
Function *
F = dyn_cast<Function>(&GV)) {
212 if (!
F->isDeclaration()) {
245 if (GVS && GVS->isReadOnly())
246 cast<GlobalVariable>(&GV)->addAttribute(
"thinlto-internalize");
249 bool DoPromote =
false;
251 ((DoPromote = shouldPromoteLocalToGlobal(&GV)) || isPerformingImport())) {
258 GV.
setName(getName(&GV, DoPromote));
275 if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
279 assert(GO->hasAvailableExternallyLinkage() &&
280 "Expected comdat on definition (possibly available external)");
281 GO->setComdat(
nullptr);
285 void FunctionImportGlobalProcessing::processGlobalsForThinLTO() {
287 processGlobalForThinLTO(GV);
289 processGlobalForThinLTO(SF);
291 processGlobalForThinLTO(GA);
295 if (!RenamedComdats.empty())
296 for (
auto &GO : M.global_objects())
297 if (
auto *
C = GO.getComdat()) {
298 auto Replacement = RenamedComdats.find(
C);
299 if (Replacement != RenamedComdats.end())
300 GO.setComdat(Replacement->second);
305 processGlobalsForThinLTO();
312 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.
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
Global variable summary information to aid decisions and implementation of importing.
Available for inspection, not emission.
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
static bool isLocalLinkage(LinkageTypes Linkage)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
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...
uint64_t entryCount() const
Get the synthetic entry count for this function.
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.
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).
bool withGlobalValueDeadStripping() const
StringRef modulePath() const
Get the path to the module containing this function.
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).
Function summary information to aid decisions and implementation of importing.
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)