| 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 "test/cctest/cctest.h" | 7 #include "test/cctest/cctest.h" |
| 8 #include "test/cctest/compiler/codegen-tester.h" | 8 #include "test/cctest/compiler/codegen-tester.h" |
| 9 #include "test/cctest/compiler/graph-builder-tester.h" | 9 #include "test/cctest/compiler/graph-builder-tester.h" |
| 10 #include "test/cctest/compiler/value-helper.h" | 10 #include "test/cctest/compiler/value-helper.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 CHECK(m.HasValue()); | 76 CHECK(m.HasValue()); |
| 77 CHECK_DOUBLE_EQ(expected, m.Value()); | 77 CHECK_DOUBLE_EQ(expected, m.Value()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 Node* Parameter(int index = 0) { | 80 Node* Parameter(int index = 0) { |
| 81 Node* n = graph()->NewNode(common()->Parameter(index), graph()->start()); | 81 Node* n = graph()->NewNode(common()->Parameter(index), graph()->start()); |
| 82 NodeProperties::SetType(n, Type::Any()); | 82 NodeProperties::SetType(n, Type::Any()); |
| 83 return n; | 83 return n; |
| 84 } | 84 } |
| 85 | 85 |
| 86 Node* Return(Node* input) { |
| 87 Node* n = graph()->NewNode(common()->Return(), input, graph()->start(), |
| 88 graph()->start()); |
| 89 return n; |
| 90 } |
| 91 |
| 86 void CheckTypeError(MachineRepresentation from, Type* from_type, | 92 void CheckTypeError(MachineRepresentation from, Type* from_type, |
| 87 MachineRepresentation to) { | 93 MachineRepresentation to) { |
| 88 changer()->testing_type_errors_ = true; | 94 changer()->testing_type_errors_ = true; |
| 89 changer()->type_error_ = false; | 95 changer()->type_error_ = false; |
| 90 Node* n = Parameter(0); | 96 Node* n = Parameter(0); |
| 91 Node* c = changer()->GetRepresentationFor(n, from, from_type, to); | 97 Node* use = Return(n); |
| 98 Node* c = changer()->GetRepresentationFor(n, from, from_type, use, |
| 99 UseInfo(to, Truncation::None())); |
| 92 CHECK(changer()->type_error_); | 100 CHECK(changer()->type_error_); |
| 93 CHECK_EQ(n, c); | 101 CHECK_EQ(n, c); |
| 94 } | 102 } |
| 95 | 103 |
| 96 void CheckNop(MachineRepresentation from, Type* from_type, | 104 void CheckNop(MachineRepresentation from, Type* from_type, |
| 97 MachineRepresentation to) { | 105 MachineRepresentation to) { |
| 98 Node* n = Parameter(0); | 106 Node* n = Parameter(0); |
| 99 Node* c = changer()->GetRepresentationFor(n, from, from_type, to); | 107 Node* use = Return(n); |
| 108 Node* c = changer()->GetRepresentationFor(n, from, from_type, use, |
| 109 UseInfo(to, Truncation::None())); |
| 100 CHECK_EQ(n, c); | 110 CHECK_EQ(n, c); |
| 101 } | 111 } |
| 102 }; | 112 }; |
| 103 | 113 |
| 104 | 114 |
| 105 const MachineType kMachineTypes[] = { | 115 const MachineType kMachineTypes[] = { |
| 106 MachineType::Float32(), MachineType::Float64(), MachineType::Int8(), | 116 MachineType::Float32(), MachineType::Float64(), MachineType::Int8(), |
| 107 MachineType::Uint8(), MachineType::Int16(), MachineType::Uint16(), | 117 MachineType::Uint8(), MachineType::Int16(), MachineType::Uint16(), |
| 108 MachineType::Int32(), MachineType::Uint32(), MachineType::Int64(), | 118 MachineType::Int32(), MachineType::Uint32(), MachineType::Int64(), |
| 109 MachineType::Uint64(), MachineType::AnyTagged()}; | 119 MachineType::Uint64(), MachineType::AnyTagged()}; |
| 110 | 120 |
| 111 | 121 |
| 112 TEST(BoolToBit_constant) { | 122 TEST(BoolToBit_constant) { |
| 113 RepresentationChangerTester r; | 123 RepresentationChangerTester r; |
| 114 | 124 |
| 115 Node* true_node = r.jsgraph()->TrueConstant(); | 125 Node* true_node = r.jsgraph()->TrueConstant(); |
| 126 Node* true_use = r.Return(true_node); |
| 116 Node* true_bit = r.changer()->GetRepresentationFor( | 127 Node* true_bit = r.changer()->GetRepresentationFor( |
| 117 true_node, MachineRepresentation::kTagged, Type::None(), | 128 true_node, MachineRepresentation::kTagged, Type::None(), true_use, |
| 118 MachineRepresentation::kBit); | 129 UseInfo(MachineRepresentation::kBit, Truncation::None())); |
| 119 r.CheckInt32Constant(true_bit, 1); | 130 r.CheckInt32Constant(true_bit, 1); |
| 120 | 131 |
| 121 Node* false_node = r.jsgraph()->FalseConstant(); | 132 Node* false_node = r.jsgraph()->FalseConstant(); |
| 133 Node* false_use = r.Return(false_node); |
| 122 Node* false_bit = r.changer()->GetRepresentationFor( | 134 Node* false_bit = r.changer()->GetRepresentationFor( |
| 123 false_node, MachineRepresentation::kTagged, Type::None(), | 135 false_node, MachineRepresentation::kTagged, Type::None(), false_use, |
| 124 MachineRepresentation::kBit); | 136 UseInfo(MachineRepresentation::kBit, Truncation::None())); |
| 125 r.CheckInt32Constant(false_bit, 0); | 137 r.CheckInt32Constant(false_bit, 0); |
| 126 } | 138 } |
| 127 | 139 |
| 128 | 140 |
| 129 TEST(BitToBool_constant) { | 141 TEST(BitToBool_constant) { |
| 130 RepresentationChangerTester r; | 142 RepresentationChangerTester r; |
| 131 | 143 |
| 132 for (int i = -5; i < 5; i++) { | 144 for (int i = -5; i < 5; i++) { |
| 133 Node* node = r.jsgraph()->Int32Constant(i); | 145 Node* node = r.jsgraph()->Int32Constant(i); |
| 146 Node* use = r.Return(node); |
| 134 Node* val = r.changer()->GetRepresentationFor( | 147 Node* val = r.changer()->GetRepresentationFor( |
| 135 node, MachineRepresentation::kBit, Type::Boolean(), | 148 node, MachineRepresentation::kBit, Type::Boolean(), use, |
| 136 MachineRepresentation::kTagged); | 149 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
| 137 r.CheckHeapConstant(val, i == 0 ? r.isolate()->heap()->false_value() | 150 r.CheckHeapConstant(val, i == 0 ? r.isolate()->heap()->false_value() |
| 138 : r.isolate()->heap()->true_value()); | 151 : r.isolate()->heap()->true_value()); |
| 139 } | 152 } |
| 140 } | 153 } |
| 141 | 154 |
| 142 | 155 |
| 143 TEST(ToTagged_constant) { | 156 TEST(ToTagged_constant) { |
| 144 RepresentationChangerTester r; | 157 RepresentationChangerTester r; |
| 145 | 158 |
| 146 { | 159 { |
| 147 FOR_FLOAT64_INPUTS(i) { | 160 FOR_FLOAT64_INPUTS(i) { |
| 148 Node* n = r.jsgraph()->Float64Constant(*i); | 161 Node* n = r.jsgraph()->Float64Constant(*i); |
| 149 Node* c = r.changer()->GetRepresentationFor( | 162 Node* use = r.Return(n); |
| 150 n, MachineRepresentation::kFloat64, Type::None(), | 163 Node* c = r.changer()->GetRepresentationFor( |
| 151 MachineRepresentation::kTagged); | 164 n, MachineRepresentation::kFloat64, Type::None(), use, |
| 152 r.CheckNumberConstant(c, *i); | 165 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
| 166 r.CheckNumberConstant(c, *i); |
| 153 } | 167 } |
| 154 } | 168 } |
| 155 | 169 |
| 156 { | 170 { |
| 157 FOR_FLOAT64_INPUTS(i) { | 171 FOR_FLOAT64_INPUTS(i) { |
| 158 Node* n = r.jsgraph()->Constant(*i); | 172 Node* n = r.jsgraph()->Constant(*i); |
| 159 Node* c = r.changer()->GetRepresentationFor( | 173 Node* use = r.Return(n); |
| 160 n, MachineRepresentation::kFloat64, Type::None(), | 174 Node* c = r.changer()->GetRepresentationFor( |
| 161 MachineRepresentation::kTagged); | 175 n, MachineRepresentation::kFloat64, Type::None(), use, |
| 162 r.CheckNumberConstant(c, *i); | 176 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
| 177 r.CheckNumberConstant(c, *i); |
| 163 } | 178 } |
| 164 } | 179 } |
| 165 | 180 |
| 166 { | 181 { |
| 167 FOR_FLOAT32_INPUTS(i) { | 182 FOR_FLOAT32_INPUTS(i) { |
| 168 Node* n = r.jsgraph()->Float32Constant(*i); | 183 Node* n = r.jsgraph()->Float32Constant(*i); |
| 169 Node* c = r.changer()->GetRepresentationFor( | 184 Node* use = r.Return(n); |
| 170 n, MachineRepresentation::kFloat32, Type::None(), | 185 Node* c = r.changer()->GetRepresentationFor( |
| 171 MachineRepresentation::kTagged); | 186 n, MachineRepresentation::kFloat32, Type::None(), use, |
| 172 r.CheckNumberConstant(c, *i); | 187 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
| 188 r.CheckNumberConstant(c, *i); |
| 173 } | 189 } |
| 174 } | 190 } |
| 175 | 191 |
| 176 { | 192 { |
| 177 FOR_INT32_INPUTS(i) { | 193 FOR_INT32_INPUTS(i) { |
| 178 Node* n = r.jsgraph()->Int32Constant(*i); | 194 Node* n = r.jsgraph()->Int32Constant(*i); |
| 179 Node* c = r.changer()->GetRepresentationFor( | 195 Node* use = r.Return(n); |
| 180 n, MachineRepresentation::kWord32, Type::Signed32(), | 196 Node* c = r.changer()->GetRepresentationFor( |
| 181 MachineRepresentation::kTagged); | 197 n, MachineRepresentation::kWord32, Type::Signed32(), use, |
| 182 r.CheckNumberConstant(c, *i); | 198 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
| 199 r.CheckNumberConstant(c, *i); |
| 183 } | 200 } |
| 184 } | 201 } |
| 185 | 202 |
| 186 { | 203 { |
| 187 FOR_UINT32_INPUTS(i) { | 204 FOR_UINT32_INPUTS(i) { |
| 188 Node* n = r.jsgraph()->Int32Constant(*i); | 205 Node* n = r.jsgraph()->Int32Constant(*i); |
| 206 Node* use = r.Return(n); |
| 189 Node* c = r.changer()->GetRepresentationFor( | 207 Node* c = r.changer()->GetRepresentationFor( |
| 190 n, MachineRepresentation::kWord32, Type::Unsigned32(), | 208 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, |
| 191 MachineRepresentation::kTagged); | 209 UseInfo(MachineRepresentation::kTagged, Truncation::None())); |
| 192 r.CheckNumberConstant(c, *i); | 210 r.CheckNumberConstant(c, *i); |
| 193 } | 211 } |
| 194 } | 212 } |
| 195 } | 213 } |
| 196 | 214 |
| 197 | 215 |
| 198 TEST(ToFloat64_constant) { | 216 TEST(ToFloat64_constant) { |
| 199 RepresentationChangerTester r; | 217 RepresentationChangerTester r; |
| 200 | 218 |
| 201 { | 219 { |
| 202 FOR_FLOAT64_INPUTS(i) { | 220 FOR_FLOAT64_INPUTS(i) { |
| 203 Node* n = r.jsgraph()->Float64Constant(*i); | 221 Node* n = r.jsgraph()->Float64Constant(*i); |
| 204 Node* c = r.changer()->GetRepresentationFor( | 222 Node* use = r.Return(n); |
| 205 n, MachineRepresentation::kFloat64, Type::None(), | 223 Node* c = r.changer()->GetRepresentationFor( |
| 206 MachineRepresentation::kFloat64); | 224 n, MachineRepresentation::kFloat64, Type::None(), use, |
| 207 CHECK_EQ(n, c); | 225 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
| 226 CHECK_EQ(n, c); |
| 208 } | 227 } |
| 209 } | 228 } |
| 210 | 229 |
| 211 { | 230 { |
| 212 FOR_FLOAT64_INPUTS(i) { | 231 FOR_FLOAT64_INPUTS(i) { |
| 213 Node* n = r.jsgraph()->Constant(*i); | 232 Node* n = r.jsgraph()->Constant(*i); |
| 214 Node* c = r.changer()->GetRepresentationFor( | 233 Node* use = r.Return(n); |
| 215 n, MachineRepresentation::kTagged, Type::None(), | 234 Node* c = r.changer()->GetRepresentationFor( |
| 216 MachineRepresentation::kFloat64); | 235 n, MachineRepresentation::kTagged, Type::None(), use, |
| 217 r.CheckFloat64Constant(c, *i); | 236 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
| 237 r.CheckFloat64Constant(c, *i); |
| 218 } | 238 } |
| 219 } | 239 } |
| 220 | 240 |
| 221 { | 241 { |
| 222 FOR_FLOAT32_INPUTS(i) { | 242 FOR_FLOAT32_INPUTS(i) { |
| 223 Node* n = r.jsgraph()->Float32Constant(*i); | 243 Node* n = r.jsgraph()->Float32Constant(*i); |
| 224 Node* c = r.changer()->GetRepresentationFor( | 244 Node* use = r.Return(n); |
| 225 n, MachineRepresentation::kFloat32, Type::None(), | 245 Node* c = r.changer()->GetRepresentationFor( |
| 226 MachineRepresentation::kFloat64); | 246 n, MachineRepresentation::kFloat32, Type::None(), use, |
| 227 r.CheckFloat64Constant(c, *i); | 247 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
| 248 r.CheckFloat64Constant(c, *i); |
| 228 } | 249 } |
| 229 } | 250 } |
| 230 | 251 |
| 231 { | 252 { |
| 232 FOR_INT32_INPUTS(i) { | 253 FOR_INT32_INPUTS(i) { |
| 233 Node* n = r.jsgraph()->Int32Constant(*i); | 254 Node* n = r.jsgraph()->Int32Constant(*i); |
| 234 Node* c = r.changer()->GetRepresentationFor( | 255 Node* use = r.Return(n); |
| 235 n, MachineRepresentation::kWord32, Type::Signed32(), | 256 Node* c = r.changer()->GetRepresentationFor( |
| 236 MachineRepresentation::kFloat64); | 257 n, MachineRepresentation::kWord32, Type::Signed32(), use, |
| 237 r.CheckFloat64Constant(c, *i); | 258 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
| 259 r.CheckFloat64Constant(c, *i); |
| 238 } | 260 } |
| 239 } | 261 } |
| 240 | 262 |
| 241 { | 263 { |
| 242 FOR_UINT32_INPUTS(i) { | 264 FOR_UINT32_INPUTS(i) { |
| 243 Node* n = r.jsgraph()->Int32Constant(*i); | 265 Node* n = r.jsgraph()->Int32Constant(*i); |
| 266 Node* use = r.Return(n); |
| 244 Node* c = r.changer()->GetRepresentationFor( | 267 Node* c = r.changer()->GetRepresentationFor( |
| 245 n, MachineRepresentation::kWord32, Type::Unsigned32(), | 268 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, |
| 246 MachineRepresentation::kFloat64); | 269 UseInfo(MachineRepresentation::kFloat64, Truncation::None())); |
| 247 r.CheckFloat64Constant(c, *i); | 270 r.CheckFloat64Constant(c, *i); |
| 248 } | 271 } |
| 249 } | 272 } |
| 250 } | 273 } |
| 251 | 274 |
| 252 | 275 |
| 253 static bool IsFloat32Int32(int32_t val) { | 276 static bool IsFloat32Int32(int32_t val) { |
| 254 return val >= -(1 << 23) && val <= (1 << 23); | 277 return val >= -(1 << 23) && val <= (1 << 23); |
| 255 } | 278 } |
| 256 | 279 |
| 257 | 280 |
| 258 static bool IsFloat32Uint32(uint32_t val) { return val <= (1 << 23); } | 281 static bool IsFloat32Uint32(uint32_t val) { return val <= (1 << 23); } |
| 259 | 282 |
| 260 | 283 |
| 261 TEST(ToFloat32_constant) { | 284 TEST(ToFloat32_constant) { |
| 262 RepresentationChangerTester r; | 285 RepresentationChangerTester r; |
| 263 | 286 |
| 264 { | 287 { |
| 265 FOR_FLOAT32_INPUTS(i) { | 288 FOR_FLOAT32_INPUTS(i) { |
| 266 Node* n = r.jsgraph()->Float32Constant(*i); | 289 Node* n = r.jsgraph()->Float32Constant(*i); |
| 267 Node* c = r.changer()->GetRepresentationFor( | 290 Node* use = r.Return(n); |
| 268 n, MachineRepresentation::kFloat32, Type::None(), | 291 Node* c = r.changer()->GetRepresentationFor( |
| 269 MachineRepresentation::kFloat32); | 292 n, MachineRepresentation::kFloat32, Type::None(), use, |
| 270 CHECK_EQ(n, c); | 293 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
| 294 CHECK_EQ(n, c); |
| 271 } | 295 } |
| 272 } | 296 } |
| 273 | 297 |
| 274 { | 298 { |
| 275 FOR_FLOAT32_INPUTS(i) { | 299 FOR_FLOAT32_INPUTS(i) { |
| 276 Node* n = r.jsgraph()->Constant(*i); | 300 Node* n = r.jsgraph()->Constant(*i); |
| 277 Node* c = r.changer()->GetRepresentationFor( | 301 Node* use = r.Return(n); |
| 278 n, MachineRepresentation::kTagged, Type::None(), | 302 Node* c = r.changer()->GetRepresentationFor( |
| 279 MachineRepresentation::kFloat32); | 303 n, MachineRepresentation::kTagged, Type::None(), use, |
| 280 r.CheckFloat32Constant(c, *i); | 304 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
| 305 r.CheckFloat32Constant(c, *i); |
| 281 } | 306 } |
| 282 } | 307 } |
| 283 | 308 |
| 284 { | 309 { |
| 285 FOR_FLOAT32_INPUTS(i) { | 310 FOR_FLOAT32_INPUTS(i) { |
| 286 Node* n = r.jsgraph()->Float64Constant(*i); | 311 Node* n = r.jsgraph()->Float64Constant(*i); |
| 287 Node* c = r.changer()->GetRepresentationFor( | 312 Node* use = r.Return(n); |
| 288 n, MachineRepresentation::kFloat64, Type::None(), | 313 Node* c = r.changer()->GetRepresentationFor( |
| 289 MachineRepresentation::kFloat32); | 314 n, MachineRepresentation::kFloat64, Type::None(), use, |
| 290 r.CheckFloat32Constant(c, *i); | 315 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
| 316 r.CheckFloat32Constant(c, *i); |
| 291 } | 317 } |
| 292 } | 318 } |
| 293 | 319 |
| 294 { | 320 { |
| 295 FOR_INT32_INPUTS(i) { | 321 FOR_INT32_INPUTS(i) { |
| 296 if (!IsFloat32Int32(*i)) continue; | 322 if (!IsFloat32Int32(*i)) continue; |
| 297 Node* n = r.jsgraph()->Int32Constant(*i); | 323 Node* n = r.jsgraph()->Int32Constant(*i); |
| 324 Node* use = r.Return(n); |
| 298 Node* c = r.changer()->GetRepresentationFor( | 325 Node* c = r.changer()->GetRepresentationFor( |
| 299 n, MachineRepresentation::kWord32, Type::Signed32(), | 326 n, MachineRepresentation::kWord32, Type::Signed32(), use, |
| 300 MachineRepresentation::kFloat32); | 327 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
| 301 r.CheckFloat32Constant(c, static_cast<float>(*i)); | 328 r.CheckFloat32Constant(c, static_cast<float>(*i)); |
| 302 } | 329 } |
| 303 } | 330 } |
| 304 | 331 |
| 305 { | 332 { |
| 306 FOR_UINT32_INPUTS(i) { | 333 FOR_UINT32_INPUTS(i) { |
| 307 if (!IsFloat32Uint32(*i)) continue; | 334 if (!IsFloat32Uint32(*i)) continue; |
| 308 Node* n = r.jsgraph()->Int32Constant(*i); | 335 Node* n = r.jsgraph()->Int32Constant(*i); |
| 336 Node* use = r.Return(n); |
| 309 Node* c = r.changer()->GetRepresentationFor( | 337 Node* c = r.changer()->GetRepresentationFor( |
| 310 n, MachineRepresentation::kWord32, Type::Unsigned32(), | 338 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, |
| 311 MachineRepresentation::kFloat32); | 339 UseInfo(MachineRepresentation::kFloat32, Truncation::None())); |
| 312 r.CheckFloat32Constant(c, static_cast<float>(*i)); | 340 r.CheckFloat32Constant(c, static_cast<float>(*i)); |
| 313 } | 341 } |
| 314 } | 342 } |
| 315 } | 343 } |
| 316 | 344 |
| 317 | 345 |
| 318 TEST(ToInt32_constant) { | 346 TEST(ToInt32_constant) { |
| 319 RepresentationChangerTester r; | 347 RepresentationChangerTester r; |
| 320 | 348 |
| 321 { | 349 { |
| 322 FOR_INT32_INPUTS(i) { | 350 FOR_INT32_INPUTS(i) { |
| 323 Node* n = r.jsgraph()->Int32Constant(*i); | 351 Node* n = r.jsgraph()->Int32Constant(*i); |
| 324 Node* c = r.changer()->GetRepresentationFor( | 352 Node* use = r.Return(n); |
| 325 n, MachineRepresentation::kWord32, Type::Signed32(), | 353 Node* c = r.changer()->GetRepresentationFor( |
| 326 MachineRepresentation::kWord32); | 354 n, MachineRepresentation::kWord32, Type::Signed32(), use, |
| 327 r.CheckInt32Constant(c, *i); | 355 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 356 r.CheckInt32Constant(c, *i); |
| 328 } | 357 } |
| 329 } | 358 } |
| 330 | 359 |
| 331 { | 360 { |
| 332 FOR_INT32_INPUTS(i) { | 361 FOR_INT32_INPUTS(i) { |
| 333 if (!IsFloat32Int32(*i)) continue; | 362 if (!IsFloat32Int32(*i)) continue; |
| 334 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); | 363 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); |
| 364 Node* use = r.Return(n); |
| 335 Node* c = r.changer()->GetRepresentationFor( | 365 Node* c = r.changer()->GetRepresentationFor( |
| 336 n, MachineRepresentation::kFloat32, Type::Signed32(), | 366 n, MachineRepresentation::kFloat32, Type::Signed32(), use, |
| 337 MachineRepresentation::kWord32); | 367 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 338 r.CheckInt32Constant(c, *i); | 368 r.CheckInt32Constant(c, *i); |
| 339 } | 369 } |
| 340 } | 370 } |
| 341 | 371 |
| 342 { | 372 { |
| 343 FOR_INT32_INPUTS(i) { | 373 FOR_INT32_INPUTS(i) { |
| 344 Node* n = r.jsgraph()->Float64Constant(*i); | 374 Node* n = r.jsgraph()->Float64Constant(*i); |
| 345 Node* c = r.changer()->GetRepresentationFor( | 375 Node* use = r.Return(n); |
| 346 n, MachineRepresentation::kFloat64, Type::Signed32(), | 376 Node* c = r.changer()->GetRepresentationFor( |
| 347 MachineRepresentation::kWord32); | 377 n, MachineRepresentation::kFloat64, Type::Signed32(), use, |
| 348 r.CheckInt32Constant(c, *i); | 378 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 379 r.CheckInt32Constant(c, *i); |
| 349 } | 380 } |
| 350 } | 381 } |
| 351 | 382 |
| 352 { | 383 { |
| 353 FOR_INT32_INPUTS(i) { | 384 FOR_INT32_INPUTS(i) { |
| 354 Node* n = r.jsgraph()->Constant(*i); | 385 Node* n = r.jsgraph()->Constant(*i); |
| 386 Node* use = r.Return(n); |
| 355 Node* c = r.changer()->GetRepresentationFor( | 387 Node* c = r.changer()->GetRepresentationFor( |
| 356 n, MachineRepresentation::kTagged, Type::Signed32(), | 388 n, MachineRepresentation::kTagged, Type::Signed32(), use, |
| 357 MachineRepresentation::kWord32); | 389 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 358 r.CheckInt32Constant(c, *i); | 390 r.CheckInt32Constant(c, *i); |
| 359 } | 391 } |
| 360 } | 392 } |
| 361 } | 393 } |
| 362 | 394 |
| 363 | 395 |
| 364 TEST(ToUint32_constant) { | 396 TEST(ToUint32_constant) { |
| 365 RepresentationChangerTester r; | 397 RepresentationChangerTester r; |
| 366 | 398 |
| 367 { | 399 { |
| 368 FOR_UINT32_INPUTS(i) { | 400 FOR_UINT32_INPUTS(i) { |
| 369 Node* n = r.jsgraph()->Int32Constant(*i); | 401 Node* n = r.jsgraph()->Int32Constant(*i); |
| 370 Node* c = r.changer()->GetRepresentationFor( | 402 Node* use = r.Return(n); |
| 371 n, MachineRepresentation::kWord32, Type::Unsigned32(), | 403 Node* c = r.changer()->GetRepresentationFor( |
| 372 MachineRepresentation::kWord32); | 404 n, MachineRepresentation::kWord32, Type::Unsigned32(), use, |
| 373 r.CheckUint32Constant(c, *i); | 405 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 406 r.CheckUint32Constant(c, *i); |
| 374 } | 407 } |
| 375 } | 408 } |
| 376 | 409 |
| 377 { | 410 { |
| 378 FOR_UINT32_INPUTS(i) { | 411 FOR_UINT32_INPUTS(i) { |
| 379 if (!IsFloat32Uint32(*i)) continue; | 412 if (!IsFloat32Uint32(*i)) continue; |
| 380 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); | 413 Node* n = r.jsgraph()->Float32Constant(static_cast<float>(*i)); |
| 414 Node* use = r.Return(n); |
| 381 Node* c = r.changer()->GetRepresentationFor( | 415 Node* c = r.changer()->GetRepresentationFor( |
| 382 n, MachineRepresentation::kFloat32, Type::Unsigned32(), | 416 n, MachineRepresentation::kFloat32, Type::Unsigned32(), use, |
| 383 MachineRepresentation::kWord32); | 417 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 384 r.CheckUint32Constant(c, *i); | 418 r.CheckUint32Constant(c, *i); |
| 385 } | 419 } |
| 386 } | 420 } |
| 387 | 421 |
| 388 { | 422 { |
| 389 FOR_UINT32_INPUTS(i) { | 423 FOR_UINT32_INPUTS(i) { |
| 390 Node* n = r.jsgraph()->Float64Constant(*i); | 424 Node* n = r.jsgraph()->Float64Constant(*i); |
| 391 Node* c = r.changer()->GetRepresentationFor( | 425 Node* use = r.Return(n); |
| 392 n, MachineRepresentation::kFloat64, Type::Unsigned32(), | 426 Node* c = r.changer()->GetRepresentationFor( |
| 393 MachineRepresentation::kWord32); | 427 n, MachineRepresentation::kFloat64, Type::Unsigned32(), use, |
| 394 r.CheckUint32Constant(c, *i); | 428 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 429 r.CheckUint32Constant(c, *i); |
| 395 } | 430 } |
| 396 } | 431 } |
| 397 | 432 |
| 398 { | 433 { |
| 399 FOR_UINT32_INPUTS(i) { | 434 FOR_UINT32_INPUTS(i) { |
| 400 Node* n = r.jsgraph()->Constant(static_cast<double>(*i)); | 435 Node* n = r.jsgraph()->Constant(static_cast<double>(*i)); |
| 436 Node* use = r.Return(n); |
| 401 Node* c = r.changer()->GetRepresentationFor( | 437 Node* c = r.changer()->GetRepresentationFor( |
| 402 n, MachineRepresentation::kTagged, Type::Unsigned32(), | 438 n, MachineRepresentation::kTagged, Type::Unsigned32(), use, |
| 403 MachineRepresentation::kWord32); | 439 UseInfo(MachineRepresentation::kWord32, Truncation::None())); |
| 404 r.CheckUint32Constant(c, *i); | 440 r.CheckUint32Constant(c, *i); |
| 405 } | 441 } |
| 406 } | 442 } |
| 407 } | 443 } |
| 408 | 444 |
| 409 | 445 |
| 410 static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, | 446 static void CheckChange(IrOpcode::Value expected, MachineRepresentation from, |
| 411 Type* from_type, MachineRepresentation to) { | 447 Type* from_type, MachineRepresentation to) { |
| 412 RepresentationChangerTester r; | 448 RepresentationChangerTester r; |
| 413 | 449 |
| 414 Node* n = r.Parameter(); | 450 Node* n = r.Parameter(); |
| 415 Node* c = r.changer()->GetRepresentationFor(n, from, from_type, to); | 451 Node* use = r.Return(n); |
| 452 Node* c = r.changer()->GetRepresentationFor(n, from, from_type, use, |
| 453 UseInfo(to, Truncation::None())); |
| 416 | 454 |
| 417 CHECK_NE(c, n); | 455 CHECK_NE(c, n); |
| 418 CHECK_EQ(expected, c->opcode()); | 456 CHECK_EQ(expected, c->opcode()); |
| 419 CHECK_EQ(n, c->InputAt(0)); | 457 CHECK_EQ(n, c->InputAt(0)); |
| 420 } | 458 } |
| 421 | 459 |
| 422 | 460 |
| 423 static void CheckTwoChanges(IrOpcode::Value expected2, | 461 static void CheckTwoChanges(IrOpcode::Value expected2, |
| 424 IrOpcode::Value expected1, | 462 IrOpcode::Value expected1, |
| 425 MachineRepresentation from, Type* from_type, | 463 MachineRepresentation from, Type* from_type, |
| 426 MachineRepresentation to) { | 464 MachineRepresentation to) { |
| 427 RepresentationChangerTester r; | 465 RepresentationChangerTester r; |
| 428 | 466 |
| 429 Node* n = r.Parameter(); | 467 Node* n = r.Parameter(); |
| 430 Node* c1 = r.changer()->GetRepresentationFor(n, from, from_type, to); | 468 Node* use = r.Return(n); |
| 469 Node* c1 = r.changer()->GetRepresentationFor(n, from, from_type, use, |
| 470 UseInfo(to, Truncation::None())); |
| 431 | 471 |
| 432 CHECK_NE(c1, n); | 472 CHECK_NE(c1, n); |
| 433 CHECK_EQ(expected1, c1->opcode()); | 473 CHECK_EQ(expected1, c1->opcode()); |
| 434 Node* c2 = c1->InputAt(0); | 474 Node* c2 = c1->InputAt(0); |
| 435 CHECK_NE(c2, n); | 475 CHECK_NE(c2, n); |
| 436 CHECK_EQ(expected2, c2->opcode()); | 476 CHECK_EQ(expected2, c2->opcode()); |
| 437 CHECK_EQ(n, c2->InputAt(0)); | 477 CHECK_EQ(n, c2->InputAt(0)); |
| 438 } | 478 } |
| 439 | 479 |
| 440 | 480 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 MachineRepresentation::kWord64); | 685 MachineRepresentation::kWord64); |
| 646 r.CheckTypeError(MachineRepresentation::kWord32, Type::Signed32(), | 686 r.CheckTypeError(MachineRepresentation::kWord32, Type::Signed32(), |
| 647 MachineRepresentation::kWord64); | 687 MachineRepresentation::kWord64); |
| 648 r.CheckTypeError(MachineRepresentation::kWord32, Type::Unsigned32(), | 688 r.CheckTypeError(MachineRepresentation::kWord32, Type::Unsigned32(), |
| 649 MachineRepresentation::kWord64); | 689 MachineRepresentation::kWord64); |
| 650 } | 690 } |
| 651 | 691 |
| 652 } // namespace compiler | 692 } // namespace compiler |
| 653 } // namespace internal | 693 } // namespace internal |
| 654 } // namespace v8 | 694 } // namespace v8 |
| OLD | NEW |