Add time trace scopes to addToCallGraph & getCFG (#174717)

This PR adds performance instrumentation to `clang::CallGraph` and
`clang::CFG` to aid in benchmarking the overhead of call
graph construction and CFG rebuilding.

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.
This commit is contained in:
Kashika Akhouri 2026-01-08 22:54:19 +05:30 committed by GitHub
parent 2926b4100d
commit 11dcb756c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View File

@ -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 @@ public:
///
/// Recursively walks the declaration to find all the dependent Decls as well.
void addToCallGraph(Decl *D) {
llvm::TimeTraceScope TimeProfile("AddToCallGraph");
TraverseDecl(D);
}

View File

@ -52,6 +52,7 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <memory>
@ -5359,6 +5360,7 @@ CFGBlock *CFG::createBlock() {
/// buildCFG - Constructs a CFG from an AST.
std::unique_ptr<CFG> CFG::buildCFG(const Decl *D, Stmt *Statement,
ASTContext *C, const BuildOptions &BO) {
llvm::TimeTraceScope TimeProfile("BuildCFG");
CFGBuilder Builder(C, BO);
return Builder.buildCFG(D, Statement);
}

View File

@ -333,8 +333,10 @@ Frontend (test.cc)
| | InstantiateFunction (fooA<int>, a.h:7)
| | | InstantiateFunction (fooB<int>, b.h:8)
| | | | DeferInstantiation (fooC<int>)
| | | | BuildCFG
| | | DeferInstantiation (fooMTA<int>)
| | | InstantiateFunction (fooC<int>, b.h:3)
| | | | BuildCFG
| | | InstantiateFunction (fooMTA<int>, a.h:4)
)",
buildTraceGraph(Json));