1fd4e5da5Sopenharmony_ci// Copyright (c) 2020 Google LLC 2fd4e5da5Sopenharmony_ci// 3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 6fd4e5da5Sopenharmony_ci// 7fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 13fd4e5da5Sopenharmony_ci// limitations under the License. 14fd4e5da5Sopenharmony_ci 15fd4e5da5Sopenharmony_ci#include "source/opt/debug_info_manager.h" 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#include <memory> 18fd4e5da5Sopenharmony_ci#include <vector> 19fd4e5da5Sopenharmony_ci 20fd4e5da5Sopenharmony_ci#include "gtest/gtest.h" 21fd4e5da5Sopenharmony_ci#include "source/opt/build_module.h" 22fd4e5da5Sopenharmony_ci#include "source/opt/instruction.h" 23fd4e5da5Sopenharmony_ci#include "spirv-tools/libspirv.hpp" 24fd4e5da5Sopenharmony_ci 25fd4e5da5Sopenharmony_ci// Constants for OpenCL.DebugInfo.100 extension instructions. 26fd4e5da5Sopenharmony_ci 27fd4e5da5Sopenharmony_cistatic const uint32_t kDebugFunctionOperandFunctionIndex = 13; 28fd4e5da5Sopenharmony_cistatic const uint32_t kDebugInlinedAtOperandLineIndex = 4; 29fd4e5da5Sopenharmony_cistatic const uint32_t kDebugInlinedAtOperandScopeIndex = 5; 30fd4e5da5Sopenharmony_cistatic const uint32_t kDebugInlinedAtOperandInlinedIndex = 6; 31fd4e5da5Sopenharmony_cistatic const uint32_t kOpLineInOperandFileIndex = 0; 32fd4e5da5Sopenharmony_cistatic const uint32_t kOpLineInOperandLineIndex = 1; 33fd4e5da5Sopenharmony_cistatic const uint32_t kOpLineInOperandColumnIndex = 2; 34fd4e5da5Sopenharmony_ci 35fd4e5da5Sopenharmony_cinamespace spvtools { 36fd4e5da5Sopenharmony_cinamespace opt { 37fd4e5da5Sopenharmony_cinamespace analysis { 38fd4e5da5Sopenharmony_cinamespace { 39fd4e5da5Sopenharmony_ci 40fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, GetDebugInlinedAt) { 41fd4e5da5Sopenharmony_ci const std::string text = R"( 42fd4e5da5Sopenharmony_ci OpCapability Shader 43fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 44fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 45fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %in_var_COLOR 46fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 47fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 48fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 49fd4e5da5Sopenharmony_civoid main(float in_var_color : COLOR) { 50fd4e5da5Sopenharmony_ci float color = in_var_color; 51fd4e5da5Sopenharmony_ci} 52fd4e5da5Sopenharmony_ci" 53fd4e5da5Sopenharmony_ci %17 = OpString "float" 54fd4e5da5Sopenharmony_ci %21 = OpString "main" 55fd4e5da5Sopenharmony_ci %24 = OpString "color" 56fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 57fd4e5da5Sopenharmony_ci OpName %main "main" 58fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 59fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 60fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 61fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 62fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 63fd4e5da5Sopenharmony_ci %void = OpTypeVoid 64fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 65fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 66fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 67fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 68fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 69fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 70fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 71fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 72fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %main 73fd4e5da5Sopenharmony_ci %100 = OpExtInst %void %1 DebugInlinedAt 7 %22 74fd4e5da5Sopenharmony_ci %main = OpFunction %void None %27 75fd4e5da5Sopenharmony_ci %28 = OpLabel 76fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 77fd4e5da5Sopenharmony_ci OpStore %100 %31 78fd4e5da5Sopenharmony_ci OpReturn 79fd4e5da5Sopenharmony_ci OpFunctionEnd 80fd4e5da5Sopenharmony_ci )"; 81fd4e5da5Sopenharmony_ci 82fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 83fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 84fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 85fd4e5da5Sopenharmony_ci DebugInfoManager manager(context.get()); 86fd4e5da5Sopenharmony_ci 87fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.GetDebugInlinedAt(150), nullptr); 88fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.GetDebugInlinedAt(31), nullptr); 89fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.GetDebugInlinedAt(22), nullptr); 90fd4e5da5Sopenharmony_ci 91fd4e5da5Sopenharmony_ci auto* inst = manager.GetDebugInlinedAt(100); 92fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->GetSingleWordOperand(kDebugInlinedAtOperandLineIndex), 7); 93fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->GetSingleWordOperand(kDebugInlinedAtOperandScopeIndex), 22); 94fd4e5da5Sopenharmony_ci} 95fd4e5da5Sopenharmony_ci 96fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, CreateDebugInlinedAt) { 97fd4e5da5Sopenharmony_ci const std::string text = R"( 98fd4e5da5Sopenharmony_ci OpCapability Shader 99fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 100fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 101fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %in_var_COLOR 102fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 103fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 104fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 105fd4e5da5Sopenharmony_civoid main(float in_var_color : COLOR) { 106fd4e5da5Sopenharmony_ci float color = in_var_color; 107fd4e5da5Sopenharmony_ci} 108fd4e5da5Sopenharmony_ci" 109fd4e5da5Sopenharmony_ci %17 = OpString "float" 110fd4e5da5Sopenharmony_ci %21 = OpString "main" 111fd4e5da5Sopenharmony_ci %24 = OpString "color" 112fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 113fd4e5da5Sopenharmony_ci OpName %main "main" 114fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 115fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 116fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 117fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 118fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 119fd4e5da5Sopenharmony_ci %void = OpTypeVoid 120fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 121fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 122fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 123fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 124fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 125fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 126fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 127fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 128fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %main 129fd4e5da5Sopenharmony_ci %100 = OpExtInst %void %1 DebugInlinedAt 7 %22 130fd4e5da5Sopenharmony_ci %main = OpFunction %void None %27 131fd4e5da5Sopenharmony_ci %28 = OpLabel 132fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 133fd4e5da5Sopenharmony_ci OpStore %100 %31 134fd4e5da5Sopenharmony_ci OpReturn 135fd4e5da5Sopenharmony_ci OpFunctionEnd 136fd4e5da5Sopenharmony_ci )"; 137fd4e5da5Sopenharmony_ci 138fd4e5da5Sopenharmony_ci DebugScope scope(22U, 0U); 139fd4e5da5Sopenharmony_ci 140fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 141fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 142fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 143fd4e5da5Sopenharmony_ci DebugInfoManager manager(context.get()); 144fd4e5da5Sopenharmony_ci 145fd4e5da5Sopenharmony_ci uint32_t inlined_at_id = manager.CreateDebugInlinedAt(nullptr, scope); 146fd4e5da5Sopenharmony_ci auto* inlined_at = manager.GetDebugInlinedAt(inlined_at_id); 147fd4e5da5Sopenharmony_ci EXPECT_NE(inlined_at, nullptr); 148fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandLineIndex), 149fd4e5da5Sopenharmony_ci 1); 150fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandScopeIndex), 151fd4e5da5Sopenharmony_ci 22); 152fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->NumOperands(), kDebugInlinedAtOperandScopeIndex + 1); 153fd4e5da5Sopenharmony_ci 154fd4e5da5Sopenharmony_ci const uint32_t line_number = 77U; 155fd4e5da5Sopenharmony_ci Instruction line(context.get(), spv::Op::OpLine); 156fd4e5da5Sopenharmony_ci line.SetInOperands({ 157fd4e5da5Sopenharmony_ci {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {5U}}, 158fd4e5da5Sopenharmony_ci {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, {line_number}}, 159fd4e5da5Sopenharmony_ci {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, {0U}}, 160fd4e5da5Sopenharmony_ci }); 161fd4e5da5Sopenharmony_ci 162fd4e5da5Sopenharmony_ci inlined_at_id = manager.CreateDebugInlinedAt(&line, scope); 163fd4e5da5Sopenharmony_ci inlined_at = manager.GetDebugInlinedAt(inlined_at_id); 164fd4e5da5Sopenharmony_ci EXPECT_NE(inlined_at, nullptr); 165fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandLineIndex), 166fd4e5da5Sopenharmony_ci line_number); 167fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandScopeIndex), 168fd4e5da5Sopenharmony_ci 22); 169fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->NumOperands(), kDebugInlinedAtOperandScopeIndex + 1); 170fd4e5da5Sopenharmony_ci 171fd4e5da5Sopenharmony_ci scope.SetInlinedAt(100U); 172fd4e5da5Sopenharmony_ci inlined_at_id = manager.CreateDebugInlinedAt(&line, scope); 173fd4e5da5Sopenharmony_ci inlined_at = manager.GetDebugInlinedAt(inlined_at_id); 174fd4e5da5Sopenharmony_ci EXPECT_NE(inlined_at, nullptr); 175fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandLineIndex), 176fd4e5da5Sopenharmony_ci line_number); 177fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandScopeIndex), 178fd4e5da5Sopenharmony_ci 22); 179fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->NumOperands(), kDebugInlinedAtOperandInlinedIndex + 1); 180fd4e5da5Sopenharmony_ci EXPECT_EQ( 181fd4e5da5Sopenharmony_ci inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandInlinedIndex), 182fd4e5da5Sopenharmony_ci 100U); 183fd4e5da5Sopenharmony_ci} 184fd4e5da5Sopenharmony_ci 185fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, CreateDebugInlinedAtWithConstantManager) { 186fd4e5da5Sopenharmony_ci // Show that CreateDebugInlinedAt will use the Constant manager to generate 187fd4e5da5Sopenharmony_ci // its line operand if the Constant and DefUse managers are valid. This is 188fd4e5da5Sopenharmony_ci // proven by checking that the id for the line operand 7 is the same as the 189fd4e5da5Sopenharmony_ci // existing constant 7. 190fd4e5da5Sopenharmony_ci // 191fd4e5da5Sopenharmony_ci // int function1() { 192fd4e5da5Sopenharmony_ci // return 1; 193fd4e5da5Sopenharmony_ci // } 194fd4e5da5Sopenharmony_ci // 195fd4e5da5Sopenharmony_ci // void main() { 196fd4e5da5Sopenharmony_ci // function1(); 197fd4e5da5Sopenharmony_ci // } 198fd4e5da5Sopenharmony_ci const std::string text = R"(OpCapability Shader 199fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info" 200fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" 201fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 202fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 203fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 204fd4e5da5Sopenharmony_ci%3 = OpString "parent3.hlsl" 205fd4e5da5Sopenharmony_ci%8 = OpString "int" 206fd4e5da5Sopenharmony_ci%19 = OpString "function1" 207fd4e5da5Sopenharmony_ci%20 = OpString "" 208fd4e5da5Sopenharmony_ci%26 = OpString "main" 209fd4e5da5Sopenharmony_ciOpName %main "main" 210fd4e5da5Sopenharmony_ciOpName %src_main "src.main" 211fd4e5da5Sopenharmony_ciOpName %bb_entry "bb.entry" 212fd4e5da5Sopenharmony_ciOpName %function1 "function1" 213fd4e5da5Sopenharmony_ciOpName %bb_entry_0 "bb.entry" 214fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 215fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 216fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0 217fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32 218fd4e5da5Sopenharmony_ci%void = OpTypeVoid 219fd4e5da5Sopenharmony_ci%uint_4 = OpConstant %uint 4 220fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0 221fd4e5da5Sopenharmony_ci%uint_3 = OpConstant %uint 3 222fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1 223fd4e5da5Sopenharmony_ci%uint_5 = OpConstant %uint 5 224fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2 225fd4e5da5Sopenharmony_ci%uint_17 = OpConstant %uint 17 226fd4e5da5Sopenharmony_ci%uint_6 = OpConstant %uint 6 227fd4e5da5Sopenharmony_ci%uint_13 = OpConstant %uint 13 228fd4e5da5Sopenharmony_ci%100 = OpConstant %uint 7 229fd4e5da5Sopenharmony_ci%31 = OpTypeFunction %void 230fd4e5da5Sopenharmony_ci%42 = OpTypeFunction %int 231fd4e5da5Sopenharmony_ci%10 = OpExtInst %void %1 DebugTypeBasic %8 %uint_32 %uint_4 %uint_0 232fd4e5da5Sopenharmony_ci%13 = OpExtInst %void %1 DebugTypeFunction %uint_3 %10 233fd4e5da5Sopenharmony_ci%15 = OpExtInst %void %1 DebugSource %3 234fd4e5da5Sopenharmony_ci%16 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %15 %uint_5 235fd4e5da5Sopenharmony_ci%21 = OpExtInst %void %1 DebugFunction %19 %13 %15 %uint_2 %uint_1 %16 %20 %uint_3 %uint_2 236fd4e5da5Sopenharmony_ci%23 = OpExtInst %void %1 DebugLexicalBlock %15 %uint_2 %uint_17 %21 237fd4e5da5Sopenharmony_ci%25 = OpExtInst %void %1 DebugTypeFunction %uint_3 %void 238fd4e5da5Sopenharmony_ci%27 = OpExtInst %void %1 DebugFunction %26 %25 %15 %uint_6 %uint_1 %16 %20 %uint_3 %uint_6 239fd4e5da5Sopenharmony_ci%29 = OpExtInst %void %1 DebugLexicalBlock %15 %uint_6 %uint_13 %27 240fd4e5da5Sopenharmony_ci%main = OpFunction %void None %31 241fd4e5da5Sopenharmony_ci%32 = OpLabel 242fd4e5da5Sopenharmony_ci%33 = OpFunctionCall %void %src_main 243fd4e5da5Sopenharmony_ciOpLine %3 8 1 244fd4e5da5Sopenharmony_ciOpReturn 245fd4e5da5Sopenharmony_ciOpFunctionEnd 246fd4e5da5Sopenharmony_ciOpLine %3 6 1 247fd4e5da5Sopenharmony_ci%src_main = OpFunction %void None %31 248fd4e5da5Sopenharmony_ciOpNoLine 249fd4e5da5Sopenharmony_ci%bb_entry = OpLabel 250fd4e5da5Sopenharmony_ci%47 = OpExtInst %void %1 DebugScope %27 251fd4e5da5Sopenharmony_ci%37 = OpExtInst %void %1 DebugFunctionDefinition %27 %src_main 252fd4e5da5Sopenharmony_ci%48 = OpExtInst %void %1 DebugScope %29 253fd4e5da5Sopenharmony_ciOpLine %3 7 3 254fd4e5da5Sopenharmony_ci%39 = OpFunctionCall %int %function1 255fd4e5da5Sopenharmony_ci%49 = OpExtInst %void %1 DebugScope %27 256fd4e5da5Sopenharmony_ciOpLine %3 8 1 257fd4e5da5Sopenharmony_ciOpReturn 258fd4e5da5Sopenharmony_ci%50 = OpExtInst %void %1 DebugNoScope 259fd4e5da5Sopenharmony_ciOpFunctionEnd 260fd4e5da5Sopenharmony_ciOpLine %3 2 1 261fd4e5da5Sopenharmony_ci%function1 = OpFunction %int None %42 262fd4e5da5Sopenharmony_ciOpNoLine 263fd4e5da5Sopenharmony_ci%bb_entry_0 = OpLabel 264fd4e5da5Sopenharmony_ci%51 = OpExtInst %void %1 DebugScope %21 265fd4e5da5Sopenharmony_ci%45 = OpExtInst %void %1 DebugFunctionDefinition %21 %function1 266fd4e5da5Sopenharmony_ci%52 = OpExtInst %void %1 DebugScope %23 267fd4e5da5Sopenharmony_ciOpLine %3 3 3 268fd4e5da5Sopenharmony_ciOpReturnValue %int_1 269fd4e5da5Sopenharmony_ci%53 = OpExtInst %void %1 DebugNoScope 270fd4e5da5Sopenharmony_ciOpFunctionEnd 271fd4e5da5Sopenharmony_ci )"; 272fd4e5da5Sopenharmony_ci 273fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 274fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 275fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 276fd4e5da5Sopenharmony_ci 277fd4e5da5Sopenharmony_ci const uint32_t line_number = 7U; 278fd4e5da5Sopenharmony_ci Instruction line(context.get(), spv::Op::OpLine); 279fd4e5da5Sopenharmony_ci line.SetInOperands({ 280fd4e5da5Sopenharmony_ci {spv_operand_type_t::SPV_OPERAND_TYPE_ID, {5U}}, 281fd4e5da5Sopenharmony_ci {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, {line_number}}, 282fd4e5da5Sopenharmony_ci {spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER, {0U}}, 283fd4e5da5Sopenharmony_ci }); 284fd4e5da5Sopenharmony_ci 285fd4e5da5Sopenharmony_ci DebugScope scope(29U, 0U); 286fd4e5da5Sopenharmony_ci 287fd4e5da5Sopenharmony_ci auto db_manager = context.get()->get_debug_info_mgr(); 288fd4e5da5Sopenharmony_ci auto du_manager = context.get()->get_def_use_mgr(); 289fd4e5da5Sopenharmony_ci auto c_manager = context.get()->get_constant_mgr(); 290fd4e5da5Sopenharmony_ci 291fd4e5da5Sopenharmony_ci (void)du_manager; 292fd4e5da5Sopenharmony_ci (void)c_manager; 293fd4e5da5Sopenharmony_ci 294fd4e5da5Sopenharmony_ci uint32_t inlined_at_id = db_manager->CreateDebugInlinedAt(&line, scope); 295fd4e5da5Sopenharmony_ci auto* inlined_at = db_manager->GetDebugInlinedAt(inlined_at_id); 296fd4e5da5Sopenharmony_ci EXPECT_NE(inlined_at, nullptr); 297fd4e5da5Sopenharmony_ci EXPECT_EQ(inlined_at->GetSingleWordOperand(kDebugInlinedAtOperandLineIndex), 298fd4e5da5Sopenharmony_ci 100); 299fd4e5da5Sopenharmony_ci} 300fd4e5da5Sopenharmony_ci 301fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, GetDebugInfoNone) { 302fd4e5da5Sopenharmony_ci const std::string text = R"( 303fd4e5da5Sopenharmony_ci OpCapability Shader 304fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 305fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 306fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %in_var_COLOR 307fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 308fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 309fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 310fd4e5da5Sopenharmony_civoid main(float in_var_color : COLOR) { 311fd4e5da5Sopenharmony_ci float color = in_var_color; 312fd4e5da5Sopenharmony_ci} 313fd4e5da5Sopenharmony_ci" 314fd4e5da5Sopenharmony_ci %17 = OpString "float" 315fd4e5da5Sopenharmony_ci %21 = OpString "main" 316fd4e5da5Sopenharmony_ci %24 = OpString "color" 317fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 318fd4e5da5Sopenharmony_ci OpName %main "main" 319fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 320fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 321fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 322fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 323fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 324fd4e5da5Sopenharmony_ci %void = OpTypeVoid 325fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 326fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 327fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 328fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 329fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 330fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 331fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 332fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 333fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %main 334fd4e5da5Sopenharmony_ci %12 = OpExtInst %void %1 DebugInfoNone 335fd4e5da5Sopenharmony_ci %25 = OpExtInst %void %1 DebugLocalVariable %24 %18 %15 1 20 %22 FlagIsLocal 0 336fd4e5da5Sopenharmony_ci %main = OpFunction %void None %27 337fd4e5da5Sopenharmony_ci %28 = OpLabel 338fd4e5da5Sopenharmony_ci %100 = OpVariable %_ptr_Function_float Function 339fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 340fd4e5da5Sopenharmony_ci OpStore %100 %31 341fd4e5da5Sopenharmony_ci %36 = OpExtInst %void %1 DebugDeclare %25 %100 %13 342fd4e5da5Sopenharmony_ci OpReturn 343fd4e5da5Sopenharmony_ci OpFunctionEnd 344fd4e5da5Sopenharmony_ci )"; 345fd4e5da5Sopenharmony_ci 346fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 347fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 348fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 349fd4e5da5Sopenharmony_ci DebugInfoManager manager(context.get()); 350fd4e5da5Sopenharmony_ci 351fd4e5da5Sopenharmony_ci Instruction* debug_info_none_inst = manager.GetDebugInfoNone(); 352fd4e5da5Sopenharmony_ci EXPECT_NE(debug_info_none_inst, nullptr); 353fd4e5da5Sopenharmony_ci EXPECT_EQ(debug_info_none_inst->GetOpenCL100DebugOpcode(), 354fd4e5da5Sopenharmony_ci OpenCLDebugInfo100DebugInfoNone); 355fd4e5da5Sopenharmony_ci EXPECT_EQ(debug_info_none_inst->PreviousNode(), nullptr); 356fd4e5da5Sopenharmony_ci} 357fd4e5da5Sopenharmony_ci 358fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, CreateDebugInfoNone) { 359fd4e5da5Sopenharmony_ci const std::string text = R"( 360fd4e5da5Sopenharmony_ci OpCapability Shader 361fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 362fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 363fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %in_var_COLOR 364fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 365fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 366fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 367fd4e5da5Sopenharmony_civoid main(float in_var_color : COLOR) { 368fd4e5da5Sopenharmony_ci float color = in_var_color; 369fd4e5da5Sopenharmony_ci} 370fd4e5da5Sopenharmony_ci" 371fd4e5da5Sopenharmony_ci %17 = OpString "float" 372fd4e5da5Sopenharmony_ci %21 = OpString "main" 373fd4e5da5Sopenharmony_ci %24 = OpString "color" 374fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 375fd4e5da5Sopenharmony_ci OpName %main "main" 376fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 377fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 378fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 379fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 380fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 381fd4e5da5Sopenharmony_ci %void = OpTypeVoid 382fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 383fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 384fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 385fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 386fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 387fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 388fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 389fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 390fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %main 391fd4e5da5Sopenharmony_ci %25 = OpExtInst %void %1 DebugLocalVariable %24 %18 %15 1 20 %22 FlagIsLocal 0 392fd4e5da5Sopenharmony_ci %main = OpFunction %void None %27 393fd4e5da5Sopenharmony_ci %28 = OpLabel 394fd4e5da5Sopenharmony_ci %100 = OpVariable %_ptr_Function_float Function 395fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 396fd4e5da5Sopenharmony_ci OpStore %100 %31 397fd4e5da5Sopenharmony_ci %36 = OpExtInst %void %1 DebugDeclare %25 %100 %13 398fd4e5da5Sopenharmony_ci OpReturn 399fd4e5da5Sopenharmony_ci OpFunctionEnd 400fd4e5da5Sopenharmony_ci )"; 401fd4e5da5Sopenharmony_ci 402fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 403fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 404fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 405fd4e5da5Sopenharmony_ci DebugInfoManager manager(context.get()); 406fd4e5da5Sopenharmony_ci 407fd4e5da5Sopenharmony_ci Instruction* debug_info_none_inst = manager.GetDebugInfoNone(); 408fd4e5da5Sopenharmony_ci EXPECT_NE(debug_info_none_inst, nullptr); 409fd4e5da5Sopenharmony_ci EXPECT_EQ(debug_info_none_inst->GetOpenCL100DebugOpcode(), 410fd4e5da5Sopenharmony_ci OpenCLDebugInfo100DebugInfoNone); 411fd4e5da5Sopenharmony_ci EXPECT_EQ(debug_info_none_inst->PreviousNode(), nullptr); 412fd4e5da5Sopenharmony_ci} 413fd4e5da5Sopenharmony_ci 414fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, GetDebugFunction) { 415fd4e5da5Sopenharmony_ci const std::string text = R"( 416fd4e5da5Sopenharmony_ci OpCapability Shader 417fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 418fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 419fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %200 "200" %in_var_COLOR 420fd4e5da5Sopenharmony_ci OpExecutionMode %200 OriginUpperLeft 421fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 422fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 423fd4e5da5Sopenharmony_civoid 200(float in_var_color : COLOR) { 424fd4e5da5Sopenharmony_ci float color = in_var_color; 425fd4e5da5Sopenharmony_ci} 426fd4e5da5Sopenharmony_ci" 427fd4e5da5Sopenharmony_ci %17 = OpString "float" 428fd4e5da5Sopenharmony_ci %21 = OpString "200" 429fd4e5da5Sopenharmony_ci %24 = OpString "color" 430fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 431fd4e5da5Sopenharmony_ci OpName %200 "200" 432fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 433fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 434fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 435fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 436fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 437fd4e5da5Sopenharmony_ci %void = OpTypeVoid 438fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 439fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 440fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 441fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 442fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 443fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 444fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 445fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 446fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %200 447fd4e5da5Sopenharmony_ci %25 = OpExtInst %void %1 DebugLocalVariable %24 %18 %15 1 20 %22 FlagIsLocal 0 448fd4e5da5Sopenharmony_ci %200 = OpFunction %void None %27 449fd4e5da5Sopenharmony_ci %28 = OpLabel 450fd4e5da5Sopenharmony_ci %100 = OpVariable %_ptr_Function_float Function 451fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 452fd4e5da5Sopenharmony_ci OpStore %100 %31 453fd4e5da5Sopenharmony_ci %36 = OpExtInst %void %1 DebugDeclare %25 %100 %13 454fd4e5da5Sopenharmony_ci OpReturn 455fd4e5da5Sopenharmony_ci OpFunctionEnd 456fd4e5da5Sopenharmony_ci )"; 457fd4e5da5Sopenharmony_ci 458fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 459fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 460fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 461fd4e5da5Sopenharmony_ci DebugInfoManager manager(context.get()); 462fd4e5da5Sopenharmony_ci 463fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.GetDebugFunction(100), nullptr); 464fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.GetDebugFunction(150), nullptr); 465fd4e5da5Sopenharmony_ci 466fd4e5da5Sopenharmony_ci Instruction* dbg_fn = manager.GetDebugFunction(200); 467fd4e5da5Sopenharmony_ci 468fd4e5da5Sopenharmony_ci EXPECT_EQ(dbg_fn->GetOpenCL100DebugOpcode(), OpenCLDebugInfo100DebugFunction); 469fd4e5da5Sopenharmony_ci EXPECT_EQ(dbg_fn->GetSingleWordOperand(kDebugFunctionOperandFunctionIndex), 470fd4e5da5Sopenharmony_ci 200); 471fd4e5da5Sopenharmony_ci} 472fd4e5da5Sopenharmony_ci 473fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, GetDebugFunction_InlinedAway) { 474fd4e5da5Sopenharmony_ci // struct PS_INPUT 475fd4e5da5Sopenharmony_ci // { 476fd4e5da5Sopenharmony_ci // float4 iColor : COLOR; 477fd4e5da5Sopenharmony_ci // }; 478fd4e5da5Sopenharmony_ci // 479fd4e5da5Sopenharmony_ci // struct PS_OUTPUT 480fd4e5da5Sopenharmony_ci // { 481fd4e5da5Sopenharmony_ci // float4 oColor : SV_Target0; 482fd4e5da5Sopenharmony_ci // }; 483fd4e5da5Sopenharmony_ci // 484fd4e5da5Sopenharmony_ci // float4 foo(float4 ic) 485fd4e5da5Sopenharmony_ci // { 486fd4e5da5Sopenharmony_ci // float4 c = ic / 2.0; 487fd4e5da5Sopenharmony_ci // return c; 488fd4e5da5Sopenharmony_ci // } 489fd4e5da5Sopenharmony_ci // 490fd4e5da5Sopenharmony_ci // PS_OUTPUT MainPs(PS_INPUT i) 491fd4e5da5Sopenharmony_ci // { 492fd4e5da5Sopenharmony_ci // PS_OUTPUT ps_output; 493fd4e5da5Sopenharmony_ci // float4 ic = i.iColor; 494fd4e5da5Sopenharmony_ci // ps_output.oColor = foo(ic); 495fd4e5da5Sopenharmony_ci // return ps_output; 496fd4e5da5Sopenharmony_ci // } 497fd4e5da5Sopenharmony_ci const std::string text = R"( 498fd4e5da5Sopenharmony_ci OpCapability Shader 499fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 500fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 501fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %MainPs "MainPs" %in_var_COLOR %out_var_SV_Target0 502fd4e5da5Sopenharmony_ci OpExecutionMode %MainPs OriginUpperLeft 503fd4e5da5Sopenharmony_ci %15 = OpString "foo2.frag" 504fd4e5da5Sopenharmony_ci %19 = OpString "PS_OUTPUT" 505fd4e5da5Sopenharmony_ci %23 = OpString "float" 506fd4e5da5Sopenharmony_ci %26 = OpString "oColor" 507fd4e5da5Sopenharmony_ci %28 = OpString "PS_INPUT" 508fd4e5da5Sopenharmony_ci %31 = OpString "iColor" 509fd4e5da5Sopenharmony_ci %33 = OpString "foo" 510fd4e5da5Sopenharmony_ci %37 = OpString "c" 511fd4e5da5Sopenharmony_ci %39 = OpString "ic" 512fd4e5da5Sopenharmony_ci %42 = OpString "src.MainPs" 513fd4e5da5Sopenharmony_ci %47 = OpString "ps_output" 514fd4e5da5Sopenharmony_ci %50 = OpString "i" 515fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 516fd4e5da5Sopenharmony_ci OpName %out_var_SV_Target0 "out.var.SV_Target0" 517fd4e5da5Sopenharmony_ci OpName %MainPs "MainPs" 518fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 519fd4e5da5Sopenharmony_ci OpDecorate %out_var_SV_Target0 Location 0 520fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 521fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 522fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 523fd4e5da5Sopenharmony_ci %v4float = OpTypeVector %float 4 524fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 525fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 526fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float 527fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 528fd4e5da5Sopenharmony_ci %void = OpTypeVoid 529fd4e5da5Sopenharmony_ci %uint_128 = OpConstant %uint 128 530fd4e5da5Sopenharmony_ci %uint_0 = OpConstant %uint 0 531fd4e5da5Sopenharmony_ci %52 = OpTypeFunction %void 532fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_v4float Input 533fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output 534fd4e5da5Sopenharmony_ci %float_0_5 = OpConstant %float 0.5 535fd4e5da5Sopenharmony_ci %130 = OpConstantComposite %v4float %float_0_5 %float_0_5 %float_0_5 %float_0_5 536fd4e5da5Sopenharmony_ci %115 = OpExtInst %void %1 DebugInfoNone 537fd4e5da5Sopenharmony_ci %49 = OpExtInst %void %1 DebugExpression 538fd4e5da5Sopenharmony_ci %17 = OpExtInst %void %1 DebugSource %15 539fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugCompilationUnit 1 4 %17 HLSL 540fd4e5da5Sopenharmony_ci %21 = OpExtInst %void %1 DebugTypeComposite %19 Structure %17 6 1 %18 %19 %uint_128 FlagIsProtected|FlagIsPrivate %22 541fd4e5da5Sopenharmony_ci %24 = OpExtInst %void %1 DebugTypeBasic %23 %uint_32 Float 542fd4e5da5Sopenharmony_ci %25 = OpExtInst %void %1 DebugTypeVector %24 4 543fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugTypeMember %26 %25 %17 8 5 %21 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate 544fd4e5da5Sopenharmony_ci %29 = OpExtInst %void %1 DebugTypeComposite %28 Structure %17 1 1 %18 %28 %uint_128 FlagIsProtected|FlagIsPrivate %30 545fd4e5da5Sopenharmony_ci %30 = OpExtInst %void %1 DebugTypeMember %31 %25 %17 3 5 %29 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate 546fd4e5da5Sopenharmony_ci %32 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %25 %25 547fd4e5da5Sopenharmony_ci %34 = OpExtInst %void %1 DebugFunction %33 %32 %17 11 1 %18 %33 FlagIsProtected|FlagIsPrivate 12 %115 548fd4e5da5Sopenharmony_ci %36 = OpExtInst %void %1 DebugLexicalBlock %17 12 1 %34 549fd4e5da5Sopenharmony_ci %38 = OpExtInst %void %1 DebugLocalVariable %37 %25 %17 13 12 %36 FlagIsLocal 550fd4e5da5Sopenharmony_ci %41 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %21 %29 551fd4e5da5Sopenharmony_ci %43 = OpExtInst %void %1 DebugFunction %42 %41 %17 17 1 %18 %42 FlagIsProtected|FlagIsPrivate 18 %115 552fd4e5da5Sopenharmony_ci %45 = OpExtInst %void %1 DebugLexicalBlock %17 18 1 %43 553fd4e5da5Sopenharmony_ci %46 = OpExtInst %void %1 DebugLocalVariable %39 %25 %17 20 12 %45 FlagIsLocal 554fd4e5da5Sopenharmony_ci %48 = OpExtInst %void %1 DebugLocalVariable %47 %21 %17 19 15 %45 FlagIsLocal 555fd4e5da5Sopenharmony_ci %107 = OpExtInst %void %1 DebugInlinedAt 21 %45 556fd4e5da5Sopenharmony_ci %MainPs = OpFunction %void None %52 557fd4e5da5Sopenharmony_ci %53 = OpLabel 558fd4e5da5Sopenharmony_ci %57 = OpLoad %v4float %in_var_COLOR 559fd4e5da5Sopenharmony_ci %131 = OpExtInst %void %1 DebugScope %45 560fd4e5da5Sopenharmony_ci OpLine %15 20 12 561fd4e5da5Sopenharmony_ci %117 = OpExtInst %void %1 DebugValue %46 %57 %49 562fd4e5da5Sopenharmony_ci %132 = OpExtInst %void %1 DebugScope %36 %107 563fd4e5da5Sopenharmony_ci OpLine %15 13 19 564fd4e5da5Sopenharmony_ci %112 = OpFMul %v4float %57 %130 565fd4e5da5Sopenharmony_ci OpLine %15 13 12 566fd4e5da5Sopenharmony_ci %116 = OpExtInst %void %1 DebugValue %38 %112 %49 567fd4e5da5Sopenharmony_ci %133 = OpExtInst %void %1 DebugScope %45 568fd4e5da5Sopenharmony_ci %128 = OpExtInst %void %1 DebugValue %48 %112 %49 %int_0 569fd4e5da5Sopenharmony_ci %134 = OpExtInst %void %1 DebugNoScope 570fd4e5da5Sopenharmony_ci OpStore %out_var_SV_Target0 %112 571fd4e5da5Sopenharmony_ci OpReturn 572fd4e5da5Sopenharmony_ci OpFunctionEnd 573fd4e5da5Sopenharmony_ci )"; 574fd4e5da5Sopenharmony_ci 575fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 576fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 577fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 578fd4e5da5Sopenharmony_ci DebugInfoManager manager(context.get()); 579fd4e5da5Sopenharmony_ci 580fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.GetDebugFunction(115), nullptr); 581fd4e5da5Sopenharmony_ci} 582fd4e5da5Sopenharmony_ci 583fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, CloneDebugInlinedAt) { 584fd4e5da5Sopenharmony_ci const std::string text = R"( 585fd4e5da5Sopenharmony_ci OpCapability Shader 586fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 587fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 588fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %in_var_COLOR 589fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 590fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 591fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 592fd4e5da5Sopenharmony_civoid main(float in_var_color : COLOR) { 593fd4e5da5Sopenharmony_ci float color = in_var_color; 594fd4e5da5Sopenharmony_ci} 595fd4e5da5Sopenharmony_ci" 596fd4e5da5Sopenharmony_ci %17 = OpString "float" 597fd4e5da5Sopenharmony_ci %21 = OpString "main" 598fd4e5da5Sopenharmony_ci %24 = OpString "color" 599fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 600fd4e5da5Sopenharmony_ci OpName %main "main" 601fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 602fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 603fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 604fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 605fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 606fd4e5da5Sopenharmony_ci %void = OpTypeVoid 607fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 608fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 609fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 610fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 611fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 612fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 613fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 614fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 615fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %main 616fd4e5da5Sopenharmony_ci %100 = OpExtInst %void %1 DebugInlinedAt 7 %22 617fd4e5da5Sopenharmony_ci %main = OpFunction %void None %27 618fd4e5da5Sopenharmony_ci %28 = OpLabel 619fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 620fd4e5da5Sopenharmony_ci OpStore %100 %31 621fd4e5da5Sopenharmony_ci OpReturn 622fd4e5da5Sopenharmony_ci OpFunctionEnd 623fd4e5da5Sopenharmony_ci )"; 624fd4e5da5Sopenharmony_ci 625fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 626fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 627fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 628fd4e5da5Sopenharmony_ci DebugInfoManager manager(context.get()); 629fd4e5da5Sopenharmony_ci 630fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.CloneDebugInlinedAt(150), nullptr); 631fd4e5da5Sopenharmony_ci EXPECT_EQ(manager.CloneDebugInlinedAt(22), nullptr); 632fd4e5da5Sopenharmony_ci 633fd4e5da5Sopenharmony_ci auto* inst = manager.CloneDebugInlinedAt(100); 634fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->GetSingleWordOperand(kDebugInlinedAtOperandLineIndex), 7); 635fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->GetSingleWordOperand(kDebugInlinedAtOperandScopeIndex), 22); 636fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->NumOperands(), kDebugInlinedAtOperandScopeIndex + 1); 637fd4e5da5Sopenharmony_ci 638fd4e5da5Sopenharmony_ci Instruction* before_100 = nullptr; 639fd4e5da5Sopenharmony_ci for (auto it = context->module()->ext_inst_debuginfo_begin(); 640fd4e5da5Sopenharmony_ci it != context->module()->ext_inst_debuginfo_end(); ++it) { 641fd4e5da5Sopenharmony_ci if (it->result_id() == 100) break; 642fd4e5da5Sopenharmony_ci before_100 = &*it; 643fd4e5da5Sopenharmony_ci } 644fd4e5da5Sopenharmony_ci EXPECT_NE(inst, before_100); 645fd4e5da5Sopenharmony_ci 646fd4e5da5Sopenharmony_ci inst = manager.CloneDebugInlinedAt(100, manager.GetDebugInlinedAt(100)); 647fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->GetSingleWordOperand(kDebugInlinedAtOperandLineIndex), 7); 648fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->GetSingleWordOperand(kDebugInlinedAtOperandScopeIndex), 22); 649fd4e5da5Sopenharmony_ci EXPECT_EQ(inst->NumOperands(), kDebugInlinedAtOperandScopeIndex + 1); 650fd4e5da5Sopenharmony_ci 651fd4e5da5Sopenharmony_ci before_100 = nullptr; 652fd4e5da5Sopenharmony_ci for (auto it = context->module()->ext_inst_debuginfo_begin(); 653fd4e5da5Sopenharmony_ci it != context->module()->ext_inst_debuginfo_end(); ++it) { 654fd4e5da5Sopenharmony_ci if (it->result_id() == 100) break; 655fd4e5da5Sopenharmony_ci before_100 = &*it; 656fd4e5da5Sopenharmony_ci } 657fd4e5da5Sopenharmony_ci EXPECT_EQ(inst, before_100); 658fd4e5da5Sopenharmony_ci} 659fd4e5da5Sopenharmony_ci 660fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, KillDebugDeclares) { 661fd4e5da5Sopenharmony_ci const std::string text = R"( 662fd4e5da5Sopenharmony_ci OpCapability Shader 663fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 664fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 665fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %in_var_COLOR 666fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 667fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 668fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 669fd4e5da5Sopenharmony_civoid main(float in_var_color : COLOR) { 670fd4e5da5Sopenharmony_ci float color = in_var_color; 671fd4e5da5Sopenharmony_ci} 672fd4e5da5Sopenharmony_ci" 673fd4e5da5Sopenharmony_ci %17 = OpString "float" 674fd4e5da5Sopenharmony_ci %21 = OpString "main" 675fd4e5da5Sopenharmony_ci %24 = OpString "color" 676fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 677fd4e5da5Sopenharmony_ci OpName %main "main" 678fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 679fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 680fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 681fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 682fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 683fd4e5da5Sopenharmony_ci %void = OpTypeVoid 684fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 685fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 686fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 687fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 688fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 689fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 690fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 691fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 692fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %main 693fd4e5da5Sopenharmony_ci %12 = OpExtInst %void %1 DebugInfoNone 694fd4e5da5Sopenharmony_ci %25 = OpExtInst %void %1 DebugLocalVariable %24 %18 %15 1 20 %22 FlagIsLocal 0 695fd4e5da5Sopenharmony_ci %main = OpFunction %void None %27 696fd4e5da5Sopenharmony_ci %28 = OpLabel 697fd4e5da5Sopenharmony_ci %100 = OpVariable %_ptr_Function_float Function 698fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 699fd4e5da5Sopenharmony_ci OpStore %100 %31 700fd4e5da5Sopenharmony_ci %36 = OpExtInst %void %1 DebugDeclare %25 %100 %13 701fd4e5da5Sopenharmony_ci %37 = OpExtInst %void %1 DebugDeclare %25 %100 %13 702fd4e5da5Sopenharmony_ci %38 = OpExtInst %void %1 DebugDeclare %25 %100 %13 703fd4e5da5Sopenharmony_ci OpReturn 704fd4e5da5Sopenharmony_ci OpFunctionEnd 705fd4e5da5Sopenharmony_ci )"; 706fd4e5da5Sopenharmony_ci 707fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 708fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 709fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 710fd4e5da5Sopenharmony_ci auto* dbg_info_mgr = context->get_debug_info_mgr(); 711fd4e5da5Sopenharmony_ci auto* def_use_mgr = context->get_def_use_mgr(); 712fd4e5da5Sopenharmony_ci 713fd4e5da5Sopenharmony_ci EXPECT_TRUE(dbg_info_mgr->IsVariableDebugDeclared(100)); 714fd4e5da5Sopenharmony_ci EXPECT_EQ(def_use_mgr->GetDef(36)->GetOpenCL100DebugOpcode(), 715fd4e5da5Sopenharmony_ci OpenCLDebugInfo100DebugDeclare); 716fd4e5da5Sopenharmony_ci EXPECT_EQ(def_use_mgr->GetDef(37)->GetOpenCL100DebugOpcode(), 717fd4e5da5Sopenharmony_ci OpenCLDebugInfo100DebugDeclare); 718fd4e5da5Sopenharmony_ci EXPECT_EQ(def_use_mgr->GetDef(38)->GetOpenCL100DebugOpcode(), 719fd4e5da5Sopenharmony_ci OpenCLDebugInfo100DebugDeclare); 720fd4e5da5Sopenharmony_ci 721fd4e5da5Sopenharmony_ci dbg_info_mgr->KillDebugDeclares(100); 722fd4e5da5Sopenharmony_ci EXPECT_EQ(def_use_mgr->GetDef(36), nullptr); 723fd4e5da5Sopenharmony_ci EXPECT_EQ(def_use_mgr->GetDef(37), nullptr); 724fd4e5da5Sopenharmony_ci EXPECT_EQ(def_use_mgr->GetDef(38), nullptr); 725fd4e5da5Sopenharmony_ci EXPECT_FALSE(dbg_info_mgr->IsVariableDebugDeclared(100)); 726fd4e5da5Sopenharmony_ci} 727fd4e5da5Sopenharmony_ci 728fd4e5da5Sopenharmony_ciTEST(DebugInfoManager, AddDebugValueForDecl) { 729fd4e5da5Sopenharmony_ci const std::string text = R"( 730fd4e5da5Sopenharmony_ci OpCapability Shader 731fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "OpenCL.DebugInfo.100" 732fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 733fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %in_var_COLOR 734fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 735fd4e5da5Sopenharmony_ci %5 = OpString "ps.hlsl" 736fd4e5da5Sopenharmony_ci %14 = OpString "#line 1 \"ps.hlsl\" 737fd4e5da5Sopenharmony_civoid main(float in_var_color : COLOR) { 738fd4e5da5Sopenharmony_ci float color = in_var_color; 739fd4e5da5Sopenharmony_ci} 740fd4e5da5Sopenharmony_ci" 741fd4e5da5Sopenharmony_ci %17 = OpString "float" 742fd4e5da5Sopenharmony_ci %21 = OpString "main" 743fd4e5da5Sopenharmony_ci %24 = OpString "color" 744fd4e5da5Sopenharmony_ci OpName %in_var_COLOR "in.var.COLOR" 745fd4e5da5Sopenharmony_ci OpName %main "main" 746fd4e5da5Sopenharmony_ci OpDecorate %in_var_COLOR Location 0 747fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 748fd4e5da5Sopenharmony_ci %uint_32 = OpConstant %uint 32 749fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 750fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 751fd4e5da5Sopenharmony_ci %void = OpTypeVoid 752fd4e5da5Sopenharmony_ci %27 = OpTypeFunction %void 753fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float 754fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input 755fd4e5da5Sopenharmony_ci %13 = OpExtInst %void %1 DebugExpression 756fd4e5da5Sopenharmony_ci %15 = OpExtInst %void %1 DebugSource %5 %14 757fd4e5da5Sopenharmony_ci %16 = OpExtInst %void %1 DebugCompilationUnit 1 4 %15 HLSL 758fd4e5da5Sopenharmony_ci %18 = OpExtInst %void %1 DebugTypeBasic %17 %uint_32 Float 759fd4e5da5Sopenharmony_ci %20 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %18 %18 760fd4e5da5Sopenharmony_ci %22 = OpExtInst %void %1 DebugFunction %21 %20 %15 1 1 %16 %21 FlagIsProtected|FlagIsPrivate 1 %main 761fd4e5da5Sopenharmony_ci %12 = OpExtInst %void %1 DebugInfoNone 762fd4e5da5Sopenharmony_ci %25 = OpExtInst %void %1 DebugLocalVariable %24 %18 %15 1 20 %22 FlagIsLocal 0 763fd4e5da5Sopenharmony_ci %main = OpFunction %void None %27 764fd4e5da5Sopenharmony_ci %28 = OpLabel 765fd4e5da5Sopenharmony_ci %100 = OpVariable %_ptr_Function_float Function 766fd4e5da5Sopenharmony_ci %31 = OpLoad %float %in_var_COLOR 767fd4e5da5Sopenharmony_ci %101 = OpExtInst %void %1 DebugScope %22 768fd4e5da5Sopenharmony_ci OpLine %5 13 7 769fd4e5da5Sopenharmony_ci OpStore %100 %31 770fd4e5da5Sopenharmony_ci OpNoLine 771fd4e5da5Sopenharmony_ci %102 = OpExtInst %void %1 DebugNoScope 772fd4e5da5Sopenharmony_ci %36 = OpExtInst %void %1 DebugDeclare %25 %100 %13 773fd4e5da5Sopenharmony_ci OpReturn 774fd4e5da5Sopenharmony_ci OpFunctionEnd 775fd4e5da5Sopenharmony_ci )"; 776fd4e5da5Sopenharmony_ci 777fd4e5da5Sopenharmony_ci std::unique_ptr<IRContext> context = 778fd4e5da5Sopenharmony_ci BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text, 779fd4e5da5Sopenharmony_ci SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 780fd4e5da5Sopenharmony_ci auto* def_use_mgr = context->get_def_use_mgr(); 781fd4e5da5Sopenharmony_ci auto* dbg_decl = def_use_mgr->GetDef(36); 782fd4e5da5Sopenharmony_ci EXPECT_EQ(dbg_decl->GetOpenCL100DebugOpcode(), 783fd4e5da5Sopenharmony_ci OpenCLDebugInfo100DebugDeclare); 784fd4e5da5Sopenharmony_ci 785fd4e5da5Sopenharmony_ci auto* dbg_info_mgr = context->get_debug_info_mgr(); 786fd4e5da5Sopenharmony_ci Instruction* store = dbg_decl->PreviousNode(); 787fd4e5da5Sopenharmony_ci auto* dbg_value = 788fd4e5da5Sopenharmony_ci dbg_info_mgr->AddDebugValueForDecl(dbg_decl, 100, dbg_decl, store); 789fd4e5da5Sopenharmony_ci 790fd4e5da5Sopenharmony_ci EXPECT_EQ(dbg_value->GetOpenCL100DebugOpcode(), OpenCLDebugInfo100DebugValue); 791fd4e5da5Sopenharmony_ci EXPECT_EQ(dbg_value->dbg_line_inst()->GetSingleWordInOperand( 792fd4e5da5Sopenharmony_ci kOpLineInOperandFileIndex), 793fd4e5da5Sopenharmony_ci 5); 794fd4e5da5Sopenharmony_ci EXPECT_EQ(dbg_value->dbg_line_inst()->GetSingleWordInOperand( 795fd4e5da5Sopenharmony_ci kOpLineInOperandLineIndex), 796fd4e5da5Sopenharmony_ci 13); 797fd4e5da5Sopenharmony_ci EXPECT_EQ(dbg_value->dbg_line_inst()->GetSingleWordInOperand( 798fd4e5da5Sopenharmony_ci kOpLineInOperandColumnIndex), 799fd4e5da5Sopenharmony_ci 7); 800fd4e5da5Sopenharmony_ci} 801fd4e5da5Sopenharmony_ci 802fd4e5da5Sopenharmony_ci} // namespace 803fd4e5da5Sopenharmony_ci} // namespace analysis 804fd4e5da5Sopenharmony_ci} // namespace opt 805fd4e5da5Sopenharmony_ci} // namespace spvtools 806