| 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/cctest/wasm/test-signatures.h" | 9 #include "test/cctest/wasm/test-signatures.h" |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty0) { | 35 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty0) { |
| 36 byte code[] = { 0 }; | 36 byte code[] = { 0 }; |
| 37 BitVector* assigned = Analyze(code, code); | 37 BitVector* assigned = Analyze(code, code); |
| 38 CHECK_NULL(assigned); | 38 CHECK_NULL(assigned); |
| 39 } | 39 } |
| 40 | 40 |
| 41 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty1) { | 41 TEST_F(WasmLoopAssignmentAnalyzerTest, Empty1) { |
| 42 byte code[] = {kExprLoop, 0}; | 42 byte code[] = {kExprLoop, kLocalVoid, 0}; |
| 43 for (int i = 0; i < 5; i++) { | 43 for (int i = 0; i < 5; i++) { |
| 44 BitVector* assigned = Analyze(code, code + arraysize(code)); | 44 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 45 for (int j = 0; j < assigned->length(); j++) { | 45 for (int j = 0; j < assigned->length(); j++) { |
| 46 CHECK_EQ(false, assigned->Contains(j)); | 46 CHECK_EQ(false, assigned->Contains(j)); |
| 47 } | 47 } |
| 48 num_locals++; | 48 num_locals++; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST_F(WasmLoopAssignmentAnalyzerTest, One) { | 52 TEST_F(WasmLoopAssignmentAnalyzerTest, One) { |
| 53 num_locals = 5; | 53 num_locals = 5; |
| 54 for (int i = 0; i < 5; i++) { | 54 for (int i = 0; i < 5; i++) { |
| 55 byte code[] = {WASM_LOOP(WASM_SET_ZERO(i))}; | 55 byte code[] = {WASM_LOOP(WASM_SET_ZERO(i))}; |
| 56 BitVector* assigned = Analyze(code, code + arraysize(code)); | 56 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 57 for (int j = 0; j < assigned->length(); j++) { | 57 for (int j = 0; j < assigned->length(); j++) { |
| 58 CHECK_EQ(j == i, assigned->Contains(j)); | 58 CHECK_EQ(j == i, assigned->Contains(j)); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(WasmLoopAssignmentAnalyzerTest, TeeOne) { |
| 64 num_locals = 5; |
| 65 for (int i = 0; i < 5; i++) { |
| 66 byte code[] = {WASM_LOOP(WASM_TEE_LOCAL(i, WASM_ZERO))}; |
| 67 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 68 for (int j = 0; j < assigned->length(); j++) { |
| 69 CHECK_EQ(j == i, assigned->Contains(j)); |
| 70 } |
| 71 } |
| 72 } |
| 73 |
| 63 TEST_F(WasmLoopAssignmentAnalyzerTest, OneBeyond) { | 74 TEST_F(WasmLoopAssignmentAnalyzerTest, OneBeyond) { |
| 64 num_locals = 5; | 75 num_locals = 5; |
| 65 for (int i = 0; i < 5; i++) { | 76 for (int i = 0; i < 5; i++) { |
| 66 byte code[] = {WASM_LOOP(WASM_SET_ZERO(i)), WASM_SET_ZERO(1)}; | 77 byte code[] = {WASM_LOOP(WASM_SET_ZERO(i)), WASM_SET_ZERO(1)}; |
| 67 BitVector* assigned = Analyze(code, code + arraysize(code)); | 78 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 68 for (int j = 0; j < assigned->length(); j++) { | 79 for (int j = 0; j < assigned->length(); j++) { |
| 69 CHECK_EQ(j == i, assigned->Contains(j)); | 80 CHECK_EQ(j == i, assigned->Contains(j)); |
| 70 } | 81 } |
| 71 } | 82 } |
| 72 } | 83 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 byte code[] = {WASM_LOOP( | 102 byte code[] = {WASM_LOOP( |
| 92 WASM_IF_ELSE(WASM_SET_ZERO(0), WASM_SET_ZERO(i), WASM_SET_ZERO(1)))}; | 103 WASM_IF_ELSE(WASM_SET_ZERO(0), WASM_SET_ZERO(i), WASM_SET_ZERO(1)))}; |
| 93 BitVector* assigned = Analyze(code, code + arraysize(code)); | 104 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 94 for (int j = 0; j < assigned->length(); j++) { | 105 for (int j = 0; j < assigned->length(); j++) { |
| 95 bool expected = i == j || j == 0 || j == 1; | 106 bool expected = i == j || j == 0 || j == 1; |
| 96 CHECK_EQ(expected, assigned->Contains(j)); | 107 CHECK_EQ(expected, assigned->Contains(j)); |
| 97 } | 108 } |
| 98 } | 109 } |
| 99 } | 110 } |
| 100 | 111 |
| 101 static byte LEBByte(uint32_t val, byte which) { | |
| 102 byte b = (val >> (which * 7)) & 0x7F; | |
| 103 if (val >> ((which + 1) * 7)) b |= 0x80; | |
| 104 return b; | |
| 105 } | |
| 106 | |
| 107 TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) { | 112 TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) { |
| 108 num_locals = 65000; | 113 num_locals = 65000; |
| 109 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)) { |
| 110 byte code[] = {kExprLoop, | 115 byte code[] = {WASM_LOOP(WASM_I8(11), kExprSetLocal, U32V_3(i))}; |
| 111 1, | |
| 112 kExprSetLocal, | |
| 113 LEBByte(i, 0), | |
| 114 LEBByte(i, 1), | |
| 115 LEBByte(i, 2), | |
| 116 11, | |
| 117 12, | |
| 118 13}; | |
| 119 | 116 |
| 120 BitVector* assigned = Analyze(code, code + arraysize(code)); | 117 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 121 for (int j = 0; j < assigned->length(); j++) { | 118 for (int j = 0; j < assigned->length(); j++) { |
| 122 bool expected = i == j; | 119 bool expected = i == j; |
| 123 CHECK_EQ(expected, assigned->Contains(j)); | 120 CHECK_EQ(expected, assigned->Contains(j)); |
| 124 } | 121 } |
| 125 } | 122 } |
| 126 } | 123 } |
| 127 | 124 |
| 128 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) { | 125 TEST_F(WasmLoopAssignmentAnalyzerTest, Break) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 WASM_BLOCK( | 162 WASM_BLOCK( |
| 166 WASM_SET_LOCAL( | 163 WASM_SET_LOCAL( |
| 167 kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), | 164 kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), |
| 168 WASM_LOAD_MEM(MachineType::Float32(), | 165 WASM_LOAD_MEM(MachineType::Float32(), |
| 169 WASM_GET_LOCAL(kIter)))), | 166 WASM_GET_LOCAL(kIter)))), |
| 170 WASM_SET_LOCAL(kIter, | 167 WASM_SET_LOCAL(kIter, |
| 171 WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I8(4))))), | 168 WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I8(4))))), |
| 172 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), | 169 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), |
| 173 WASM_GET_LOCAL(kIter))}; | 170 WASM_GET_LOCAL(kIter))}; |
| 174 | 171 |
| 175 BitVector* assigned = Analyze(code + 1, code + arraysize(code)); | 172 BitVector* assigned = Analyze(code + 2, code + arraysize(code)); |
| 176 for (int j = 0; j < assigned->length(); j++) { | 173 for (int j = 0; j < assigned->length(); j++) { |
| 177 bool expected = j == kIter || j == kSum; | 174 bool expected = j == kIter || j == kSum; |
| 178 CHECK_EQ(expected, assigned->Contains(j)); | 175 CHECK_EQ(expected, assigned->Contains(j)); |
| 179 } | 176 } |
| 180 } | 177 } |
| 181 | 178 |
| 182 TEST_F(WasmLoopAssignmentAnalyzerTest, Malformed) { | 179 TEST_F(WasmLoopAssignmentAnalyzerTest, Malformed) { |
| 183 byte code[] = {kExprLoop, kExprF32Neg, kExprBrTable, 0x0e, 'h', 'e', | 180 byte code[] = {kExprLoop, kLocalVoid, kExprF32Neg, kExprBrTable, 0x0e, 'h', |
| 184 'l', 'l', 'o', ',', ' ', 'w', | 181 'e', 'l', 'l', 'o', ',', ' ', |
| 185 'o', 'r', 'l', 'd', '!'}; | 182 'w', 'o', 'r', 'l', 'd', '!'}; |
| 186 BitVector* assigned = Analyze(code, code + arraysize(code)); | 183 BitVector* assigned = Analyze(code, code + arraysize(code)); |
| 187 CHECK_NULL(assigned); | 184 CHECK_NULL(assigned); |
| 188 } | 185 } |
| 189 | 186 |
| 190 TEST_F(WasmLoopAssignmentAnalyzerTest, regress_642867) { | 187 TEST_F(WasmLoopAssignmentAnalyzerTest, regress_642867) { |
| 191 static const byte code[] = { | 188 static const byte code[] = { |
| 192 WASM_LOOP(WASM_ZERO, kExprSetLocal, 0xfa, 0xff, 0xff, 0xff, | 189 WASM_LOOP(WASM_ZERO, kExprSetLocal, 0xfa, 0xff, 0xff, 0xff, |
| 193 0x0f)}; // local index LEB128 0xfffffffa | 190 0x0f)}; // local index LEB128 0xfffffffa |
| 194 // Just make sure that the analysis does not crash. | 191 // Just make sure that the analysis does not crash. |
| 195 Analyze(code, code + arraysize(code)); | 192 Analyze(code, code + arraysize(code)); |
| 196 } | 193 } |
| 197 | 194 |
| 198 } // namespace wasm | 195 } // namespace wasm |
| 199 } // namespace internal | 196 } // namespace internal |
| 200 } // namespace v8 | 197 } // namespace v8 |
| OLD | NEW |