Skip to content

Commit

Permalink
Insert DebugValue with Deref into the first block of function
Browse files Browse the repository at this point in the history
  • Loading branch information
jaebaek committed Jul 22, 2020
1 parent 6e4d9f2 commit a1678d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 4 additions & 1 deletion source/opt/debug_info_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,11 @@ bool DebugInfoManager::IsDeclareVisibleToInstr(Instruction* dbg_declare,
Instruction* DebugInfoManager::AddDebugValueWithIndex(
uint32_t dbg_local_var_id, uint32_t value_id, uint32_t expr_id,
uint32_t index_id, Instruction* insert_before) {
uint32_t result_id = context()->TakeNextId();
if (!result_id) return nullptr;
std::unique_ptr<Instruction> new_dbg_value(new Instruction(
context(), SpvOpExtInst, context()->get_type_mgr()->GetVoidTypeId(),
context()->TakeNextId(),
result_id,
{
{spv_operand_type_t::SPV_OPERAND_TYPE_ID,
{context()
Expand Down Expand Up @@ -511,6 +513,7 @@ void DebugInfoManager::AddDebugValueIfVarDeclIsVisible(
AddDebugValueWithIndex(dbg_decl_or_val->GetSingleWordOperand(
kDebugValueOperandLocalVariableIndex),
value_id, 0, index_id, insert_before);
assert(added_dbg_value != nullptr);
added_dbg_value->UpdateDebugInfoFrom(scope_and_line);
}
}
Expand Down
12 changes: 8 additions & 4 deletions source/opt/scalar_replacement_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ bool ScalarReplacementPass::ReplaceWholeDebugDeclare(
// Add DebugValue instruction with Indexes operand and Deref operation.
int32_t idx = 0;
for (const auto* var : replacements) {
context()->get_debug_info_mgr()->AddDebugValueWithIndex(
dbg_decl->GetSingleWordOperand(kDebugDeclareOperandLocalVariableIndex),
var->result_id(), deref_expr->result_id(),
context()->get_constant_mgr()->GetSIntConst(idx), dbg_decl);
Instruction* added_dbg_value =
context()->get_debug_info_mgr()->AddDebugValueWithIndex(
dbg_decl->GetSingleWordOperand(
kDebugDeclareOperandLocalVariableIndex),
var->result_id(), deref_expr->result_id(),
context()->get_constant_mgr()->GetSIntConst(idx), var->NextNode());
if (added_dbg_value == nullptr) return false;
added_dbg_value->UpdateDebugInfoFrom(dbg_decl);
++idx;
}
return true;
Expand Down
12 changes: 6 additions & 6 deletions test/opt/scalar_replacement_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1935,13 +1935,13 @@ OpName %6 "simple_struct"
; CHECK: [[dbg_local_var:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable
; CHECK: [[deref_expr:%\w+]] = OpExtInst %void [[ext]] DebugExpression [[deref]]
; CHECK: [[repl3:%\w+]] = OpVariable %_ptr_Function_uint Function
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl3]] [[deref_expr]] %int_3
; CHECK: [[repl2:%\w+]] = OpVariable %_ptr_Function_uint Function
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl2]] [[deref_expr]] %int_2
; CHECK: [[repl1:%\w+]] = OpVariable %_ptr_Function_uint Function
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl1]] [[deref_expr]] %int_1
; CHECK: [[repl0:%\w+]] = OpVariable %_ptr_Function_uint Function
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl0]] [[deref_expr]] %int_0
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl1]] [[deref_expr]] %int_1
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl2]] [[deref_expr]] %int_2
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl3]] [[deref_expr]] %int_3
; CHECK-NOT: DebugDeclare
%decl = OpExtInst %1 %ext DebugDeclare %dbg_foo %14 %null_expr
Expand Down Expand Up @@ -2058,11 +2058,11 @@ OpName %6 "simple_struct"
; CHECK: [[repl2:%\w+]] = OpVariable %_ptr_Function_float Function %float_1
; CHECK: [[repl1:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_32
; CHECK: [[repl3:%\w+]] = OpVariable %_ptr_Function_float Function %float_1
; CHECK: [[repl0:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_32
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl0]] [[deref_expr]] %int_0
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl3]] [[deref_expr]] %int_2
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl1]] [[deref_expr]] %int_1 %int_0
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl2]] [[deref_expr]] %int_1 %int_1
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl3]] [[deref_expr]] %int_2
; CHECK: [[repl0:%\w+]] = OpVariable %_ptr_Function_uint Function %uint_32
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_local_var]] [[repl0]] [[deref_expr]] %int_0
; CHECK-NOT: DebugDeclare
%decl = OpExtInst %1 %ext DebugDeclare %dbg_foo %14 %null_expr
Expand Down

0 comments on commit a1678d0

Please sign in to comment.