| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
| 9 #include "test/cctest/compiler/graph-builder-tester.h" | 9 #include "test/cctest/compiler/graph-builder-tester.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 ValueMatcher<double> m(n); | 58 ValueMatcher<double> m(n); |
| 59 CHECK_EQ(IrOpcode::kNumberConstant, n->opcode()); | 59 CHECK_EQ(IrOpcode::kNumberConstant, n->opcode()); |
| 60 CHECK(m.HasValue()); | 60 CHECK(m.HasValue()); |
| 61 CHECK_EQ(expected, m.Value()); | 61 CHECK_EQ(expected, m.Value()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 Node* Parameter(int index = 0) { | 64 Node* Parameter(int index = 0) { |
| 65 return graph()->NewNode(common()->Parameter(index), graph()->start()); | 65 return graph()->NewNode(common()->Parameter(index), graph()->start()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void CheckTypeError(RepTypeUnion from, RepTypeUnion to) { | 68 void CheckTypeError(MachineTypeUnion from, MachineTypeUnion to) { |
| 69 changer()->testing_type_errors_ = true; | 69 changer()->testing_type_errors_ = true; |
| 70 changer()->type_error_ = false; | 70 changer()->type_error_ = false; |
| 71 Node* n = Parameter(0); | 71 Node* n = Parameter(0); |
| 72 Node* c = changer()->GetRepresentationFor(n, from, to); | 72 Node* c = changer()->GetRepresentationFor(n, from, to); |
| 73 CHECK(changer()->type_error_); |
| 73 CHECK_EQ(n, c); | 74 CHECK_EQ(n, c); |
| 74 CHECK(changer()->type_error_); | |
| 75 } | 75 } |
| 76 | 76 |
| 77 void CheckNop(RepTypeUnion from, RepTypeUnion to) { | 77 void CheckNop(MachineTypeUnion from, MachineTypeUnion to) { |
| 78 Node* n = Parameter(0); | 78 Node* n = Parameter(0); |
| 79 Node* c = changer()->GetRepresentationFor(n, from, to); | 79 Node* c = changer()->GetRepresentationFor(n, from, to); |
| 80 CHECK_EQ(n, c); | 80 CHECK_EQ(n, c); |
| 81 } | 81 } |
| 82 }; | 82 }; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 } // namespace v8::internal::compiler | 85 } // namespace v8::internal::compiler |
| 86 | 86 |
| 87 | 87 |
| 88 static const RepType all_reps[] = {rBit, rWord32, rWord64, rFloat64, rTagged}; | 88 static const MachineType all_reps[] = {rBit, rWord32, rWord64, rFloat64, |
| 89 rTagged}; |
| 89 | 90 |
| 90 | 91 |
| 91 // TODO(titzer): lift this to ValueHelper | 92 // TODO(titzer): lift this to ValueHelper |
| 92 static const double double_inputs[] = { | 93 static const double double_inputs[] = { |
| 93 0.0, -0.0, 1.0, -1.0, 0.1, 1.4, -1.7, | 94 0.0, -0.0, 1.0, -1.0, 0.1, 1.4, -1.7, |
| 94 2, 5, 6, 982983, 888, -999.8, 3.1e7, | 95 2, 5, 6, 982983, 888, -999.8, 3.1e7, |
| 95 -2e66, 2.3e124, -12e73, V8_INFINITY, -V8_INFINITY}; | 96 -2e66, 2.3e124, -12e73, V8_INFINITY, -V8_INFINITY}; |
| 96 | 97 |
| 97 | 98 |
| 98 static const int32_t int32_inputs[] = { | 99 static const int32_t int32_inputs[] = { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 150 } |
| 150 | 151 |
| 151 for (size_t i = 0; i < ARRAY_SIZE(uint32_inputs); i++) { | 152 for (size_t i = 0; i < ARRAY_SIZE(uint32_inputs); i++) { |
| 152 Node* n = r.jsgraph()->Int32Constant(uint32_inputs[i]); | 153 Node* n = r.jsgraph()->Int32Constant(uint32_inputs[i]); |
| 153 Node* c = r.changer()->GetRepresentationFor(n, rWord32 | tUint32, rTagged); | 154 Node* c = r.changer()->GetRepresentationFor(n, rWord32 | tUint32, rTagged); |
| 154 r.CheckNumberConstant(c, static_cast<double>(uint32_inputs[i])); | 155 r.CheckNumberConstant(c, static_cast<double>(uint32_inputs[i])); |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 | 158 |
| 158 | 159 |
| 159 static void CheckChange(IrOpcode::Value expected, RepTypeUnion from, | 160 static void CheckChange(IrOpcode::Value expected, MachineTypeUnion from, |
| 160 RepTypeUnion to) { | 161 MachineTypeUnion to) { |
| 161 RepresentationChangerTester r; | 162 RepresentationChangerTester r; |
| 162 | 163 |
| 163 Node* n = r.Parameter(); | 164 Node* n = r.Parameter(); |
| 164 Node* c = r.changer()->GetRepresentationFor(n, from, to); | 165 Node* c = r.changer()->GetRepresentationFor(n, from, to); |
| 165 | 166 |
| 166 CHECK_NE(c, n); | 167 CHECK_NE(c, n); |
| 167 CHECK_EQ(expected, c->opcode()); | 168 CHECK_EQ(expected, c->opcode()); |
| 168 CHECK_EQ(n, c->InputAt(0)); | 169 CHECK_EQ(n, c->InputAt(0)); |
| 169 } | 170 } |
| 170 | 171 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 for (size_t i = 0; i < ARRAY_SIZE(all_reps); i++) { | 208 for (size_t i = 0; i < ARRAY_SIZE(all_reps); i++) { |
| 208 r.CheckNop(all_reps[i], all_reps[i]); | 209 r.CheckNop(all_reps[i], all_reps[i]); |
| 209 } | 210 } |
| 210 | 211 |
| 211 // 32-bit or 64-bit words can be used as branch conditions (rBit). | 212 // 32-bit or 64-bit words can be used as branch conditions (rBit). |
| 212 r.CheckNop(rWord32, rBit); | 213 r.CheckNop(rWord32, rBit); |
| 213 r.CheckNop(rWord32, rBit | tBool); | 214 r.CheckNop(rWord32, rBit | tBool); |
| 214 r.CheckNop(rWord64, rBit); | 215 r.CheckNop(rWord64, rBit); |
| 215 r.CheckNop(rWord64, rBit | tBool); | 216 r.CheckNop(rWord64, rBit | tBool); |
| 216 | 217 |
| 218 // 32-bit words can be used as smaller word sizes and vice versa, because |
| 219 // loads from memory implicitly sign or zero extend the value to the |
| 220 // full machine word size, and stores implicitly truncate. |
| 221 r.CheckNop(rWord32, rWord8); |
| 222 r.CheckNop(rWord32, rWord16); |
| 223 r.CheckNop(rWord32, rWord32); |
| 224 r.CheckNop(rWord8, rWord32); |
| 225 r.CheckNop(rWord16, rWord32); |
| 226 |
| 217 // rBit (result of comparison) is implicitly a wordish thing. | 227 // rBit (result of comparison) is implicitly a wordish thing. |
| 228 r.CheckNop(rBit, rWord8); |
| 229 r.CheckNop(rBit | tBool, rWord8); |
| 230 r.CheckNop(rBit, rWord16); |
| 231 r.CheckNop(rBit | tBool, rWord16); |
| 218 r.CheckNop(rBit, rWord32); | 232 r.CheckNop(rBit, rWord32); |
| 219 r.CheckNop(rBit | tBool, rWord32); | 233 r.CheckNop(rBit | tBool, rWord32); |
| 220 r.CheckNop(rBit, rWord64); | 234 r.CheckNop(rBit, rWord64); |
| 221 r.CheckNop(rBit | tBool, rWord64); | 235 r.CheckNop(rBit | tBool, rWord64); |
| 222 } | 236 } |
| 223 | 237 |
| 224 | 238 |
| 225 TEST(TypeErrors) { | 239 TEST(TypeErrors) { |
| 226 RepresentationChangerTester r; | 240 RepresentationChangerTester r; |
| 227 | 241 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // rW64 | 281 // rW64 |
| 268 // tIrW64 | 282 // tIrW64 |
| 269 // tUrW64 | 283 // tUrW64 |
| 270 // rF64 | 284 // rF64 |
| 271 // tIrF64 | 285 // tIrF64 |
| 272 // tUrF64 | 286 // tUrF64 |
| 273 // tArF64 | 287 // tArF64 |
| 274 // rT | 288 // rT |
| 275 // tArT | 289 // tArT |
| 276 } | 290 } |
| OLD | NEW |