[clang] 14af435 - [NFC][support]Add operator- to TimeRecord (#163361)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 21 06:04:34 PDT 2025
Author: Arseniy Zaostrovnykh
Date: 2025-10-21T13:04:29Z
New Revision: 14af43532f66b84512238d5c8c8038c0f782f812
URL: https://github.com/llvm/llvm-project/commit/14af43532f66b84512238d5c8c8038c0f782f812
DIFF: https://github.com/llvm/llvm-project/commit/14af43532f66b84512238d5c8c8038c0f782f812.diff
LOG: [NFC][support]Add operator- to TimeRecord (#163361)
A common use case for the Timer is to measure time duration between two
points. Lack of operator- forced an non-intuitive two-step duration
computation: get the end time, then decrement it by the start time.
Now, as demonstrated on the example of `SyntaxCheckTimer` and
`ExprEngineTimer` one can compute duration directly.
Added:
Modified:
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
llvm/include/llvm/Support/Timer.h
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 871400e29362f..82b560b2613f8 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -760,11 +760,11 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
++NumFunctionsAnalyzedSyntaxOnly;
if (SyntaxCheckTimer) {
SyntaxCheckTimer->stopTimer();
- llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
- CheckerEndTime -= CheckerStartTime;
+ llvm::TimeRecord CheckerDuration =
+ SyntaxCheckTimer->getTotalTime() - CheckerStartTime;
FunctionSummaries.findOrInsertSummary(D)->second.SyntaxRunningTime =
- std::lround(CheckerEndTime.getWallTime() * 1000);
- DisplayTime(CheckerEndTime);
+ std::lround(CheckerDuration.getWallTime() * 1000);
+ DisplayTime(CheckerDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
@@ -825,11 +825,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
Mgr->options.MaxNodesPerTopLevelFunction);
if (ExprEngineTimer) {
ExprEngineTimer->stopTimer();
- llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime();
- ExprEngineEndTime -= ExprEngineStartTime;
+ llvm::TimeRecord ExprEngineDuration =
+ ExprEngineTimer->getTotalTime() - ExprEngineStartTime;
PathRunningTime.set(static_cast<unsigned>(
- std::lround(ExprEngineEndTime.getWallTime() * 1000)));
- DisplayTime(ExprEngineEndTime);
+ std::lround(ExprEngineDuration.getWallTime() * 1000)));
+ DisplayTime(ExprEngineDuration);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
}
diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h
index a4ed712577582..6a4475882000a 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -66,6 +66,12 @@ class TimeRecord {
MemUsed -= RHS.MemUsed;
InstructionsExecuted -= RHS.InstructionsExecuted;
}
+ TimeRecord operator-(const TimeRecord &RHS) const {
+ TimeRecord R = *this;
+ R -= RHS;
+ return R;
+ }
+ // Feel free to add operator+ if you need it
/// Print the current time record to \p OS, with a breakdown showing
/// contributions to the \p Total time record.
More information about the cfe-commits
mailing list