26    "use-source-filename-for-promoted-locals", 
cl::Hidden,
 
   27    cl::desc(
"Uses the source file name instead of the Module hash. " 
   28             "This requires that the source filename has a unique name / " 
   29             "path to avoid name collisions."));
 
   32    "thinlto-move-symbols",
 
   34        "Move the symbols with the given name. This will delete these symbols " 
   35        "wherever they are originally defined, and make sure their " 
   36        "linkage is External where they are imported. It is meant to be " 
   37        "used with the name of contextual profiling roots."),
 
   45    : M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport),
 
   46      ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {
 
   52    HasExportedFunctions = ImportIndex.hasExportedFunctions(M);
 
 
   67bool FunctionImportGlobalProcessing::doImportAsDefinition(
 
   69  if (!isPerformingImport())
 
   73  if (!GlobalsToImport->count(
const_cast<GlobalValue *
>(SGV)))
 
   77         "Unexpected global alias in the import list.");
 
   83bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
 
   95  if (!isPerformingImport() && !isModuleExporting())
 
   98  if (isPerformingImport()) {
 
  101           "Attempting to promote non-renamable local");
 
  115  auto Summary = ImportIndex.findSummaryInModule(
 
  117  assert(Summary && 
"Missing summary for global value when exporting");
 
  120    assert(!isNonRenamableLocal(*SGV) &&
 
  121           "Attempting to promote non-renamable local");
 
  129bool FunctionImportGlobalProcessing::isNonRenamableLocal(
 
  136  if (Used.count(
const_cast<GlobalValue *
>(&GV)))
 
  143FunctionImportGlobalProcessing::getPromotedName(
const GlobalValue *SGV) {
 
  152    std::replace_if(std::begin(Suffix), std::end(Suffix),
 
  153                    [&](
char ch) { 
return !
isAlnum(ch); }, 
'_');
 
  164FunctionImportGlobalProcessing::getLinkage(
const GlobalValue *SGV,
 
  170  if (isModuleExporting()) {
 
  177  if (!isPerformingImport())
 
  188      return SymbolsToMove.contains(SGV->
getGUID())
 
  197    if (!doImportAsDefinition(SGV))
 
  209    assert(!doImportAsDefinition(SGV));
 
  247    assert(!doImportAsDefinition(SGV));
 
  260void FunctionImportGlobalProcessing::processGlobalForThinLTO(
GlobalValue &GV) {
 
  264    VI = ImportIndex.getValueInfo(GV.
getGUID());
 
  269         (isPerformingImport() && !doImportAsDefinition(&GV)));
 
  280  if (!GV.
isDeclaration() && VI && ImportIndex.withAttributePropagation()) {
 
  292          ImportIndex.findSummaryInModule(VI, M.getModuleIdentifier()));
 
  294          (ImportIndex.isReadOnly(GVS) || ImportIndex.isWriteOnly(GVS))) {
 
  295        V->addAttribute(
"thinlto-internalize");
 
  303        if (ImportIndex.isWriteOnly(GVS))
 
  312    GV.
setName(getPromotedName(&GV));
 
  320      if (
C->getName() == Name)
 
  321        RenamedComdats.try_emplace(
C, M.getOrInsertComdat(GV.
getName()));
 
  328  if (ClearDSOLocalOnDeclarations &&
 
  330       (isPerformingImport() && !doImportAsDefinition(&GV))) &&
 
  333  } 
else if (VI && 
VI.isDSOLocal(ImportIndex.withDSOLocalPropagation())) {
 
  345  if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
 
  349    assert(GO->hasAvailableExternallyLinkage() &&
 
  350           "Expected comdat on definition (possibly available external)");
 
  351    GO->setComdat(
nullptr);
 
  355void FunctionImportGlobalProcessing::processGlobalsForThinLTO() {
 
  356  for (GlobalVariable &GV : M.globals())
 
  357    processGlobalForThinLTO(GV);
 
  358  for (Function &SF : M)
 
  359    processGlobalForThinLTO(SF);
 
  360  for (GlobalAlias &GA : M.aliases())
 
  361    processGlobalForThinLTO(GA);
 
  365  if (!RenamedComdats.empty())
 
  366    for (
auto &GO : M.global_objects())
 
  367      if (
auto *
C = GO.getComdat()) {
 
  368        auto Replacement = RenamedComdats.find(
C);
 
  369        if (Replacement != RenamedComdats.end())
 
  370          GO.setComdat(Replacement->second);
 
  377                                  bool ClearDSOLocalOnDeclarations,
 
  381                                                   ClearDSOLocalOnDeclarations);
 
  382  ThinLTOProcessing.
run();
 
 
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
cl::list< GlobalValue::GUID > MoveSymbolGUID
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)
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.
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.