[clang] Add time trace scopes to addToCallGraph & getCFG (PR #174717)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 7 01:06:37 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-analysis
Author: Kashika Akhouri (kashika0112)
<details>
<summary>Changes</summary>
his PR adds performance instrumentation to `clang::CallGraph` and `clang::AnalysisDeclContext` to aid in benchmarking the overhead of call graph construction and CFG rebuilding.
Changes
- `clang/include/clang/Analysis/CallGraph.h`: Added a TimeTraceScope labeled `AddToCallGraph` to instrument the discovery of function nodes and call edges across the Translation Unit.
- `clang/lib/Analysis/AnalysisDeclContext.cpp`: Added a TimeTraceScope labeled `BuildCFG` inside `getCFG()`. The scope is placed within the `!builtCFG` block to measure the actual construction time.
This aims to facilitate benchmarking on large codebases like LLVM to ensure that the performance impact of new analysis-based warnings remains within acceptable regressions.
---
Full diff: https://github.com/llvm/llvm-project/pull/174717.diff
2 Files Affected:
- (modified) clang/include/clang/Analysis/CallGraph.h (+2)
- (modified) clang/lib/Analysis/AnalysisDeclContext.cpp (+2)
``````````diff
diff --git a/clang/include/clang/Analysis/CallGraph.h b/clang/include/clang/Analysis/CallGraph.h
index c11d163f8fe20..f1c0d7a88643a 100644
--- a/clang/include/clang/Analysis/CallGraph.h
+++ b/clang/include/clang/Analysis/CallGraph.h
@@ -26,6 +26,7 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/TimeProfiler.h"
#include <memory>
namespace clang {
@@ -61,6 +62,7 @@ class CallGraph : public DynamicRecursiveASTVisitor {
///
/// Recursively walks the declaration to find all the dependent Decls as well.
void addToCallGraph(Decl *D) {
+ llvm::TimeTraceScope TimeProfile("AddToCallGraph");
TraverseDecl(D);
}
diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp
index 6f153e7e65255..2985a6e57dc18 100644
--- a/clang/lib/Analysis/AnalysisDeclContext.cpp
+++ b/clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -42,6 +42,7 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SaveAndRestore.h"
+#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <memory>
@@ -218,6 +219,7 @@ CFG *AnalysisDeclContext::getCFG() {
return getUnoptimizedCFG();
if (!builtCFG) {
+ llvm::TimeTraceScope TimeProfile("BuildCFG");
cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
// Even when the cfg is not successfully built, we don't
// want to try building it again.
``````````
</details>
https://github.com/llvm/llvm-project/pull/174717
More information about the cfe-commits
mailing list