private_to_local_test.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. // Copyright (c) 2017 Google Inc.
  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 <string>
  15. #include "gmock/gmock.h"
  16. #include "source/opt/value_number_table.h"
  17. #include "test/opt/assembly_builder.h"
  18. #include "test/opt/pass_fixture.h"
  19. #include "test/opt/pass_utils.h"
  20. namespace spvtools {
  21. namespace opt {
  22. namespace {
  23. using ::testing::HasSubstr;
  24. using ::testing::MatchesRegex;
  25. using PrivateToLocalTest = PassTest<::testing::Test>;
  26. TEST_F(PrivateToLocalTest, ChangeToLocal) {
  27. // Change the private variable to a local, and change the types accordingly.
  28. const std::string text = R"(
  29. OpCapability Shader
  30. %1 = OpExtInstImport "GLSL.std.450"
  31. OpMemoryModel Logical GLSL450
  32. OpEntryPoint Fragment %2 "main"
  33. OpExecutionMode %2 OriginUpperLeft
  34. OpSource GLSL 430
  35. %3 = OpTypeVoid
  36. %4 = OpTypeFunction %3
  37. ; CHECK: [[float:%[a-zA-Z_\d]+]] = OpTypeFloat 32
  38. %5 = OpTypeFloat 32
  39. ; CHECK: [[newtype:%[a-zA-Z_\d]+]] = OpTypePointer Function [[float]]
  40. %6 = OpTypePointer Private %5
  41. ; CHECK-NOT: OpVariable [[.+]] Private
  42. %8 = OpVariable %6 Private
  43. ; CHECK: OpFunction
  44. %2 = OpFunction %3 None %4
  45. ; CHECK: OpLabel
  46. %7 = OpLabel
  47. ; CHECK-NEXT: [[newvar:%[a-zA-Z_\d]+]] = OpVariable [[newtype]] Function
  48. ; CHECK: OpLoad [[float]] [[newvar]]
  49. %9 = OpLoad %5 %8
  50. OpReturn
  51. OpFunctionEnd
  52. )";
  53. SinglePassRunAndMatch<PrivateToLocalPass>(text, false);
  54. }
  55. TEST_F(PrivateToLocalTest, ReuseExistingType) {
  56. // Change the private variable to a local, and change the types accordingly.
  57. const std::string text = R"(
  58. OpCapability Shader
  59. %1 = OpExtInstImport "GLSL.std.450"
  60. OpMemoryModel Logical GLSL450
  61. OpEntryPoint Fragment %2 "main"
  62. OpExecutionMode %2 OriginUpperLeft
  63. OpSource GLSL 430
  64. %3 = OpTypeVoid
  65. %4 = OpTypeFunction %3
  66. ; CHECK: [[float:%[a-zA-Z_\d]+]] = OpTypeFloat 32
  67. %5 = OpTypeFloat 32
  68. %func_ptr = OpTypePointer Function %5
  69. ; CHECK: [[newtype:%[a-zA-Z_\d]+]] = OpTypePointer Function [[float]]
  70. ; CHECK-NOT: [[%[a-zA-Z_\d]+]] = OpTypePointer Function [[float]]
  71. %6 = OpTypePointer Private %5
  72. ; CHECK-NOT: OpVariable [[.+]] Private
  73. %8 = OpVariable %6 Private
  74. ; CHECK: OpFunction
  75. %2 = OpFunction %3 None %4
  76. ; CHECK: OpLabel
  77. %7 = OpLabel
  78. ; CHECK-NEXT: [[newvar:%[a-zA-Z_\d]+]] = OpVariable [[newtype]] Function
  79. ; CHECK: OpLoad [[float]] [[newvar]]
  80. %9 = OpLoad %5 %8
  81. OpReturn
  82. OpFunctionEnd
  83. )";
  84. SinglePassRunAndMatch<PrivateToLocalPass>(text, false);
  85. }
  86. TEST_F(PrivateToLocalTest, UpdateAccessChain) {
  87. // Change the private variable to a local, and change the AccessChain.
  88. const std::string text = R"(
  89. OpCapability Shader
  90. %1 = OpExtInstImport "GLSL.std.450"
  91. OpMemoryModel Logical GLSL450
  92. OpEntryPoint Fragment %2 "main"
  93. OpExecutionMode %2 OriginUpperLeft
  94. OpSource GLSL 430
  95. %uint = OpTypeInt 32 0
  96. %uint_0 = OpConstant %uint 0
  97. %void = OpTypeVoid
  98. %6 = OpTypeFunction %void
  99. ; CHECK: [[float:%[a-zA-Z_\d]+]] = OpTypeFloat
  100. %float = OpTypeFloat 32
  101. ; CHECK: [[struct:%[a-zA-Z_\d]+]] = OpTypeStruct
  102. %_struct_8 = OpTypeStruct %float
  103. %_ptr_Private_float = OpTypePointer Private %float
  104. ; CHECK: [[new_struct_type:%[a-zA-Z_\d]+]] = OpTypePointer Function [[struct]]
  105. ; CHECK: [[new_float_type:%[a-zA-Z_\d]+]] = OpTypePointer Function [[float]]
  106. %_ptr_Private__struct_8 = OpTypePointer Private %_struct_8
  107. ; CHECK-NOT: OpVariable [[.+]] Private
  108. %11 = OpVariable %_ptr_Private__struct_8 Private
  109. ; CHECK: OpFunction
  110. %2 = OpFunction %void None %6
  111. ; CHECK: OpLabel
  112. %12 = OpLabel
  113. ; CHECK-NEXT: [[newvar:%[a-zA-Z_\d]+]] = OpVariable [[new_struct_type]] Function
  114. ; CHECK: [[member:%[a-zA-Z_\d]+]] = OpAccessChain [[new_float_type]] [[newvar]]
  115. %13 = OpAccessChain %_ptr_Private_float %11 %uint_0
  116. ; CHECK: OpLoad [[float]] [[member]]
  117. %14 = OpLoad %float %13
  118. OpReturn
  119. OpFunctionEnd
  120. )";
  121. SinglePassRunAndMatch<PrivateToLocalPass>(text, false);
  122. }
  123. TEST_F(PrivateToLocalTest, UseTexelPointer) {
  124. // Change the private variable to a local, and change the OpImageTexelPointer.
  125. const std::string text = R"(
  126. OpCapability SampledBuffer
  127. OpCapability StorageImageExtendedFormats
  128. OpCapability ImageBuffer
  129. OpCapability Shader
  130. %1 = OpExtInstImport "GLSL.std.450"
  131. OpMemoryModel Logical GLSL450
  132. OpEntryPoint GLCompute %2 "min" %gl_GlobalInvocationID
  133. OpExecutionMode %2 LocalSize 64 1 1
  134. OpSource HLSL 600
  135. OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
  136. OpDecorate %4 DescriptorSet 4
  137. OpDecorate %4 Binding 70
  138. %uint = OpTypeInt 32 0
  139. %6 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
  140. %_ptr_UniformConstant_6 = OpTypePointer UniformConstant %6
  141. %_ptr_Private_6 = OpTypePointer Private %6
  142. %void = OpTypeVoid
  143. %10 = OpTypeFunction %void
  144. %uint_0 = OpConstant %uint 0
  145. %uint_1 = OpConstant %uint 1
  146. %v3uint = OpTypeVector %uint 3
  147. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  148. %_ptr_Image_uint = OpTypePointer Image %uint
  149. %4 = OpVariable %_ptr_UniformConstant_6 UniformConstant
  150. %16 = OpVariable %_ptr_Private_6 Private
  151. %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
  152. %2 = OpFunction %void None %10
  153. %17 = OpLabel
  154. ; Make sure the variable was moved.
  155. ; CHECK: OpFunction
  156. ; CHECK-NEXT: OpLabel
  157. ; CHECK-NEXT: OpVariable %_ptr_Function_6 Function
  158. %18 = OpLoad %6 %4
  159. OpStore %16 %18
  160. %19 = OpImageTexelPointer %_ptr_Image_uint %16 %uint_0 %uint_0
  161. %20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1
  162. OpReturn
  163. OpFunctionEnd
  164. )";
  165. SinglePassRunAndMatch<PrivateToLocalPass>(text, false);
  166. }
  167. TEST_F(PrivateToLocalTest, UsedInTwoFunctions) {
  168. // Should not change because it is used in multiple functions.
  169. const std::string text = R"(
  170. OpCapability Shader
  171. %1 = OpExtInstImport "GLSL.std.450"
  172. OpMemoryModel Logical GLSL450
  173. OpEntryPoint Fragment %2 "main"
  174. OpExecutionMode %2 OriginUpperLeft
  175. OpSource GLSL 430
  176. %3 = OpTypeVoid
  177. %4 = OpTypeFunction %3
  178. %5 = OpTypeFloat 32
  179. %6 = OpTypePointer Private %5
  180. %8 = OpVariable %6 Private
  181. %2 = OpFunction %3 None %4
  182. %7 = OpLabel
  183. %9 = OpLoad %5 %8
  184. OpReturn
  185. OpFunctionEnd
  186. %10 = OpFunction %3 None %4
  187. %11 = OpLabel
  188. %12 = OpLoad %5 %8
  189. OpReturn
  190. OpFunctionEnd
  191. )";
  192. auto result = SinglePassRunAndDisassemble<StrengthReductionPass>(
  193. text, /* skip_nop = */ true, /* do_validation = */ false);
  194. EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
  195. }
  196. TEST_F(PrivateToLocalTest, UsedInFunctionCall) {
  197. // Should not change because it is used in a function call. Changing the
  198. // signature of the function would require cloning the function, which is not
  199. // worth it.
  200. const std::string text = R"(
  201. OpCapability Shader
  202. %1 = OpExtInstImport "GLSL.std.450"
  203. OpMemoryModel Logical GLSL450
  204. OpEntryPoint Fragment %2 "main"
  205. OpExecutionMode %2 OriginUpperLeft
  206. OpSource GLSL 430
  207. %void = OpTypeVoid
  208. %4 = OpTypeFunction %void
  209. %float = OpTypeFloat 32
  210. %_ptr_Private_float = OpTypePointer Private %float
  211. %7 = OpTypeFunction %void %_ptr_Private_float
  212. %8 = OpVariable %_ptr_Private_float Private
  213. %2 = OpFunction %void None %4
  214. %9 = OpLabel
  215. %10 = OpFunctionCall %void %11 %8
  216. OpReturn
  217. OpFunctionEnd
  218. %11 = OpFunction %void None %7
  219. %12 = OpFunctionParameter %_ptr_Private_float
  220. %13 = OpLabel
  221. %14 = OpLoad %float %12
  222. OpReturn
  223. OpFunctionEnd
  224. )";
  225. auto result = SinglePassRunAndDisassemble<StrengthReductionPass>(
  226. text, /* skip_nop = */ true, /* do_validation = */ false);
  227. EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
  228. }
  229. TEST_F(PrivateToLocalTest, CreatePointerToAmbiguousStruct1) {
  230. // Test that the correct pointer type is picked up.
  231. const std::string text = R"(
  232. ; CHECK: [[struct1:%[a-zA-Z_\d]+]] = OpTypeStruct
  233. ; CHECK: [[struct2:%[a-zA-Z_\d]+]] = OpTypeStruct
  234. ; CHECK: [[priv_ptr:%[\w]+]] = OpTypePointer Private [[struct1]]
  235. ; CHECK: [[fuct_ptr2:%[\w]+]] = OpTypePointer Function [[struct2]]
  236. ; CHECK: [[fuct_ptr1:%[\w]+]] = OpTypePointer Function [[struct1]]
  237. ; CHECK: OpFunction
  238. ; CHECK: OpLabel
  239. ; CHECK-NEXT: [[newvar:%[a-zA-Z_\d]+]] = OpVariable [[fuct_ptr1]] Function
  240. ; CHECK: OpLoad [[struct1]] [[newvar]]
  241. OpCapability Shader
  242. %1 = OpExtInstImport "GLSL.std.450"
  243. OpMemoryModel Logical GLSL450
  244. OpEntryPoint Fragment %2 "main"
  245. OpExecutionMode %2 OriginUpperLeft
  246. OpSource GLSL 430
  247. %3 = OpTypeVoid
  248. %4 = OpTypeFunction %3
  249. %5 = OpTypeFloat 32
  250. %struct1 = OpTypeStruct %5
  251. %struct2 = OpTypeStruct %5
  252. %6 = OpTypePointer Private %struct1
  253. %func_ptr2 = OpTypePointer Function %struct2
  254. %8 = OpVariable %6 Private
  255. %2 = OpFunction %3 None %4
  256. %7 = OpLabel
  257. %9 = OpLoad %struct1 %8
  258. OpReturn
  259. OpFunctionEnd
  260. )";
  261. SinglePassRunAndMatch<PrivateToLocalPass>(text, false);
  262. }
  263. TEST_F(PrivateToLocalTest, CreatePointerToAmbiguousStruct2) {
  264. // Test that the correct pointer type is picked up.
  265. const std::string text = R"(
  266. ; CHECK: [[struct1:%[a-zA-Z_\d]+]] = OpTypeStruct
  267. ; CHECK: [[struct2:%[a-zA-Z_\d]+]] = OpTypeStruct
  268. ; CHECK: [[priv_ptr:%[\w]+]] = OpTypePointer Private [[struct2]]
  269. ; CHECK: [[fuct_ptr1:%[\w]+]] = OpTypePointer Function [[struct1]]
  270. ; CHECK: [[fuct_ptr2:%[\w]+]] = OpTypePointer Function [[struct2]]
  271. ; CHECK: OpFunction
  272. ; CHECK: OpLabel
  273. ; CHECK-NEXT: [[newvar:%[a-zA-Z_\d]+]] = OpVariable [[fuct_ptr2]] Function
  274. ; CHECK: OpLoad [[struct2]] [[newvar]]
  275. OpCapability Shader
  276. %1 = OpExtInstImport "GLSL.std.450"
  277. OpMemoryModel Logical GLSL450
  278. OpEntryPoint Fragment %2 "main"
  279. OpExecutionMode %2 OriginUpperLeft
  280. OpSource GLSL 430
  281. %3 = OpTypeVoid
  282. %4 = OpTypeFunction %3
  283. %5 = OpTypeFloat 32
  284. %struct1 = OpTypeStruct %5
  285. %struct2 = OpTypeStruct %5
  286. %6 = OpTypePointer Private %struct2
  287. %func_ptr2 = OpTypePointer Function %struct1
  288. %8 = OpVariable %6 Private
  289. %2 = OpFunction %3 None %4
  290. %7 = OpLabel
  291. %9 = OpLoad %struct2 %8
  292. OpReturn
  293. OpFunctionEnd
  294. )";
  295. SinglePassRunAndMatch<PrivateToLocalPass>(text, false);
  296. }
  297. TEST_F(PrivateToLocalTest, SPV14RemoveFromInterface) {
  298. const std::string text = R"(
  299. ; CHECK-NOT: OpEntryPoint GLCompute %foo "foo" %in %priv
  300. ; CHECK: OpEntryPoint GLCompute %foo "foo" %in
  301. ; CHECK: %priv = OpVariable {{%\w+}} Function
  302. OpCapability Shader
  303. OpMemoryModel Logical GLSL450
  304. OpEntryPoint GLCompute %foo "foo" %in %priv
  305. OpExecutionMode %foo LocalSize 1 1 1
  306. OpName %foo "foo"
  307. OpName %in "in"
  308. OpName %priv "priv"
  309. %void = OpTypeVoid
  310. %int = OpTypeInt 32 0
  311. %ptr_ssbo_int = OpTypePointer StorageBuffer %int
  312. %ptr_private_int = OpTypePointer Private %int
  313. %in = OpVariable %ptr_ssbo_int StorageBuffer
  314. %priv = OpVariable %ptr_private_int Private
  315. %void_fn = OpTypeFunction %void
  316. %foo = OpFunction %void None %void_fn
  317. %entry = OpLabel
  318. %ld = OpLoad %int %in
  319. OpStore %priv %ld
  320. OpReturn
  321. OpFunctionEnd
  322. )";
  323. SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
  324. SinglePassRunAndMatch<PrivateToLocalPass>(text, true);
  325. }
  326. TEST_F(PrivateToLocalTest, SPV14RemoveFromInterfaceMultipleEntryPoints) {
  327. const std::string text = R"(
  328. ; CHECK-NOT: OpEntryPoint GLCompute %foo "foo" %in %priv
  329. ; CHECK-NOT: OpEntryPoint GLCompute %foo "bar" %in %priv
  330. ; CHECK: OpEntryPoint GLCompute %foo "foo" %in
  331. ; CHECK: OpEntryPoint GLCompute %foo "bar" %in
  332. ; CHECK: %priv = OpVariable {{%\w+}} Function
  333. OpCapability Shader
  334. OpMemoryModel Logical GLSL450
  335. OpEntryPoint GLCompute %foo "foo" %in %priv
  336. OpEntryPoint GLCompute %foo "bar" %in %priv
  337. OpExecutionMode %foo LocalSize 1 1 1
  338. OpName %foo "foo"
  339. OpName %in "in"
  340. OpName %priv "priv"
  341. %void = OpTypeVoid
  342. %int = OpTypeInt 32 0
  343. %ptr_ssbo_int = OpTypePointer StorageBuffer %int
  344. %ptr_private_int = OpTypePointer Private %int
  345. %in = OpVariable %ptr_ssbo_int StorageBuffer
  346. %priv = OpVariable %ptr_private_int Private
  347. %void_fn = OpTypeFunction %void
  348. %foo = OpFunction %void None %void_fn
  349. %entry = OpLabel
  350. %ld = OpLoad %int %in
  351. OpStore %priv %ld
  352. OpReturn
  353. OpFunctionEnd
  354. )";
  355. SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
  356. SinglePassRunAndMatch<PrivateToLocalPass>(text, true);
  357. }
  358. TEST_F(PrivateToLocalTest, SPV14RemoveFromInterfaceMultipleVariables) {
  359. const std::string text = R"(
  360. ; CHECK-NOT: OpEntryPoint GLCompute %foo "foo" %in %priv1 %priv2
  361. ; CHECK: OpEntryPoint GLCompute %foo "foo" %in
  362. ; CHECK: %priv1 = OpVariable {{%\w+}} Function
  363. ; CHECK: %priv2 = OpVariable {{%\w+}} Function
  364. OpCapability Shader
  365. OpMemoryModel Logical GLSL450
  366. OpEntryPoint GLCompute %foo "foo" %in %priv1 %priv2
  367. OpExecutionMode %foo LocalSize 1 1 1
  368. OpName %foo "foo"
  369. OpName %in "in"
  370. OpName %priv1 "priv1"
  371. OpName %priv2 "priv2"
  372. %void = OpTypeVoid
  373. %int = OpTypeInt 32 0
  374. %ptr_ssbo_int = OpTypePointer StorageBuffer %int
  375. %ptr_private_int = OpTypePointer Private %int
  376. %in = OpVariable %ptr_ssbo_int StorageBuffer
  377. %priv1 = OpVariable %ptr_private_int Private
  378. %priv2 = OpVariable %ptr_private_int Private
  379. %void_fn = OpTypeFunction %void
  380. %foo = OpFunction %void None %void_fn
  381. %entry = OpLabel
  382. %1 = OpFunctionCall %void %bar1
  383. %2 = OpFunctionCall %void %bar2
  384. OpReturn
  385. OpFunctionEnd
  386. %bar1 = OpFunction %void None %void_fn
  387. %3 = OpLabel
  388. %ld1 = OpLoad %int %in
  389. OpStore %priv1 %ld1
  390. OpReturn
  391. OpFunctionEnd
  392. %bar2 = OpFunction %void None %void_fn
  393. %4 = OpLabel
  394. %ld2 = OpLoad %int %in
  395. OpStore %priv2 %ld2
  396. OpReturn
  397. OpFunctionEnd
  398. )";
  399. SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
  400. SinglePassRunAndMatch<PrivateToLocalPass>(text, true);
  401. }
  402. TEST_F(PrivateToLocalTest, IdBoundOverflow1) {
  403. const std::string text = R"(
  404. OpCapability Shader
  405. OpMemoryModel Logical GLSL450
  406. OpEntryPoint Fragment %4 "main"
  407. OpExecutionMode %4 OriginLowerLeft
  408. OpSource HLSL 84
  409. %2 = OpTypeVoid
  410. %3 = OpTypeFunction %2
  411. %6 = OpTypeFloat 32
  412. %7 = OpTypeVector %6 4
  413. %8 = OpTypeStruct %7
  414. %4194302 = OpTypeStruct %8 %8
  415. %9 = OpTypeStruct %8 %8
  416. %11 = OpTypePointer Private %7
  417. %18 = OpTypeStruct %6 %9
  418. %12 = OpVariable %11 Private
  419. %4 = OpFunction %2 None %3
  420. %5 = OpLabel
  421. %13 = OpLoad %7 %12
  422. OpReturn
  423. OpFunctionEnd
  424. )";
  425. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  426. std::vector<Message> messages = {
  427. {SPV_MSG_ERROR, "", 0, 0, "ID overflow. Try running compact-ids."}};
  428. SetMessageConsumer(GetTestMessageConsumer(messages));
  429. auto result = SinglePassRunToBinary<PrivateToLocalPass>(text, true);
  430. EXPECT_EQ(Pass::Status::Failure, std::get<1>(result));
  431. }
  432. TEST_F(PrivateToLocalTest, DebugPrivateToLocal) {
  433. // Debug instructions must not have any impact on changing the private
  434. // variable to a local.
  435. const std::string text = R"(
  436. OpCapability Shader
  437. %1 = OpExtInstImport "GLSL.std.450"
  438. %10 = OpExtInstImport "OpenCL.DebugInfo.100"
  439. OpMemoryModel Logical GLSL450
  440. OpEntryPoint Fragment %2 "main"
  441. OpExecutionMode %2 OriginUpperLeft
  442. %11 = OpString "test"
  443. OpSource GLSL 430
  444. %13 = OpTypeInt 32 0
  445. %14 = OpConstant %13 32
  446. %3 = OpTypeVoid
  447. %4 = OpTypeFunction %3
  448. ; CHECK: [[float:%[a-zA-Z_\d]+]] = OpTypeFloat 32
  449. %5 = OpTypeFloat 32
  450. ; CHECK: [[newtype:%[a-zA-Z_\d]+]] = OpTypePointer Function [[float]]
  451. %6 = OpTypePointer Private %5
  452. ; CHECK-NOT: OpVariable [[.+]] Private
  453. %8 = OpVariable %6 Private
  454. %12 = OpExtInst %3 %10 DebugTypeBasic %11 %14 Float
  455. %15 = OpExtInst %3 %10 DebugSource %11
  456. %16 = OpExtInst %3 %10 DebugCompilationUnit 1 4 %15 GLSL
  457. ; CHECK-NOT: DebugGlobalVariable
  458. ; CHECK: [[dbg_newvar:%[a-zA-Z_\d]+]] = OpExtInst {{%\w+}} {{%\w+}} DebugLocalVariable
  459. %17 = OpExtInst %3 %10 DebugGlobalVariable %11 %12 %15 0 0 %16 %11 %8 FlagIsDefinition
  460. ; CHECK: OpFunction
  461. %2 = OpFunction %3 None %4
  462. ; CHECK: OpLabel
  463. %7 = OpLabel
  464. ; CHECK-NEXT: [[newvar:%[a-zA-Z_\d]+]] = OpVariable [[newtype]] Function
  465. ; CHECK-NEXT: DebugDeclare [[dbg_newvar]] [[newvar]]
  466. ; CHECK: OpLoad [[float]] [[newvar]]
  467. %9 = OpLoad %5 %8
  468. OpReturn
  469. OpFunctionEnd
  470. )";
  471. SinglePassRunAndMatch<PrivateToLocalPass>(text, true);
  472. }
  473. } // namespace
  474. } // namespace opt
  475. } // namespace spvtools