Lines Matching +full:stm +full:- +full:base

1 //===--- CodeGenPGO.cpp - PGO Instrumentation for LLVM CodeGen --*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Instrumentation-based profile-guided optimization
11 //===----------------------------------------------------------------------===//
31 EnableValueProfiling("enable-value-profiling",
43 PGOReader ? PGOReader->getVersion() : llvm::IndexedInstrProf::Version); in setFuncName()
51 setFuncName(Fn->getName(), Fn->getLinkage()); in setFuncName()
72 /// profiles -- i.e., don't do it.
151 if (PGOReader->getVersion() <= 4) in getPGOHashVersion()
153 if (PGOReader->getVersion() <= 5) in getPGOHashVersion()
160 using Base = RecursiveASTVisitor<MapRegionCounters>; typedef
190 for (auto C : zip(LE->captures(), LE->capture_inits())) in TraverseLambdaExpr()
197 switch (D->getKind()) { in VisitDecl()
208 CounterMap[D->getBody()] = NextCounter++; in VisitDecl()
226 /// of the number of leaf-level conditions in the boolean expression so that a
251 const BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E->IgnoreParens()); in dataTraverseStmtPre()
252 if (BinOp && BinOp->isLogicalOp()) { in dataTraverseStmtPre()
253 /// Check for "split-nested" logical operators. This happens when a new in dataTraverseStmtPre()
254 /// boolean expression logical-op nest is encountered within an existing in dataTraverseStmtPre()
255 /// boolean expression, separated by a non-logical operator. For in dataTraverseStmtPre()
258 /// conditions by the operator foo(). Split-nested cases are not in dataTraverseStmtPre()
267 /// Keep track of non-logical operators. These are OK as long as we don't in dataTraverseStmtPre()
284 const BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E->IgnoreParens()); in dataTraverseStmtPost()
285 if (BinOp && BinOp->isLogicalOp()) { in dataTraverseStmtPost()
291 /// Was the "split-nested" logical operator case encountered? in dataTraverseStmtPost()
298 Diag.Report(S->getBeginLoc(), DiagID); in dataTraverseStmtPost()
309 Diag.Report(S->getBeginLoc(), DiagID) << NumCond << MCDCMaxCond; in dataTraverseStmtPost()
332 if (S->isLogicalOp()) { in VisitBinaryOperator()
333 if (CodeGenFunction::isInstrumentedCondition(S->getLHS())) in VisitBinaryOperator()
336 if (CodeGenFunction::isInstrumentedCondition(S->getRHS())) { in VisitBinaryOperator()
338 CounterMap[S->getRHS()] = NextCounter++; in VisitBinaryOperator()
343 return Base::VisitBinaryOperator(S); in VisitBinaryOperator()
347 if (llvm::EnableSingleByteCoverage && S->getTrueExpr()) in VisitConditionalOperator()
348 CounterMap[S->getTrueExpr()] = NextCounter++; in VisitConditionalOperator()
349 if (llvm::EnableSingleByteCoverage && S->getFalseExpr()) in VisitConditionalOperator()
350 CounterMap[S->getFalseExpr()] = NextCounter++; in VisitConditionalOperator()
351 return Base::VisitConditionalOperator(S); in VisitConditionalOperator()
367 return Base::TraverseIfStmt(If); in TraverseIfStmt()
372 for (Stmt *CS : If->children()) { in TraverseIfStmt()
375 if (CS == If->getThen()) in TraverseIfStmt()
376 CounterMap[If->getThen()] = NextCounter++; in TraverseIfStmt()
377 else if (CS == If->getElse()) in TraverseIfStmt()
378 CounterMap[If->getElse()] = NextCounter++; in TraverseIfStmt()
384 for (Stmt *CS : If->children()) { in TraverseIfStmt()
387 if (CS == If->getThen()) in TraverseIfStmt()
389 else if (CS == If->getElse()) in TraverseIfStmt()
401 for (Stmt *CS : While->children()) { in TraverseWhileStmt()
404 if (CS == While->getCond()) in TraverseWhileStmt()
405 CounterMap[While->getCond()] = NextCounter++; in TraverseWhileStmt()
406 else if (CS == While->getBody()) in TraverseWhileStmt()
407 CounterMap[While->getBody()] = NextCounter++; in TraverseWhileStmt()
410 Base::TraverseWhileStmt(While); in TraverseWhileStmt()
420 for (Stmt *CS : Do->children()) { in TraverseDoStmt()
423 if (CS == Do->getCond()) in TraverseDoStmt()
424 CounterMap[Do->getCond()] = NextCounter++; in TraverseDoStmt()
425 else if (CS == Do->getBody()) in TraverseDoStmt()
426 CounterMap[Do->getBody()] = NextCounter++; in TraverseDoStmt()
429 Base::TraverseDoStmt(Do); in TraverseDoStmt()
439 for (Stmt *CS : For->children()) { in TraverseForStmt()
442 if (CS == For->getCond()) in TraverseForStmt()
443 CounterMap[For->getCond()] = NextCounter++; in TraverseForStmt()
444 else if (CS == For->getInc()) in TraverseForStmt()
445 CounterMap[For->getInc()] = NextCounter++; in TraverseForStmt()
446 else if (CS == For->getBody()) in TraverseForStmt()
447 CounterMap[For->getBody()] = NextCounter++; in TraverseForStmt()
450 Base::TraverseForStmt(For); in TraverseForStmt()
459 for (Stmt *CS : ForRange->children()) { in TraverseCXXForRangeStmt()
462 if (CS == ForRange->getBody()) in TraverseCXXForRangeStmt()
463 CounterMap[ForRange->getBody()] = NextCounter++; in TraverseCXXForRangeStmt()
466 Base::TraverseCXXForRangeStmt(ForRange); in TraverseCXXForRangeStmt()
477 Base::Traverse##N(S); \
489 switch (S->getStmtClass()) { in DEFINE_NESTABLE_TRAVERSAL()
522 if (BO->getOpcode() == BO_LAnd) in DEFINE_NESTABLE_TRAVERSAL()
524 if (BO->getOpcode() == BO_LOr) in DEFINE_NESTABLE_TRAVERSAL()
527 switch (BO->getOpcode()) { in DEFINE_NESTABLE_TRAVERSAL()
549 switch (S->getStmtClass()) { in DEFINE_NESTABLE_TRAVERSAL()
566 if (UO->getOpcode() == UO_LNot) in DEFINE_NESTABLE_TRAVERSAL()
593 /// BreakContinueStack - Keep counts of breaks and continues inside loops.
620 for (const Stmt *Child : S->children()) in VisitStmt()
622 this->Visit(Child); in VisitStmt()
627 uint64_t BodyCount = setCount(PGO.getRegionCount(D->getBody())); in VisitFunctionDecl()
628 CountMap[D->getBody()] = BodyCount; in VisitFunctionDecl()
629 Visit(D->getBody()); in VisitFunctionDecl()
639 uint64_t BodyCount = setCount(PGO.getRegionCount(D->getBody())); in VisitCapturedDecl()
640 CountMap[D->getBody()] = BodyCount; in VisitCapturedDecl()
641 Visit(D->getBody()); in VisitCapturedDecl()
646 uint64_t BodyCount = setCount(PGO.getRegionCount(D->getBody())); in VisitObjCMethodDecl()
647 CountMap[D->getBody()] = BodyCount; in VisitObjCMethodDecl()
648 Visit(D->getBody()); in VisitObjCMethodDecl()
653 uint64_t BodyCount = setCount(PGO.getRegionCount(D->getBody())); in VisitBlockDecl()
654 CountMap[D->getBody()] = BodyCount; in VisitBlockDecl()
655 Visit(D->getBody()); in VisitBlockDecl()
660 if (S->getRetValue()) in VisitReturnStmt()
661 Visit(S->getRetValue()); in VisitReturnStmt()
668 if (E->getSubExpr()) in VisitCXXThrowExpr()
669 Visit(E->getSubExpr()); in VisitCXXThrowExpr()
685 Visit(S->getSubStmt()); in VisitLabelStmt()
712 CountMap[S->getBody()] = CurrentCount; in VisitWhileStmt()
713 Visit(S->getBody()); in VisitWhileStmt()
723 CountMap[S->getCond()] = CondCount; in VisitWhileStmt()
724 Visit(S->getCond()); in VisitWhileStmt()
725 setCount(BC.BreakCount + CondCount - BodyCount); in VisitWhileStmt()
736 CountMap[S->getBody()] = BodyCount; in VisitDoStmt()
737 Visit(S->getBody()); in VisitDoStmt()
744 CountMap[S->getCond()] = CondCount; in VisitDoStmt()
745 Visit(S->getCond()); in VisitDoStmt()
746 setCount(BC.BreakCount + CondCount - LoopCount); in VisitDoStmt()
752 if (S->getInit()) in VisitForStmt()
753 Visit(S->getInit()); in VisitForStmt()
761 CountMap[S->getBody()] = BodyCount; in VisitForStmt()
762 Visit(S->getBody()); in VisitForStmt()
768 if (S->getInc()) { in VisitForStmt()
770 CountMap[S->getInc()] = IncCount; in VisitForStmt()
771 Visit(S->getInc()); in VisitForStmt()
777 if (S->getCond()) { in VisitForStmt()
778 CountMap[S->getCond()] = CondCount; in VisitForStmt()
779 Visit(S->getCond()); in VisitForStmt()
781 setCount(BC.BreakCount + CondCount - BodyCount); in VisitForStmt()
787 if (S->getInit()) in VisitCXXForRangeStmt()
788 Visit(S->getInit()); in VisitCXXForRangeStmt()
789 Visit(S->getLoopVarStmt()); in VisitCXXForRangeStmt()
790 Visit(S->getRangeStmt()); in VisitCXXForRangeStmt()
791 Visit(S->getBeginStmt()); in VisitCXXForRangeStmt()
792 Visit(S->getEndStmt()); in VisitCXXForRangeStmt()
799 CountMap[S->getBody()] = BodyCount; in VisitCXXForRangeStmt()
800 Visit(S->getBody()); in VisitCXXForRangeStmt()
807 CountMap[S->getInc()] = IncCount; in VisitCXXForRangeStmt()
808 Visit(S->getInc()); in VisitCXXForRangeStmt()
813 CountMap[S->getCond()] = CondCount; in VisitCXXForRangeStmt()
814 Visit(S->getCond()); in VisitCXXForRangeStmt()
815 setCount(BC.BreakCount + CondCount - BodyCount); in VisitCXXForRangeStmt()
821 Visit(S->getElement()); in VisitObjCForCollectionStmt()
826 CountMap[S->getBody()] = BodyCount; in VisitObjCForCollectionStmt()
827 Visit(S->getBody()); in VisitObjCForCollectionStmt()
831 setCount(BC.BreakCount + ParentCount + BackedgeCount + BC.ContinueCount - in VisitObjCForCollectionStmt()
838 if (S->getInit()) in VisitSwitchStmt()
839 Visit(S->getInit()); in VisitSwitchStmt()
840 Visit(S->getCond()); in VisitSwitchStmt()
843 Visit(S->getBody()); in VisitSwitchStmt()
864 Visit(S->getSubStmt()); in VisitSwitchCase()
870 if (S->isConsteval()) { in VisitIfStmt()
871 const Stmt *Stm = S->isNegatedConsteval() ? S->getThen() : S->getElse(); in VisitIfStmt() local
872 if (Stm) in VisitIfStmt()
873 Visit(Stm); in VisitIfStmt()
878 if (S->getInit()) in VisitIfStmt()
879 Visit(S->getInit()); in VisitIfStmt()
880 Visit(S->getCond()); in VisitIfStmt()
885 CountMap[S->getThen()] = ThenCount; in VisitIfStmt()
886 Visit(S->getThen()); in VisitIfStmt()
889 uint64_t ElseCount = ParentCount - ThenCount; in VisitIfStmt()
890 if (S->getElse()) { in VisitIfStmt()
892 CountMap[S->getElse()] = ElseCount; in VisitIfStmt()
893 Visit(S->getElse()); in VisitIfStmt()
903 Visit(S->getTryBlock()); in VisitCXXTryStmt()
904 for (unsigned I = 0, E = S->getNumHandlers(); I < E; ++I) in VisitCXXTryStmt()
905 Visit(S->getHandler(I)); in VisitCXXTryStmt()
916 Visit(S->getHandlerBlock()); in VisitCXXCatchStmt()
922 Visit(E->getCond()); in VisitAbstractConditionalOperator()
927 CountMap[E->getTrueExpr()] = TrueCount; in VisitAbstractConditionalOperator()
928 Visit(E->getTrueExpr()); in VisitAbstractConditionalOperator()
931 uint64_t FalseCount = setCount(ParentCount - TrueCount); in VisitAbstractConditionalOperator()
932 CountMap[E->getFalseExpr()] = FalseCount; in VisitAbstractConditionalOperator()
933 Visit(E->getFalseExpr()); in VisitAbstractConditionalOperator()
943 Visit(E->getLHS()); in VisitBinLAnd()
946 CountMap[E->getRHS()] = RHSCount; in VisitBinLAnd()
947 Visit(E->getRHS()); in VisitBinLAnd()
948 setCount(ParentCount + RHSCount - CurrentCount); in VisitBinLAnd()
955 Visit(E->getLHS()); in VisitBinLOr()
958 CountMap[E->getRHS()] = RHSCount; in VisitBinLOr()
959 Visit(E->getRHS()); in VisitBinLOr()
960 setCount(ParentCount + RHSCount - CurrentCount); in VisitBinLOr()
988 // No need to byte swap here, since none of the math was endian-dependent. in finalize()
989 // This number will be byte-swapped as required on endianness transitions, in finalize()
995 // Keep the buggy behavior from v1 and v2 for backward-compatibility. This in finalize()
1015 if (!D->hasBody()) in assignRegionCounters()
1020 D->hasAttr<CUDAGlobalAttr>()) in assignRegionCounters()
1027 if (D->isImplicit()) in assignRegionCounters()
1030 // If so, instrument only base variant, others are implemented by delegation in assignRegionCounters()
1031 // to the base one, it would be counted twice otherwise. in assignRegionCounters()
1042 if (Fn->hasFnAttribute(llvm::Attribute::NoProfile)) in assignRegionCounters()
1044 if (Fn->hasFnAttribute(llvm::Attribute::SkipProfile)) in assignRegionCounters()
1049 SM.isInSystemHeader(D->getLocation())) in assignRegionCounters()
1058 loadRegionCounts(PGOReader, SM.isInMainFile(D->getLocation())); in assignRegionCounters()
1071 ProfileVersion = PGOReader->getVersion(); in mapRegionCounters()
1079 // the maximum value is hard-coded at 6 conditions, which is more than enough in mapRegionCounters()
1082 // the future, this value could be adjusted with a command-line option. in mapRegionCounters()
1105 if (!D->getBody()) in skipRegionMappingForDecl()
1108 // Skip host-only functions in the CUDA device compilation and device-only in skipRegionMappingForDecl()
1110 // the function attributes. If there are effectively host-only or device-only in skipRegionMappingForDecl()
1113 ((CGM.getLangOpts().CUDAIsDevice && !D->hasAttr<CUDADeviceAttr>() && in skipRegionMappingForDecl()
1114 !D->hasAttr<CUDAGlobalAttr>()) || in skipRegionMappingForDecl()
1116 (D->hasAttr<CUDAGlobalAttr>() || in skipRegionMappingForDecl()
1117 (!D->hasAttr<CUDAHostAttr>() && D->hasAttr<CUDADeviceAttr>()))))) in skipRegionMappingForDecl()
1122 auto Loc = D->getBody()->getBeginLoc(); in skipRegionMappingForDecl()
1132 RegionMCDCState->BranchByStmt.clear(); in emitCounterRegionMapping()
1142 CGM.getCoverageMapping()->addFunctionMappingRecord( in emitCounterRegionMapping()
1164 CGM.getCoverageMapping()->addFunctionMappingRecord( in emitEmptyCounterMapping()
1188 Fn->setEntryCount(FunctionCount); in applyFunctionAttributes()
1232 Builder.getInt32(RegionMCDCState->BitmapBits)}; in emitMCDCParameters()
1244 S = S->IgnoreParens(); in emitMCDCTestVectorBitmapUpdate()
1246 auto DecisionStateIter = RegionMCDCState->DecisionByStmt.find(S); in emitMCDCTestVectorBitmapUpdate()
1247 if (DecisionStateIter == RegionMCDCState->DecisionByStmt.end()) in emitMCDCTestVectorBitmapUpdate()
1252 if (DecisionStateIter->second.Indices.size() == 0) in emitMCDCTestVectorBitmapUpdate()
1256 unsigned MCDCTestVectorBitmapOffset = DecisionStateIter->second.BitmapIdx; in emitMCDCTestVectorBitmapUpdate()
1277 S = S->IgnoreParens(); in emitMCDCCondBitmapReset()
1279 if (!RegionMCDCState->DecisionByStmt.contains(S)) in emitMCDCCondBitmapReset()
1293 // Even though, for simplicity, parentheses and unary logical-NOT operators in emitMCDCCondBitmapUpdate()
1297 // consistency since parentheses and logical-NOTs are ignored when checking in emitMCDCCondBitmapUpdate()
1302 auto BranchStateIter = RegionMCDCState->BranchByStmt.find(S); in emitMCDCCondBitmapUpdate()
1303 if (BranchStateIter == RegionMCDCState->BranchByStmt.end()) in emitMCDCCondBitmapUpdate()
1307 const auto &Branch = BranchStateIter->second; in emitMCDCCondBitmapUpdate()
1313 RegionMCDCState->DecisionByStmt.find(Branch.DecisionStmt); in emitMCDCCondBitmapUpdate()
1314 if (DecisionIter == RegionMCDCState->DecisionByStmt.end()) in emitMCDCCondBitmapUpdate()
1317 const auto &TVIdxs = DecisionIter->second.Indices[Branch.ID]; in emitMCDCCondBitmapUpdate()
1347 IRLevelVersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility); in setProfileVersion()
1350 IRLevelVersionVariable->setLinkage(llvm::GlobalValue::ExternalLinkage); in setProfileVersion()
1351 IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName)); in setProfileVersion()
1353 IRLevelVersionVariable->setDSOLocal(true); in setProfileVersion()
1357 // This method either inserts a call to the profile run-time during
1396 if (NumValueSites[ValueKind] >= ProfRecord->getNumValueSites(ValueKind)) in valueProfile()
1412 PGOReader->getInstrProfRecord(FuncName, FunctionHash); in loadRegionCounts()
1426 RegionCounts = ProfRecord->Counts; in loadRegionCounts()
1439 /// Scale a 64-bit weight down to 32-bits using \c Scale.
1449 assert(Scaled <= UINT32_MAX && "overflow 32-bits"); in scaleBranchWeight()
1459 // Calculate how to scale down to 32-bits. in createProfileWeights()
1478 // Calculate how to scale down to 32-bits. in createProfileWeights()
1499 std::max(*CondCount, LoopCount) - LoopCount); in createProfileWeightsForLoop()