Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class FunctionSummariesTy {
/// The number of times the function has been inlined.
unsigned TimesInlined : 32;

/// Running time for syntax-based AST analysis in milliseconds.
std::optional<unsigned> SyntaxRunningTime = std::nullopt;

FunctionSummary()
: TotalBasicBlocks(0), InlineChecked(0), MayInline(0),
TimesInlined(0) {}
Expand All @@ -69,6 +72,11 @@ class FunctionSummariesTy {
return I;
}

FunctionSummary const *findSummary(const Decl *D) const {
auto I = Map.find(D);
return I == Map.end() ? nullptr : &I->second;
}

void markMayInline(const Decl *D) {
MapTy::iterator I = findOrInsertSummary(D);
I->second.InlineChecked = 1;
Expand Down
41 changes: 41 additions & 0 deletions clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode Mode) {
}

static UnsignedEPStat PathRunningTime("PathRunningTime");
static UnsignedEPStat SyntaxRunningTime("SyntaxRunningTime");

void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
ExprEngine::InliningModes IMode,
Expand Down Expand Up @@ -759,6 +760,8 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
SyntaxCheckTimer->stopTimer();
llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime();
CheckerEndTime -= CheckerStartTime;
FunctionSummaries.findOrInsertSummary(D)->second.SyntaxRunningTime =
std::lround(CheckerEndTime.getWallTime() * 1000);
DisplayTime(CheckerEndTime);
if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) {
AnalyzerTimers->clear();
Expand All @@ -776,6 +779,34 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
}
}

template <typename DeclT>
static clang::Decl *preferDefinitionImpl(clang::Decl *D) {
if (auto *X = dyn_cast<DeclT>(D))
if (auto *Def = X->getDefinition())
return Def;
return D;
}

template <> clang::Decl *preferDefinitionImpl<ObjCMethodDecl>(clang::Decl *D) {
if (const auto *X = dyn_cast<ObjCMethodDecl>(D)) {
for (auto *I : X->redecls())
if (I->hasBody())
return I;
}
return D;
}

static Decl *getDefinitionOrCanonicalDecl(Decl *D) {
assert(D);
D = D->getCanonicalDecl();
D = preferDefinitionImpl<VarDecl>(D);
D = preferDefinitionImpl<FunctionDecl>(D);
D = preferDefinitionImpl<TagDecl>(D);
D = preferDefinitionImpl<ObjCMethodDecl>(D);
assert(D);
return D;
}

//===----------------------------------------------------------------------===//
// Path-sensitive checking.
//===----------------------------------------------------------------------===//
Expand All @@ -792,6 +823,16 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
if (!Mgr->getAnalysisDeclContext(D)->getAnalysis<RelaxedLiveVariables>())
return;

const Decl *DefDecl = getDefinitionOrCanonicalDecl(D);

// Get the SyntaxRunningTime from the function summary, because it is computed
// during the AM_Syntax analysis, which is done at a different point in time
// and in different order, but always before AM_Path.
if (const auto *Summary = FunctionSummaries.findSummary(DefDecl);
Summary && Summary->SyntaxRunningTime.has_value()) {
SyntaxRunningTime.set(*Summary->SyntaxRunningTime);
}

ExprEngine Eng(CTU, *Mgr, VisitedCallees, &FunctionSummaries, IMode);

// Execute the worklist algorithm.
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Analysis/analyzer-stats/entry-point-stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
// CHECK-NEXT: "DebugName": "fib(unsigned int)",
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}",
// CHECK-NEXT: "SyntaxRunningTime": "{{[0-9]+}}",
// CHECK-NEXT: "MaxBugClassSize": "{{[0-9]+}}",
// CHECK-NEXT: "MaxCFGSize": "{{[0-9]+}}",
// CHECK-NEXT: "MaxQueueSize": "{{[0-9]+}}",
Expand Down Expand Up @@ -46,6 +47,7 @@
// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
// CHECK-NEXT: "DebugName": "main(int, char **)",
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}",
// CHECK-NEXT: "SyntaxRunningTime": "{{[0-9]+}}",
// CHECK-NEXT: "MaxBugClassSize": "{{[0-9]+}}",
// CHECK-NEXT: "MaxCFGSize": "{{[0-9]+}}",
// CHECK-NEXT: "MaxQueueSize": "{{[0-9]+}}",
Expand Down
Loading