@@ -213,6 +213,16 @@ struct LinkingAndOptimizationOptions
213
213
CLikeSourceEmitter* sourceEmitter = nullptr ;
214
214
};
215
215
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
+ //
216
226
struct RequiredLoweringPassSet
217
227
{
218
228
bool resultType;
@@ -233,6 +243,9 @@ struct RequiredLoweringPassSet
233
243
bool byteAddressBuffer;
234
244
};
235
245
246
+ // Scan the IR module and determine which lowering/legalization passes are needed based
247
+ // on the instructions we see.
248
+ //
236
249
void calcRequiredLoweringPassSet (RequiredLoweringPassSet& result, CodeGenContext* codeGenContext, IRInst* inst)
237
250
{
238
251
switch (inst->getOp ())
@@ -594,9 +607,9 @@ Result linkAndOptimizeIR(
594
607
performMandatoryEarlyInlining (irModule);
595
608
596
609
// Unroll loops.
597
- if (codeGenContext-> getSink ()-> getErrorCount () == 0 )
610
+ if (!fastIRSimplificationOptions. minimalOptimization )
598
611
{
599
- if (!fastIRSimplificationOptions. minimalOptimization )
612
+ if (codeGenContext-> getSink ()-> getErrorCount () == 0 )
600
613
{
601
614
if (!unrollLoopsInModule (targetProgram, irModule, codeGenContext->getSink ()))
602
615
return SLANG_FAIL;
@@ -611,14 +624,14 @@ Result linkAndOptimizeIR(
611
624
if (requiredLoweringPassSet.higherOrderFunc )
612
625
changed |= specializeHigherOrderParameters (codeGenContext, irModule);
613
626
614
- dumpIRIfEnabled (codeGenContext, irModule, " BEFORE-AUTODIFF" );
615
- enableIRValidationAtInsert ();
616
627
if (requiredLoweringPassSet.autodiff )
617
628
{
629
+ dumpIRIfEnabled (codeGenContext, irModule, " BEFORE-AUTODIFF" );
630
+ enableIRValidationAtInsert ();
618
631
changed |= processAutodiffCalls (targetProgram, irModule, sink);
632
+ disableIRValidationAtInsert ();
633
+ dumpIRIfEnabled (codeGenContext, irModule, " AFTER-AUTODIFF" );
619
634
}
620
- disableIRValidationAtInsert ();
621
- dumpIRIfEnabled (codeGenContext, irModule, " AFTER-AUTODIFF" );
622
635
623
636
if (!changed)
624
637
break ;
@@ -687,7 +700,8 @@ Result linkAndOptimizeIR(
687
700
simplifyIR (targetProgram, irModule, fastIRSimplificationOptions, sink);
688
701
}
689
702
690
- if (!ArtifactDescUtil::isCpuLikeTarget (artifactDesc))
703
+ if (!ArtifactDescUtil::isCpuLikeTarget (artifactDesc) &&
704
+ targetProgram->getOptionSet ().shouldRunNonEssentialValidation ())
691
705
{
692
706
// We could fail because (perhaps, somehow) end up with getStringHash that the operand is not a string literal
693
707
SLANG_RETURN_ON_FAIL (checkGetStringHashInsts (irModule, sink));
0 commit comments