From e3e0132743ada1569cefe18bfbf54178330204c4 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 5 May 2022 09:09:25 -0400 Subject: Preliminary Liveness tracking (#2218) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP tracking liveness. * Skeleton around adding liveness instructions. * Calling into liveness tracking logic. Adds live start to var insts. * Liveness macros have initial output. * Looking at different initialization scenarios. * Some discussion around liveness. * WIP for working out liveness end. * WIP Updated liveness using use lists. * Is now adding liveness information * Some small fixes. * WIP around liveness. * Seems to output liveness correctly for current scenario. * Tidy up liveness code. * Update comment arounds liveness to current status. * Small fixes to liveness test. * Add support for call in liveness analysis. * Improve liveness example with array access. * Small updates to comments. * Disable liveness test because inconsistencies with output on CI system. * Fix some issues brought up in PR. * Rename liveness instructions. --- source/slang/slang-emit.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index d09217b58..0f43762c1 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -38,6 +38,8 @@ #include "slang-ir-union.h" #include "slang-ir-validate.h" #include "slang-ir-wrap-structured-buffers.h" +#include "slang-ir-liveness.h" + #include "slang-legalize-types.h" #include "slang-lower-to-ir.h" #include "slang-mangle.h" @@ -484,9 +486,9 @@ Result linkAndOptimizeIR( { wrapStructuredBuffersOfMatrices(irModule); #if 0 - dumpIRIfEnabled(codeGenContext, irModule, "STRUCTURED BUFFERS WRAPPED"); + dumpIRIfEnabled(codeGenContext, irModule, "STRUCTURED BUFFERS WRAPPED"); #endif - validateIRModuleIfEnabled(codeGenContext, irModule); + validateIRModuleIfEnabled(codeGenContext, irModule); } break; @@ -728,6 +730,40 @@ Result linkAndOptimizeIR( lowerBitCast(targetRequest, irModule); simplifyIR(irModule); + // TODO(JS): We probably want to add a pass that moves phi-node temporaries to + // IR. + // + // Currently these are added as part of emit in + // emitPhiVarAssignments and emitPhiVarDecls + // + // A possible mechanism might be: + // 1) Find all of the parameters passed between blocks + // 2) Make a variable for each one of them + // This could be at the scope for the function, or more ideally a scope that is 'most appropriate' for how the parameter is passed + // ie the closest scope such that the variable is in scope across the branch. + // 3) Replace all uses of the parameters passed into a block (except the entry block), with the temporary + // 3a) Remove the parameters from the start of a block (other than the entry block) + // 4) For all of the branches in a function + // 4a) For each parameter passed in the branch, assign to the temporary + // 4b) Replace the branch with a branch that has no parameters + // + // This should lead to an equivalent function, where the parameter passing between blocks is removed, and all the temporaries + // are explicit in the output. + // + // I guess there could be a desire to combine the liveness tracking into this pass, because once a phi-temporary has been moved + // we have lost(?) information about liveness. That could potentially be recovered, but for the phi-temporaries, their + // initial liveness is trivial, it's when the assignment takes place, at the branch point. + // + // If all the temporaries were marked as such, then this would be fairly trivial to recreate. + + // TODO(JS): Without a pass to make all variables (including phi ones), the liveness tracking can't track everything + if (codeGenContext->shouldTrackLiveness()) + { + addLivenessTrackingToModule(irModule); + + dumpIRIfEnabled(codeGenContext, irModule, "LIVENESS"); + } + // We include one final step to (optionally) dump the IR and validate // it after all of the optimization passes are complete. This should // reflect the IR that code is generated from as closely as possible. -- cgit v1.2.3