summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-05-23 15:19:27 -0700
committerGitHub <noreply@github.com>2023-05-23 15:19:27 -0700
commitf88e1299b7715190ce82f3f4473f0d0eeaa2000e (patch)
tree7aba3971505ab50b8ee2d387695cef4da81344de /source
parenta291dbf0ce774fdc11c820471e26bda656bf1666 (diff)
Add API for querying total compile time. (#2898)
* Add API for querying total compile time. * Optimize. * Remove redundant simplifyIR calls. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-compiler.cpp2
-rwxr-xr-xsource/slang/slang-compiler.h25
-rw-r--r--source/slang/slang-emit.cpp5
-rw-r--r--source/slang/slang-ir-defunctionalization.cpp1
-rw-r--r--source/slang/slang-ir-specialize-function-call.cpp3
-rw-r--r--source/slang/slang-ir-specialize-resources.cpp1
-rw-r--r--source/slang/slang-ir-specialize.cpp5
-rw-r--r--source/slang/slang.cpp11
8 files changed, 42 insertions, 11 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 8426b7eec..a5f46da3e 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -1548,6 +1548,8 @@ namespace Slang
// Do emit logic for a zero or more entry points
SlangResult CodeGenContext::emitEntryPoints(ComPtr<IArtifact>& outArtifact)
{
+ CompileTimerRAII recordCompileTime(getSession());
+
auto target = getTargetFormat();
switch (target)
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 4d3df5433..66454b2da 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -2947,9 +2947,10 @@ namespace Slang
SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerForTransition(SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler) override;
SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDownstreamCompilerForTransition(SlangCompileTarget source, SlangCompileTarget target) override;
- SLANG_NO_THROW double SLANG_MCALL getDownstreamCompilerElapsedTime() override
+ SLANG_NO_THROW void SLANG_MCALL getCompilerElapsedTime(double* outTotalTime, double* outDownstreamTime) override
{
- return m_downstreamCompileTime;
+ *outDownstreamTime = m_downstreamCompileTime;
+ *outTotalTime = m_totalCompileTime;
}
/// Get the downstream compiler for a transition
@@ -3028,6 +3029,7 @@ namespace Slang
~Session();
void addDownstreamCompileTime(double time) { m_downstreamCompileTime += time; }
+ void addTotalCompileTime(double time) { m_totalCompileTime += time; }
ComPtr<ISlangSharedLibraryLoader> m_sharedLibraryLoader; ///< The shared library loader (never null)
@@ -3060,6 +3062,7 @@ namespace Slang
CodeGenTransitionMap m_codeGenTransitionMap;
double m_downstreamCompileTime = 0.0;
+ double m_totalCompileTime = 0.0;
};
void checkTranslationUnit(
@@ -3164,6 +3167,24 @@ SLANG_FORCE_INLINE SlangCompileTarget asExternal(CodeGenTarget target) { return
SLANG_FORCE_INLINE SlangSourceLanguage asExternal(SourceLanguage sourceLanguage) { return (SlangSourceLanguage)sourceLanguage; }
+// Helper class for recording compile time.
+struct CompileTimerRAII
+{
+ std::chrono::high_resolution_clock::time_point startTime;
+ Session* session;
+ CompileTimerRAII(Session* inSession)
+ {
+ startTime = std::chrono::high_resolution_clock::now();
+ session = inSession;
+ }
+ ~CompileTimerRAII()
+ {
+ double elapsedTime = std::chrono::duration_cast<std::chrono::microseconds>(
+ std::chrono::high_resolution_clock::now() - startTime)
+ .count() / 1e6;
+ session->addTotalCompileTime(elapsedTime);
+ }
+};
}
#endif
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 071ea9639..a96cb6908 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -584,17 +584,14 @@ Result linkAndOptimizeIR(
specializeResourceUsage(codeGenContext, irModule);
specializeFuncsForBufferLoadArgs(codeGenContext, irModule);
- //
- simplifyIR(irModule);
-
// For GLSL targets, we also want to specialize calls to functions that
// takes array parameters if possible, to avoid performance issues on
// those platforms.
if (isKhronosTarget(targetRequest))
{
specializeArrayParameters(codeGenContext, irModule);
- simplifyIR(irModule);
}
+ simplifyIR(irModule);
// Rewrite functions that return arrays to return them via `out` parameter,
// since our target languages doesn't allow returning arrays.
diff --git a/source/slang/slang-ir-defunctionalization.cpp b/source/slang/slang-ir-defunctionalization.cpp
index ac4258753..15e5a3ff7 100644
--- a/source/slang/slang-ir-defunctionalization.cpp
+++ b/source/slang/slang-ir-defunctionalization.cpp
@@ -30,7 +30,6 @@ bool specializeHigherOrderParameters(
while (changed)
{
changed = specializeFunctionCalls(codeGenContext, module, &condition);
- simplifyIR(module);
result |= changed;
}
return result;
diff --git a/source/slang/slang-ir-specialize-function-call.cpp b/source/slang/slang-ir-specialize-function-call.cpp
index e0a757e11..2fa93087f 100644
--- a/source/slang/slang-ir-specialize-function-call.cpp
+++ b/source/slang/slang-ir-specialize-function-call.cpp
@@ -4,6 +4,7 @@
#include "slang-ir.h"
#include "slang-ir-clone.h"
#include "slang-ir-insts.h"
+#include "slang-ir-ssa-simplification.h"
namespace Slang
{
@@ -888,6 +889,8 @@ struct FunctionParameterSpecializationContext
//
addCallsToWorkListRec(newFunc);
+ simplifyFunc(newFunc);
+
return newFunc;
}
};
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp
index 83f280d9b..3d28e0bb0 100644
--- a/source/slang/slang-ir-specialize-resources.cpp
+++ b/source/slang/slang-ir-specialize-resources.cpp
@@ -95,7 +95,6 @@ bool specializeResourceParameters(
while (changed)
{
changed = specializeFunctionCalls(codeGenContext, module, &condition);
- simplifyIR(module);
result |= changed;
}
return result;
diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp
index 5962f6dbb..80dcec82b 100644
--- a/source/slang/slang-ir-specialize.cpp
+++ b/source/slang/slang-ir-specialize.cpp
@@ -6,6 +6,7 @@
#include "slang-ir-insts.h"
#include "slang-ir-ssa-simplification.h"
#include "slang-ir-lower-witness-lookup.h"
+#include "slang-ir-dce.h"
namespace Slang
{
@@ -929,8 +930,8 @@ struct SpecializationContext
if (iterChanged)
{
- simplifyIR(module);
this->changed = true;
+ eliminateDeadCode(module->getModuleInst(), IRDeadCodeEliminationOptions());
}
else
{
@@ -1617,6 +1618,8 @@ struct SpecializationContext
//
addToWorkList(newFunc);
+ simplifyFunc(newFunc);
+
return newFunc;
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index ead1e338f..d651f0737 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -2997,6 +2997,8 @@ RefPtr<Module> Linkage::loadModule(
DiagnosticSink* sink,
const LoadedModuleDictionary* additionalLoadedModules)
{
+ CompileTimerRAII recordCompileTime(static_cast<Session*>(getGlobalSession()));
+
RefPtr<FrontEndCompileRequest> frontEndReq = new FrontEndCompileRequest(this, nullptr, sink);
frontEndReq->additionalLoadedModules = additionalLoadedModules;
@@ -5118,9 +5120,11 @@ SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile()
{
SlangResult res = SLANG_FAIL;
double downstreamStartTime = 0.0;
+ double totalStartTime = 0.0;
+
if (m_reportDownstreamCompileTime)
{
- downstreamStartTime = getSession()->getDownstreamCompilerElapsedTime();
+ getSession()->getCompilerElapsedTime(&totalStartTime, &downstreamStartTime);
}
#if !defined(SLANG_DEBUG_INTERNAL_ERROR)
// By default we'd like to catch as many internal errors as possible,
@@ -5171,7 +5175,10 @@ SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile()
if (m_reportDownstreamCompileTime)
{
- double downstreamTime = getSession()->getDownstreamCompilerElapsedTime() - downstreamStartTime;
+ double downstreamEndTime = 0;
+ double totalEndTime = 0;
+ getSession()->getCompilerElapsedTime(&totalEndTime, &downstreamEndTime);
+ double downstreamTime = downstreamEndTime - downstreamStartTime;
String downstreamTimeStr = String(downstreamTime, "%.2f");
getSink()->diagnose(SourceLoc(), Diagnostics::downstreamCompileTime, downstreamTimeStr);