[clang] [analyzer] Add time-trace scopes for high-level analyzer steps (PR #125508)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 00:05:26 PST 2025
================
@@ -179,8 +181,41 @@ bool CoreEngine::ExecuteWorkList(const LocationContext *L, unsigned MaxSteps,
return WList->hasWork();
}
-void CoreEngine::dispatchWorkItem(ExplodedNode* Pred, ProgramPoint Loc,
- const WorkListUnit& WU) {
+static std::string timeTraceScopeName(const ProgramPoint &Loc) {
+ if (llvm::timeTraceProfilerEnabled()) {
+ return llvm::formatv("Loc {0}",
+ ProgramPoint::getProgramPointKindName(Loc.getKind()))
+ .str();
+ }
+ return "";
+}
+
+static llvm::TimeTraceMetadata timeTraceMetadata(const ExplodedNode *Pred,
+ const ProgramPoint &Loc) {
+ // If time-trace profiler is not enabled, this function is never called.
+ assert(llvm::timeTraceProfilerEnabled());
+ std::string Detail = "";
+ if (const auto SP = Loc.getAs<StmtPoint>()) {
+ if (const Stmt *S = SP->getStmt())
+ Detail = S->getStmtClassName();
+ }
+ auto SLoc = Loc.getSourceLocation();
+ if (!SLoc)
+ return llvm::TimeTraceMetadata{Detail, ""};
+ const auto &SM = Pred->getLocationContext()
+ ->getAnalysisDeclContext()
+ ->getASTContext()
+ .getSourceManager();
+ auto Line = SM.getPresumedLineNumber(*SLoc);
+ auto Fname = SM.getFilename(*SLoc);
+ return llvm::TimeTraceMetadata{Detail, Fname.str(), static_cast<int>(Line)};
+}
+
+void CoreEngine::dispatchWorkItem(ExplodedNode *Pred, ProgramPoint Loc,
+ const WorkListUnit &WU) {
+ llvm::TimeTraceScope tcs{timeTraceScopeName(Loc), [Loc, Pred]() {
+ return timeTraceMetadata(Pred, Loc);
+ }};
----------------
balazs-benics-sonarsource wrote:
It took me a while to correlate the name `Loc PostStmt` with this place. I wonder if we should use `work item` as a disambiguation.
https://github.com/llvm/llvm-project/pull/125508
More information about the cfe-commits
mailing list