private_to_local_test.cpp 18 KB

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