remove_dontinline_test.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 <vector>
  15. #include "test/opt/pass_fixture.h"
  16. #include "test/opt/pass_utils.h"
  17. namespace spvtools {
  18. namespace opt {
  19. namespace {
  20. using StrengthReductionBasicTest = PassTest<::testing::Test>;
  21. TEST_F(StrengthReductionBasicTest, ClearDontInline) {
  22. const std::vector<const char*> text = {
  23. // clang-format off
  24. "OpCapability Shader",
  25. "%1 = OpExtInstImport \"GLSL.std.450\"",
  26. "OpMemoryModel Logical GLSL450",
  27. "OpEntryPoint Vertex %main \"main\"",
  28. "%void = OpTypeVoid",
  29. "%4 = OpTypeFunction %void",
  30. "; CHECK: OpFunction %void None",
  31. "%main = OpFunction %void DontInline %4",
  32. "%8 = OpLabel",
  33. "OpReturn",
  34. "OpFunctionEnd"
  35. // clang-format on
  36. };
  37. SinglePassRunAndMatch<RemoveDontInline>(JoinAllInsts(text), true);
  38. }
  39. TEST_F(StrengthReductionBasicTest, LeaveUnchanged1) {
  40. const std::vector<const char*> text = {
  41. // clang-format off
  42. "OpCapability Shader",
  43. "%1 = OpExtInstImport \"GLSL.std.450\"",
  44. "OpMemoryModel Logical GLSL450",
  45. "OpEntryPoint Vertex %main \"main\"",
  46. "%void = OpTypeVoid",
  47. "%4 = OpTypeFunction %void",
  48. "%main = OpFunction %void None %4",
  49. "%8 = OpLabel",
  50. "OpReturn",
  51. "OpFunctionEnd"
  52. // clang-format on
  53. };
  54. EXPECT_EQ(Pass::Status::SuccessWithoutChange,
  55. std::get<1>(SinglePassRunAndDisassemble<RemoveDontInline>(
  56. JoinAllInsts(text), false, true)));
  57. }
  58. TEST_F(StrengthReductionBasicTest, LeaveUnchanged2) {
  59. const std::vector<const char*> text = {
  60. // clang-format off
  61. "OpCapability Shader",
  62. "%1 = OpExtInstImport \"GLSL.std.450\"",
  63. "OpMemoryModel Logical GLSL450",
  64. "OpEntryPoint Vertex %main \"main\"",
  65. "%void = OpTypeVoid",
  66. "%4 = OpTypeFunction %void",
  67. "%main = OpFunction %void Inline %4",
  68. "%8 = OpLabel",
  69. "OpReturn",
  70. "OpFunctionEnd"
  71. // clang-format on
  72. };
  73. EXPECT_EQ(Pass::Status::SuccessWithoutChange,
  74. std::get<1>(SinglePassRunAndDisassemble<RemoveDontInline>(
  75. JoinAllInsts(text), false, true)));
  76. }
  77. TEST_F(StrengthReductionBasicTest, ClearMultipleDontInline) {
  78. const std::vector<const char*> text = {
  79. // clang-format off
  80. "OpCapability Shader",
  81. "%1 = OpExtInstImport \"GLSL.std.450\"",
  82. "OpMemoryModel Logical GLSL450",
  83. "OpEntryPoint Vertex %main1 \"main1\"",
  84. "OpEntryPoint Vertex %main2 \"main2\"",
  85. "OpEntryPoint Vertex %main3 \"main3\"",
  86. "OpEntryPoint Vertex %main4 \"main4\"",
  87. "%void = OpTypeVoid",
  88. "%4 = OpTypeFunction %void",
  89. "; CHECK: OpFunction %void None",
  90. "%main1 = OpFunction %void DontInline %4",
  91. "%8 = OpLabel",
  92. "OpReturn",
  93. "OpFunctionEnd",
  94. "; CHECK: OpFunction %void Inline",
  95. "%main2 = OpFunction %void Inline %4",
  96. "%9 = OpLabel",
  97. "OpReturn",
  98. "OpFunctionEnd",
  99. "; CHECK: OpFunction %void Pure",
  100. "%main3 = OpFunction %void DontInline|Pure %4",
  101. "%10 = OpLabel",
  102. "OpReturn",
  103. "OpFunctionEnd",
  104. "; CHECK: OpFunction %void None",
  105. "%main4 = OpFunction %void None %4",
  106. "%11 = OpLabel",
  107. "OpReturn",
  108. "OpFunctionEnd"
  109. // clang-format on
  110. };
  111. SinglePassRunAndMatch<RemoveDontInline>(JoinAllInsts(text), true);
  112. }
  113. } // namespace
  114. } // namespace opt
  115. } // namespace spvtools