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