Skip to content

Commit

Permalink
[OPT] Fix generating debugLocalVariable from debugGlobalVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
s-perron committed Sep 12, 2024
1 parent 7c9210c commit 91d98b2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions source/opt/debug_info_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,15 +768,29 @@ void DebugInfoManager::ConvertDebugGlobalToLocalVariable(
local_var->opcode() == spv::Op::OpFunctionParameter);

// Convert |dbg_global_var| to DebugLocalVariable
// All of the operands upto the scope operand are the same for the type
// instructions. The flag operand needs to move from operand
// kDebugGlobalVariableOperandFlagsIndex to
// kDebugLocalVariableOperandFlagsIndex. No other operands are needed for to
// define the DebugLocalVariable.

// Modify the opcode.
dbg_global_var->SetInOperand(kExtInstInstructionInIdx,
{CommonDebugInfoDebugLocalVariable});

// Move the flags operand.
auto flags = dbg_global_var->GetSingleWordOperand(
kDebugGlobalVariableOperandFlagsIndex);
for (uint32_t i = dbg_global_var->NumInOperands() - 1;
i >= kDebugLocalVariableOperandFlagsIndex; --i) {
dbg_global_var->SetOperand(kDebugLocalVariableOperandFlagsIndex, {flags});

// Remove the extra operands. Starting at the end to avoid copying too much
// data.
for (uint32_t i = dbg_global_var->NumOperands() - 1;
i > kDebugLocalVariableOperandFlagsIndex; --i) {
dbg_global_var->RemoveOperand(i);
}
dbg_global_var->SetOperand(kDebugLocalVariableOperandFlagsIndex, {flags});

// Update the def-use manager.
context()->ForgetUses(dbg_global_var);
context()->AnalyzeUses(dbg_global_var);

Expand Down

0 comments on commit 91d98b2

Please sign in to comment.