Lines Matching +full:compute +full:- +full:cb
1 //===- ModuleSummaryAnalysis.cpp - Module summary index builder -----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
63 #define DEBUG_TYPE "module-summary-analysis"
66 // -import-cold-multiplier is set to 0. Useful for debugging.
73 "force-summary-edges-cold", cl::Hidden, cl::location(ForceSummaryEdgesCold),
77 "all-non-critical", "All non-critical edges."),
81 "module-summary-dot-file", cl::Hidden, cl::value_desc("filename"),
101 // local-linkage ifunc.
113 const auto *CB = dyn_cast<CallBase>(U);
115 for (const auto &OI : U->operands()) {
127 if (!(CB && CB->isCallee(&OI))) {
133 GI && GI->hasLocalLinkage()) {
165 if (PSI->isHotCount(ProfileCount))
167 if (PSI->isColdCount(ProfileCount))
186 for (auto &Arg : drop_begin(Call.CB.args())) {
188 if (!CI || CI->getBitWidth() > 64) {
192 Args.push_back(CI->getZExtValue());
198 /// summary, do so via the non-constant reference arguments.
213 switch (CI->getCalledFunction()->getIntrinsicID()) {
216 auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(1));
217 auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
220 GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
226 bool HasNonAssumeUses = llvm::any_of(CI->uses(), [](const Use &CIU) {
244 auto *TypeMDVal = cast<MetadataAsValue>(CI->getArgOperand(2));
245 auto *TypeId = dyn_cast<MDString>(TypeMDVal->getMetadata());
248 GlobalValue::GUID Guid = GlobalValue::getGUID(TypeId->getString());
256 // Any non-call uses of the result of llvm.type.checked.load will
273 return !LI->isVolatile();
280 return !SI->isVolatile();
345 // inlining may lead to an invalid cross-function reference. So we shouldn't
348 for (User *U : BlockAddress::get(const_cast<BasicBlock *>(&BB))->users())
365 // Postpone processing of non-volatile load instructions
374 // can be considered write-only if they're not referenced by any
375 // non-store instruction. References from first operand of store
376 // (stored value) can't be treated either as read- or as write-only
378 // except non-volatile load.
390 const auto *CB = dyn_cast<CallBase>(&I);
391 if (!CB) {
403 if (HasLocalsInUsedOrAsm && CI && CI->isInlineAsm())
406 auto *CalledValue = CB->getCalledOperand();
407 auto *CalledFunction = CB->getCalledFunction();
409 CalledValue = CalledValue->stripPointerCasts();
417 CalledFunction = dyn_cast<Function>(GA->getAliaseeObject());
422 if (CI && CalledFunction->isIntrinsic()) {
429 assert(CalledFunction->hasName());
430 auto ScaledCount = PSI->getProfileCount(*CB, BFI);
443 if (CB->isTailCall())
448 uint64_t BBFreq = BFI->getBlockFreq(&BB).getFrequency();
449 uint64_t EntryFreq = BFI->getEntryFreq().getFrequency();
460 // Non-local ifunc is not cloned and does not have the issue.
462 if (GI->hasLocalLinkage())
465 if (CI && CI->isInlineAsm())
476 for (const auto &Op : MD->operands()) {
510 assert(mayHaveMemprofSummary(CB));
512 CallsThatMayHaveMemprofSummary.insert(CB);
515 // Compute the list of stack ids first (so we can trim them from the stack
523 for (auto &MDOp : MemProfMD->operands()) {
568 if (PSI->hasPartialSampleProfile() && ScalePartialSampleProfileWorkingSetSize)
583 // non-volatile loads and non-volatile value stores. Let's find
641 const auto *CB = dyn_cast<CallBase>(&I);
642 if (!CB)
645 if (CallsThatMayHaveMemprofSummary.count(CB))
647 assert(!mayHaveMemprofSummary(CB));
672 ParamAccesses = SSI->getParamAccesses(Index);
695 if (I->getType()->isPointerTy()) {
696 auto C = I->stripPointerCasts();
698 if (isa<Function>(C) || (A && isa<Function>(A->getAliasee()))) {
703 if (GV && GV->getName() != "__cxa_pure_virtual")
713 StructType *STy = dyn_cast<StructType>(C->getType());
715 const StructLayout *SL = DL.getStructLayout(C->getType());
717 for (auto EI : llvm::enumerate(STy->elements())) {
718 auto Offset = SL->getElementOffset(EI.index());
719 unsigned Op = SL->getElementContainingOffset(Offset);
720 findFuncPointers(cast<Constant>(I->getOperand(Op)),
724 ArrayType *ATy = C->getType();
725 Type *EltTy = ATy->getElementType();
727 for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
728 findFuncPointers(cast<Constant>(I->getOperand(i)),
733 // For relative vtables, the next sub-component should be a trunc.
734 if (CE->getOpcode() != Instruction::Trunc ||
735 !(CE = dyn_cast<ConstantExpr>(CE->getOperand(0))))
741 if (CE->getOpcode() == Instruction::Sub) {
744 if (IsConstantOffsetFromGlobal(CE->getOperand(0), LHS, LHSOffset, DL) &&
745 IsConstantOffsetFromGlobal(CE->getOperand(1), RHS, RHSOffset, DL) &&
754 static_cast<uint64_t>(DL.getTypeAllocSize(OrigGV.getInitializer()->getType()))) {
790 auto TypeID = Type->getOperand(1).get();
794 cast<ConstantAsMetadata>(Type->getOperand(0))->getValue())
795 ->getZExtValue();
798 Index.getOrInsertTypeIdCompatibleVtableSummary(TypeId->getString())
821 // If splitting is not enabled, then we compute the summary information
822 // necessary for index-based whole program devirtualization.
835 // Don't mark variables we won't be able to internalize as read/write-only.
848 GVarSummary->setNotEligibleToImport();
850 GVarSummary->setVTableFuncs(VTableFuncs);
867 auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
870 "Expected a single entry per aliasee in per-module index");
871 AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
881 Summary->setLive(true);
894 EnableSplitLTOUnit = MD->getZExtValue();
897 UnifiedLTO = MD->getZExtValue();
913 if (V->hasLocalLinkage()) {
915 CantBePromoted.insert(V->getGUID());
940 assert(GV->isDeclaration() && "Def in module asm already has definition");
945 /* Local */ GV->isDSOLocal(), GV->canBeOmittedFromSymbolTable(),
947 CantBePromoted.insert(GV->getGUID());
954 F->hasFnAttribute(Attribute::ReadNone),
955 F->hasFnAttribute(Attribute::ReadOnly),
956 F->hasFnAttribute(Attribute::NoRecurse),
957 F->returnDoesNotAlias(),
959 F->hasFnAttribute(Attribute::AlwaysInline),
960 F->hasFnAttribute(Attribute::NoUnwind),
979 false, false, cast<GlobalVariable>(GV)->isConstant(),
990 IsThinLTO = MD->getZExtValue();
992 // Compute summaries for all functions defined in module, and save in the
1015 // Compute summaries for all variables defined in module, and save in the
1024 // Compute summaries for all aliases defined in module, and save in the
1032 Index.getGlobalValueSummary(GV)->setLive(true);
1039 Summary->setNotEligibleToImport();
1043 // to flag them as live in the index to ensure index-based dead value
1060 Summary->setNotEligibleToImport();
1065 llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
1069 Summary->setNotEligibleToImport();
1075 FuncSummary->calls(), [&](const FunctionSummary::EdgeTy &Edge) {
1079 Summary->setNotEligibleToImport();
1109 [&FAM, NeedSSI](const Function &F) -> const StackSafetyInfo * {
1118 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
1123 INITIALIZE_PASS_END(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
1141 return &(this->getAnalysis<BlockFrequencyInfoWrapperPass>(
1146 [&](const Function &F) -> const StackSafetyInfo * {
1186 INITIALIZE_PASS(ImmutableModuleSummaryIndexWrapperPass, "module-summary-info",
1189 bool llvm::mayHaveMemprofSummary(const CallBase *CB) {
1190 if (!CB)
1192 if (CB->isDebugOrPseudoInst())
1194 auto *CI = dyn_cast<CallInst>(CB);
1195 auto *CalledValue = CB->getCalledOperand();
1196 auto *CalledFunction = CB->getCalledFunction();
1198 CalledValue = CalledValue->stripPointerCasts();
1207 CalledFunction = dyn_cast<Function>(GA->getAliaseeObject());
1212 if (CI && CalledFunction->isIntrinsic())