From 47b43f8b15ef35c520b9b287fd17ff25e36bfe95 Mon Sep 17 00:00:00 2001 From: Dietrich Geisler Date: Mon, 29 Jun 2020 17:42:12 -0400 Subject: Backend for Multiple Entry Points (#1411) * Backend for Multiple Entry Points Introduces the basic backend on the compiler for zero or more entry points. Entry points have been extended to lists for several functions, with loopFunctions have been extended to take in entry points and indices as appropriate, to allow for multiple entry points once the frontend is expanded. Several functions are currently being assumed to have a single entry point for simplicity and provide a work in progress commit. * Progress on debugging fixes * Tests passing * Refactored emitEntryPoints * Updated lists to be by constant reference * Fixes to formatting * Refactoring updates for the compiler * Fix for compilation errors * Reformatting * More reformatting * Moved struct around to help with compilation Co-authored-by: Tim Foley --- source/slang/slang-emit.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 59b059e91..e59cfae37 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -160,9 +160,10 @@ struct LinkingAndOptimizationOptions CLikeSourceEmitter* sourceEmitter = nullptr; }; +// TODO(DG): A bit tricky; this needs to be generalized to multiple entry points Result linkAndOptimizeIR( BackEndCompileRequest* compileRequest, - Int entryPointIndex, + List entryPointIndices, CodeGenTarget target, TargetRequest* targetRequest, LinkingAndOptimizationOptions const& options, @@ -184,7 +185,7 @@ Result linkAndOptimizeIR( // outLinkedIR = linkIR( compileRequest, - entryPointIndex, + entryPointIndices, target, targetProgram); auto irModule = outLinkedIR.module; @@ -287,6 +288,9 @@ Result linkAndOptimizeIR( break; } + // TODO(DG): There are multiple DCE steps here, which need to be changed + // CHECK: how to these modules work? + // so that they don't just throw out any non-entry point code // Debugging code for IR transformations... #if 0 dumpIRIfEnabled(compileRequest, irModule, "SPECIALIZED"); @@ -605,19 +609,23 @@ Result linkAndOptimizeIR( return SLANG_OK; } +// TODO(DG): This probably needs to be generalized to a list SlangResult emitEntryPointSourceFromIR( BackEndCompileRequest* compileRequest, - Int entryPointIndex, + List entryPointIndices, CodeGenTarget target, TargetRequest* targetRequest, SourceResult& outSource) { + // Temporary assertion for checkpoint + SLANG_ASSERT(entryPointIndices.getCount() == 1); outSource.reset(); auto sink = compileRequest->getSink(); auto program = compileRequest->getProgram(); - auto entryPoint = program->getEntryPoint(entryPointIndex); + // TODO(DG): Update from assertion + auto entryPoint = program->getEntryPoint(entryPointIndices[0]); auto lineDirectiveMode = compileRequest->getLineDirectiveMode(); // To try to make the default behavior reasonable, we will @@ -637,6 +645,7 @@ SlangResult emitEntryPointSourceFromIR( desc.compileRequest = compileRequest; desc.target = target; + // TODO(DG): Can't assume a single entry point stage for multiple entry points desc.entryPointStage = entryPoint->getStage(); desc.effectiveProfile = getEffectiveProfile(entryPoint, targetRequest); desc.sourceWriter = &sourceWriter; @@ -700,7 +709,7 @@ SlangResult emitEntryPointSourceFromIR( linkAndOptimizeIR( compileRequest, - entryPointIndex, + entryPointIndices, target, targetRequest, linkingAndOptimizationOptions, @@ -769,25 +778,27 @@ SlangResult emitSPIRVFromIR( IRFunc* irEntryPoint, List& spirvOut); -SlangResult emitSPIRVForEntryPointDirectly( +SlangResult emitSPIRVForEntryPointsDirectly( BackEndCompileRequest* compileRequest, - Int entryPointIndex, + List entryPointIndices, TargetRequest* targetRequest, List& spirvOut) { + // TODO(DG): Temporary assertion for checkpoint + SLANG_ASSERT(entryPointIndices.getCount() == 1); auto sink = compileRequest->getSink(); auto program = compileRequest->getProgram(); auto targetProgram = program->getTargetProgram(targetRequest); auto programLayout = targetProgram->getOrCreateLayout(sink); - RefPtr entryPointLayout = programLayout->entryPoints[entryPointIndex]; + RefPtr entryPointLayout = programLayout->entryPoints[entryPointIndices[0]]; // Outside because we want to keep IR in scope whilst we are processing emits LinkedIR linkedIR; LinkingAndOptimizationOptions linkingAndOptimizationOptions; linkAndOptimizeIR( compileRequest, - entryPointIndex, + entryPointIndices, targetRequest->getTarget(), targetRequest, linkingAndOptimizationOptions, -- cgit v1.2.3