ir_context_test.cpp 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  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 "source/opt/ir_context.h"
  15. #include <algorithm>
  16. #include <memory>
  17. #include <utility>
  18. #include "OpenCLDebugInfo100.h"
  19. #include "gmock/gmock.h"
  20. #include "gtest/gtest.h"
  21. #include "source/opt/pass.h"
  22. #include "test/opt/pass_fixture.h"
  23. #include "test/opt/pass_utils.h"
  24. static const uint32_t kDebugDeclareOperandVariableIndex = 5;
  25. static const uint32_t kDebugValueOperandValueIndex = 5;
  26. namespace spvtools {
  27. namespace opt {
  28. namespace {
  29. using Analysis = IRContext::Analysis;
  30. using ::testing::Each;
  31. using ::testing::UnorderedElementsAre;
  32. class NoopPassPreservesNothing : public Pass {
  33. public:
  34. NoopPassPreservesNothing(Status s) : Pass(), status_to_return_(s) {}
  35. const char* name() const override { return "noop-pass"; }
  36. Status Process() override { return status_to_return_; }
  37. private:
  38. Status status_to_return_;
  39. };
  40. class NoopPassPreservesAll : public Pass {
  41. public:
  42. NoopPassPreservesAll(Status s) : Pass(), status_to_return_(s) {}
  43. const char* name() const override { return "noop-pass"; }
  44. Status Process() override { return status_to_return_; }
  45. Analysis GetPreservedAnalyses() override {
  46. return Analysis(IRContext::kAnalysisEnd - 1);
  47. }
  48. private:
  49. Status status_to_return_;
  50. };
  51. class NoopPassPreservesFirst : public Pass {
  52. public:
  53. NoopPassPreservesFirst(Status s) : Pass(), status_to_return_(s) {}
  54. const char* name() const override { return "noop-pass"; }
  55. Status Process() override { return status_to_return_; }
  56. Analysis GetPreservedAnalyses() override { return IRContext::kAnalysisBegin; }
  57. private:
  58. Status status_to_return_;
  59. };
  60. using IRContextTest = PassTest<::testing::Test>;
  61. TEST_F(IRContextTest, IndividualValidAfterBuild) {
  62. std::unique_ptr<Module> module(new Module());
  63. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, std::move(module),
  64. spvtools::MessageConsumer());
  65. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  66. i <<= 1) {
  67. localContext.BuildInvalidAnalyses(i);
  68. EXPECT_TRUE(localContext.AreAnalysesValid(i));
  69. }
  70. }
  71. TEST_F(IRContextTest, DontRebuildValidAnalysis) {
  72. std::unique_ptr<Module> module(new Module());
  73. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, std::move(module),
  74. spvtools::MessageConsumer());
  75. auto* oldCfg = localContext.cfg();
  76. auto* oldDefUse = localContext.get_def_use_mgr();
  77. localContext.BuildInvalidAnalyses(IRContext::kAnalysisCFG |
  78. IRContext::kAnalysisDefUse);
  79. auto* newCfg = localContext.cfg();
  80. auto* newDefUse = localContext.get_def_use_mgr();
  81. EXPECT_EQ(oldCfg, newCfg);
  82. EXPECT_EQ(oldDefUse, newDefUse);
  83. }
  84. TEST_F(IRContextTest, AllValidAfterBuild) {
  85. std::unique_ptr<Module> module = MakeUnique<Module>();
  86. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, std::move(module),
  87. spvtools::MessageConsumer());
  88. Analysis built_analyses = IRContext::kAnalysisNone;
  89. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  90. i <<= 1) {
  91. localContext.BuildInvalidAnalyses(i);
  92. built_analyses |= i;
  93. }
  94. EXPECT_TRUE(localContext.AreAnalysesValid(built_analyses));
  95. }
  96. TEST_F(IRContextTest, AllValidAfterPassNoChange) {
  97. std::unique_ptr<Module> module = MakeUnique<Module>();
  98. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, std::move(module),
  99. spvtools::MessageConsumer());
  100. Analysis built_analyses = IRContext::kAnalysisNone;
  101. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  102. i <<= 1) {
  103. localContext.BuildInvalidAnalyses(i);
  104. built_analyses |= i;
  105. }
  106. NoopPassPreservesNothing pass(Pass::Status::SuccessWithoutChange);
  107. Pass::Status s = pass.Run(&localContext);
  108. EXPECT_EQ(s, Pass::Status::SuccessWithoutChange);
  109. EXPECT_TRUE(localContext.AreAnalysesValid(built_analyses));
  110. }
  111. TEST_F(IRContextTest, NoneValidAfterPassWithChange) {
  112. std::unique_ptr<Module> module = MakeUnique<Module>();
  113. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, std::move(module),
  114. spvtools::MessageConsumer());
  115. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  116. i <<= 1) {
  117. localContext.BuildInvalidAnalyses(i);
  118. }
  119. NoopPassPreservesNothing pass(Pass::Status::SuccessWithChange);
  120. Pass::Status s = pass.Run(&localContext);
  121. EXPECT_EQ(s, Pass::Status::SuccessWithChange);
  122. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  123. i <<= 1) {
  124. EXPECT_FALSE(localContext.AreAnalysesValid(i));
  125. }
  126. }
  127. TEST_F(IRContextTest, AllPreservedAfterPassWithChange) {
  128. std::unique_ptr<Module> module = MakeUnique<Module>();
  129. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, std::move(module),
  130. spvtools::MessageConsumer());
  131. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  132. i <<= 1) {
  133. localContext.BuildInvalidAnalyses(i);
  134. }
  135. NoopPassPreservesAll pass(Pass::Status::SuccessWithChange);
  136. Pass::Status s = pass.Run(&localContext);
  137. EXPECT_EQ(s, Pass::Status::SuccessWithChange);
  138. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  139. i <<= 1) {
  140. EXPECT_TRUE(localContext.AreAnalysesValid(i));
  141. }
  142. }
  143. TEST_F(IRContextTest, PreserveFirstOnlyAfterPassWithChange) {
  144. std::unique_ptr<Module> module = MakeUnique<Module>();
  145. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, std::move(module),
  146. spvtools::MessageConsumer());
  147. for (Analysis i = IRContext::kAnalysisBegin; i < IRContext::kAnalysisEnd;
  148. i <<= 1) {
  149. localContext.BuildInvalidAnalyses(i);
  150. }
  151. NoopPassPreservesFirst pass(Pass::Status::SuccessWithChange);
  152. Pass::Status s = pass.Run(&localContext);
  153. EXPECT_EQ(s, Pass::Status::SuccessWithChange);
  154. EXPECT_TRUE(localContext.AreAnalysesValid(IRContext::kAnalysisBegin));
  155. for (Analysis i = IRContext::kAnalysisBegin << 1; i < IRContext::kAnalysisEnd;
  156. i <<= 1) {
  157. EXPECT_FALSE(localContext.AreAnalysesValid(i));
  158. }
  159. }
  160. TEST_F(IRContextTest, KillMemberName) {
  161. const std::string text = R"(
  162. OpCapability Shader
  163. %1 = OpExtInstImport "GLSL.std.450"
  164. OpMemoryModel Logical GLSL450
  165. OpEntryPoint Fragment %2 "main"
  166. OpExecutionMode %2 OriginUpperLeft
  167. OpSource GLSL 430
  168. OpName %3 "stuff"
  169. OpMemberName %3 0 "refZ"
  170. OpMemberDecorate %3 0 Offset 0
  171. OpDecorate %3 Block
  172. %4 = OpTypeFloat 32
  173. %3 = OpTypeStruct %4
  174. %5 = OpTypeVoid
  175. %6 = OpTypeFunction %5
  176. %2 = OpFunction %5 None %6
  177. %7 = OpLabel
  178. OpReturn
  179. OpFunctionEnd
  180. )";
  181. std::unique_ptr<IRContext> context =
  182. BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  183. // Build the decoration manager.
  184. context->get_decoration_mgr();
  185. // Delete the OpTypeStruct. Should delete the OpName, OpMemberName, and
  186. // OpMemberDecorate associated with it.
  187. context->KillDef(3);
  188. // Make sure all of the name are removed.
  189. for (auto& inst : context->debugs2()) {
  190. EXPECT_EQ(inst.opcode(), spv::Op::OpNop);
  191. }
  192. // Make sure all of the decorations are removed.
  193. for (auto& inst : context->annotations()) {
  194. EXPECT_EQ(inst.opcode(), spv::Op::OpNop);
  195. }
  196. }
  197. TEST_F(IRContextTest, KillGroupDecoration) {
  198. const std::string text = R"(
  199. OpCapability Shader
  200. %1 = OpExtInstImport "GLSL.std.450"
  201. OpMemoryModel Logical GLSL450
  202. OpEntryPoint Fragment %2 "main"
  203. OpExecutionMode %2 OriginUpperLeft
  204. OpSource GLSL 430
  205. OpDecorate %3 Restrict
  206. %3 = OpDecorationGroup
  207. OpGroupDecorate %3 %4 %5
  208. %6 = OpTypeFloat 32
  209. %7 = OpTypePointer Function %6
  210. %8 = OpTypeStruct %6
  211. %9 = OpTypeVoid
  212. %10 = OpTypeFunction %9
  213. %2 = OpFunction %9 None %10
  214. %11 = OpLabel
  215. %4 = OpVariable %7 Function
  216. %5 = OpVariable %7 Function
  217. OpReturn
  218. OpFunctionEnd
  219. )";
  220. std::unique_ptr<IRContext> context =
  221. BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  222. // Build the decoration manager.
  223. context->get_decoration_mgr();
  224. // Delete the second variable.
  225. context->KillDef(5);
  226. // The three decorations instructions should still be there. The first two
  227. // should be the same, but the third should have %5 removed.
  228. // Check the OpDecorate instruction
  229. auto inst = context->annotation_begin();
  230. EXPECT_EQ(inst->opcode(), spv::Op::OpDecorate);
  231. EXPECT_EQ(inst->GetSingleWordInOperand(0), 3);
  232. // Check the OpDecorationGroup Instruction
  233. ++inst;
  234. EXPECT_EQ(inst->opcode(), spv::Op::OpDecorationGroup);
  235. EXPECT_EQ(inst->result_id(), 3);
  236. // Check that %5 is no longer part of the group.
  237. ++inst;
  238. EXPECT_EQ(inst->opcode(), spv::Op::OpGroupDecorate);
  239. EXPECT_EQ(inst->NumInOperands(), 2);
  240. EXPECT_EQ(inst->GetSingleWordInOperand(0), 3);
  241. EXPECT_EQ(inst->GetSingleWordInOperand(1), 4);
  242. // Check that we are at the end.
  243. ++inst;
  244. EXPECT_EQ(inst, context->annotation_end());
  245. }
  246. TEST_F(IRContextTest, TakeNextUniqueIdIncrementing) {
  247. const uint32_t NUM_TESTS = 1000;
  248. IRContext localContext(SPV_ENV_UNIVERSAL_1_2, nullptr);
  249. for (uint32_t i = 1; i < NUM_TESTS; ++i)
  250. EXPECT_EQ(i, localContext.TakeNextUniqueId());
  251. }
  252. TEST_F(IRContextTest, KillGroupDecorationWitNoDecorations) {
  253. const std::string text = R"(
  254. OpCapability Shader
  255. %1 = OpExtInstImport "GLSL.std.450"
  256. OpMemoryModel Logical GLSL450
  257. OpEntryPoint Fragment %2 "main"
  258. OpExecutionMode %2 OriginUpperLeft
  259. OpSource GLSL 430
  260. %3 = OpDecorationGroup
  261. OpGroupDecorate %3 %4 %5
  262. %6 = OpTypeFloat 32
  263. %7 = OpTypePointer Function %6
  264. %8 = OpTypeStruct %6
  265. %9 = OpTypeVoid
  266. %10 = OpTypeFunction %9
  267. %2 = OpFunction %9 None %10
  268. %11 = OpLabel
  269. %4 = OpVariable %7 Function
  270. %5 = OpVariable %7 Function
  271. OpReturn
  272. OpFunctionEnd
  273. )";
  274. std::unique_ptr<IRContext> context =
  275. BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  276. // Build the decoration manager.
  277. context->get_decoration_mgr();
  278. // Delete the second variable.
  279. context->KillDef(5);
  280. // The two decoration instructions should still be there. The first one
  281. // should be the same, but the second should have %5 removed.
  282. // Check the OpDecorationGroup Instruction
  283. auto inst = context->annotation_begin();
  284. EXPECT_EQ(inst->opcode(), spv::Op::OpDecorationGroup);
  285. EXPECT_EQ(inst->result_id(), 3);
  286. // Check that %5 is no longer part of the group.
  287. ++inst;
  288. EXPECT_EQ(inst->opcode(), spv::Op::OpGroupDecorate);
  289. EXPECT_EQ(inst->NumInOperands(), 2);
  290. EXPECT_EQ(inst->GetSingleWordInOperand(0), 3);
  291. EXPECT_EQ(inst->GetSingleWordInOperand(1), 4);
  292. // Check that we are at the end.
  293. ++inst;
  294. EXPECT_EQ(inst, context->annotation_end());
  295. }
  296. TEST_F(IRContextTest, KillDecorationGroup) {
  297. const std::string text = R"(
  298. OpCapability Shader
  299. %1 = OpExtInstImport "GLSL.std.450"
  300. OpMemoryModel Logical GLSL450
  301. OpEntryPoint Fragment %2 "main"
  302. OpExecutionMode %2 OriginUpperLeft
  303. OpSource GLSL 430
  304. %3 = OpDecorationGroup
  305. OpGroupDecorate %3 %4 %5
  306. %6 = OpTypeFloat 32
  307. %7 = OpTypePointer Function %6
  308. %8 = OpTypeStruct %6
  309. %9 = OpTypeVoid
  310. %10 = OpTypeFunction %9
  311. %2 = OpFunction %9 None %10
  312. %11 = OpLabel
  313. %4 = OpVariable %7 Function
  314. %5 = OpVariable %7 Function
  315. OpReturn
  316. OpFunctionEnd
  317. )";
  318. std::unique_ptr<IRContext> context =
  319. BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  320. // Build the decoration manager.
  321. context->get_decoration_mgr();
  322. // Delete the second variable.
  323. context->KillDef(3);
  324. // Check the OpDecorationGroup Instruction is still there.
  325. EXPECT_TRUE(context->annotations().empty());
  326. }
  327. TEST_F(IRContextTest, KillFunctionFromDebugFunction) {
  328. const std::string text = R"(
  329. OpCapability Shader
  330. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  331. OpMemoryModel Logical GLSL450
  332. OpEntryPoint Fragment %2 "main"
  333. OpExecutionMode %2 OriginUpperLeft
  334. %3 = OpString "ps.hlsl"
  335. %4 = OpString "foo"
  336. OpSource HLSL 600
  337. %void = OpTypeVoid
  338. %6 = OpTypeFunction %void
  339. %7 = OpExtInst %void %1 DebugSource %3
  340. %8 = OpExtInst %void %1 DebugCompilationUnit 1 4 %7 HLSL
  341. %9 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
  342. %10 = OpExtInst %void %1 DebugFunction %4 %9 %7 1 1 %8 %4 FlagIsProtected|FlagIsPrivate 1 %11
  343. %2 = OpFunction %void None %6
  344. %12 = OpLabel
  345. OpReturn
  346. OpFunctionEnd
  347. %11 = OpFunction %void None %6
  348. %13 = OpLabel
  349. OpReturn
  350. OpFunctionEnd
  351. )";
  352. std::unique_ptr<IRContext> context =
  353. BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  354. // Delete the second variable.
  355. context->KillDef(11);
  356. // Get DebugInfoNone id.
  357. uint32_t debug_info_none_id = 0;
  358. for (auto it = context->ext_inst_debuginfo_begin();
  359. it != context->ext_inst_debuginfo_end(); ++it) {
  360. if (it->GetOpenCL100DebugOpcode() == OpenCLDebugInfo100DebugInfoNone) {
  361. debug_info_none_id = it->result_id();
  362. }
  363. }
  364. EXPECT_NE(0, debug_info_none_id);
  365. // Check the Function operand of DebugFunction is DebugInfoNone.
  366. const uint32_t kDebugFunctionOperandFunctionIndex = 13;
  367. bool checked = false;
  368. for (auto it = context->ext_inst_debuginfo_begin();
  369. it != context->ext_inst_debuginfo_end(); ++it) {
  370. if (it->GetOpenCL100DebugOpcode() == OpenCLDebugInfo100DebugFunction) {
  371. EXPECT_FALSE(checked);
  372. EXPECT_EQ(it->GetOperand(kDebugFunctionOperandFunctionIndex).words[0],
  373. debug_info_none_id);
  374. checked = true;
  375. }
  376. }
  377. EXPECT_TRUE(checked);
  378. }
  379. TEST_F(IRContextTest, KillVariableFromDebugGlobalVariable) {
  380. const std::string text = R"(
  381. OpCapability Shader
  382. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  383. OpMemoryModel Logical GLSL450
  384. OpEntryPoint Fragment %2 "main"
  385. OpExecutionMode %2 OriginUpperLeft
  386. %3 = OpString "ps.hlsl"
  387. %4 = OpString "foo"
  388. %5 = OpString "int"
  389. OpSource HLSL 600
  390. %uint = OpTypeInt 32 0
  391. %uint_32 = OpConstant %uint 32
  392. %_ptr_Private_uint = OpTypePointer Private %uint
  393. %void = OpTypeVoid
  394. %10 = OpTypeFunction %void
  395. %11 = OpVariable %_ptr_Private_uint Private
  396. %12 = OpExtInst %void %1 DebugSource %3
  397. %13 = OpExtInst %void %1 DebugCompilationUnit 1 4 %12 HLSL
  398. %14 = OpExtInst %void %1 DebugTypeBasic %5 %uint_32 Signed
  399. %15 = OpExtInst %void %1 DebugGlobalVariable %4 %14 %12 1 12 %13 %4 %11 FlagIsDefinition
  400. %2 = OpFunction %void None %10
  401. %16 = OpLabel
  402. OpReturn
  403. OpFunctionEnd
  404. )";
  405. std::unique_ptr<IRContext> context =
  406. BuildModule(SPV_ENV_UNIVERSAL_1_2, nullptr, text);
  407. // Delete the second variable.
  408. context->KillDef(11);
  409. // Get DebugInfoNone id.
  410. uint32_t debug_info_none_id = 0;
  411. for (auto it = context->ext_inst_debuginfo_begin();
  412. it != context->ext_inst_debuginfo_end(); ++it) {
  413. if (it->GetOpenCL100DebugOpcode() == OpenCLDebugInfo100DebugInfoNone) {
  414. debug_info_none_id = it->result_id();
  415. }
  416. }
  417. EXPECT_NE(0, debug_info_none_id);
  418. // Check the Function operand of DebugFunction is DebugInfoNone.
  419. const uint32_t kDebugGlobalVariableOperandVariableIndex = 11;
  420. bool checked = false;
  421. for (auto it = context->ext_inst_debuginfo_begin();
  422. it != context->ext_inst_debuginfo_end(); ++it) {
  423. if (it->GetOpenCL100DebugOpcode() ==
  424. OpenCLDebugInfo100DebugGlobalVariable) {
  425. EXPECT_FALSE(checked);
  426. EXPECT_EQ(
  427. it->GetOperand(kDebugGlobalVariableOperandVariableIndex).words[0],
  428. debug_info_none_id);
  429. checked = true;
  430. }
  431. }
  432. EXPECT_TRUE(checked);
  433. }
  434. TEST_F(IRContextTest, BasicVisitFromEntryPoint) {
  435. // Make sure we visit the entry point, and the function it calls.
  436. // Do not visit Dead or Exported.
  437. const std::string text = R"(
  438. OpCapability Shader
  439. OpMemoryModel Logical GLSL450
  440. OpEntryPoint Fragment %10 "main"
  441. OpName %10 "main"
  442. OpName %Dead "Dead"
  443. OpName %11 "Constant"
  444. OpName %ExportedFunc "ExportedFunc"
  445. OpDecorate %ExportedFunc LinkageAttributes "ExportedFunc" Export
  446. %void = OpTypeVoid
  447. %6 = OpTypeFunction %void
  448. %10 = OpFunction %void None %6
  449. %14 = OpLabel
  450. %15 = OpFunctionCall %void %11
  451. %16 = OpFunctionCall %void %11
  452. OpReturn
  453. OpFunctionEnd
  454. %11 = OpFunction %void None %6
  455. %18 = OpLabel
  456. OpReturn
  457. OpFunctionEnd
  458. %Dead = OpFunction %void None %6
  459. %19 = OpLabel
  460. OpReturn
  461. OpFunctionEnd
  462. %ExportedFunc = OpFunction %void None %7
  463. %20 = OpLabel
  464. %21 = OpFunctionCall %void %11
  465. OpReturn
  466. OpFunctionEnd
  467. )";
  468. // clang-format on
  469. std::unique_ptr<IRContext> localContext =
  470. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  471. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  472. EXPECT_NE(nullptr, localContext) << "Assembling failed for shader:\n"
  473. << text << std::endl;
  474. std::vector<uint32_t> processed;
  475. Pass::ProcessFunction mark_visited = [&processed](Function* fp) {
  476. processed.push_back(fp->result_id());
  477. return false;
  478. };
  479. localContext->ProcessEntryPointCallTree(mark_visited);
  480. EXPECT_THAT(processed, UnorderedElementsAre(10, 11));
  481. }
  482. TEST_F(IRContextTest, BasicVisitReachable) {
  483. // Make sure we visit the entry point, exported function, and the function
  484. // they call. Do not visit Dead.
  485. const std::string text = R"(
  486. OpCapability Shader
  487. OpMemoryModel Logical GLSL450
  488. OpEntryPoint Fragment %10 "main"
  489. OpName %10 "main"
  490. OpName %Dead "Dead"
  491. OpName %11 "Constant"
  492. OpName %12 "ExportedFunc"
  493. OpName %13 "Constant2"
  494. OpDecorate %12 LinkageAttributes "ExportedFunc" Export
  495. %void = OpTypeVoid
  496. %6 = OpTypeFunction %void
  497. %10 = OpFunction %void None %6
  498. %14 = OpLabel
  499. %15 = OpFunctionCall %void %11
  500. %16 = OpFunctionCall %void %11
  501. OpReturn
  502. OpFunctionEnd
  503. %11 = OpFunction %void None %6
  504. %18 = OpLabel
  505. OpReturn
  506. OpFunctionEnd
  507. %Dead = OpFunction %void None %6
  508. %19 = OpLabel
  509. OpReturn
  510. OpFunctionEnd
  511. %12 = OpFunction %void None %6
  512. %20 = OpLabel
  513. %21 = OpFunctionCall %void %13
  514. OpReturn
  515. OpFunctionEnd
  516. %13 = OpFunction %void None %6
  517. %22 = OpLabel
  518. OpReturn
  519. OpFunctionEnd
  520. )";
  521. // clang-format on
  522. std::unique_ptr<IRContext> localContext =
  523. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  524. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  525. EXPECT_NE(nullptr, localContext) << "Assembling failed for shader:\n"
  526. << text << std::endl;
  527. std::vector<uint32_t> processed;
  528. Pass::ProcessFunction mark_visited = [&processed](Function* fp) {
  529. processed.push_back(fp->result_id());
  530. return false;
  531. };
  532. localContext->ProcessReachableCallTree(mark_visited);
  533. EXPECT_THAT(processed, UnorderedElementsAre(10, 11, 12, 13));
  534. }
  535. TEST_F(IRContextTest, BasicVisitOnlyOnce) {
  536. // Make sure we visit %12 only once, even if it is called from two different
  537. // functions.
  538. const std::string text = R"(
  539. OpCapability Shader
  540. OpMemoryModel Logical GLSL450
  541. OpEntryPoint Fragment %10 "main"
  542. OpName %10 "main"
  543. OpName %Dead "Dead"
  544. OpName %11 "Constant"
  545. OpName %12 "ExportedFunc"
  546. OpDecorate %12 LinkageAttributes "ExportedFunc" Export
  547. %void = OpTypeVoid
  548. %6 = OpTypeFunction %void
  549. %10 = OpFunction %void None %6
  550. %14 = OpLabel
  551. %15 = OpFunctionCall %void %11
  552. %16 = OpFunctionCall %void %12
  553. OpReturn
  554. OpFunctionEnd
  555. %11 = OpFunction %void None %6
  556. %18 = OpLabel
  557. %19 = OpFunctionCall %void %12
  558. OpReturn
  559. OpFunctionEnd
  560. %Dead = OpFunction %void None %6
  561. %20 = OpLabel
  562. OpReturn
  563. OpFunctionEnd
  564. %12 = OpFunction %void None %6
  565. %21 = OpLabel
  566. OpReturn
  567. OpFunctionEnd
  568. )";
  569. // clang-format on
  570. std::unique_ptr<IRContext> localContext =
  571. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  572. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  573. EXPECT_NE(nullptr, localContext) << "Assembling failed for shader:\n"
  574. << text << std::endl;
  575. std::vector<uint32_t> processed;
  576. Pass::ProcessFunction mark_visited = [&processed](Function* fp) {
  577. processed.push_back(fp->result_id());
  578. return false;
  579. };
  580. localContext->ProcessReachableCallTree(mark_visited);
  581. EXPECT_THAT(processed, UnorderedElementsAre(10, 11, 12));
  582. }
  583. TEST_F(IRContextTest, BasicDontVisitExportedVariable) {
  584. // Make sure we only visit functions and not exported variables.
  585. const std::string text = R"(
  586. OpCapability Shader
  587. OpMemoryModel Logical GLSL450
  588. OpEntryPoint Fragment %10 "main"
  589. OpExecutionMode %10 OriginUpperLeft
  590. OpSource GLSL 150
  591. OpName %10 "main"
  592. OpName %12 "export_var"
  593. OpDecorate %12 LinkageAttributes "export_var" Export
  594. %void = OpTypeVoid
  595. %6 = OpTypeFunction %void
  596. %float = OpTypeFloat 32
  597. %float_1 = OpConstant %float 1
  598. %12 = OpVariable %float Output
  599. %10 = OpFunction %void None %6
  600. %14 = OpLabel
  601. OpStore %12 %float_1
  602. OpReturn
  603. OpFunctionEnd
  604. )";
  605. // clang-format on
  606. std::unique_ptr<IRContext> localContext =
  607. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  608. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  609. EXPECT_NE(nullptr, localContext) << "Assembling failed for shader:\n"
  610. << text << std::endl;
  611. std::vector<uint32_t> processed;
  612. Pass::ProcessFunction mark_visited = [&processed](Function* fp) {
  613. processed.push_back(fp->result_id());
  614. return false;
  615. };
  616. localContext->ProcessReachableCallTree(mark_visited);
  617. EXPECT_THAT(processed, UnorderedElementsAre(10));
  618. }
  619. TEST_F(IRContextTest, IdBoundTestAtLimit) {
  620. const std::string text = R"(
  621. OpCapability Shader
  622. OpCapability Linkage
  623. OpMemoryModel Logical GLSL450
  624. %1 = OpTypeVoid
  625. %2 = OpTypeFunction %1
  626. %3 = OpFunction %1 None %2
  627. %4 = OpLabel
  628. OpReturn
  629. OpFunctionEnd)";
  630. std::unique_ptr<IRContext> context =
  631. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  632. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  633. uint32_t current_bound = context->module()->id_bound();
  634. context->set_max_id_bound(current_bound);
  635. uint32_t next_id_bound = context->TakeNextId();
  636. EXPECT_EQ(next_id_bound, 0);
  637. EXPECT_EQ(current_bound, context->module()->id_bound());
  638. next_id_bound = context->TakeNextId();
  639. EXPECT_EQ(next_id_bound, 0);
  640. }
  641. TEST_F(IRContextTest, IdBoundTestBelowLimit) {
  642. const std::string text = R"(
  643. OpCapability Shader
  644. OpCapability Linkage
  645. OpMemoryModel Logical GLSL450
  646. %1 = OpTypeVoid
  647. %2 = OpTypeFunction %1
  648. %3 = OpFunction %1 None %2
  649. %4 = OpLabel
  650. OpReturn
  651. OpFunctionEnd)";
  652. std::unique_ptr<IRContext> context =
  653. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  654. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  655. uint32_t current_bound = context->module()->id_bound();
  656. context->set_max_id_bound(current_bound + 100);
  657. uint32_t next_id_bound = context->TakeNextId();
  658. EXPECT_EQ(next_id_bound, current_bound);
  659. EXPECT_EQ(current_bound + 1, context->module()->id_bound());
  660. next_id_bound = context->TakeNextId();
  661. EXPECT_EQ(next_id_bound, current_bound + 1);
  662. }
  663. TEST_F(IRContextTest, IdBoundTestNearLimit) {
  664. const std::string text = R"(
  665. OpCapability Shader
  666. OpCapability Linkage
  667. OpMemoryModel Logical GLSL450
  668. %1 = OpTypeVoid
  669. %2 = OpTypeFunction %1
  670. %3 = OpFunction %1 None %2
  671. %4 = OpLabel
  672. OpReturn
  673. OpFunctionEnd)";
  674. std::unique_ptr<IRContext> context =
  675. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  676. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  677. uint32_t current_bound = context->module()->id_bound();
  678. context->set_max_id_bound(current_bound + 1);
  679. uint32_t next_id_bound = context->TakeNextId();
  680. EXPECT_EQ(next_id_bound, current_bound);
  681. EXPECT_EQ(current_bound + 1, context->module()->id_bound());
  682. next_id_bound = context->TakeNextId();
  683. EXPECT_EQ(next_id_bound, 0);
  684. }
  685. TEST_F(IRContextTest, IdBoundTestUIntMax) {
  686. const std::string text = R"(
  687. OpCapability Shader
  688. OpCapability Linkage
  689. OpMemoryModel Logical GLSL450
  690. %1 = OpTypeVoid
  691. %2 = OpTypeFunction %1
  692. %3 = OpFunction %1 None %2
  693. %4294967294 = OpLabel ; ID is UINT_MAX-1
  694. OpReturn
  695. OpFunctionEnd)";
  696. std::unique_ptr<IRContext> context =
  697. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  698. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  699. uint32_t current_bound = context->module()->id_bound();
  700. // Expecting |BuildModule| to preserve the numeric ids.
  701. EXPECT_EQ(current_bound, std::numeric_limits<uint32_t>::max());
  702. context->set_max_id_bound(current_bound);
  703. uint32_t next_id_bound = context->TakeNextId();
  704. EXPECT_EQ(next_id_bound, 0);
  705. EXPECT_EQ(current_bound, context->module()->id_bound());
  706. }
  707. TEST_F(IRContextTest, CfgAndDomAnalysis) {
  708. const std::string text = R"(
  709. OpCapability Shader
  710. OpCapability Linkage
  711. OpMemoryModel Logical GLSL450
  712. %1 = OpTypeVoid
  713. %2 = OpTypeFunction %1
  714. %3 = OpFunction %1 None %2
  715. %4 = OpLabel
  716. OpReturn
  717. OpFunctionEnd)";
  718. std::unique_ptr<IRContext> ctx =
  719. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  720. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  721. // Building the dominator analysis should build the CFG.
  722. ASSERT_TRUE(ctx->module()->begin() != ctx->module()->end());
  723. ctx->GetDominatorAnalysis(&*ctx->module()->begin());
  724. EXPECT_TRUE(ctx->AreAnalysesValid(IRContext::kAnalysisCFG));
  725. EXPECT_TRUE(ctx->AreAnalysesValid(IRContext::kAnalysisDominatorAnalysis));
  726. // Invalidating the CFG analysis should invalidate the dominator analysis.
  727. ctx->InvalidateAnalyses(IRContext::kAnalysisCFG);
  728. EXPECT_FALSE(ctx->AreAnalysesValid(IRContext::kAnalysisCFG));
  729. EXPECT_FALSE(ctx->AreAnalysesValid(IRContext::kAnalysisDominatorAnalysis));
  730. }
  731. TEST_F(IRContextTest, AsanErrorTest) {
  732. std::string shader = R"(
  733. OpCapability Shader
  734. %1 = OpExtInstImport "GLSL.std.450"
  735. OpMemoryModel Logical GLSL450
  736. OpEntryPoint Fragment %4 "main"
  737. OpExecutionMode %4 OriginUpperLeft
  738. OpSource ESSL 310
  739. OpName %4 "main"
  740. OpName %8 "x"
  741. OpName %10 "y"
  742. OpDecorate %8 RelaxedPrecision
  743. OpDecorate %10 RelaxedPrecision
  744. OpDecorate %11 RelaxedPrecision
  745. %2 = OpTypeVoid
  746. %3 = OpTypeFunction %2
  747. %6 = OpTypeInt 32 1
  748. %7 = OpTypePointer Function %6
  749. %9 = OpConstant %6 1
  750. %4 = OpFunction %2 None %3
  751. %5 = OpLabel
  752. %8 = OpVariable %7 Function
  753. %10 = OpVariable %7 Function
  754. OpStore %8 %9
  755. %11 = OpLoad %6 %8
  756. OpBranch %20
  757. %20 = OpLabel
  758. %21 = OpPhi %6 %11 %5
  759. OpStore %10 %21
  760. OpReturn
  761. OpFunctionEnd
  762. )";
  763. const auto env = SPV_ENV_UNIVERSAL_1_3;
  764. const auto consumer = nullptr;
  765. const auto context = BuildModule(
  766. env, consumer, shader, SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  767. opt::Function* fun =
  768. context->cfg()->block(5)->GetParent(); // Computes the CFG analysis
  769. opt::DominatorAnalysis* dom = nullptr;
  770. // NOLINTNEXTLINE
  771. dom = context->GetDominatorAnalysis(fun); // Computes the dominator analysis,
  772. // which depends on the CFG
  773. // analysis
  774. context->InvalidateAnalysesExceptFor(
  775. opt::IRContext::Analysis::kAnalysisDominatorAnalysis); // Invalidates the
  776. // CFG analysis
  777. dom = context->GetDominatorAnalysis(
  778. fun); // Recompute the CFG analysis because the Dominator tree uses it.
  779. auto bb = dom->ImmediateDominator(5);
  780. std::cout
  781. << bb->id(); // Make sure asan does not complain about use after free.
  782. }
  783. TEST_F(IRContextTest, DebugInstructionReplaceSingleUse) {
  784. const std::string text = R"(
  785. OpCapability Shader
  786. OpCapability Linkage
  787. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  788. OpMemoryModel Logical GLSL450
  789. %2 = OpString "test"
  790. %3 = OpTypeVoid
  791. %4 = OpTypeFunction %3
  792. %5 = OpTypeFloat 32
  793. %6 = OpTypePointer Function %5
  794. %7 = OpConstant %5 0
  795. %8 = OpTypeInt 32 0
  796. %9 = OpConstant %8 32
  797. %10 = OpExtInst %3 %1 DebugExpression
  798. %11 = OpExtInst %3 %1 DebugSource %2
  799. %12 = OpExtInst %3 %1 DebugCompilationUnit 1 4 %11 HLSL
  800. %13 = OpExtInst %3 %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %3
  801. %14 = OpExtInst %3 %1 DebugFunction %2 %13 %11 0 0 %12 %2 FlagIsProtected|FlagIsPrivate 0 %17
  802. %15 = OpExtInst %3 %1 DebugTypeBasic %2 %9 Float
  803. %16 = OpExtInst %3 %1 DebugLocalVariable %2 %15 %11 0 0 %14 FlagIsLocal
  804. %17 = OpFunction %3 None %4
  805. %18 = OpLabel
  806. %19 = OpExtInst %3 %1 DebugScope %14
  807. %20 = OpVariable %6 Function
  808. %26 = OpVariable %6 Function
  809. OpBranch %21
  810. %21 = OpLabel
  811. %22 = OpPhi %5 %7 %18
  812. OpBranch %23
  813. %23 = OpLabel
  814. OpLine %2 0 0
  815. OpStore %20 %7
  816. %24 = OpExtInst %3 %1 DebugValue %16 %22 %10
  817. %25 = OpExtInst %3 %1 DebugDeclare %16 %26 %10
  818. OpReturn
  819. OpFunctionEnd)";
  820. std::unique_ptr<IRContext> ctx =
  821. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  822. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  823. ctx->BuildInvalidAnalyses(IRContext::kAnalysisDebugInfo);
  824. NoopPassPreservesAll pass(Pass::Status::SuccessWithChange);
  825. pass.Run(ctx.get());
  826. EXPECT_TRUE(ctx->AreAnalysesValid(IRContext::kAnalysisDebugInfo));
  827. auto* dbg_value = ctx->get_def_use_mgr()->GetDef(24);
  828. EXPECT_TRUE(dbg_value->GetSingleWordOperand(kDebugValueOperandValueIndex) ==
  829. 22);
  830. EXPECT_TRUE(ctx->ReplaceAllUsesWith(22, 7));
  831. dbg_value = ctx->get_def_use_mgr()->GetDef(24);
  832. EXPECT_TRUE(dbg_value->GetSingleWordOperand(kDebugValueOperandValueIndex) ==
  833. 7);
  834. auto* dbg_decl = ctx->get_def_use_mgr()->GetDef(25);
  835. EXPECT_TRUE(
  836. dbg_decl->GetSingleWordOperand(kDebugDeclareOperandVariableIndex) == 26);
  837. EXPECT_TRUE(ctx->ReplaceAllUsesWith(26, 20));
  838. dbg_decl = ctx->get_def_use_mgr()->GetDef(25);
  839. EXPECT_TRUE(
  840. dbg_decl->GetSingleWordOperand(kDebugDeclareOperandVariableIndex) == 20);
  841. }
  842. TEST_F(IRContextTest, DebugInstructionReplaceAllUses) {
  843. const std::string text = R"(
  844. OpCapability Shader
  845. OpCapability Linkage
  846. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  847. OpMemoryModel Logical GLSL450
  848. %2 = OpString "test"
  849. %3 = OpTypeVoid
  850. %4 = OpTypeFunction %3
  851. %5 = OpTypeFloat 32
  852. %6 = OpTypePointer Function %5
  853. %7 = OpConstant %5 0
  854. %8 = OpTypeInt 32 0
  855. %9 = OpConstant %8 32
  856. %10 = OpExtInst %3 %1 DebugExpression
  857. %11 = OpExtInst %3 %1 DebugSource %2
  858. %12 = OpExtInst %3 %1 DebugCompilationUnit 1 4 %11 HLSL
  859. %13 = OpExtInst %3 %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %3
  860. %14 = OpExtInst %3 %1 DebugFunction %2 %13 %11 0 0 %12 %2 FlagIsProtected|FlagIsPrivate 0 %17
  861. %15 = OpExtInst %3 %1 DebugTypeBasic %2 %9 Float
  862. %16 = OpExtInst %3 %1 DebugLocalVariable %2 %15 %11 0 0 %14 FlagIsLocal
  863. %27 = OpExtInst %3 %1 DebugLocalVariable %2 %15 %11 1 0 %14 FlagIsLocal
  864. %17 = OpFunction %3 None %4
  865. %18 = OpLabel
  866. %19 = OpExtInst %3 %1 DebugScope %14
  867. %20 = OpVariable %6 Function
  868. %26 = OpVariable %6 Function
  869. OpBranch %21
  870. %21 = OpLabel
  871. %22 = OpPhi %5 %7 %18
  872. OpBranch %23
  873. %23 = OpLabel
  874. OpLine %2 0 0
  875. OpStore %20 %7
  876. %24 = OpExtInst %3 %1 DebugValue %16 %22 %10
  877. %25 = OpExtInst %3 %1 DebugDeclare %16 %26 %10
  878. %28 = OpExtInst %3 %1 DebugValue %27 %22 %10
  879. %29 = OpExtInst %3 %1 DebugDeclare %27 %26 %10
  880. OpReturn
  881. OpFunctionEnd)";
  882. std::unique_ptr<IRContext> ctx =
  883. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  884. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  885. ctx->BuildInvalidAnalyses(IRContext::kAnalysisDebugInfo);
  886. NoopPassPreservesAll pass(Pass::Status::SuccessWithChange);
  887. pass.Run(ctx.get());
  888. EXPECT_TRUE(ctx->AreAnalysesValid(IRContext::kAnalysisDebugInfo));
  889. auto* dbg_value0 = ctx->get_def_use_mgr()->GetDef(24);
  890. auto* dbg_value1 = ctx->get_def_use_mgr()->GetDef(28);
  891. EXPECT_TRUE(dbg_value0->GetSingleWordOperand(kDebugValueOperandValueIndex) ==
  892. 22);
  893. EXPECT_TRUE(dbg_value1->GetSingleWordOperand(kDebugValueOperandValueIndex) ==
  894. 22);
  895. EXPECT_TRUE(ctx->ReplaceAllUsesWith(22, 7));
  896. dbg_value0 = ctx->get_def_use_mgr()->GetDef(24);
  897. dbg_value1 = ctx->get_def_use_mgr()->GetDef(28);
  898. EXPECT_TRUE(dbg_value0->GetSingleWordOperand(kDebugValueOperandValueIndex) ==
  899. 7);
  900. EXPECT_TRUE(dbg_value1->GetSingleWordOperand(kDebugValueOperandValueIndex) ==
  901. 7);
  902. auto* dbg_decl0 = ctx->get_def_use_mgr()->GetDef(25);
  903. auto* dbg_decl1 = ctx->get_def_use_mgr()->GetDef(29);
  904. EXPECT_TRUE(
  905. dbg_decl0->GetSingleWordOperand(kDebugDeclareOperandVariableIndex) == 26);
  906. EXPECT_TRUE(
  907. dbg_decl1->GetSingleWordOperand(kDebugDeclareOperandVariableIndex) == 26);
  908. EXPECT_TRUE(ctx->ReplaceAllUsesWith(26, 20));
  909. dbg_decl0 = ctx->get_def_use_mgr()->GetDef(25);
  910. dbg_decl1 = ctx->get_def_use_mgr()->GetDef(29);
  911. EXPECT_TRUE(
  912. dbg_decl0->GetSingleWordOperand(kDebugDeclareOperandVariableIndex) == 20);
  913. EXPECT_TRUE(
  914. dbg_decl1->GetSingleWordOperand(kDebugDeclareOperandVariableIndex) == 20);
  915. }
  916. TEST_F(IRContextTest, DebugInstructionReplaceDebugScopeAndDebugInlinedAt) {
  917. const std::string text = R"(
  918. OpCapability Shader
  919. OpCapability Linkage
  920. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  921. OpMemoryModel Logical GLSL450
  922. %2 = OpString "test"
  923. %3 = OpTypeVoid
  924. %4 = OpTypeFunction %3
  925. %5 = OpTypeFloat 32
  926. %6 = OpTypePointer Function %5
  927. %7 = OpConstant %5 0
  928. %8 = OpTypeInt 32 0
  929. %9 = OpConstant %8 32
  930. %10 = OpExtInst %3 %1 DebugExpression
  931. %11 = OpExtInst %3 %1 DebugSource %2
  932. %12 = OpExtInst %3 %1 DebugCompilationUnit 1 4 %11 HLSL
  933. %13 = OpExtInst %3 %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %3
  934. %14 = OpExtInst %3 %1 DebugFunction %2 %13 %11 0 0 %12 %2 FlagIsProtected|FlagIsPrivate 0 %17
  935. %15 = OpExtInst %3 %1 DebugInfoNone
  936. %16 = OpExtInst %3 %1 DebugFunction %2 %13 %11 10 10 %12 %2 FlagIsProtected|FlagIsPrivate 0 %15
  937. %25 = OpExtInst %3 %1 DebugInlinedAt 0 %14
  938. %26 = OpExtInst %3 %1 DebugInlinedAt 2 %14
  939. %17 = OpFunction %3 None %4
  940. %18 = OpLabel
  941. %19 = OpExtInst %3 %1 DebugScope %14
  942. %20 = OpVariable %6 Function
  943. OpBranch %21
  944. %21 = OpLabel
  945. %24 = OpExtInst %3 %1 DebugScope %16
  946. %22 = OpPhi %5 %7 %18
  947. OpBranch %23
  948. %23 = OpLabel
  949. %27 = OpExtInst %3 %1 DebugScope %16 %25
  950. OpLine %2 0 0
  951. %28 = OpFAdd %5 %7 %7
  952. OpStore %20 %28
  953. OpReturn
  954. OpFunctionEnd)";
  955. std::unique_ptr<IRContext> ctx =
  956. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  957. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  958. ctx->BuildInvalidAnalyses(IRContext::kAnalysisDebugInfo);
  959. NoopPassPreservesAll pass(Pass::Status::SuccessWithChange);
  960. pass.Run(ctx.get());
  961. EXPECT_TRUE(ctx->AreAnalysesValid(IRContext::kAnalysisDebugInfo));
  962. auto* inst0 = ctx->get_def_use_mgr()->GetDef(20);
  963. auto* inst1 = ctx->get_def_use_mgr()->GetDef(22);
  964. auto* inst2 = ctx->get_def_use_mgr()->GetDef(28);
  965. EXPECT_EQ(inst0->GetDebugScope().GetLexicalScope(), 14);
  966. EXPECT_EQ(inst1->GetDebugScope().GetLexicalScope(), 16);
  967. EXPECT_EQ(inst2->GetDebugScope().GetLexicalScope(), 16);
  968. EXPECT_EQ(inst2->GetDebugInlinedAt(), 25);
  969. EXPECT_TRUE(ctx->ReplaceAllUsesWith(14, 12));
  970. EXPECT_TRUE(ctx->ReplaceAllUsesWith(16, 14));
  971. EXPECT_TRUE(ctx->ReplaceAllUsesWith(25, 26));
  972. EXPECT_EQ(inst0->GetDebugScope().GetLexicalScope(), 12);
  973. EXPECT_EQ(inst1->GetDebugScope().GetLexicalScope(), 14);
  974. EXPECT_EQ(inst2->GetDebugScope().GetLexicalScope(), 14);
  975. EXPECT_EQ(inst2->GetDebugInlinedAt(), 26);
  976. }
  977. TEST_F(IRContextTest, AddDebugValueAfterReplaceUse) {
  978. const std::string text = R"(
  979. OpCapability Shader
  980. OpCapability Linkage
  981. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  982. OpMemoryModel Logical GLSL450
  983. %2 = OpString "test"
  984. %3 = OpTypeVoid
  985. %4 = OpTypeFunction %3
  986. %5 = OpTypeFloat 32
  987. %6 = OpTypePointer Function %5
  988. %7 = OpConstant %5 0
  989. %8 = OpTypeInt 32 0
  990. %9 = OpConstant %8 32
  991. %10 = OpExtInst %3 %1 DebugExpression
  992. %11 = OpExtInst %3 %1 DebugSource %2
  993. %12 = OpExtInst %3 %1 DebugCompilationUnit 1 4 %11 HLSL
  994. %13 = OpExtInst %3 %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %3
  995. %14 = OpExtInst %3 %1 DebugFunction %2 %13 %11 0 0 %12 %2 FlagIsProtected|FlagIsPrivate 0 %17
  996. %15 = OpExtInst %3 %1 DebugTypeBasic %2 %9 Float
  997. %16 = OpExtInst %3 %1 DebugLocalVariable %2 %15 %11 0 0 %14 FlagIsLocal
  998. %17 = OpFunction %3 None %4
  999. %18 = OpLabel
  1000. %19 = OpExtInst %3 %1 DebugScope %14
  1001. %20 = OpVariable %6 Function
  1002. %26 = OpVariable %6 Function
  1003. OpBranch %21
  1004. %21 = OpLabel
  1005. %27 = OpExtInst %3 %1 DebugScope %14
  1006. %22 = OpPhi %5 %7 %18
  1007. OpBranch %23
  1008. %23 = OpLabel
  1009. %28 = OpExtInst %3 %1 DebugScope %14
  1010. OpLine %2 0 0
  1011. OpStore %20 %7
  1012. %24 = OpExtInst %3 %1 DebugValue %16 %22 %10
  1013. %25 = OpExtInst %3 %1 DebugDeclare %16 %26 %10
  1014. OpReturn
  1015. OpFunctionEnd)";
  1016. std::unique_ptr<IRContext> ctx =
  1017. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  1018. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1019. ctx->BuildInvalidAnalyses(IRContext::kAnalysisDebugInfo);
  1020. NoopPassPreservesAll pass(Pass::Status::SuccessWithChange);
  1021. pass.Run(ctx.get());
  1022. EXPECT_TRUE(ctx->AreAnalysesValid(IRContext::kAnalysisDebugInfo));
  1023. // Replace all uses of result it '26' with '20'
  1024. auto* dbg_decl = ctx->get_def_use_mgr()->GetDef(25);
  1025. EXPECT_EQ(dbg_decl->GetSingleWordOperand(kDebugDeclareOperandVariableIndex),
  1026. 26);
  1027. EXPECT_TRUE(ctx->ReplaceAllUsesWith(26, 20));
  1028. dbg_decl = ctx->get_def_use_mgr()->GetDef(25);
  1029. EXPECT_EQ(dbg_decl->GetSingleWordOperand(kDebugDeclareOperandVariableIndex),
  1030. 20);
  1031. }
  1032. struct TargetEnvCompareTestData {
  1033. spv_target_env later_env, earlier_env;
  1034. };
  1035. using TargetEnvCompareTest = ::testing::TestWithParam<TargetEnvCompareTestData>;
  1036. TEST_P(TargetEnvCompareTest, IsTargetEnvAtLeast) {
  1037. const auto& tc = GetParam();
  1038. std::unique_ptr<Module> module(new Module());
  1039. IRContext localContext(tc.later_env, std::move(module),
  1040. spvtools::MessageConsumer());
  1041. EXPECT_TRUE(localContext.IsTargetEnvAtLeast(tc.earlier_env));
  1042. if (tc.earlier_env != tc.later_env) {
  1043. std::unique_ptr<Module> module(new Module());
  1044. IRContext localContext(tc.earlier_env, std::move(module),
  1045. spvtools::MessageConsumer());
  1046. EXPECT_FALSE(localContext.IsTargetEnvAtLeast(tc.later_env));
  1047. }
  1048. }
  1049. TEST_F(IRContextTest, ReturnsTrueWhenExtensionIsRemoved) {
  1050. const std::string text = R"(
  1051. OpCapability Shader
  1052. OpExtension "SPV_KHR_shader_clock"
  1053. OpMemoryModel Logical GLSL450
  1054. OpEntryPoint GLCompute %1 "main"
  1055. %void = OpTypeVoid
  1056. %6 = OpTypeFunction %void
  1057. %1 = OpFunction %void None %6
  1058. %9 = OpLabel
  1059. OpReturn
  1060. OpFunctionEnd)";
  1061. std::unique_ptr<IRContext> ctx =
  1062. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1063. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1064. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1065. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1066. ctx->module()->extension_end()),
  1067. 1);
  1068. EXPECT_TRUE(ctx->RemoveExtension(kSPV_KHR_shader_clock));
  1069. EXPECT_FALSE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1070. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1071. ctx->module()->extension_end()),
  1072. 0);
  1073. }
  1074. TEST_F(IRContextTest, ReturnsFalseWhenExtensionIsNotRemoved) {
  1075. const std::string text = R"(
  1076. OpCapability Shader
  1077. OpExtension "SPV_KHR_device_group"
  1078. OpMemoryModel Logical GLSL450
  1079. OpEntryPoint GLCompute %1 "main"
  1080. %void = OpTypeVoid
  1081. %6 = OpTypeFunction %void
  1082. %1 = OpFunction %void None %6
  1083. %9 = OpLabel
  1084. OpReturn
  1085. OpFunctionEnd)";
  1086. std::unique_ptr<IRContext> ctx =
  1087. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1088. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1089. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_device_group));
  1090. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1091. ctx->module()->extension_end()),
  1092. 1);
  1093. EXPECT_FALSE(ctx->RemoveExtension(kSPV_KHR_shader_clock));
  1094. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_device_group));
  1095. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1096. ctx->module()->extension_end()),
  1097. 1);
  1098. }
  1099. TEST_F(IRContextTest, RemovesExtensionIfLast) {
  1100. const std::string text = R"(
  1101. OpCapability Shader
  1102. OpExtension "SPV_KHR_device_group"
  1103. OpExtension "SPV_KHR_shader_clock"
  1104. OpMemoryModel Logical GLSL450
  1105. OpEntryPoint GLCompute %1 "main"
  1106. %void = OpTypeVoid
  1107. %6 = OpTypeFunction %void
  1108. %1 = OpFunction %void None %6
  1109. %9 = OpLabel
  1110. OpReturn
  1111. OpFunctionEnd)";
  1112. std::unique_ptr<IRContext> ctx =
  1113. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1114. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1115. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_device_group));
  1116. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1117. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1118. ctx->module()->extension_end()),
  1119. 2);
  1120. EXPECT_TRUE(ctx->RemoveExtension(kSPV_KHR_shader_clock));
  1121. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_device_group));
  1122. EXPECT_FALSE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1123. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1124. ctx->module()->extension_end()),
  1125. 1);
  1126. }
  1127. TEST_F(IRContextTest, RemovesExtensionIfFirst) {
  1128. const std::string text = R"(
  1129. OpCapability Shader
  1130. OpExtension "SPV_KHR_shader_clock"
  1131. OpExtension "SPV_KHR_device_group"
  1132. OpMemoryModel Logical GLSL450
  1133. OpEntryPoint GLCompute %1 "main"
  1134. %void = OpTypeVoid
  1135. %6 = OpTypeFunction %void
  1136. %1 = OpFunction %void None %6
  1137. %9 = OpLabel
  1138. OpReturn
  1139. OpFunctionEnd)";
  1140. std::unique_ptr<IRContext> ctx =
  1141. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1142. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1143. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_device_group));
  1144. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1145. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1146. ctx->module()->extension_end()),
  1147. 2);
  1148. EXPECT_TRUE(ctx->RemoveExtension(kSPV_KHR_shader_clock));
  1149. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_device_group));
  1150. EXPECT_FALSE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1151. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1152. ctx->module()->extension_end()),
  1153. 1);
  1154. }
  1155. TEST_F(IRContextTest, RemovesMultipleExtensions) {
  1156. const std::string text = R"(
  1157. OpCapability Shader
  1158. OpExtension "SPV_KHR_shader_clock"
  1159. OpExtension "SPV_KHR_shader_clock"
  1160. OpMemoryModel Logical GLSL450
  1161. OpEntryPoint GLCompute %1 "main"
  1162. %void = OpTypeVoid
  1163. %6 = OpTypeFunction %void
  1164. %1 = OpFunction %void None %6
  1165. %9 = OpLabel
  1166. OpReturn
  1167. OpFunctionEnd)";
  1168. std::unique_ptr<IRContext> ctx =
  1169. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1170. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1171. EXPECT_TRUE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1172. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1173. ctx->module()->extension_end()),
  1174. 2);
  1175. EXPECT_TRUE(ctx->RemoveExtension(kSPV_KHR_shader_clock));
  1176. EXPECT_FALSE(ctx->get_feature_mgr()->HasExtension(kSPV_KHR_shader_clock));
  1177. EXPECT_EQ(std::distance(ctx->module()->extension_begin(),
  1178. ctx->module()->extension_end()),
  1179. 0);
  1180. }
  1181. TEST_F(IRContextTest, ReturnsTrueWhenCapabilityIsRemoved) {
  1182. const std::string text = R"(
  1183. OpCapability Shader
  1184. OpCapability ShaderClockKHR
  1185. OpExtension "SPV_KHR_shader_clock"
  1186. OpMemoryModel Logical GLSL450
  1187. OpEntryPoint GLCompute %1 "main"
  1188. %void = OpTypeVoid
  1189. %6 = OpTypeFunction %void
  1190. %1 = OpFunction %void None %6
  1191. %9 = OpLabel
  1192. OpReturn
  1193. OpFunctionEnd)";
  1194. std::unique_ptr<IRContext> ctx =
  1195. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1196. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1197. EXPECT_TRUE(
  1198. ctx->get_feature_mgr()->HasCapability(spv::Capability::ShaderClockKHR));
  1199. EXPECT_EQ(std::distance(ctx->module()->capability_begin(),
  1200. ctx->module()->capability_end()),
  1201. 2);
  1202. EXPECT_TRUE(ctx->RemoveCapability(spv::Capability::ShaderClockKHR));
  1203. EXPECT_FALSE(
  1204. ctx->get_feature_mgr()->HasCapability(spv::Capability::ShaderClockKHR));
  1205. EXPECT_EQ(std::distance(ctx->module()->capability_begin(),
  1206. ctx->module()->capability_end()),
  1207. 1);
  1208. }
  1209. TEST_F(IRContextTest, ReturnsFalseWhenCapabilityIsNotRemoved) {
  1210. const std::string text = R"(
  1211. OpCapability Shader
  1212. OpCapability DeviceGroup
  1213. OpExtension "SPV_KHR_device_group"
  1214. OpMemoryModel Logical GLSL450
  1215. OpEntryPoint GLCompute %1 "main"
  1216. %void = OpTypeVoid
  1217. %6 = OpTypeFunction %void
  1218. %1 = OpFunction %void None %6
  1219. %9 = OpLabel
  1220. OpReturn
  1221. OpFunctionEnd)";
  1222. std::unique_ptr<IRContext> ctx =
  1223. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1224. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1225. EXPECT_TRUE(
  1226. ctx->get_feature_mgr()->HasCapability(spv::Capability::DeviceGroup));
  1227. EXPECT_EQ(std::distance(ctx->module()->capability_begin(),
  1228. ctx->module()->capability_end()),
  1229. 2);
  1230. EXPECT_FALSE(ctx->RemoveCapability(spv::Capability::ShaderClockKHR));
  1231. EXPECT_TRUE(
  1232. ctx->get_feature_mgr()->HasCapability(spv::Capability::DeviceGroup));
  1233. EXPECT_EQ(std::distance(ctx->module()->capability_begin(),
  1234. ctx->module()->capability_end()),
  1235. 2);
  1236. }
  1237. TEST_F(IRContextTest, RemovesMultipleCapabilities) {
  1238. const std::string text = R"(
  1239. OpCapability Shader
  1240. OpCapability DeviceGroup
  1241. OpCapability DeviceGroup
  1242. OpExtension "SPV_KHR_device_group"
  1243. OpMemoryModel Logical GLSL450
  1244. OpEntryPoint GLCompute %1 "main"
  1245. %void = OpTypeVoid
  1246. %6 = OpTypeFunction %void
  1247. %1 = OpFunction %void None %6
  1248. %9 = OpLabel
  1249. OpReturn
  1250. OpFunctionEnd)";
  1251. std::unique_ptr<IRContext> ctx =
  1252. BuildModule(SPV_ENV_UNIVERSAL_1_6, nullptr, text,
  1253. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1254. EXPECT_TRUE(
  1255. ctx->get_feature_mgr()->HasCapability(spv::Capability::DeviceGroup));
  1256. EXPECT_EQ(std::distance(ctx->module()->capability_begin(),
  1257. ctx->module()->capability_end()),
  1258. 3);
  1259. EXPECT_TRUE(ctx->RemoveCapability(spv::Capability::DeviceGroup));
  1260. EXPECT_FALSE(
  1261. ctx->get_feature_mgr()->HasCapability(spv::Capability::DeviceGroup));
  1262. EXPECT_EQ(std::distance(ctx->module()->capability_begin(),
  1263. ctx->module()->capability_end()),
  1264. 1);
  1265. }
  1266. // If new environments are added, then we must update the list of tests.
  1267. static_assert(SPV_ENV_VULKAN_1_4 + 1 == SPV_ENV_MAX);
  1268. INSTANTIATE_TEST_SUITE_P(
  1269. TestCase, TargetEnvCompareTest,
  1270. ::testing::Values(
  1271. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_0},
  1272. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_1, SPV_ENV_UNIVERSAL_1_0},
  1273. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_2, SPV_ENV_UNIVERSAL_1_0},
  1274. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_3, SPV_ENV_UNIVERSAL_1_0},
  1275. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_0},
  1276. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_UNIVERSAL_1_0},
  1277. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_UNIVERSAL_1_0},
  1278. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_1, SPV_ENV_UNIVERSAL_1_1},
  1279. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_2, SPV_ENV_UNIVERSAL_1_1},
  1280. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_3, SPV_ENV_UNIVERSAL_1_1},
  1281. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_1},
  1282. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_UNIVERSAL_1_1},
  1283. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_UNIVERSAL_1_1},
  1284. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_2, SPV_ENV_UNIVERSAL_1_2},
  1285. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_3, SPV_ENV_UNIVERSAL_1_2},
  1286. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_2},
  1287. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_UNIVERSAL_1_2},
  1288. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_UNIVERSAL_1_2},
  1289. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_3, SPV_ENV_UNIVERSAL_1_3},
  1290. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_3},
  1291. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_UNIVERSAL_1_3},
  1292. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_UNIVERSAL_1_3},
  1293. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_4},
  1294. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_UNIVERSAL_1_4},
  1295. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_UNIVERSAL_1_4},
  1296. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_UNIVERSAL_1_5},
  1297. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_UNIVERSAL_1_5},
  1298. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_UNIVERSAL_1_6},
  1299. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_0, SPV_ENV_UNIVERSAL_1_0},
  1300. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_1, SPV_ENV_VULKAN_1_0},
  1301. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_2, SPV_ENV_VULKAN_1_0},
  1302. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_3, SPV_ENV_VULKAN_1_0},
  1303. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_4, SPV_ENV_VULKAN_1_0},
  1304. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_VULKAN_1_0},
  1305. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_VULKAN_1_0},
  1306. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_1, SPV_ENV_UNIVERSAL_1_0},
  1307. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_1, SPV_ENV_UNIVERSAL_1_1},
  1308. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_1, SPV_ENV_UNIVERSAL_1_2},
  1309. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_1, SPV_ENV_UNIVERSAL_1_3},
  1310. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_1, SPV_ENV_VULKAN_1_0},
  1311. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_4, SPV_ENV_VULKAN_1_1},
  1312. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_5, SPV_ENV_VULKAN_1_1},
  1313. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_VULKAN_1_1},
  1314. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_2, SPV_ENV_UNIVERSAL_1_0},
  1315. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_2, SPV_ENV_UNIVERSAL_1_1},
  1316. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_2, SPV_ENV_UNIVERSAL_1_2},
  1317. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_2, SPV_ENV_UNIVERSAL_1_3},
  1318. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_2, SPV_ENV_UNIVERSAL_1_4},
  1319. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_2, SPV_ENV_UNIVERSAL_1_5},
  1320. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_2, SPV_ENV_VULKAN_1_1},
  1321. TargetEnvCompareTestData{SPV_ENV_UNIVERSAL_1_6, SPV_ENV_VULKAN_1_2},
  1322. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_UNIVERSAL_1_0},
  1323. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_UNIVERSAL_1_1},
  1324. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_UNIVERSAL_1_2},
  1325. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_UNIVERSAL_1_3},
  1326. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_UNIVERSAL_1_4},
  1327. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_UNIVERSAL_1_5},
  1328. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_UNIVERSAL_1_6},
  1329. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_3, SPV_ENV_VULKAN_1_2},
  1330. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_UNIVERSAL_1_0},
  1331. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_UNIVERSAL_1_1},
  1332. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_UNIVERSAL_1_2},
  1333. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_UNIVERSAL_1_3},
  1334. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_UNIVERSAL_1_4},
  1335. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_UNIVERSAL_1_5},
  1336. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_UNIVERSAL_1_6},
  1337. TargetEnvCompareTestData{SPV_ENV_VULKAN_1_4, SPV_ENV_VULKAN_1_3}));
  1338. } // namespace
  1339. } // namespace opt
  1340. } // namespace spvtools