Skip to content

Commit d705257

Browse files
committed
Add comments.
1 parent b377521 commit d705257

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

source/slang/slang-emit.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ struct LinkingAndOptimizationOptions
213213
CLikeSourceEmitter* sourceEmitter = nullptr;
214214
};
215215

216+
// To improve the performance of our backend, we will try to avoid running
217+
// passes related to features not used in the user code.
218+
// To do so, we will scan the IR module once, and determine which passes are needed
219+
// based on the instructions used in the IR module.
220+
// This will allow us to skip running passes that are not needed, without having to
221+
// run all the passes only to find out that no work is needed.
222+
// This is especially important for the performance of the backend, as some passes
223+
// have an initialization cost (such as building reference graphs or DOM trees) that
224+
// can be expensive.
225+
//
216226
struct RequiredLoweringPassSet
217227
{
218228
bool resultType;
@@ -233,6 +243,9 @@ struct RequiredLoweringPassSet
233243
bool byteAddressBuffer;
234244
};
235245

246+
// Scan the IR module and determine which lowering/legalization passes are needed based
247+
// on the instructions we see.
248+
//
236249
void calcRequiredLoweringPassSet(RequiredLoweringPassSet& result, CodeGenContext* codeGenContext, IRInst* inst)
237250
{
238251
switch (inst->getOp())
@@ -594,9 +607,9 @@ Result linkAndOptimizeIR(
594607
performMandatoryEarlyInlining(irModule);
595608

596609
// Unroll loops.
597-
if (codeGenContext->getSink()->getErrorCount() == 0)
610+
if (!fastIRSimplificationOptions.minimalOptimization)
598611
{
599-
if (!fastIRSimplificationOptions.minimalOptimization)
612+
if (codeGenContext->getSink()->getErrorCount() == 0)
600613
{
601614
if (!unrollLoopsInModule(targetProgram, irModule, codeGenContext->getSink()))
602615
return SLANG_FAIL;
@@ -611,14 +624,14 @@ Result linkAndOptimizeIR(
611624
if (requiredLoweringPassSet.higherOrderFunc)
612625
changed |= specializeHigherOrderParameters(codeGenContext, irModule);
613626

614-
dumpIRIfEnabled(codeGenContext, irModule, "BEFORE-AUTODIFF");
615-
enableIRValidationAtInsert();
616627
if (requiredLoweringPassSet.autodiff)
617628
{
629+
dumpIRIfEnabled(codeGenContext, irModule, "BEFORE-AUTODIFF");
630+
enableIRValidationAtInsert();
618631
changed |= processAutodiffCalls(targetProgram, irModule, sink);
632+
disableIRValidationAtInsert();
633+
dumpIRIfEnabled(codeGenContext, irModule, "AFTER-AUTODIFF");
619634
}
620-
disableIRValidationAtInsert();
621-
dumpIRIfEnabled(codeGenContext, irModule, "AFTER-AUTODIFF");
622635

623636
if (!changed)
624637
break;
@@ -687,7 +700,8 @@ Result linkAndOptimizeIR(
687700
simplifyIR(targetProgram, irModule, fastIRSimplificationOptions, sink);
688701
}
689702

690-
if (!ArtifactDescUtil::isCpuLikeTarget(artifactDesc))
703+
if (!ArtifactDescUtil::isCpuLikeTarget(artifactDesc) &&
704+
targetProgram->getOptionSet().shouldRunNonEssentialValidation())
691705
{
692706
// We could fail because (perhaps, somehow) end up with getStringHash that the operand is not a string literal
693707
SLANG_RETURN_ON_FAIL(checkGetStringHashInsts(irModule, sink));

source/slang/slang-lower-to-ir.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10824,7 +10824,7 @@ RefPtr<IRModule> generateIRForTranslationUnit(
1082410824

1082510825
// Generate DebugValue insts to store values into debug variables,
1082610826
// if debug symbols are enabled.
10827-
if (compileRequest->getLinkage()->m_optionSet.getEnumOption<DebugInfoLevel>(CompilerOptionName::DebugInformation) != DebugInfoLevel::None)
10827+
if (context->includeDebugInfo)
1082810828
{
1082910829
insertDebugValueStore(module);
1083010830
}

0 commit comments

Comments
 (0)