OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "test/common/wasm/test-signatures.h" | 9 #include "test/common/wasm/test-signatures.h" |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 for (int j = 0; j < assigned->length(); j++) { | 105 for (int j = 0; j < assigned->length(); j++) { |
106 bool expected = i == j || j == 0 || j == 1; | 106 bool expected = i == j || j == 0 || j == 1; |
107 CHECK_EQ(expected, assigned->Contains(j)); | 107 CHECK_EQ(expected, assigned->Contains(j)); |
108 } | 108 } |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) { | 112 TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) { |
113 num_locals = 65000; | 113 num_locals = 65000; |
114 for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) { | 114 for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) { |
115 byte code[] = {WASM_LOOP(WASM_I8(11), kExprSetLocal, U32V_3(i))}; | 115 byte code[] = {WASM_LOOP(WASM_I32V_1(11), kExprSetLocal, U32V_3(i))}; |
116 | 116 |
117 BitVector* assigned = Analyze(code, code + arraysize(code)); | 117 BitVector* assigned = Analyze(code, code + arraysize(code)); |
118 for (int j = 0; j < assigned->length(); j++) { | 118 for (int j = 0; j < assigned->length(); j++) { |
119 bool expected = i == j; | 119 bool expected = i == j; |
120 CHECK_EQ(expected, assigned->Contains(j)); | 120 CHECK_EQ(expected, assigned->Contains(j)); |
121 } | 121 } |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) { | 125 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) { |
126 num_locals = 3; | 126 num_locals = 3; |
127 byte code[] = { | 127 byte code[] = { |
128 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_SET_ZERO(1)))), | 128 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_SET_ZERO(1)))), |
129 WASM_SET_ZERO(0)}; | 129 WASM_SET_ZERO(0)}; |
130 | 130 |
131 BitVector* assigned = Analyze(code, code + arraysize(code)); | 131 BitVector* assigned = Analyze(code, code + arraysize(code)); |
132 for (int j = 0; j < assigned->length(); j++) { | 132 for (int j = 0; j < assigned->length(); j++) { |
133 bool expected = j == 1; | 133 bool expected = j == 1; |
134 CHECK_EQ(expected, assigned->Contains(j)); | 134 CHECK_EQ(expected, assigned->Contains(j)); |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) { | 138 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) { |
139 num_locals = 5; | 139 num_locals = 5; |
140 byte code[] = { | 140 byte code[] = { |
141 WASM_LOOP(WASM_IF( | 141 WASM_LOOP(WASM_IF( |
142 WASM_GET_LOCAL(0), | 142 WASM_GET_LOCAL(0), |
143 WASM_BRV(0, WASM_SET_LOCAL( | 143 WASM_BRV(0, WASM_SET_LOCAL(3, WASM_I32_SUB(WASM_GET_LOCAL(0), |
144 3, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))))), | 144 WASM_I32V_1(1)))))), |
145 WASM_GET_LOCAL(0)}; | 145 WASM_GET_LOCAL(0)}; |
146 | 146 |
147 BitVector* assigned = Analyze(code, code + arraysize(code)); | 147 BitVector* assigned = Analyze(code, code + arraysize(code)); |
148 for (int j = 0; j < assigned->length(); j++) { | 148 for (int j = 0; j < assigned->length(); j++) { |
149 bool expected = j == 3; | 149 bool expected = j == 3; |
150 CHECK_EQ(expected, assigned->Contains(j)); | 150 CHECK_EQ(expected, assigned->Contains(j)); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) { | 154 TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) { |
155 num_locals = 6; | 155 num_locals = 6; |
156 const byte kIter = 0; | 156 const byte kIter = 0; |
157 const byte kSum = 3; | 157 const byte kSum = 3; |
158 | 158 |
159 byte code[] = {WASM_BLOCK( | 159 byte code[] = {WASM_BLOCK( |
160 WASM_WHILE( | 160 WASM_WHILE( |
161 WASM_GET_LOCAL(kIter), | 161 WASM_GET_LOCAL(kIter), |
162 WASM_BLOCK( | 162 WASM_BLOCK( |
163 WASM_SET_LOCAL( | 163 WASM_SET_LOCAL( |
164 kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), | 164 kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), |
165 WASM_LOAD_MEM(MachineType::Float32(), | 165 WASM_LOAD_MEM(MachineType::Float32(), |
166 WASM_GET_LOCAL(kIter)))), | 166 WASM_GET_LOCAL(kIter)))), |
167 WASM_SET_LOCAL(kIter, | 167 WASM_SET_LOCAL( |
168 WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I8(4))))), | 168 kIter, WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I32V_1(4))))), |
169 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), | 169 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), |
170 WASM_GET_LOCAL(kIter))}; | 170 WASM_GET_LOCAL(kIter))}; |
171 | 171 |
172 BitVector* assigned = Analyze(code + 2, code + arraysize(code)); | 172 BitVector* assigned = Analyze(code + 2, code + arraysize(code)); |
173 for (int j = 0; j < assigned->length(); j++) { | 173 for (int j = 0; j < assigned->length(); j++) { |
174 bool expected = j == kIter || j == kSum; | 174 bool expected = j == kIter || j == kSum; |
175 CHECK_EQ(expected, assigned->Contains(j)); | 175 CHECK_EQ(expected, assigned->Contains(j)); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 TEST_F(WasmLoopAssignmentAnalyzerTest, Malformed) { | 179 TEST_F(WasmLoopAssignmentAnalyzerTest, Malformed) { |
180 byte code[] = {kExprLoop, kLocalVoid, kExprF32Neg, kExprBrTable, 0x0e, 'h', | 180 byte code[] = {kExprLoop, kLocalVoid, kExprF32Neg, kExprBrTable, 0x0e, 'h', |
181 'e', 'l', 'l', 'o', ',', ' ', | 181 'e', 'l', 'l', 'o', ',', ' ', |
182 'w', 'o', 'r', 'l', 'd', '!'}; | 182 'w', 'o', 'r', 'l', 'd', '!'}; |
183 BitVector* assigned = Analyze(code, code + arraysize(code)); | 183 BitVector* assigned = Analyze(code, code + arraysize(code)); |
184 CHECK_NULL(assigned); | 184 CHECK_NULL(assigned); |
185 } | 185 } |
186 | 186 |
187 TEST_F(WasmLoopAssignmentAnalyzerTest, regress_642867) { | 187 TEST_F(WasmLoopAssignmentAnalyzerTest, regress_642867) { |
188 static const byte code[] = { | 188 static const byte code[] = { |
189 WASM_LOOP(WASM_ZERO, kExprSetLocal, 0xfa, 0xff, 0xff, 0xff, | 189 WASM_LOOP(WASM_ZERO, kExprSetLocal, 0xfa, 0xff, 0xff, 0xff, |
190 0x0f)}; // local index LEB128 0xfffffffa | 190 0x0f)}; // local index LEB128 0xfffffffa |
191 // Just make sure that the analysis does not crash. | 191 // Just make sure that the analysis does not crash. |
192 Analyze(code, code + arraysize(code)); | 192 Analyze(code, code + arraysize(code)); |
193 } | 193 } |
194 | 194 |
195 } // namespace wasm | 195 } // namespace wasm |
196 } // namespace internal | 196 } // namespace internal |
197 } // namespace v8 | 197 } // namespace v8 |
OLD | NEW |