mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-10-19 03:20:14 +00:00
Preserve debug info for wrap-opkill (#3331)
Preserve debug info for wrap-opkill
This commit is contained in:
parent
d2b4862194
commit
c8590c18bd
@ -291,6 +291,8 @@ class Instruction : public utils::IntrusiveNodeBase<Instruction> {
|
|||||||
// Sets DebugScope.
|
// Sets DebugScope.
|
||||||
inline void SetDebugScope(const DebugScope& scope);
|
inline void SetDebugScope(const DebugScope& scope);
|
||||||
inline const DebugScope& GetDebugScope() const { return dbg_scope_; }
|
inline const DebugScope& GetDebugScope() const { return dbg_scope_; }
|
||||||
|
// Updates OpLine and DebugScope based on the information of |from|.
|
||||||
|
inline void UpdateDebugInfo(const Instruction* from);
|
||||||
// Remove the |index|-th operand
|
// Remove the |index|-th operand
|
||||||
void RemoveOperand(uint32_t index) {
|
void RemoveOperand(uint32_t index) {
|
||||||
operands_.erase(operands_.begin() + index);
|
operands_.erase(operands_.begin() + index);
|
||||||
@ -636,6 +638,14 @@ inline void Instruction::SetDebugScope(const DebugScope& scope) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Instruction::UpdateDebugInfo(const Instruction* from) {
|
||||||
|
if (from == nullptr) return;
|
||||||
|
clear_dbg_line_insts();
|
||||||
|
if (!from->dbg_line_insts().empty())
|
||||||
|
dbg_line_insts().push_back(from->dbg_line_insts()[0]);
|
||||||
|
SetDebugScope(from->GetDebugScope());
|
||||||
|
}
|
||||||
|
|
||||||
inline void Instruction::SetResultType(uint32_t ty_id) {
|
inline void Instruction::SetResultType(uint32_t ty_id) {
|
||||||
// TODO(dsinclair): Allow setting a type id if there wasn't one
|
// TODO(dsinclair): Allow setting a type id if there wasn't one
|
||||||
// previously. Need to make room in the operands_ array to place the result,
|
// previously. Need to make room in the operands_ array to place the result,
|
||||||
|
@ -59,9 +59,12 @@ bool WrapOpKill::ReplaceWithFunctionCall(Instruction* inst) {
|
|||||||
if (func_id == 0) {
|
if (func_id == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ir_builder.AddFunctionCall(GetVoidTypeId(), func_id, {}) == nullptr) {
|
Instruction* call_inst =
|
||||||
|
ir_builder.AddFunctionCall(GetVoidTypeId(), func_id, {});
|
||||||
|
if (call_inst == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
call_inst->UpdateDebugInfo(inst);
|
||||||
|
|
||||||
Instruction* return_inst = nullptr;
|
Instruction* return_inst = nullptr;
|
||||||
uint32_t return_type_id = GetOwningFunctionsReturnType(inst);
|
uint32_t return_type_id = GetOwningFunctionsReturnType(inst);
|
||||||
|
@ -589,6 +589,63 @@ TEST_F(WrapOpKillTest, KillInSingleBlockLoop) {
|
|||||||
SinglePassRunAndMatch<WrapOpKill>(text, true);
|
SinglePassRunAndMatch<WrapOpKill>(text, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(WrapOpKillTest, DebugInfoSimple) {
|
||||||
|
const std::string text = R"(
|
||||||
|
; CHECK: OpEntryPoint Fragment [[main:%\w+]]
|
||||||
|
; CHECK: [[main]] = OpFunction
|
||||||
|
; CHECK: OpFunctionCall %void [[orig_kill:%\w+]]
|
||||||
|
; CHECK: [[orig_kill]] = OpFunction
|
||||||
|
; CHECK-NEXT: OpLabel
|
||||||
|
; CHECK-NEXT: {{%\d+}} = OpExtInst %void [[ext:%\d+]] DebugScope
|
||||||
|
; CHECK-NEXT: OpLine [[file:%\d+]] 100 200
|
||||||
|
; CHECK-NEXT: OpFunctionCall %void [[new_kill:%\w+]]
|
||||||
|
; CHECK-NEXT: {{%\d+}} = OpExtInst %void [[ext]] DebugNoScope
|
||||||
|
; CHECK-NEXT: OpReturn
|
||||||
|
; CHECK: [[new_kill]] = OpFunction
|
||||||
|
; CHECK-NEXT: OpLabel
|
||||||
|
; CHECK-NEXT: OpKill
|
||||||
|
; CHECK-NEXT: OpFunctionEnd
|
||||||
|
OpCapability Shader
|
||||||
|
%1 = OpExtInstImport "OpenCL.DebugInfo.100"
|
||||||
|
OpMemoryModel Logical GLSL450
|
||||||
|
OpEntryPoint Fragment %main "main"
|
||||||
|
OpExecutionMode %main OriginUpperLeft
|
||||||
|
%2 = OpString "File name"
|
||||||
|
OpSource GLSL 330
|
||||||
|
OpName %main "main"
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%5 = OpTypeFunction %void
|
||||||
|
%bool = OpTypeBool
|
||||||
|
%true = OpConstantTrue %bool
|
||||||
|
%3 = OpExtInst %void %1 DebugSource %2
|
||||||
|
%4 = OpExtInst %void %1 DebugCompilationUnit 0 0 %3 GLSL
|
||||||
|
%main = OpFunction %void None %5
|
||||||
|
%8 = OpLabel
|
||||||
|
OpBranch %9
|
||||||
|
%9 = OpLabel
|
||||||
|
OpLoopMerge %10 %11 None
|
||||||
|
OpBranch %12
|
||||||
|
%12 = OpLabel
|
||||||
|
OpBranchConditional %true %13 %10
|
||||||
|
%13 = OpLabel
|
||||||
|
OpBranch %11
|
||||||
|
%11 = OpLabel
|
||||||
|
%14 = OpFunctionCall %void %kill_
|
||||||
|
OpBranch %9
|
||||||
|
%10 = OpLabel
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
%kill_ = OpFunction %void None %5
|
||||||
|
%15 = OpLabel
|
||||||
|
%16 = OpExtInst %void %1 DebugScope %4
|
||||||
|
OpLine %2 100 200
|
||||||
|
OpKill
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
|
||||||
|
SinglePassRunAndMatch<WrapOpKill>(text, true);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace opt
|
} // namespace opt
|
||||||
} // namespace spvtools
|
} // namespace spvtools
|
||||||
|
Loading…
Reference in New Issue
Block a user