Skip to content

Commit c837be3

Browse files
opt: Pass DebugDeclare scope to DebugValue (KhronosGroup#6178)
1 parent 7ddec72 commit c837be3

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

source/opt/debug_info_manager.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,11 @@ bool DebugInfoManager::IsDeclareVisibleToInstr(Instruction* dbg_declare,
558558
return false;
559559
}
560560

561-
bool DebugInfoManager::AddDebugValueForVariable(Instruction* scope_and_line,
561+
bool DebugInfoManager::AddDebugValueForVariable(Instruction* line,
562562
uint32_t variable_id,
563563
uint32_t value_id,
564564
Instruction* insert_pos) {
565-
assert(scope_and_line != nullptr);
565+
assert(line != nullptr);
566566

567567
auto dbg_decl_itr = var_id_to_dbg_decl_.find(variable_id);
568568
if (dbg_decl_itr == var_id_to_dbg_decl_.end()) return false;
@@ -577,14 +577,15 @@ bool DebugInfoManager::AddDebugValueForVariable(Instruction* scope_and_line,
577577
insert_before = insert_before->NextNode();
578578
}
579579
modified |= AddDebugValueForDecl(dbg_decl_or_val, value_id, insert_before,
580-
scope_and_line) != nullptr;
580+
line) != nullptr;
581581
}
582582
return modified;
583583
}
584584

