debug_info_manager_test.cpp 35 KB

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