Debian Codegraph @

test/opt/ir_context_test.cpp

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