Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions changelog/dmd.ftime-trace-inline.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
`-ftime-trace`: add instrumentation for the inliner pass

The `-ftime-trace` output previously had no coverage for the inliner pass.
When compiling with `-inline`, the time spent scanning and inlining functions
did not appear in the trace at all.

Two new spans are now emitted: `Inlining` covers the entire inliner pass, and
`Inline: <function>` covers each function scanned individually.
These are visible in trace viewers like $(LINK2 https://ui.perfetto.dev/, Perfetto).
4 changes: 4 additions & 0 deletions compiler/src/dmd/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,10 @@ public:
fd.inlineScanned = true;
fd.semanticRun = pass;

import dmd.timetrace;
timeTraceBeginEvent(TimeTraceEventType.inlineFunction);
scope (exit) timeTraceEndEvent(TimeTraceEventType.inlineFunction, fd);

scope InlineScanVisitor v = new InlineScanVisitor(fd, pass, eSink);

do
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ private int tryMain(const(char)[][] argv, out Param params)
if (global.errors)
removeHdrFilesAndFail(params, modules);

{
timeTraceBeginEvent(TimeTraceEventType.inlineGeneral);
scope (exit) timeTraceEndEvent(TimeTraceEventType.inlineGeneral);

// Scan for modules with always inline functions
foreach (m; modules)
{
Expand All @@ -686,6 +690,7 @@ private int tryMain(const(char)[][] argv, out Param params)
inlineScanAllFunctions(m, global.errorSink);
}
}
}

if (global.warnings)
errorOnWarning();
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dmd/timetrace.d
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ enum TimeTraceEventType
sema1Function,
sema2,
sema3,
inlineGeneral, /// top-level span for the entire inliner pass
inlineFunction, /// per-function span during inlining
dfa,
ctfe,
ctfeCall,
Expand Down Expand Up @@ -211,6 +213,8 @@ private immutable string[] eventPrefixes = [
"Sema1: Function ",
"Sema2: ",
"Sema3: ",
"Inlining",
"Inline: ",
"DFA: ",
"Ctfe: ",
"Ctfe: call ",
Expand Down
1 change: 1 addition & 0 deletions compiler/test/compilable/ftimetrace.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DFA: fun, object.fun
DFA: id, object.id!int.id
DFA: uses, object.uses
Import object.object, object.object
Inlining,
Parse: Module object, object
Parsing,
Sema1: Function add, object.add
Expand Down
37 changes: 37 additions & 0 deletions compiler/test/compilable/ftimetrace_inline.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
REQUIRED_ARGS: -ftime-trace -ftime-trace-file=- -ftime-trace-granularity=0 -inline
TRANSFORM_OUTPUT: sanitize_timetrace
TEST_OUTPUT:
---
Code generation,
Codegen: function add, object.add
Codegen: function uses, object.uses
Codegen: module object, object
Import object.object, object.object
Inline: add, object.add
Inline: uses, object.uses
Inlining,
Parse: Module object, object
Parsing,
Sema1: Function add, object.add
Sema1: Function uses, object.uses
Sema1: Module object, object
Sema2: add, object.add
Sema2: uses, object.uses
Sema3: add, object.add
Sema3: uses, object.uses
Semantic analysis,
---
*/

module object; // Don't clutter time trace output with object.d

int add(int x, int y)
{
return x + y;
}

void uses()
{
int a = add(1, 2);
}
43 changes: 43 additions & 0 deletions compiler/test/compilable/ftimetrace_pragma.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
REQUIRED_ARGS: -ftime-trace -ftime-trace-file=- -ftime-trace-granularity=0
TRANSFORM_OUTPUT: sanitize_timetrace
TEST_OUTPUT:
---
Code generation,
Codegen: function cube, object.cube
Codegen: function square, object.square
Codegen: function uses, object.uses
Codegen: module object, object
Import object.object, object.object
Inline: cube, object.cube
Inline: uses, object.uses
Inlining,
Parse: Module object, object
Parsing,
Sema1: Function cube, object.cube
Sema1: Function square, object.square
Sema1: Function uses, object.uses
Sema1: Module object, object
Sema2: cube, object.cube
Sema2: square, object.square
Sema2: uses, object.uses
Sema3: cube, object.cube
Sema3: square, object.square
Sema3: uses, object.uses
Semantic analysis,
---
*/

module object; // Don't clutter time trace output with object.d

pragma(inline, true)
int square(int x) { return x * x; }

pragma(inline, true)
int cube(int x) { return x * square(x); }

void uses()
{
int a = cube(3);
int b = square(4);
}
Loading