1fd4e5da5Sopenharmony_ci// Copyright (c) 2017 Google Inc.
2fd4e5da5Sopenharmony_ci//
3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
6fd4e5da5Sopenharmony_ci//
7fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8fd4e5da5Sopenharmony_ci//
9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
13fd4e5da5Sopenharmony_ci// limitations under the License.
14fd4e5da5Sopenharmony_ci
15fd4e5da5Sopenharmony_ci#include <vector>
16fd4e5da5Sopenharmony_ci
17fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h"
18fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h"
19fd4e5da5Sopenharmony_ci
20fd4e5da5Sopenharmony_cinamespace spvtools {
21fd4e5da5Sopenharmony_cinamespace opt {
22fd4e5da5Sopenharmony_cinamespace {
23fd4e5da5Sopenharmony_ci
24fd4e5da5Sopenharmony_ciusing StrengthReductionBasicTest = PassTest<::testing::Test>;
25fd4e5da5Sopenharmony_ci
26fd4e5da5Sopenharmony_ciTEST_F(StrengthReductionBasicTest, ClearDontInline) {
27fd4e5da5Sopenharmony_ci  const std::vector<const char*> text = {
28fd4e5da5Sopenharmony_ci      // clang-format off
29fd4e5da5Sopenharmony_ci               "OpCapability Shader",
30fd4e5da5Sopenharmony_ci          "%1 = OpExtInstImport \"GLSL.std.450\"",
31fd4e5da5Sopenharmony_ci               "OpMemoryModel Logical GLSL450",
32fd4e5da5Sopenharmony_ci               "OpEntryPoint Vertex %main \"main\"",
33fd4e5da5Sopenharmony_ci       "%void = OpTypeVoid",
34fd4e5da5Sopenharmony_ci          "%4 = OpTypeFunction %void",
35fd4e5da5Sopenharmony_ci"; CHECK: OpFunction %void None",
36fd4e5da5Sopenharmony_ci       "%main = OpFunction %void DontInline %4",
37fd4e5da5Sopenharmony_ci          "%8 = OpLabel",
38fd4e5da5Sopenharmony_ci               "OpReturn",
39fd4e5da5Sopenharmony_ci               "OpFunctionEnd"
40fd4e5da5Sopenharmony_ci      // clang-format on
41fd4e5da5Sopenharmony_ci  };
42fd4e5da5Sopenharmony_ci
43fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<RemoveDontInline>(JoinAllInsts(text), true);
44fd4e5da5Sopenharmony_ci}
45fd4e5da5Sopenharmony_ci
46fd4e5da5Sopenharmony_ciTEST_F(StrengthReductionBasicTest, LeaveUnchanged1) {
47fd4e5da5Sopenharmony_ci  const std::vector<const char*> text = {
48fd4e5da5Sopenharmony_ci      // clang-format off
49fd4e5da5Sopenharmony_ci      "OpCapability Shader",
50fd4e5da5Sopenharmony_ci      "%1 = OpExtInstImport \"GLSL.std.450\"",
51fd4e5da5Sopenharmony_ci      "OpMemoryModel Logical GLSL450",
52fd4e5da5Sopenharmony_ci      "OpEntryPoint Vertex %main \"main\"",
53fd4e5da5Sopenharmony_ci      "%void = OpTypeVoid",
54fd4e5da5Sopenharmony_ci      "%4 = OpTypeFunction %void",
55fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %4",
56fd4e5da5Sopenharmony_ci      "%8 = OpLabel",
57fd4e5da5Sopenharmony_ci      "OpReturn",
58fd4e5da5Sopenharmony_ci      "OpFunctionEnd"
59fd4e5da5Sopenharmony_ci      // clang-format on
60fd4e5da5Sopenharmony_ci  };
61fd4e5da5Sopenharmony_ci
62fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange,
63fd4e5da5Sopenharmony_ci            std::get<1>(SinglePassRunAndDisassemble<RemoveDontInline>(
64fd4e5da5Sopenharmony_ci                JoinAllInsts(text), false, true)));
65fd4e5da5Sopenharmony_ci}
66fd4e5da5Sopenharmony_ci
67fd4e5da5Sopenharmony_ciTEST_F(StrengthReductionBasicTest, LeaveUnchanged2) {
68fd4e5da5Sopenharmony_ci  const std::vector<const char*> text = {
69fd4e5da5Sopenharmony_ci      // clang-format off
70fd4e5da5Sopenharmony_ci      "OpCapability Shader",
71fd4e5da5Sopenharmony_ci      "%1 = OpExtInstImport \"GLSL.std.450\"",
72fd4e5da5Sopenharmony_ci      "OpMemoryModel Logical GLSL450",
73fd4e5da5Sopenharmony_ci      "OpEntryPoint Vertex %main \"main\"",
74fd4e5da5Sopenharmony_ci      "%void = OpTypeVoid",
75fd4e5da5Sopenharmony_ci      "%4 = OpTypeFunction %void",
76fd4e5da5Sopenharmony_ci      "%main = OpFunction %void Inline %4",
77fd4e5da5Sopenharmony_ci      "%8 = OpLabel",
78fd4e5da5Sopenharmony_ci      "OpReturn",
79fd4e5da5Sopenharmony_ci      "OpFunctionEnd"
80fd4e5da5Sopenharmony_ci      // clang-format on
81fd4e5da5Sopenharmony_ci  };
82fd4e5da5Sopenharmony_ci
83fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange,
84fd4e5da5Sopenharmony_ci            std::get<1>(SinglePassRunAndDisassemble<RemoveDontInline>(
85fd4e5da5Sopenharmony_ci                JoinAllInsts(text), false, true)));
86fd4e5da5Sopenharmony_ci}
87fd4e5da5Sopenharmony_ci
88fd4e5da5Sopenharmony_ciTEST_F(StrengthReductionBasicTest, ClearMultipleDontInline) {
89fd4e5da5Sopenharmony_ci  const std::vector<const char*> text = {
90fd4e5da5Sopenharmony_ci      // clang-format off
91fd4e5da5Sopenharmony_ci      "OpCapability Shader",
92fd4e5da5Sopenharmony_ci      "%1 = OpExtInstImport \"GLSL.std.450\"",
93fd4e5da5Sopenharmony_ci      "OpMemoryModel Logical GLSL450",
94fd4e5da5Sopenharmony_ci      "OpEntryPoint Vertex %main1 \"main1\"",
95fd4e5da5Sopenharmony_ci      "OpEntryPoint Vertex %main2 \"main2\"",
96fd4e5da5Sopenharmony_ci      "OpEntryPoint Vertex %main3 \"main3\"",
97fd4e5da5Sopenharmony_ci      "OpEntryPoint Vertex %main4 \"main4\"",
98fd4e5da5Sopenharmony_ci      "%void = OpTypeVoid",
99fd4e5da5Sopenharmony_ci      "%4 = OpTypeFunction %void",
100fd4e5da5Sopenharmony_ci      "; CHECK: OpFunction %void None",
101fd4e5da5Sopenharmony_ci      "%main1 = OpFunction %void DontInline %4",
102fd4e5da5Sopenharmony_ci      "%8 = OpLabel",
103fd4e5da5Sopenharmony_ci      "OpReturn",
104fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
105fd4e5da5Sopenharmony_ci      "; CHECK: OpFunction %void Inline",
106fd4e5da5Sopenharmony_ci      "%main2 = OpFunction %void Inline %4",
107fd4e5da5Sopenharmony_ci      "%9 = OpLabel",
108fd4e5da5Sopenharmony_ci      "OpReturn",
109fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
110fd4e5da5Sopenharmony_ci      "; CHECK: OpFunction %void Pure",
111fd4e5da5Sopenharmony_ci      "%main3 = OpFunction %void DontInline|Pure %4",
112fd4e5da5Sopenharmony_ci      "%10 = OpLabel",
113fd4e5da5Sopenharmony_ci      "OpReturn",
114fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
115fd4e5da5Sopenharmony_ci      "; CHECK: OpFunction %void None",
116fd4e5da5Sopenharmony_ci      "%main4 = OpFunction %void None %4",
117fd4e5da5Sopenharmony_ci      "%11 = OpLabel",
118fd4e5da5Sopenharmony_ci      "OpReturn",
119fd4e5da5Sopenharmony_ci      "OpFunctionEnd"
120fd4e5da5Sopenharmony_ci      // clang-format on
121fd4e5da5Sopenharmony_ci  };
122fd4e5da5Sopenharmony_ci
123fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<RemoveDontInline>(JoinAllInsts(text), true);
124fd4e5da5Sopenharmony_ci}
125fd4e5da5Sopenharmony_ci}  // namespace
126fd4e5da5Sopenharmony_ci}  // namespace opt
127fd4e5da5Sopenharmony_ci}  // namespace spvtools
128