Skip to content

Commit 213e266

Browse files
committed
Add options to speedup compilation.
1 parent c1e34c5 commit 213e266

15 files changed

+240
-207
lines changed

build/visual-studio/slang/slang.vcxproj

-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla
444444
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-optional-type.h" />
445445
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-reinterpret.h" />
446446
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-result-type.h" />
447-
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-size-of.h" />
448447
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-tuple-types.h" />
449448
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-witness-lookup.h" />
450449
<ClInclude Include="..\..\..\source\slang\slang-ir-marshal-native-call.h" />
@@ -685,7 +684,6 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla
685684
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-optional-type.cpp" />
686685
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-reinterpret.cpp" />
687686
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-result-type.cpp" />
688-
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-size-of.cpp" />
689687
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-tuple-types.cpp" />
690688
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-witness-lookup.cpp" />
691689
<ClCompile Include="..\..\..\source\slang\slang-ir-marshal-native-call.cpp" />

build/visual-studio/slang/slang.vcxproj.filters

-6
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,6 @@
420420
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-result-type.h">
421421
<Filter>Header Files</Filter>
422422
</ClInclude>
423-
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-size-of.h">
424-
<Filter>Header Files</Filter>
425-
</ClInclude>
426423
<ClInclude Include="..\..\..\source\slang\slang-ir-lower-tuple-types.h">
427424
<Filter>Header Files</Filter>
428425
</ClInclude>
@@ -1139,9 +1136,6 @@
11391136
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-result-type.cpp">
11401137
<Filter>Source Files</Filter>
11411138
</ClCompile>
1142-
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-size-of.cpp">
1143-
<Filter>Source Files</Filter>
1144-
</ClCompile>
11451139
<ClCompile Include="..\..\..\source\slang\slang-ir-lower-tuple-types.cpp">
11461140
<Filter>Source Files</Filter>
11471141
</ClCompile>

slang.h

+1
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ extern "C"
863863
SourceEmbedLanguage,
864864
DisableShortCircuit, // bool
865865
MinimumSlangOptimization, // bool
866+
DisableNonEssentialValidations, // bool
866867

867868
// Target
868869

source/slang/slang-check-modifier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ namespace Slang
16781678
{
16791679
if (mapExclusiveGroupToModifier.tryGetValue(conflictGroup, existingModifier))
16801680
{
1681-
getSink()->diagnose(modifier->loc, Diagnostics::duplicateModifier, modifier, existingModifier);
1681+
//getSink()->diagnose(modifier->loc, Diagnostics::duplicateModifier, modifier, existingModifier);
16821682
}
16831683
mapExclusiveGroupToModifier[conflictGroup] = modifier;
16841684
}

source/slang/slang-emit.cpp

+158-29
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include "slang-ir-lower-bit-cast.h"
4949
#include "slang-ir-lower-combined-texture-sampler.h"
5050
#include "slang-ir-lower-l-value-cast.h"
51-
#include "slang-ir-lower-size-of.h"
5251
#include "slang-ir-lower-reinterpret.h"
5352
#include "slang-ir-loop-unroll.h"
5453
#include "slang-ir-legalize-vector-types.h"
@@ -214,6 +213,99 @@ struct LinkingAndOptimizationOptions
214213
CLikeSourceEmitter* sourceEmitter = nullptr;
215214
};
216215

