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