From 51ad07d1fbffd41c758eba172aa77ebba3204924 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 23 Feb 2025 10:31:05 -0800 Subject: Improve performance when compiling small shaders. (#6396) Improve performance when compiling small shaders. Avoid copying witness table entries that are not getting used during linking. Avoid copying auto-diff related decorations and derivative functions during linking, if the user modules doesn't use autodiff. Cache operator overload resolution results on global session, so each new Session doesn't need to repetitively run through overload resolution from scratch. --- source/slang/slang-lower-to-ir.cpp | 43 ++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'source/slang/slang-lower-to-ir.cpp') diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index fbe6d8a84..e5037bf04 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -8168,24 +8168,34 @@ struct DeclLoweringVisitor : DeclVisitor // If the witness table is for a COM interface, always keep it alive. if (irWitnessTableBaseType->findDecoration()) { - subBuilder->addPublicDecoration(irWitnessTable); + subBuilder->addHLSLExportDecoration(irWitnessTable); } - if (parentDecl->findModifier()) + for (auto mod : parentDecl->modifiers) { - subBuilder->addHLSLExportDecoration(irWitnessTable); - subBuilder->addKeepAliveDecoration(irWitnessTable); + if (as(mod)) + { + subBuilder->addHLSLExportDecoration(irWitnessTable); + subBuilder->addKeepAliveDecoration(irWitnessTable); + } + else if (as(mod)) + { + subBuilder->addAutoDiffBuiltinDecoration(irWitnessTable); + } } // Make sure that all the entries in the witness table have been filled in, // including any cases where there are sub-witness-tables for conformances - Dictionary mapASTToIRWitnessTable; - lowerWitnessTable( - subContext, - inheritanceDecl->witnessTable, - irWitnessTable, - mapASTToIRWitnessTable); - + bool isExplicitExtern = false; + if (!isImportedDecl(context, parentDecl, isExplicitExtern)) + { + Dictionary mapASTToIRWitnessTable; + lowerWitnessTable( + subContext, + inheritanceDecl->witnessTable, + irWitnessTable, + mapASTToIRWitnessTable); + } irWitnessTable->moveToEnd(); return LoweredValInfo::simple( @@ -11536,6 +11546,8 @@ RefPtr generateIRForTranslationUnit( RefPtr module = IRModule::create(session); + module->setName(translationUnit->getModuleDecl()->getName()); + IRBuilder builderStorage(module); IRBuilder* builder = &builderStorage; @@ -11804,6 +11816,8 @@ RefPtr generateIRForTranslationUnit( stripOptions.stripSourceLocs = false; stripFrontEndOnlyInstructions(module, stripOptions); + stripImportedWitnessTable(module); + // Stripping out decorations could leave some dead code behind // in the module, and in some cases that extra code is also // undesirable (e.g., the string literals referenced by name-hint @@ -11847,6 +11861,8 @@ RefPtr generateIRForTranslationUnit( &writer); } + module->buildMangledNameToGlobalInstMap(); + return module; } @@ -11884,7 +11900,7 @@ struct SpecializedComponentTypeIRGenContext : ComponentTypeVisitor context->irBuilder = builder; componentType->acceptVisitor(this, nullptr); - + module->buildMangledNameToGlobalInstMap(); return module; } @@ -12040,6 +12056,7 @@ struct TypeConformanceIRGenContext { builder->addSequentialIDDecoration(witness, conformanceIdOverride); } + module->buildMangledNameToGlobalInstMap(); return module; } }; @@ -12507,7 +12524,7 @@ RefPtr TargetProgram::createIRModuleForLayout(DiagnosticSink* sink) // Eliminate any dead code eliminateDeadCode(irModule, options); } - + irModule->buildMangledNameToGlobalInstMap(); m_irModuleForLayout = irModule; return irModule; } -- cgit v1.2.3