Skip to content

Commit ec28baa

Browse files
Add -ftime-trace instrumentation for the inliner pass
noticed the inliner pass was invisible in -ftime-trace output — was looking at a trace after #22825 and realized the whole inlining phase just disappears. added inlineGeneral and per-function inline spans following the same pattern as the existing sema/parse spans. makes it possible to see which functions are taking time during inlining, useful for diagnosing compile-time issues in codebases that use -inline heavily.
1 parent 16f3201 commit ec28baa

File tree

7 files changed

+103
-0
lines changed

7 files changed

+103
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`-ftime-trace`: add instrumentation for the inliner pass
2+
3+
The `-ftime-trace` output previously had no coverage for the inliner pass.
4+
When compiling with `-inline`, the time spent scanning and inlining functions
5+
did not appear in the trace at all.
6+
7+
Two new spans are now emitted: `Inlining` covers the entire inliner pass, and
8+
`Inline: <function>` covers each function scanned individually.
9+
These are visible in trace viewers like $(LINK2 https://ui.perfetto.dev/, Perfetto).

compiler/src/dmd/inline.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,10 @@ public:
18231823
fd.inlineScanned = true;
18241824
fd.semanticRun = pass;
18251825

1826+
import dmd.timetrace;
1827+
timeTraceBeginEvent(TimeTraceEventType.inlineFunction);
1828+
scope (exit) timeTraceEndEvent(TimeTraceEventType.inlineFunction, fd);
1829+
18261830
scope InlineScanVisitor v = new InlineScanVisitor(fd, pass, eSink);
18271831

18281832
do

compiler/src/dmd/main.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ private int tryMain(const(char)[][] argv, out Param params)
665665
if (global.errors)
666666
removeHdrFilesAndFail(params, modules);
667667

668+
{
669+
timeTraceBeginEvent(TimeTraceEventType.inlineGeneral);
670+
scope (exit) timeTraceEndEvent(TimeTraceEventType.inlineGeneral);
671+
668672
// Scan for modules with always inline functions
669673
foreach (m; modules)
670674
{
@@ -686,6 +690,7 @@ private int tryMain(const(char)[][] argv, out Param params)
686690
inlineScanAllFunctions(m, global.errorSink);
687691
}
688692
}
693+
}
689694

690695
if (global.warnings)
691696
errorOnWarning();

compiler/src/dmd/timetrace.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ enum TimeTraceEventType
184184
sema1Function,
185185
sema2,
186186
sema3,
187+
inlineGeneral, /// top-level span for the entire inliner pass
188+
inlineFunction, /// per-function span during inlining
187189
dfa,
188190
ctfe,
189191
ctfeCall,
@@ -211,6 +213,8 @@ private immutable string[] eventPrefixes = [
211213
"Sema1: Function ",
212214
"Sema2: ",
213215
"Sema3: ",
216+
"Inlining",
217+
"Inline: ",
214218
"DFA: ",
215219
"Ctfe: ",
216220
"Ctfe: call ",

compiler/test/compilable/ftimetrace.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ DFA: fun, object.fun
1616
DFA: id, object.id!int.id
1717
DFA: uses, object.uses
1818
Import object.object, object.object
19+
Inlining,
1920
Parse: Module object, object
2021
Parsing,
2122
Sema1: Function add, object.add
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
REQUIRED_ARGS: -ftime-trace -ftime-trace-file=- -ftime-trace-granularity=0 -inline
3+
TRANSFORM_OUTPUT: sanitize_timetrace
4+
TEST_OUTPUT:
5+
---
6+
Code generation,
7+
Codegen: function add, object.add
8+
Codegen: function uses, object.uses
9+
Codegen: module object, object
10+
Import object.object, object.object
11+
Inline: add, object.add
12+
Inline: uses, object.uses
13+
Inlining,
14+
Parse: Module object, object
15+
Parsing,
16+
Sema1: Function add, object.add
17+
Sema1: Function uses, object.uses
18+
Sema1: Module object, object
19+
Sema2: add, object.add
20+
Sema2: uses, object.uses
21+
Sema3: add, object.add
22+
Sema3: uses, object.uses
23+
Semantic analysis,
24+
---
25+
*/
26+
27+
module object; // Don't clutter time trace output with object.d
28+
29+
int add(int x, int y)
30+
{
31+
return x + y;
32+
}
33+
34+
void uses()
35+
{
36+
int a = add(1, 2);
37+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
REQUIRED_ARGS: -ftime-trace -ftime-trace-file=- -ftime-trace-granularity=0
3+
TRANSFORM_OUTPUT: sanitize_timetrace
4+
TEST_OUTPUT:
5+
---
6+
Code generation,
7+
Codegen: function cube, object.cube
8+
Codegen: function square, object.square
9+
Codegen: function uses, object.uses
10+
Codegen: module object, object
11+
Import object.object, object.object
12+
Inline: cube, object.cube
13+
Inline: uses, object.uses
14+
Inlining,
15+
Parse: Module object, object
16+
Parsing,
17+
Sema1: Function cube, object.cube
18+
Sema1: Function square, object.square
19+
Sema1: Function uses, object.uses
20+
Sema1: Module object, object
21+
Sema2: cube, object.cube
22+
Sema2: square, object.square
23+
Sema2: uses, object.uses
24+
Sema3: cube, object.cube
25+
Sema3: square, object.square
26+
Sema3: uses, object.uses
27+
Semantic analysis,
28+
---
29+
*/
30+
31+
module object; // Don't clutter time trace output with object.d
32+
33+
pragma(inline, true)
34+
int square(int x) { return x * x; }
35+
36+
pragma(inline, true)
37+
int cube(int x) { return x * square(x); }
38+
39+
void uses()
40+
{
41+
int a = cube(3);
42+
int b = square(4);
43+
}

0 commit comments

Comments
 (0)