Lines Matching +full:cold +full:- +full:temp
1 //===-LTO.cpp - LLVM Link Time Optimizer ----------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
25 #include "llvm/Config/llvm-config.h"
72 DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden,
78 "enable-lto-internalization", cl::init(true), cl::Hidden,
81 /// Indicate we are linking with an allocator that supports hot/cold operator
132 // command-line flags (which is unsupported in production), but may set
144 AddUnsigned(-1);
148 AddUnsigned(-1);
185 StringRef getIdentifier() const { return ModIt->getFirst(); }
187 return ModIt->second;
190 const ModuleHash &getHash() const { return ModInfo->second; }
198 ImportModulesVector.push_back({It, Index.getModule(It->getFirst())});
203 [](const ImportModule &Lhs, const ImportModule &Rhs) -> bool {
248 AddUnsigned(GS->getVisibility());
249 AddUnsigned(GS->isLive());
250 AddUnsigned(GS->canAutoHide());
251 for (const ValueInfo &VI : GS->refs()) {
256 AddUnsigned(GVS->maybeReadOnly());
257 AddUnsigned(GVS->maybeWriteOnly());
260 for (auto &TT : FS->type_tests())
262 for (auto &TT : FS->type_test_assume_vcalls())
264 for (auto &TT : FS->type_checked_load_vcalls())
266 for (auto &TT : FS->type_test_assume_const_vcalls())
268 for (auto &TT : FS->type_checked_load_const_vcalls())
270 for (auto &ET : FS->calls()) {
280 GlobalValue::LinkageTypes Linkage = GS.second->linkage();
297 AddUsedThings(AS->getBaseObject());
334 AddTypeIdSummary(It->second.first, It->second.second);
348 Hasher.update(FileOrErr.get()->getBuffer());
353 Hasher.update(FileOrErr.get()->getBuffer());
373 GlobalValue::LinkageTypes OriginalLinkage = S->linkage();
377 GlobalValue::isAppendingLinkage(S->linkage()))
381 // This is both a compile-time optimization and a correctness
383 // a reference - we need to convert the linkonce to weak to
389 S->setLinkage(GlobalValue::getWeakLinkage(
391 // The kept copy is eligible for auto-hiding (hidden visibility) if all
400 S->setCanAutoHide(VI.canAutoHide() &&
404 Visibility = S->getVisibility();
409 S->setLinkage(GlobalValue::AvailableExternallyLinkage);
415 S->setVisibility(Visibility);
417 if (S->linkage() != OriginalLinkage)
418 recordNewLinkage(S->modulePath(), VI.getGUID(), S->linkage());
423 GlobalValue::LinkageTypes OriginalLinkage = S->linkage();
425 GlobalValue::isAppendingLinkage(S->linkage()))
427 S->setVisibility(Visibility);
452 GlobalInvolvedWithAlias.insert(&AS->getAliasee());
467 return !GlobalValue::isLocalLinkage(Summary->linkage());
473 if (isExported(S->modulePath(), VI)) {
474 if (GlobalValue::isLocalLinkage(S->linkage()))
475 S->setLinkage(GlobalValue::ExternalLinkage);
483 // Non-exported values with external linkage can be internalized.
484 if (GlobalValue::isExternalLinkage(S->linkage())) {
485 S->setLinkage(GlobalValue::InternalLinkage);
489 // Non-exported function and variable definitions with a weak-for-linker
492 // don't break pointer equality checks, and that variables are either read-
493 // or write-only. For functions, this is the case if either all copies are
496 // they are read or write-only).
498 // However, we only get to this code for weak-for-linkage values in one of
506 // are llvm-lto based tests of the legacy LTO API that do not mark
510 // Generally, we only want to internalize a weak-for-linker value in case
512 // is read or write-only. We also don't want to bloat the binary with
513 // multiple internalized copies of non-prevailing linkonce/weak functions.
514 // Note if we don't internalize, we will convert non-prevailing copies to
522 // read or write-only variables (processGlobalForThinLTO).
527 // write-only.
528 if (!GlobalValue::isWeakForLinker(S->linkage()) ||
529 GlobalValue::isExternalWeakLinkage(S->linkage()))
533 S->setLinkage(GlobalValue::InternalLinkage);
538 // as external and non-exported values as internal.
559 File->TargetTriple = FOrErr->TheReader.getTargetTriple();
560 File->SourceFileName = FOrErr->TheReader.getSourceFileName();
561 File->COFFLinkerOpts = FOrErr->TheReader.getCOFFLinkerOpts();
562 File->DependentLibraries = FOrErr->TheReader.getDependentLibraries();
563 File->ComdatTable = FOrErr->TheReader.getComdatTable();
565 for (unsigned I = 0; I != FOrErr->Mods.size(); ++I) {
566 size_t Begin = File->Symbols.size();
568 FOrErr->TheReader.module_symbols(I))
572 File->Symbols.push_back(Sym);
573 File->ModuleSymIndices.push_back({Begin, File->Symbols.size()});
576 File->Mods = FOrErr->Mods;
577 File->Strtab = std::move(FOrErr->Strtab);
593 Ctx(Conf), CombinedModule(std::make_unique<Module>("ld-temp.o", Ctx)),
595 CombinedModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat;
601 this->Backend =
608 RegularLTO(ParallelCodeGenParallelismLevel, this->Conf),
624 const Triple TT(RegularLTO.CombinedModule->getTargetTriple());
662 // Set the partition to external if we know it is re-defined by the linker
663 // with -defsym or -wrap options, used elsewhere, e.g. it is visible to a
685 StringRef Path = Input->getName();
688 for (const InputFile::Symbol &Sym : Input->symbols()) {
692 OS << "-r=" << Path << ',' << Sym.getName() << ',';
714 if (RegularLTO.CombinedModule->getTargetTriple().empty()) {
715 RegularLTO.CombinedModule->setTargetTriple(Input->getTargetTriple());
716 if (Triple(Input->getTargetTriple()).isOSBinFormatELF())
721 for (unsigned I = 0; I != Input->Mods.size(); ++I)
740 if (*EnableSplitLTOUnit != LTOInfo->EnableSplitLTOUnit)
743 EnableSplitLTOUnit = LTOInfo->EnableSplitLTOUnit;
748 !LTOInfo->UnifiedLTO)
751 "compatible bitcode modules (use -funified-lto)",
754 if (LTOInfo->UnifiedLTO && LTOMode == LTOK_Default)
757 bool IsThinLTO = LTOInfo->IsThinLTO && (LTOMode != LTOK_UnifiedRegular);
762 LTOInfo->HasSummary);
773 if (!LTOInfo->HasSummary)
784 // Checks whether the given global value is in a non-prevailing comdat
789 // regular LTO modules, in case we are in a mixed-LTO mode (both regular
806 // are discarded as a unit. The non-local linkage global values avoid
811 GO->setComdat(nullptr);
889 // For symbols re-defined with linker -wrap and -defsym options,
893 GV->setLinkage(GlobalValue::WeakAnyLinkage);
895 GlobalValue::LinkageTypes OriginalLinkage = GV->getLinkage();
897 GV->setLinkage(GlobalValue::getWeakLinkage(
900 (GV->hasLinkOnceODRLinkage() || GV->hasWeakODRLinkage() ||
901 GV->hasAvailableExternallyLinkage()) &&
909 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
910 if (GV->hasComdat())
911 NonPrevailingComdats.insert(GV->getComdat());
912 cast<GlobalObject>(GV)->setComdat(nullptr);
917 GV->setDSOLocal(true);
918 if (GV->hasDLLImportStorageClass())
919 GV->setDLLStorageClass(GlobalValue::DLLStorageClassTypes::
924 // Collect non-prevailing symbols.
926 NonPrevailingAsmSymbols.insert(AS->first);
976 if (LivenessFromIndex && !ThinLTO.CombinedIndex.isGUIDLive(GV->getGUID())) {
979 if (Error Err = F->materialize())
990 if (!GV->hasAvailableExternallyLinkage()) {
998 RegularLTO.CombinedModule->getNamedValue(GV->getName());
999 if (CombinedGV && !CombinedGV->isDeclaration())
1005 return RegularLTO.Mover->move(std::move(Mod.M), Keep, nullptr,
1046 // For linker redefined symbols (via --wrap or --defsym) we want to
1053 S->setLinkage(GlobalValue::WeakAnyLinkage);
1061 S->setDSOLocal(true);
1079 ThinLTO.ModulesToCompile->insert({BM.getModuleIdentifier(), BM});
1091 auto ModuleCount = ThinLTO.ModulesToCompile ? ThinLTO.ModulesToCompile->size()
1102 Function *TypeTestFunc = RegularLTO.CombinedModule->getFunction(
1104 Function *TypeCheckedLoadFunc = RegularLTO.CombinedModule->getFunction(
1107 RegularLTO.CombinedModule->getFunction(
1112 if ((TypeTestFunc && !TypeTestFunc->use_empty()) ||
1113 (TypeCheckedLoadFunc && !TypeCheckedLoadFunc->use_empty()) ||
1115 !TypeCheckedLoadRelativeFunc->use_empty()))
1117 "inconsistent LTO Unit splitting (recompile with -fsplit-lto-unit)",
1127 if (!FS->type_test_assume_vcalls().empty() ||
1128 !FS->type_checked_load_vcalls().empty() ||
1129 !FS->type_test_assume_const_vcalls().empty() ||
1130 !FS->type_checked_load_const_vcalls().empty() ||
1131 !FS->type_tests().empty())
1133 "inconsistent LTO Unit splitting (recompile with -fsplit-lto-unit)",
1167 return It->second;
1193 PrintStatisticsJSON(StatsFile->os());
1204 // and those will cause us to generate calls to the hot/cold interfaces
1205 // unconditionally. If supports-hot-cold-new was not enabled in the LTO
1214 if (CI->hasFnAttr("memprof"))
1215 CI->removeFnAttr("memprof");
1220 // and cold, we will need to update the metadata based on the allocator
1222 CI->setMetadata(LLVMContext::MD_memprof, nullptr);
1223 CI->setMetadata(LLVMContext::MD_callsite, nullptr);
1232 RegularLTO.CombinedModule->getContext(), Conf.RemarksFilename,
1256 const DataLayout &DL = RegularLTO.CombinedModule->getDataLayout();
1261 GlobalVariable *OldGV = RegularLTO.CombinedModule->getNamedGlobal(I.first);
1262 if (OldGV && DL.getTypeAllocSize(OldGV->getValueType()) == I.second.Size) {
1265 OldGV->setAlignment(I.second.Alignment);
1273 GV->setAlignment(I.second.Alignment);
1275 OldGV->replaceAllUsesWith(GV);
1276 GV->takeName(OldGV);
1277 OldGV->eraseFromParent();
1279 GV->setName(I.first);
1294 auto It = GlobalResolutions->find(name);
1295 return (It == GlobalResolutions->end() || It->second.VisibleOutsideSummary);
1314 RegularLTO.CombinedModule->getNamedValue(R.second.IRName);
1323 if (!GV || GV->hasLocalLinkage() || GV->isDeclaration())
1336 ((GV->getDLLStorageClass() != GlobalValue::DefaultStorageClass) ||
1337 GV->hasAvailableExternallyLinkage() || GV->hasAppendingLinkage()))
1340 GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global
1343 GV->setLinkage(GlobalValue::InternalLinkage);
1515 ModuleToDefinedGVSummaries.find(ModulePath)->second;
1585 return "apple-a12";
1658 // re-ordering and avoid non-determinism in the final link.
1690 if (ThinLTO.ModulesToCompile && ThinLTO.ModulesToCompile->empty()) {
1699 // Collect for each module the list of function it defines (GUID ->
1739 // upgraded because they correspond to typeIDs outside of index-based
1747 auto It = GlobalResolutions->find(name);
1748 return (It == GlobalResolutions->end() ||
1749 It->second.VisibleOutsideSummary);
1763 // Perform index-based WPD. This will return immediately if there are
1765 // performing IR-based WPD in hybrid regular/thin LTO mode).
1771 return ThinLTO.PrevailingModuleForGUID[GUID] == S->modulePath();
1779 // at -O0 because summary-based DCE is implemented using internalization, and
1790 // Mark exported unless index-based analysis determined it to be dead.
1816 return (ExportList != ExportLists.end() && ExportList->second.count(VI)) ||
1820 // Update local devirtualized targets that were exported by cross-module
1852 auto ProcessOneModule = [&](int I) -> Error {
1854 // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
1856 return BackendProc->start(RegularLTO.ParallelCodeGenParallelismLevel + I,
1862 if (BackendProc->getThreadCount() == 1) {
1863 // Process the modules in the order they were provided on the command-line.
1873 // This saves about 15 sec on a 36-core machine while link `clang.exe` (out
1883 return BackendProc->wait();
1893 if (!Filename.empty() && Count != -1)
1905 (*ResultOrErr)->keep();
1923 StatsFile->keep();
1929 // possible. This is purely a compile-time optimization.
1934 auto LSize = R[LeftIndex]->getBuffer().size();
1935 auto RSize = R[RightIndex]->getBuffer().size();