From c571bcb025009f9c662e8d631fa49dbfed560287 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 28 Apr 2023 23:28:23 -0700 Subject: SSA Register Allocation improvements. (#2857) * SSA Register Allocation improvements. * Fix. * Rename `Use`->`UseOrPseudoUse`. --------- Co-authored-by: Yong He --- source/slang/slang-emit-spirv.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-emit-spirv.cpp') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index fc2505d63..b17ccf483 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1473,7 +1473,20 @@ struct SPIRVEmitContext // for( auto irBlock : irFunc->getBlocks() ) { - emitInst(spvFunc, irBlock, SpvOpLabel, kResultID); + auto spvBlock = emitInst(spvFunc, irBlock, SpvOpLabel, kResultID); + if (irBlock == irFunc->getFirstBlock()) + { + // OpVariable + // All variables used in the function must be declared before anything else. + for (auto block : irFunc->getBlocks()) + { + for (auto inst : block->getChildren()) + { + if (as(inst)) + emitLocalInst(spvBlock, inst); + } + } + } // In addition to normal basic blocks, // all loops gets a header block. @@ -1517,6 +1530,9 @@ struct SPIRVEmitContext // Any instructions local to the block will be emitted as children // of the block. // + // Skip vars because they are already emitted. + if (as(irInst)) + continue; emitLocalInst(spvBlock, irInst); if (irInst->getOp() == kIROp_loop) pendingLoopInsts.add(as(irInst)); -- cgit v1.2.3