585-
Instruction* DebugInfoManager::AddDebugValueForDecl(
586-
Instruction* dbg_decl, uint32_t value_id, Instruction* insert_before,
587-
Instruction* scope_and_line) {
585+
Instruction* DebugInfoManager::AddDebugValueForDecl(Instruction* dbg_decl,
586+
uint32_t value_id,
587+
Instruction* insert_before,
588+
Instruction* line) {
588589
if (dbg_decl == nullptr || !IsDebugDeclare(dbg_decl)) return nullptr;
589590

590591
std::unique_ptr<Instruction> dbg_val(dbg_decl->Clone(context()));
@@ -593,7 +594,7 @@ Instruction* DebugInfoManager::AddDebugValueForDecl(
593594
dbg_val->SetOperand(kDebugDeclareOperandVariableIndex, {value_id});
594595
dbg_val->SetOperand(kDebugValueOperandExpressionIndex,
595596
{GetEmptyDebugExpression()->result_id()});
596-
dbg_val->UpdateDebugInfoFrom(scope_and_line);
597+
dbg_val->UpdateDebugInfoFrom(dbg_decl, line);
597598

598599
auto* added_dbg_val = insert_before->InsertBefore(std::move(dbg_val));
599600
AnalyzeDebugInst(added_dbg_val);

source/opt/debug_info_manager.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,21 @@ class DebugInfoManager {
143143
bool KillDebugDeclares(uint32_t variable_id);
144144

145145
// Generates a DebugValue instruction with value |value_id| for every local
146-
// variable that is in the scope of |scope_and_line| and whose memory is
147-
// |variable_id| and inserts it after the instruction |insert_pos|.
146+
// variable that is in the scope of |line| and whose memory is |variable_id|
147+
// and inserts it after the instruction |insert_pos|.
148148
// Returns whether a DebugValue is added or not.
149-
bool AddDebugValueForVariable(Instruction* scope_and_line,
150-
uint32_t variable_id, uint32_t value_id,
151-
Instruction* insert_pos);
149+
bool AddDebugValueForVariable(Instruction* line, uint32_t variable_id,
150+
uint32_t value_id, Instruction* insert_pos);
152151

153152
// Creates a DebugValue for DebugDeclare |dbg_decl| and inserts it before
154-
// |insert_before|. The new DebugValue has the same line and scope as
155-
// |scope_and_line|, or no scope and line information if |scope_and_line|
156-
// is nullptr. The new DebugValue has the same operands as DebugDeclare
157-
// but it uses |value_id| for the value. Returns the created DebugValue,
153+
// |insert_before|. The new DebugValue has the same line as |line} and the
154+
// same scope as |dbg_decl|. The new DebugValue has the same operands as
155+
// DebugDeclare but it uses |value_id| for the value. Returns the created
156+
// DebugValue,
158157
// or nullptr if fails to create one.
159158
Instruction* AddDebugValueForDecl(Instruction* dbg_decl, uint32_t value_id,
160159
Instruction* insert_before,
161-
Instruction* scope_and_line);
160+
Instruction* line);
162161

163162
// Erases |instr| from data structures of this class.
164163
void ClearDebugInfo(Instruction* instr);

source/opt/instruction.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,13 @@ void Instruction::ClearDbgLineInsts() {
546546
clear_dbg_line_insts();
547547
}
548548

549-
void Instruction::UpdateDebugInfoFrom(const Instruction* from) {
549+
void Instruction::UpdateDebugInfoFrom(const Instruction* from,
550+
const Instruction* line) {
550551
if (from == nullptr) return;
551552
ClearDbgLineInsts();
552-
if (!from->dbg_line_insts().empty())
553-
AddDebugLine(&from->dbg_line_insts().back());
553+
const Instruction* fromLine = line != nullptr ? line : from;
554+
if (!fromLine->dbg_line_insts().empty())
555+
AddDebugLine(&fromLine->dbg_line_insts().back());
554556
SetDebugScope(from->GetDebugScope());
555557
if (!IsLineInst() &&
556558
context()->AreAnalysesValid(IRContext::kAnalysisDebugInfo)) {

source/opt/instruction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ class Instruction : public utils::IntrusiveNodeBase<Instruction> {
338338
// Updates lexical scope of DebugScope and OpLine.
339339
void UpdateLexicalScope(uint32_t scope);
340340
// Updates OpLine and DebugScope based on the information of |from|.
341-
void UpdateDebugInfoFrom(const Instruction* from);
341+
void UpdateDebugInfoFrom(const Instruction* from,
342+
const Instruction* line = nullptr);
342343
// Remove the |index|-th operand
343344
void RemoveOperand(uint32_t index) {
344345
operands_.erase(operands_.begin() + index);

source/opt/scalar_replacement_pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ bool ScalarReplacementPass::ReplaceWholeDebugDeclare(
186186
Instruction* added_dbg_value =
187187
context()->get_debug_info_mgr()->AddDebugValueForDecl(
188188
dbg_decl, /*value_id=*/var->result_id(),
189-
/*insert_before=*/insert_before, /*scope_and_line=*/dbg_decl);
189+
/*insert_before=*/insert_before, /*line=*/dbg_decl);
190190

191191
if (added_dbg_value == nullptr) return false;
192192
added_dbg_value->AddOperand(

test/opt/debug_info_manager_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,6 @@ void main(float in_var_color : COLOR) {
767767
%101 = OpExtInst %void %1 DebugScope %22
768768
OpLine %5 13 7
769769
OpStore %100 %31
770-
OpNoLine
771-
%102 = OpExtInst %void %1 DebugNoScope
772770
%36 = OpExtInst %void %1 DebugDeclare %25 %100 %13
773771
OpReturn
774772
OpFunctionEnd

test/opt/local_ssa_elim_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,7 +2978,9 @@ TEST_F(LocalSSAElimTest, DebugValueForReferenceVariableInBB) {
29782978
29792979
; CHECK: OpExtInst %void [[ext]] DebugScope [[dbg_main]]
29802980
; CHECK: OpStore %f %float_0
2981+
; CHECK-NEXT: OpExtInst %void [[ext]] DebugScope [[dbg_bb]]
29812982
; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_x]] %float_0
2983+
; CHECK-NEXT: OpExtInst %void [[ext]] DebugScope [[dbg_main]]
29822984
; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
29832985
; CHECK-NEXT: OpStore %i %int_0
29842986
; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
@@ -5434,6 +5436,7 @@ float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
54345436
%1614 = OpLabel
54355437
;CHECK: %1614 = OpLabel
54365438
;CHECK-NEXT: [[phi:%\w+]] = OpPhi
5439+
;CHECK-NEXT: {{%\w+}} = OpExtInst %void {{%\w+}} DebugScope %179
54375440
;CHECK-NEXT: {{%\w+}} = OpExtInst %void {{%\w+}} DebugValue %233
54385441
%2335 = OpExtInst %void %2 DebugScope %179
54395442
%1795 = OpExtInst %void %2 DebugLine %64 %uint_149 %uint_149 %uint_16 %uint_16

0 commit comments

Comments
 (0)