Skip to content

Commit 01825cb

Browse files
committed
[Frontend] Move some stat collection to performEndOfPipelineActions
This better fits the model of an inverted pipeline and ensures we capture all the work performed.
1 parent 7b679fa commit 01825cb

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ static void countStatsOfSourceFile(UnifiedStatsReporter &Stats,
682682
}
683683
}
684684

685-
static void countStatsPostSema(UnifiedStatsReporter &Stats,
686-
CompilerInstance& Instance) {
685+
static void countASTStats(UnifiedStatsReporter &Stats,
686+
CompilerInstance& Instance) {
687687
auto &C = Stats.getFrontendCounters();
688688
auto &SM = Instance.getSourceMgr();
689689
C.NumSourceBuffers = SM.getLLVMSourceMgr().getNumBuffers();
@@ -1223,6 +1223,16 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
12231223
static void performEndOfPipelineActions(CompilerInstance &Instance) {
12241224
assert(Instance.hasASTContext());
12251225
auto &ctx = Instance.getASTContext();
1226+
const auto &Invocation = Instance.getInvocation();
1227+
const auto &opts = Invocation.getFrontendOptions();
1228+
1229+
// If we were asked to print Clang stats, do so.
1230+
if (opts.PrintClangStats && ctx.getClangModuleLoader())
1231+
ctx.getClangModuleLoader()->printStatistics();
1232+
1233+
// Report AST stats if needed.
1234+
if (auto *stats = ctx.Stats)
1235+
countASTStats(*stats, Instance);
12261236

12271237
// Make sure we didn't load a module during a parse-only invocation, unless
12281238
// it's -emit-imported-modules, which can load modules.
@@ -1327,10 +1337,6 @@ static bool performCompile(CompilerInstance &Instance,
13271337
if (observer)
13281338
observer->performedSemanticAnalysis(Instance);
13291339

1330-
if (auto *Stats = Context.Stats) {
1331-
countStatsPostSema(*Stats, Instance);
1332-
}
1333-
13341340
{
13351341
FrontendOptions::DebugCrashMode CrashMode = opts.CrashMode;
13361342
if (CrashMode == FrontendOptions::DebugCrashMode::AssertAfterParse)
@@ -1351,10 +1357,6 @@ static bool performCompile(CompilerInstance &Instance,
13511357
if (auto r = dumpASTIfNeeded(Instance))
13521358
return *r;
13531359

1354-
// If we were asked to print Clang stats, do so.
1355-
if (opts.PrintClangStats && Context.getClangModuleLoader())
1356-
Context.getClangModuleLoader()->printStatistics();
1357-
13581360
emitSwiftRangesForAllPrimaryInputsIfNeeded(Instance);
13591361
emitCompiledSourceForAllPrimaryInputsIfNeeded(Instance);
13601362

0 commit comments

Comments
 (0)