216+
struct RequiredLoweringPassSet
217+
{
218+
bool resultType;
219+
bool optionalType;
220+
bool combinedTextureSamplers;
221+
bool reinterpret;
222+
bool generics;
223+
bool autodiff;
224+
bool derivativePyBindWrapper;
225+
bool bitcast;
226+
bool existentialTypeLayout;
227+
bool bindingQuery;
228+
bool meshOutput;
229+
};
230+
231+
void calcRequiredLoweringPassSet(RequiredLoweringPassSet& result, CodeGenContext* codeGenContext, IRInst* inst)
232+
{
233+
switch (inst->getOp())
234+
{
235+
case kIROp_ResultType:
236+
result.resultType = true;
237+
break;
238+
case kIROp_OptionalType:
239+
result.optionalType = true;
240+
break;
241+
case kIROp_TextureType:
242+
if (!isKhronosTarget(codeGenContext->getTargetReq()))
243+
{
244+
if (auto texType = as<IRTextureType>(inst))
245+
{
246+
auto isCombined = texType->getIsCombinedInst();
247+
if (auto isCombinedVal = as<IRIntLit>(isCombined))
248+
{
249+
if (isCombinedVal->getValue() != 0)
250+
{
251+
result.combinedTextureSamplers = true;
252+
}
253+
}
254+
else
255+
{
256+
result.combinedTextureSamplers = true;
257+
}
258+
}
259+
}
260+
break;
261+
case kIROp_PseudoPtrType:
262+
result.existentialTypeLayout = true;
263+
break;
264+
case kIROp_GetRegisterIndex:
265+
case kIROp_GetRegisterSpace:
266+
result.bindingQuery = true;
267+
break;
268+
case kIROp_BackwardDifferentiate:
269+
case kIROp_ForwardDifferentiate:
270+
result.autodiff = true;
271+
break;
272+
case kIROp_VerticesType:
273+
case kIROp_IndicesType:
274+
case kIROp_PrimitivesType:
275+
result.meshOutput = true;
276+
break;
277+
case kIROp_CreateExistentialObject:
278+
case kIROp_MakeExistential:
279+
case kIROp_ExtractExistentialType:
280+
case kIROp_ExtractExistentialValue:
281+
case kIROp_ExtractExistentialWitnessTable:
282+
case kIROp_WrapExistential:
283+
case kIROp_LookupWitness:
284+
result.generics = true;
285+
break;
286+
case kIROp_Specialize:
287+
{
288+
auto specInst = as<IRSpecialize>(inst);
289+
if (!findAnyTargetIntrinsicDecoration(getResolvedInstForDecorations(specInst)))
290+
result.generics = true;
291+
}
292+
break;
293+
case kIROp_Reinterpret:
294+
result.reinterpret = true;
295+
break;
296+
case kIROp_BitCast:
297+
result.bitcast = true;
298+
break;
299+
case kIROp_AutoPyBindCudaDecoration:
300+
result.derivativePyBindWrapper = true;
301+
break;
302+
}
303+
for (auto child : inst->getDecorationsAndChildren())
304+
{
305+
calcRequiredLoweringPassSet(result, codeGenContext, child);
306+
}
307+
}
308+
217309
Result linkAndOptimizeIR(
218310
CodeGenContext* codeGenContext,
219311
LinkingAndOptimizationOptions const& options,
@@ -354,7 +446,11 @@ Result linkAndOptimizeIR(
354446
break;
355447
}
356448

357-
lowerOptionalType(irModule, sink);
449+
RequiredLoweringPassSet requiredLoweringPassSet = {};
450+
calcRequiredLoweringPassSet(requiredLoweringPassSet, codeGenContext, irModule->getModuleInst());
451+
452+
if (requiredLoweringPassSet.optionalType)
453+
lowerOptionalType(irModule, sink);
358454

359455
switch (target)
360456
{
@@ -370,7 +466,8 @@ Result linkAndOptimizeIR(
370466
}
371467

372468
// Lower `Result<T,E>` types into ordinary struct types.
373-
lowerResultType(irModule, sink);
469+
if (requiredLoweringPassSet.resultType)
470+
lowerResultType(irModule, sink);
374471

375472
#if 0
376473
dumpIRIfEnabled(codeGenContext, irModule, "UNIONS DESUGARED");
@@ -403,7 +500,8 @@ Result linkAndOptimizeIR(
403500
fuseCallsToSaturatedCooperation(irModule);
404501

405502
// Generate any requested derivative wrappers
406-
generateDerivativeWrappers(irModule, sink);
503+
if (requiredLoweringPassSet.derivativePyBindWrapper)
504+
generateDerivativeWrappers(irModule, sink);
407505

408506
// Next, we need to ensure that the code we emit for
409507
// the target doesn't contain any operations that would
@@ -448,8 +546,11 @@ Result linkAndOptimizeIR(
448546
// Unroll loops.
449547
if (codeGenContext->getSink()->getErrorCount() == 0)
450548
{
451-
if (!unrollLoopsInModule(targetProgram, irModule, codeGenContext->getSink()))
452-
return SLANG_FAIL;
549+
if (!fastIRSimplificationOptions.minimalOptimization)
550+
{
551+
if (!unrollLoopsInModule(targetProgram, irModule, codeGenContext->getSink()))
552+
return SLANG_FAIL;
553+
}
453554
}
454555

455556
// Few of our targets support higher order functions, and
@@ -462,15 +563,19 @@ Result linkAndOptimizeIR(
462563

463564
dumpIRIfEnabled(codeGenContext, irModule, "BEFORE-AUTODIFF");
464565
enableIRValidationAtInsert();
465-
changed |= processAutodiffCalls(targetProgram, irModule, sink);
566+
if (requiredLoweringPassSet.autodiff)
567+
{
568+
changed |= processAutodiffCalls(targetProgram, irModule, sink);
569+
}
466570
disableIRValidationAtInsert();
467571
dumpIRIfEnabled(codeGenContext, irModule, "AFTER-AUTODIFF");
468572

469573
if (!changed)
470574
break;
471575
}
472576

473-
finalizeAutoDiffPass(targetProgram, irModule);
577+
if (requiredLoweringPassSet.autodiff)
578+
finalizeAutoDiffPass(targetProgram, irModule);
474579

475580
finalizeSpecialization(irModule);
476581

@@ -507,7 +612,9 @@ Result linkAndOptimizeIR(
507612
SLANG_RETURN_ON_FAIL(performTypeInlining(irModule, sink));
508613
}
509614

510-
lowerReinterpret(targetProgram, irModule, sink);
615+
if (requiredLoweringPassSet.reinterpret)
616+
lowerReinterpret(targetProgram, irModule, sink);
617+
511618
if (sink->getErrorCount() != 0)
512619
return SLANG_FAIL;
513620

@@ -517,20 +624,33 @@ Result linkAndOptimizeIR(
517624
// but are not used for dynamic dispatch, unpin them so we don't
518625
// do unnecessary work to lower them.
519626
unpinWitnessTables(irModule);
520-
521-
simplifyIR(targetProgram, irModule, fastIRSimplificationOptions, sink);
627+
628+
if (fastIRSimplificationOptions.minimalOptimization)
629+
{
630+
eliminateDeadCode(irModule);
631+
}
632+
else
633+
{
634+
simplifyIR(targetProgram, irModule, fastIRSimplificationOptions, sink);
635+
}
522636

523637
if (!ArtifactDescUtil::isCpuLikeTarget(artifactDesc))
524638
{
525639
// We could fail because (perhaps, somehow) end up with getStringHash that the operand is not a string literal
526640
SLANG_RETURN_ON_FAIL(checkGetStringHashInsts(irModule, sink));
527641
}
528642

643+
requiredLoweringPassSet = {};
644+
calcRequiredLoweringPassSet(requiredLoweringPassSet, codeGenContext, irModule->getModuleInst());
645+
529646
// For targets that supports dynamic dispatch, we need to lower the
530647
// generics / interface types to ordinary functions and types using
531648
// function pointers.
532649
dumpIRIfEnabled(codeGenContext, irModule, "BEFORE-LOWER-GENERICS");
533-
lowerGenerics(targetProgram, irModule, sink);
650+
if (requiredLoweringPassSet.generics)
651+
lowerGenerics(targetProgram, irModule, sink);
652+
else
653+
cleanupGenerics(targetProgram, irModule, sink);
534654
dumpIRIfEnabled(codeGenContext, irModule, "AFTER-LOWER-GENERICS");
535655

536656
if (sink->getErrorCount() != 0)
@@ -547,7 +667,10 @@ Result linkAndOptimizeIR(
547667
// up downstream passes like type legalization, so we
548668
// will run a DCE pass to clean up after the specialization.
549669
//
550-
simplifyIR(targetProgram, irModule, defaultIRSimplificationOptions, sink);
670+
if (!fastIRSimplificationOptions.minimalOptimization)
671+
{
672+
simplifyIR(targetProgram, irModule, defaultIRSimplificationOptions, sink);
673+
}
551674

552675
validateIRModuleIfEnabled(codeGenContext, irModule);
553676

@@ -569,11 +692,15 @@ Result linkAndOptimizeIR(
569692
case CodeGenTarget::Metal:
570693
case CodeGenTarget::MetalLib:
571694
case CodeGenTarget::MetalLibAssembly:
572-
lowerCombinedTextureSamplers(irModule, sink);
695+
if (requiredLoweringPassSet.combinedTextureSamplers)
696+
lowerCombinedTextureSamplers(irModule, sink);
573697
break;
574698
}
575699

576-
addUserTypeHintDecorations(irModule);
700+
if (codeGenContext->getTargetProgram()->getOptionSet().getBoolOption(CompilerOptionName::VulkanEmitReflection))
701+
{
702+
addUserTypeHintDecorations(irModule);
703+
}
577704

578705
// We don't need the legalize pass for C/C++ based types
579706
if(options.shouldLegalizeExistentialAndResourceTypes )
@@ -603,10 +730,13 @@ Result linkAndOptimizeIR(
603730
// we need to replace it with just an `X`, after which we
604731
// will have (more) legal shader code.
605732
//
606-
legalizeExistentialTypeLayout(
607-
targetProgram,
608-
irModule,
609-
sink);
733+
if (requiredLoweringPassSet.existentialTypeLayout)
734+
{
735+
legalizeExistentialTypeLayout(
736+
targetProgram,
737+
irModule,
738+
sink);
739+
}
610740

611741
#if 0
612742
dumpIRIfEnabled(codeGenContext, irModule, "EXISTENTIALS LEGALIZED");
@@ -652,7 +782,8 @@ Result linkAndOptimizeIR(
652782
// to see if we can clean up any temporaries created by legalization.
653783
// (e.g., things that used to be aggregated might now be split up,
654784
// so that we can work with the individual fields).
655-
simplifyIR(targetProgram, irModule, fastIRSimplificationOptions, sink);
785+
if (!fastIRSimplificationOptions.minimalOptimization)
786+
simplifyIR(targetProgram, irModule, fastIRSimplificationOptions, sink);
656787

657788
#if 0
658789
dumpIRIfEnabled(codeGenContext, irModule, "AFTER SSA");
@@ -678,7 +809,6 @@ Result linkAndOptimizeIR(
678809
{
679810
specializeArrayParameters(codeGenContext, irModule);
680811
}
681-
eliminateDeadCode(irModule);
682812

683813
#if 0
684814
dumpIRIfEnabled(codeGenContext, irModule, "AFTER RESOURCE SPECIALIZATION");
@@ -965,14 +1095,16 @@ Result linkAndOptimizeIR(
9651095

9661096
// Lower the `getRegisterIndex` and `getRegisterSpace` intrinsics.
9671097
//
968-
lowerBindingQueries(irModule, sink);
1098+
if (requiredLoweringPassSet.bindingQuery)
1099+
lowerBindingQueries(irModule, sink);
9691100

9701101
// For some small improvement in type safety we represent these as opaque
9711102
// structs instead of regular arrays.
9721103
//
9731104
// If any have survived this far, change them back to regular (decorated)
9741105
// arrays that the emitters can deal with.
975-
legalizeMeshOutputTypes(irModule);
1106+
if (requiredLoweringPassSet.meshOutput)
1107+
legalizeMeshOutputTypes(irModule);
9761108

9771109
if (options.shouldLegalizeExistentialAndResourceTypes)
9781110
{
@@ -997,13 +1129,10 @@ Result linkAndOptimizeIR(
9971129
rcpWOfPositionInput(irModule);
9981130
}
9991131

1000-
// Lower sizeof/alignof
1001-
1002-
lowerSizeOfLike(targetProgram, irModule, sink);
1003-
10041132
// Lower all bit_cast operations on complex types into leaf-level
10051133
// bit_cast on basic types.
1006-
lowerBitCast(targetProgram, irModule, sink);
1134+
if (requiredLoweringPassSet.bitcast)
1135+
lowerBitCast(targetProgram, irModule, sink);
10071136

10081137
bool emitSpirvDirectly = targetProgram->shouldEmitSPIRVDirectly();
10091138

@@ -1076,7 +1205,7 @@ Result linkAndOptimizeIR(
10761205
// For now we are avoiding that problem by simply *not* emitting live-range
10771206
// information when we fix variable scoping later on.
10781207

1079-
// Depending on the target, certain things that were represented as
1208+
// Depending on the target, certain things that were represented ass
10801209
// single IR instructions will need to be emitted with the help of
10811210
// function declaratons in output high-level code.
10821211
//

source/slang/slang-ir-dce.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ bool shouldInstBeLiveIfParentIsLive(IRInst* inst, IRDeadCodeEliminationOptions o
307307
// First, if `inst` is an instruction that might have some effects
308308
// when it is executed, then we should keep it around.
309309
//
310-
if (inst->mightHaveSideEffects(SideEffectAnalysisOptions::UseDominanceTree))
310+
if (inst->mightHaveSideEffects(SideEffectAnalysisOptions::None))
311311
{
312312
return true;
313313
}

0 commit comments

Comments
 (0)