summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-05-10 14:10:53 -0700
committerGitHub <noreply@github.com>2023-05-10 14:10:53 -0700
commit99bc31fdd6fd9a6cbce6afd5fa9b52fb47873f61 (patch)
treeae6f8c301c771f5a27d1f775729a4fc759f1d804 /source
parentc8e6a6452f4e531dca09152178bae2f9a2fb999a (diff)
Add slangc options for reporting downstream compile time. (#2878)
* Add slangc options for reporting downstream compile time. * Update doc. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rwxr-xr-xsource/slang/slang-compiler.h3
-rw-r--r--source/slang/slang-diagnostic-defs.h2
-rw-r--r--source/slang/slang-options.cpp9
-rw-r--r--source/slang/slang.cpp19
4 files changed, 29 insertions, 4 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 42fc3ca1f..1386b37e8 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -2637,7 +2637,7 @@ namespace Slang
virtual SLANG_NO_THROW SlangDiagnosticFlags SLANG_MCALL getDiagnosticFlags() SLANG_OVERRIDE;
virtual SLANG_NO_THROW void SLANG_MCALL setDiagnosticFlags(SlangDiagnosticFlags flags) SLANG_OVERRIDE;
virtual SLANG_NO_THROW void SLANG_MCALL setDebugInfoFormat(SlangDebugInfoFormat format) SLANG_OVERRIDE;
-
+ virtual SLANG_NO_THROW void SLANG_MCALL setReportDownstreamTime(bool value) SLANG_OVERRIDE;
void setHLSLToVulkanLayoutOptions(int targetIndex, HLSLToVulkanLayoutOptions* vulkanLayoutOptions);
EndToEndCompileRequest(
@@ -2675,6 +2675,7 @@ namespace Slang
// Are we being driven by the command-line `slangc`, and should act accordingly?
bool m_isCommandLineCompile = false;
+ bool m_reportDownstreamCompileTime = false;
String m_diagnosticOutput;
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 723dc4d64..d4bb63f52 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -138,7 +138,7 @@ DIAGNOSTIC( 99, Error, unknownDebugOption, "unknown debug option, known optio
DIAGNOSTIC( 100, Error, failedToLoadDownstreamCompiler, "failed to load downstream compiler '$0'")
DIAGNOSTIC( 101, Error, downstreamCompilerDoesntSupportWholeProgramCompilation, "downstream compiler '$0' doesn't support whole program compilation")
-
+DIAGNOSTIC( 102, Note, downstreamCompileTime, "downstream compile time: $0s")
DIAGNOSTIC(99999, Note, noteFailedToLoadDynamicLibrary, "failed to load dynamic library '$0'")
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index cb04632cc..f69e0ec3a 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -70,6 +70,7 @@ enum class OptionKind
DumpWarningDiagnostics,
InputFilesRemain,
EmitIr,
+ ReportDownstreamTime,
// Target
@@ -413,7 +414,8 @@ void initCommandOptions(CommandOptions& options)
{ OptionKind::EnableWarning, "-W...", "-W<id>", "Enable a warning with the specified id."},
{ OptionKind::DisableWarning, "-Wno-...", "-Wno-<id>", "Disable warning with <id>"},
{ OptionKind::DumpWarningDiagnostics, "-dump-warning-diagnostics", nullptr, "Dump to output list of warning diagnostic numeric and name ids." },
- { OptionKind::InputFilesRemain, "--", nullptr, "Treat the rest of the command line as input files."}
+ { OptionKind::InputFilesRemain, "--", nullptr, "Treat the rest of the command line as input files."},
+ { OptionKind::ReportDownstreamTime, "-report-downstream-time", nullptr, "Reports the time spent in the downstream compiler." },
};
_addOptions(makeConstArrayView(generalOpts), options);
@@ -1838,6 +1840,11 @@ SlangResult OptionsParser::_parse(
}
break;
}
+ case OptionKind::ReportDownstreamTime:
+ {
+ m_compileRequest->setReportDownstreamTime(true);
+ break;
+ }
case OptionKind::ModuleName:
{
CommandLineArg moduleName;
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index f2598786f..ead1e338f 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -4806,6 +4806,11 @@ void EndToEndCompileRequest::setPassThrough(SlangPassThrough inPassThrough)
m_passThrough = PassThroughMode(inPassThrough);
}
+void EndToEndCompileRequest::setReportDownstreamTime(bool value)
+{
+ m_reportDownstreamCompileTime = value;
+}
+
void EndToEndCompileRequest::setDiagnosticCallback(SlangDiagnosticCallback callback, void const* userData)
{
ComPtr<ISlangWriter> writer(new CallbackWriter(callback, userData, WriterFlag::IsConsole));
@@ -5112,7 +5117,11 @@ SlangResult EndToEndCompileRequest::setTypeNameForEntryPointExistentialTypeParam
SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile()
{
SlangResult res = SLANG_FAIL;
-
+ double downstreamStartTime = 0.0;
+ if (m_reportDownstreamCompileTime)
+ {
+ downstreamStartTime = getSession()->getDownstreamCompilerElapsedTime();
+ }
#if !defined(SLANG_DEBUG_INTERNAL_ERROR)
// By default we'd like to catch as many internal errors as possible,
// and report them to the user nicely (rather than just crash their
@@ -5160,6 +5169,14 @@ SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile()
}
#endif
+ if (m_reportDownstreamCompileTime)
+ {
+ double downstreamTime = getSession()->getDownstreamCompilerElapsedTime() - downstreamStartTime;
+ String downstreamTimeStr = String(downstreamTime, "%.2f");
+ getSink()->diagnose(SourceLoc(), Diagnostics::downstreamCompileTime, downstreamTimeStr);
+
+ }
+
// Repro dump handling
{
if (m_dumpRepro.getLength())