Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/compiler/typer.cc

Issue 656003002: Revert "Reland "Refine expression typing, esp. by propagating range information."" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/typer.h ('k') | src/types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/compiler/graph-inl.h" 5 #include "src/compiler/graph-inl.h"
6 #include "src/compiler/js-operator.h" 6 #include "src/compiler/js-operator.h"
7 #include "src/compiler/node.h" 7 #include "src/compiler/node.h"
8 #include "src/compiler/node-properties-inl.h" 8 #include "src/compiler/node-properties-inl.h"
9 #include "src/compiler/node-properties.h" 9 #include "src/compiler/node-properties.h"
10 #include "src/compiler/simplified-operator.h" 10 #include "src/compiler/simplified-operator.h"
11 #include "src/compiler/typer.h" 11 #include "src/compiler/typer.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 namespace compiler { 15 namespace compiler {
16 16
17 Typer::Typer(Zone* zone) : zone_(zone) { 17 Typer::Typer(Zone* zone) : zone_(zone) {
18 Factory* f = zone->isolate()->factory(); 18 Factory* f = zone->isolate()->factory();
19 19
20 Handle<Object> zero = f->NewNumber(0);
21 Handle<Object> one = f->NewNumber(1);
22 Handle<Object> positive_infinity = f->NewNumber(+V8_INFINITY);
23 Handle<Object> negative_infinity = f->NewNumber(-V8_INFINITY);
24
25 negative_signed32 = Type::Union(
26 Type::SignedSmall(), Type::OtherSigned32(), zone);
27 non_negative_signed32 = Type::Union(
28 Type::UnsignedSmall(), Type::OtherUnsigned31(), zone);
29 undefined_or_null = Type::Union(Type::Undefined(), Type::Null(), zone);
30 singleton_false = Type::Constant(f->false_value(), zone);
31 singleton_true = Type::Constant(f->true_value(), zone);
32 singleton_zero = Type::Range(zero, zero, zone);
33 singleton_one = Type::Range(one, one, zone);
34 zero_or_one = Type::Union(singleton_zero, singleton_one, zone);
35 zeroish = Type::Union(
36 singleton_zero, Type::Union(Type::NaN(), Type::MinusZero(), zone), zone);
37 falsish = Type::Union(Type::Undetectable(),
38 Type::Union(zeroish, undefined_or_null, zone), zone);
39 integer = Type::Range(negative_infinity, positive_infinity, zone);
40
41 Type* number = Type::Number(); 20 Type* number = Type::Number();
42 Type* signed32 = Type::Signed32(); 21 Type* signed32 = Type::Signed32();
43 Type* unsigned32 = Type::Unsigned32(); 22 Type* unsigned32 = Type::Unsigned32();
44 Type* integral32 = Type::Integral32(); 23 Type* integral32 = Type::Integral32();
45 Type* object = Type::Object(); 24 Type* object = Type::Object();
46 Type* undefined = Type::Undefined(); 25 Type* undefined = Type::Undefined();
47 Type* weakint = Type::Union( 26 Type* weakint = Type::Union(
48 integer, Type::Union(Type::NaN(), Type::MinusZero(), zone), zone); 27 Type::Range(f->NewNumber(-V8_INFINITY), f->NewNumber(+V8_INFINITY), zone),
28 Type::Union(Type::NaN(), Type::MinusZero(), zone), zone);
49 29
50 number_fun0_ = Type::Function(number, zone); 30 number_fun0_ = Type::Function(number, zone);
51 number_fun1_ = Type::Function(number, number, zone); 31 number_fun1_ = Type::Function(number, number, zone);
52 number_fun2_ = Type::Function(number, number, number, zone); 32 number_fun2_ = Type::Function(number, number, number, zone);
53 weakint_fun1_ = Type::Function(weakint, number, zone); 33 weakint_fun1_ = Type::Function(weakint, number, zone);
54 imul_fun_ = Type::Function(signed32, integral32, integral32, zone); 34 imul_fun_ = Type::Function(signed32, integral32, integral32, zone);
55 random_fun_ = Type::Function(Type::Union( 35 random_fun_ = Type::Function(Type::Union(
56 Type::UnsignedSmall(), Type::OtherNumber(), zone), zone); 36 Type::UnsignedSmall(), Type::OtherNumber(), zone), zone);
57 37
58 Type* int8 = Type::Intersect(
59 Type::Range(f->NewNumber(-0x7F), f->NewNumber(0x7F-1), zone),
60 Type::UntaggedInt8(), zone);
61 Type* int16 = Type::Intersect(
62 Type::Range(f->NewNumber(-0x7FFF), f->NewNumber(0x7FFF-1), zone),
63 Type::UntaggedInt16(), zone);
64 Type* uint8 = Type::Intersect(
65 Type::Range(zero, f->NewNumber(0xFF-1), zone),
66 Type::UntaggedInt8(), zone);
67 Type* uint16 = Type::Intersect(
68 Type::Range(zero, f->NewNumber(0xFFFF-1), zone),
69 Type::UntaggedInt16(), zone);
70 38
71 #define NATIVE_TYPE(sem, rep) \ 39 #define NATIVE_TYPE(sem, rep) \
72 Type::Intersect(Type::sem(), Type::rep(), zone) 40 Type::Intersect(Type::sem(zone), Type::rep(zone), zone)
41 // TODO(rossberg): Use range types for more precision, once we have them.
42 Type* int8 = NATIVE_TYPE(SignedSmall, UntaggedInt8);
43 Type* int16 = NATIVE_TYPE(SignedSmall, UntaggedInt16);
73 Type* int32 = NATIVE_TYPE(Signed32, UntaggedInt32); 44 Type* int32 = NATIVE_TYPE(Signed32, UntaggedInt32);
45 Type* uint8 = NATIVE_TYPE(UnsignedSmall, UntaggedInt8);
46 Type* uint16 = NATIVE_TYPE(UnsignedSmall, UntaggedInt16);
74 Type* uint32 = NATIVE_TYPE(Unsigned32, UntaggedInt32); 47 Type* uint32 = NATIVE_TYPE(Unsigned32, UntaggedInt32);
75 Type* float32 = NATIVE_TYPE(Number, UntaggedFloat32); 48 Type* float32 = NATIVE_TYPE(Number, UntaggedFloat32);
76 Type* float64 = NATIVE_TYPE(Number, UntaggedFloat64); 49 Type* float64 = NATIVE_TYPE(Number, UntaggedFloat64);
77 #undef NATIVE_TYPE 50 #undef NATIVE_TYPE
78
79 Type* buffer = Type::Buffer(zone); 51 Type* buffer = Type::Buffer(zone);
80 Type* int8_array = Type::Array(int8, zone); 52 Type* int8_array = Type::Array(int8, zone);
81 Type* int16_array = Type::Array(int16, zone); 53 Type* int16_array = Type::Array(int16, zone);
82 Type* int32_array = Type::Array(int32, zone); 54 Type* int32_array = Type::Array(int32, zone);
83 Type* uint8_array = Type::Array(uint8, zone); 55 Type* uint8_array = Type::Array(uint8, zone);
84 Type* uint16_array = Type::Array(uint16, zone); 56 Type* uint16_array = Type::Array(uint16, zone);
85 Type* uint32_array = Type::Array(uint32, zone); 57 Type* uint32_array = Type::Array(uint32, zone);
86 Type* float32_array = Type::Array(float32, zone); 58 Type* float32_array = Type::Array(float32, zone);
87 Type* float64_array = Type::Array(float64, zone); 59 Type* float64_array = Type::Array(float64, zone);
88 Type* arg1 = Type::Union(unsigned32, object, zone); 60 Type* arg1 = Type::Union(unsigned32, object, zone);
(...skipping 11 matching lines...) Expand all
100 } 72 }
101 73
102 74
103 class Typer::Visitor : public NullNodeVisitor { 75 class Typer::Visitor : public NullNodeVisitor {
104 public: 76 public:
105 Visitor(Typer* typer, MaybeHandle<Context> context) 77 Visitor(Typer* typer, MaybeHandle<Context> context)
106 : typer_(typer), context_(context) {} 78 : typer_(typer), context_(context) {}
107 79
108 Bounds TypeNode(Node* node) { 80 Bounds TypeNode(Node* node) {
109 switch (node->opcode()) { 81 switch (node->opcode()) {
110 #define DECLARE_CASE(x) \
111 case IrOpcode::k##x: return TypeBinaryOp(node, x##Typer);
112 JS_SIMPLE_BINOP_LIST(DECLARE_CASE)
113 #undef DECLARE_CASE
114
115 #define DECLARE_CASE(x) case IrOpcode::k##x: return Type##x(node); 82 #define DECLARE_CASE(x) case IrOpcode::k##x: return Type##x(node);
116 DECLARE_CASE(Start) 83 DECLARE_CASE(Start)
117 // VALUE_OP_LIST without JS_SIMPLE_BINOP_LIST: 84 VALUE_OP_LIST(DECLARE_CASE)
118 COMMON_OP_LIST(DECLARE_CASE)
119 SIMPLIFIED_OP_LIST(DECLARE_CASE)
120 MACHINE_OP_LIST(DECLARE_CASE)
121 JS_SIMPLE_UNOP_LIST(DECLARE_CASE)
122 JS_OBJECT_OP_LIST(DECLARE_CASE)
123 JS_CONTEXT_OP_LIST(DECLARE_CASE)
124 JS_OTHER_OP_LIST(DECLARE_CASE)
125 #undef DECLARE_CASE 85 #undef DECLARE_CASE
126 86
127 #define DECLARE_CASE(x) case IrOpcode::k##x: 87 #define DECLARE_CASE(x) case IrOpcode::k##x:
128 DECLARE_CASE(End) 88 DECLARE_CASE(End)
129 INNER_CONTROL_OP_LIST(DECLARE_CASE) 89 INNER_CONTROL_OP_LIST(DECLARE_CASE)
130 #undef DECLARE_CASE 90 #undef DECLARE_CASE
131 break; 91 break;
132 } 92 }
133 UNREACHABLE(); 93 UNREACHABLE();
134 return Bounds(); 94 return Bounds();
135 } 95 }
136 96
137 Type* TypeConstant(Handle<Object> value); 97 Type* TypeConstant(Handle<Object> value);
138 98
139 protected: 99 protected:
140 #define DECLARE_METHOD(x) inline Bounds Type##x(Node* node); 100 #define DECLARE_METHOD(x) inline Bounds Type##x(Node* node);
141 DECLARE_METHOD(Start) 101 DECLARE_METHOD(Start)
142 VALUE_OP_LIST(DECLARE_METHOD) 102 VALUE_OP_LIST(DECLARE_METHOD)
143 #undef DECLARE_METHOD 103 #undef DECLARE_METHOD
144 104
145 static Bounds OperandType(Node* node, int i) { 105 Bounds OperandType(Node* node, int i) {
146 return NodeProperties::GetBounds(NodeProperties::GetValueInput(node, i)); 106 return NodeProperties::GetBounds(NodeProperties::GetValueInput(node, i));
147 } 107 }
148 108
149 static Type* ContextType(Node* node) { 109 Type* ContextType(Node* node) {
150 Bounds result = 110 Bounds result =
151 NodeProperties::GetBounds(NodeProperties::GetContextInput(node)); 111 NodeProperties::GetBounds(NodeProperties::GetContextInput(node));
152 DCHECK(result.upper->Maybe(Type::Internal())); 112 DCHECK(result.upper->Maybe(Type::Internal()));
153 // TODO(rossberg): More precisely, instead of the above assertion, we should 113 // TODO(rossberg): More precisely, instead of the above assertion, we should
154 // back-propagate the constraint that it has to be a subtype of Internal. 114 // back-propagate the constraint that it has to be a subtype of Internal.
155 return result.upper; 115 return result.upper;
156 } 116 }
157 117
158 Zone* zone() { return typer_->zone(); } 118 Zone* zone() { return typer_->zone(); }
159 Isolate* isolate() { return typer_->isolate(); } 119 Isolate* isolate() { return typer_->isolate(); }
160 MaybeHandle<Context> context() { return context_; } 120 MaybeHandle<Context> context() { return context_; }
161 121
162 private: 122 private:
163 Typer* typer_; 123 Typer* typer_;
164 MaybeHandle<Context> context_; 124 MaybeHandle<Context> context_;
165
166 typedef Type* (*UnaryTyperFun)(Type*, Typer* t);
167 typedef Type* (*BinaryTyperFun)(Type*, Type*, Typer* t);
168
169 Bounds TypeUnaryOp(Node* node, UnaryTyperFun);
170 Bounds TypeBinaryOp(Node* node, BinaryTyperFun);
171
172 static Type* Invert(Type*, Typer*);
173 static Type* FalsifyUndefined(Type*, Typer*);
174
175 static Type* ToPrimitive(Type*, Typer*);
176 static Type* ToBoolean(Type*, Typer*);
177 static Type* ToNumber(Type*, Typer*);
178 static Type* ToString(Type*, Typer*);
179 static Type* NumberToInt32(Type*, Typer*);
180 static Type* NumberToUint32(Type*, Typer*);
181
182 static Type* JSAddRanger(Type::RangeType*, Type::RangeType*, Typer*);
183 static Type* JSSubtractRanger(Type::RangeType*, Type::RangeType*, Typer*);
184 static Type* JSMultiplyRanger(Type::RangeType*, Type::RangeType*, Typer*);
185 static Type* JSDivideRanger(Type::RangeType*, Type::RangeType*, Typer*);
186
187 static Type* JSCompareTyper(Type*, Type*, Typer*);
188
189 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*);
190 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD)
191 #undef DECLARE_METHOD
192
193 static Type* JSUnaryNotTyper(Type*, Typer*);
194 static Type* JSLoadPropertyTyper(Type*, Type*, Typer*);
195 static Type* JSCallFunctionTyper(Type*, Typer*);
196 }; 125 };
197 126
198 127
199 class Typer::RunVisitor : public Typer::Visitor { 128 class Typer::RunVisitor : public Typer::Visitor {
200 public: 129 public:
201 RunVisitor(Typer* typer, MaybeHandle<Context> context) 130 RunVisitor(Typer* typer, MaybeHandle<Context> context)
202 : Visitor(typer, context), 131 : Visitor(typer, context),
203 redo(NodeSet::key_compare(), NodeSet::allocator_type(typer->zone())) {} 132 redo(NodeSet::key_compare(), NodeSet::allocator_type(typer->zone())) {}
204 133
205 GenericGraphVisit::Control Post(Node* node) { 134 GenericGraphVisit::Control Post(Node* node) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 if (OperatorProperties::HasValueOutput(node->op())) { 230 if (OperatorProperties::HasValueOutput(node->op())) {
302 Visitor typing(this, MaybeHandle<Context>()); 231 Visitor typing(this, MaybeHandle<Context>());
303 Bounds bounds = typing.TypeNode(node); 232 Bounds bounds = typing.TypeNode(node);
304 NodeProperties::SetBounds(node, bounds); 233 NodeProperties::SetBounds(node, bounds);
305 } 234 }
306 } 235 }
307 236
308 237
309 // ----------------------------------------------------------------------------- 238 // -----------------------------------------------------------------------------
310 239
311 // Helper functions that lift a function f on types to a function on bounds,
312 // and uses that to type the given node. Note that f is never called with None
313 // as an argument.
314
315
316 Bounds Typer::Visitor::TypeUnaryOp(Node* node, UnaryTyperFun f) {
317 Bounds input = OperandType(node, 0);
318 Type* upper = input.upper->Is(Type::None())
319 ? Type::None()
320 : f(input.upper, typer_);
321 Type* lower = input.lower->Is(Type::None())
322 ? Type::None()
323 : (input.lower == input.upper || upper->IsConstant())
324 ? upper // TODO(neis): Extend this to Range(x,x), NaN, MinusZero, ...?
325 : f(input.lower, typer_);
326 // TODO(neis): Figure out what to do with lower bound.
327 return Bounds(lower, upper);
328 }
329
330
331 Bounds Typer::Visitor::TypeBinaryOp(Node* node, BinaryTyperFun f) {
332 Bounds left = OperandType(node, 0);
333 Bounds right = OperandType(node, 1);
334 Type* upper = left.upper->Is(Type::None()) || right.upper->Is(Type::None())
335 ? Type::None()
336 : f(left.upper, right.upper, typer_);
337 Type* lower = left.lower->Is(Type::None()) || right.lower->Is(Type::None())
338 ? Type::None()
339 : ((left.lower == left.upper && right.lower == right.upper) ||
340 upper->IsConstant())
341 ? upper
342 : f(left.lower, right.lower, typer_);
343 // TODO(neis): Figure out what to do with lower bound.
344 return Bounds(lower, upper);
345 }
346
347
348 Type* Typer::Visitor::Invert(Type* type, Typer* t) {
349 if (type->Is(t->singleton_false)) return t->singleton_true;
350 if (type->Is(t->singleton_true)) return t->singleton_false;
351 return type;
352 }
353
354
355 Type* Typer::Visitor::FalsifyUndefined(Type* type, Typer* t) {
356 if (type->Is(Type::Undefined())) return t->singleton_false;
357 return type;
358 }
359
360
361 // Type conversion.
362
363
364 Type* Typer::Visitor::ToPrimitive(Type* type, Typer* t) {
365 if (type->Is(Type::Primitive()) && !type->Maybe(Type::Receiver())) {
366 return type;
367 }
368 return Type::Primitive();
369 }
370
371
372 Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) {
373 if (type->Is(Type::Boolean())) return type;
374 if (type->Is(t->falsish)) return t->singleton_false;
375 if (type->Is(Type::DetectableReceiver())) return t->singleton_true;
376 if (type->Is(Type::OrderedNumber()) && (type->Max() < 0 || 0 < type->Min())) {
377 return t->singleton_true; // Ruled out nan, -0 and +0.
378 }
379 return Type::Boolean();
380 }
381
382
383 Type* Typer::Visitor::ToNumber(Type* type, Typer* t) {
384 if (type->Is(Type::Number())) return type;
385 if (type->Is(Type::Undefined())) return Type::NaN();
386 if (type->Is(t->singleton_false)) return t->singleton_zero;
387 if (type->Is(t->singleton_true)) return t->singleton_one;
388 if (type->Is(Type::Boolean())) return t->zero_or_one;
389 return Type::Number();
390 }
391
392
393 Type* Typer::Visitor::ToString(Type* type, Typer* t) {
394 if (type->Is(Type::String())) return type;
395 return Type::String();
396 }
397
398
399 Type* Typer::Visitor::NumberToInt32(Type* type, Typer* t) {
400 // TODO(neis): DCHECK(type->Is(Type::Number()));
401 if (type->Is(Type::Signed32())) return type;
402 if (type->Is(t->zeroish)) return t->singleton_zero;
403 return Type::Signed32();
404 }
405
406
407 Type* Typer::Visitor::NumberToUint32(Type* type, Typer* t) {
408 // TODO(neis): DCHECK(type->Is(Type::Number()));
409 if (type->Is(Type::Unsigned32())) return type;
410 if (type->Is(t->zeroish)) return t->singleton_zero;
411 return Type::Unsigned32();
412 }
413
414
415 // -----------------------------------------------------------------------------
416
417 240
418 // Control operators. 241 // Control operators.
419 242
420
421 Bounds Typer::Visitor::TypeStart(Node* node) { 243 Bounds Typer::Visitor::TypeStart(Node* node) {
422 return Bounds(Type::Internal()); 244 return Bounds(Type::Internal(zone()));
423 } 245 }
424 246
425 247
426 // Common operators. 248 // Common operators.
427 249
428
429 Bounds Typer::Visitor::TypeParameter(Node* node) { 250 Bounds Typer::Visitor::TypeParameter(Node* node) {
430 return Bounds::Unbounded(zone()); 251 return Bounds::Unbounded(zone());
431 } 252 }
432 253
433 254
434 Bounds Typer::Visitor::TypeInt32Constant(Node* node) { 255 Bounds Typer::Visitor::TypeInt32Constant(Node* node) {
435 Factory* f = zone()->isolate()->factory(); 256 // TODO(titzer): only call Type::Of() if the type is not already known.
436 Handle<Object> number = f->NewNumber(OpParameter<int32_t>(node)); 257 return Bounds(Type::Of(OpParameter<int32_t>(node), zone()));
437 return Bounds(Type::Intersect(
438 Type::Range(number, number, zone()), Type::UntaggedInt32(), zone()));
439 } 258 }
440 259
441 260
442 Bounds Typer::Visitor::TypeInt64Constant(Node* node) { 261 Bounds Typer::Visitor::TypeInt64Constant(Node* node) {
443 return Bounds(Type::Internal()); // TODO(rossberg): Add int64 bitset type? 262 // TODO(titzer): only call Type::Of() if the type is not already known.
263 return Bounds(
264 Type::Of(static_cast<double>(OpParameter<int64_t>(node)), zone()));
444 } 265 }
445 266
446 267
447 Bounds Typer::Visitor::TypeFloat32Constant(Node* node) { 268 Bounds Typer::Visitor::TypeFloat32Constant(Node* node) {
448 return Bounds(Type::Intersect( 269 // TODO(titzer): only call Type::Of() if the type is not already known.
449 Type::Of(OpParameter<float>(node), zone()), 270 return Bounds(Type::Of(OpParameter<float>(node), zone()));
450 Type::UntaggedFloat32(), zone()));
451 } 271 }
452 272
453 273
454 Bounds Typer::Visitor::TypeFloat64Constant(Node* node) { 274 Bounds Typer::Visitor::TypeFloat64Constant(Node* node) {
455 return Bounds(Type::Intersect( 275 // TODO(titzer): only call Type::Of() if the type is not already known.
456 Type::Of(OpParameter<double>(node), zone()), 276 return Bounds(Type::Of(OpParameter<double>(node), zone()));
457 Type::UntaggedFloat64(), zone()));
458 } 277 }
459 278
460 279
461 Bounds Typer::Visitor::TypeNumberConstant(Node* node) { 280 Bounds Typer::Visitor::TypeNumberConstant(Node* node) {
462 Factory* f = zone()->isolate()->factory(); 281 // TODO(titzer): only call Type::Of() if the type is not already known.
463 return Bounds(Type::Constant( 282 return Bounds(Type::Of(OpParameter<double>(node), zone()));
464 f->NewNumber(OpParameter<double>(node)), zone()));
465 } 283 }
466 284
467 285
468 Bounds Typer::Visitor::TypeHeapConstant(Node* node) { 286 Bounds Typer::Visitor::TypeHeapConstant(Node* node) {
469 return Bounds(TypeConstant(OpParameter<Unique<Object> >(node).handle())); 287 return Bounds(TypeConstant(OpParameter<Unique<Object> >(node).handle()));
470 } 288 }
471 289
472 290
473 Bounds Typer::Visitor::TypeExternalConstant(Node* node) { 291 Bounds Typer::Visitor::TypeExternalConstant(Node* node) {
474 return Bounds(Type::Internal()); 292 return Bounds(Type::Internal(zone()));
475 } 293 }
476 294
477 295
478 Bounds Typer::Visitor::TypePhi(Node* node) { 296 Bounds Typer::Visitor::TypePhi(Node* node) {
479 int arity = OperatorProperties::GetValueInputCount(node->op()); 297 int arity = OperatorProperties::GetValueInputCount(node->op());
480 Bounds bounds = OperandType(node, 0); 298 Bounds bounds = OperandType(node, 0);
481 for (int i = 1; i < arity; ++i) { 299 for (int i = 1; i < arity; ++i) {
482 bounds = Bounds::Either(bounds, OperandType(node, i), zone()); 300 bounds = Bounds::Either(bounds, OperandType(node, i), zone());
483 } 301 }
484 return bounds; 302 return bounds;
(...skipping 12 matching lines...) Expand all
497 } 315 }
498 316
499 317
500 Bounds Typer::Visitor::TypeFinish(Node* node) { 318 Bounds Typer::Visitor::TypeFinish(Node* node) {
501 return OperandType(node, 0); 319 return OperandType(node, 0);
502 } 320 }
503 321
504 322
505 Bounds Typer::Visitor::TypeFrameState(Node* node) { 323 Bounds Typer::Visitor::TypeFrameState(Node* node) {
506 // TODO(rossberg): Ideally FrameState wouldn't have a value output. 324 // TODO(rossberg): Ideally FrameState wouldn't have a value output.
507 return Bounds(Type::Internal()); 325 return Bounds(Type::Internal(zone()));
508 } 326 }
509 327
510 328
511 Bounds Typer::Visitor::TypeStateValues(Node* node) { 329 Bounds Typer::Visitor::TypeStateValues(Node* node) {
512 return Bounds(Type::Internal()); 330 return Bounds(Type::Internal(zone()));
513 } 331 }
514 332
515 333
516 Bounds Typer::Visitor::TypeCall(Node* node) { 334 Bounds Typer::Visitor::TypeCall(Node* node) {
517 return Bounds::Unbounded(zone()); 335 return Bounds::Unbounded(zone());
518 } 336 }
519 337
520 338
521 Bounds Typer::Visitor::TypeProjection(Node* node) { 339 Bounds Typer::Visitor::TypeProjection(Node* node) {
522 // TODO(titzer): use the output type of the input to determine the bounds. 340 // TODO(titzer): use the output type of the input to determine the bounds.
523 return Bounds::Unbounded(zone()); 341 return Bounds::Unbounded(zone());
524 } 342 }
525 343
526 344
527 // JS comparison operators. 345 // JS comparison operators.
528 346
529 347 #define DEFINE_METHOD(x) \
530 Type* Typer::Visitor::JSEqualTyper(Type* lhs, Type* rhs, Typer* t) { 348 Bounds Typer::Visitor::Type##x(Node* node) { \
531 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false; 349 return Bounds(Type::Boolean(zone())); \
532 if (lhs->Is(t->undefined_or_null) && rhs->Is(t->undefined_or_null)) {
533 return t->singleton_true;
534 } 350 }
535 if (lhs->Is(Type::Number()) && rhs->Is(Type::Number()) && 351 JS_COMPARE_BINOP_LIST(DEFINE_METHOD)
536 (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) { 352 #undef DEFINE_METHOD
537 return t->singleton_false;
538 }
539 if (lhs->IsConstant() && rhs->Is(lhs)) {
540 // Types are equal and are inhabited only by a single semantic value,
541 // which is not nan due to the earlier check.
542 // TODO(neis): Extend this to Range(x,x), MinusZero, ...?
543 return t->singleton_true;
544 }
545 return Type::Boolean();
546 }
547
548
549 Type* Typer::Visitor::JSNotEqualTyper(Type* lhs, Type* rhs, Typer* t) {
550 return Invert(JSEqualTyper(lhs, rhs, t), t);
551 }
552
553
554 static Type* JSType(Type* type) {
555 if (type->Is(Type::Boolean())) return Type::Boolean();
556 if (type->Is(Type::String())) return Type::String();
557 if (type->Is(Type::Number())) return Type::Number();
558 if (type->Is(Type::Undefined())) return Type::Undefined();
559 if (type->Is(Type::Null())) return Type::Null();
560 if (type->Is(Type::Symbol())) return Type::Symbol();
561 if (type->Is(Type::Receiver())) return Type::Receiver(); // JS "Object"
562 return Type::Any();
563 }
564
565
566 Type* Typer::Visitor::JSStrictEqualTyper(Type* lhs, Type* rhs, Typer* t) {
567 if (!JSType(lhs)->Maybe(JSType(rhs))) return t->singleton_false;
568 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false;
569 if (lhs->Is(Type::Number()) && rhs->Is(Type::Number()) &&
570 (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) {
571 return t->singleton_false;
572 }
573 if (lhs->IsConstant() && rhs->Is(lhs)) {
574 // Types are equal and are inhabited only by a single semantic value,
575 // which is not nan due to the earlier check.
576 return t->singleton_true;
577 }
578 return Type::Boolean();
579 }
580
581
582 Type* Typer::Visitor::JSStrictNotEqualTyper(Type* lhs, Type* rhs, Typer* t) {
583 return Invert(JSStrictEqualTyper(lhs, rhs, t), t);
584 }
585
586
587 // The EcmaScript specification defines the four relational comparison operators
588 // (<, <=, >=, >) with the help of a single abstract one. It behaves like <
589 // but returns undefined when the inputs cannot be compared.
590 // We implement the typing analogously.
591 Type* Typer::Visitor::JSCompareTyper(Type* lhs, Type* rhs, Typer* t) {
592 lhs = ToPrimitive(lhs, t);
593 rhs = ToPrimitive(rhs, t);
594 if (lhs->Maybe(Type::String()) && rhs->Maybe(Type::String())) {
595 return Type::Boolean();
596 }
597 lhs = ToNumber(lhs, t);
598 rhs = ToNumber(rhs, t);
599 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::Undefined();
600 if (lhs->IsConstant() && rhs->Is(lhs)) {
601 // Types are equal and are inhabited only by a single semantic value,
602 // which is not NaN due to the previous check.
603 return t->singleton_false;
604 }
605 if (lhs->Min() >= rhs->Max()) return t->singleton_false;
606 if (lhs->Max() < rhs->Min() &&
607 !lhs->Maybe(Type::NaN()) && !rhs->Maybe(Type::NaN())) {
608 return t->singleton_true;
609 }
610 return Type::Boolean();
611 }
612
613
614 Type* Typer::Visitor::JSLessThanTyper(Type* lhs, Type* rhs, Typer* t) {
615 return FalsifyUndefined(JSCompareTyper(lhs, rhs, t), t);
616 }
617
618
619 Type* Typer::Visitor::JSGreaterThanTyper(Type* lhs, Type* rhs, Typer* t) {
620 return FalsifyUndefined(JSCompareTyper(rhs, lhs, t), t);
621 }
622
623
624 Type* Typer::Visitor::JSLessThanOrEqualTyper(Type* lhs, Type* rhs, Typer* t) {
625 return FalsifyUndefined(Invert(JSCompareTyper(rhs, lhs, t), t), t);
626 }
627
628
629 Type* Typer::Visitor::JSGreaterThanOrEqualTyper(
630 Type* lhs, Type* rhs, Typer* t) {
631 return FalsifyUndefined(Invert(JSCompareTyper(lhs, rhs, t), t), t);
632 }
633 353
634 354
635 // JS bitwise operators. 355 // JS bitwise operators.
636 356
637 357 Bounds Typer::Visitor::TypeJSBitwiseOr(Node* node) {
638 Type* Typer::Visitor::JSBitwiseOrTyper(Type* lhs, Type* rhs, Typer* t) { 358 Bounds left = OperandType(node, 0);
639 Factory* f = t->zone()->isolate()->factory(); 359 Bounds right = OperandType(node, 1);
640 lhs = NumberToInt32(ToNumber(lhs, t), t); 360 Type* upper = Type::Union(left.upper, right.upper, zone());
641 rhs = NumberToInt32(ToNumber(rhs, t), t); 361 if (!upper->Is(Type::Signed32())) upper = Type::Signed32(zone());
642 double lmin = lhs->Min(); 362 Type* lower = Type::Intersect(Type::SignedSmall(zone()), upper, zone());
643 double rmin = rhs->Min(); 363 return Bounds(lower, upper);
644 double lmax = lhs->Max();
645 double rmax = rhs->Max();
646 // Or-ing any two values results in a value no smaller than their minimum.
647 // Even no smaller than their maximum if both values are non-negative.
648 Handle<Object> min = f->NewNumber(
649 lmin >= 0 && rmin >= 0 ? std::max(lmin, rmin) : std::min(lmin, rmin));
650 if (lmax < 0 || rmax < 0) {
651 // Or-ing two values of which at least one is negative results in a negative
652 // value.
653 Handle<Object> max = f->NewNumber(-1);
654 return Type::Range(min, max, t->zone());
655 }
656 Handle<Object> max = f->NewNumber(Type::Signed32()->Max());
657 return Type::Range(min, max, t->zone());
658 // TODO(neis): Be precise for singleton inputs, here and elsewhere.
659 } 364 }
660 365
661 366
662 Type* Typer::Visitor::JSBitwiseAndTyper(Type* lhs, Type* rhs, Typer* t) { 367 Bounds Typer::Visitor::TypeJSBitwiseAnd(Node* node) {
663 Factory* f = t->zone()->isolate()->factory(); 368 Bounds left = OperandType(node, 0);
664 lhs = NumberToInt32(ToNumber(lhs, t), t); 369 Bounds right = OperandType(node, 1);
665 rhs = NumberToInt32(ToNumber(rhs, t), t); 370 Type* upper = Type::Union(left.upper, right.upper, zone());
666 double lmin = lhs->Min(); 371 if (!upper->Is(Type::Signed32())) upper = Type::Signed32(zone());
667 double rmin = rhs->Min(); 372 Type* lower = Type::Intersect(Type::SignedSmall(zone()), upper, zone());
668 double lmax = lhs->Max(); 373 return Bounds(lower, upper);
669 double rmax = rhs->Max();
670 // And-ing any two values results in a value no larger than their maximum.
671 // Even no larger than their minimum if both values are non-negative.
672 Handle<Object> max = f->NewNumber(
673 lmin >= 0 && rmin >= 0 ? std::min(lmax, rmax) : std::max(lmax, rmax));
674 if (lmin >= 0 || rmin >= 0) {
675 // And-ing two values of which at least one is non-negative results in a
676 // non-negative value.
677 Handle<Object> min = f->NewNumber(0);
678 return Type::Range(min, max, t->zone());
679 }
680 Handle<Object> min = f->NewNumber(Type::Signed32()->Min());
681 return Type::Range(min, max, t->zone());
682 } 374 }
683 375
684 376
685 Type* Typer::Visitor::JSBitwiseXorTyper(Type* lhs, Type* rhs, Typer* t) { 377 Bounds Typer::Visitor::TypeJSBitwiseXor(Node* node) {
686 lhs = NumberToInt32(ToNumber(lhs, t), t); 378 return Bounds(Type::SignedSmall(zone()), Type::Signed32(zone()));
687 rhs = NumberToInt32(ToNumber(rhs, t), t);
688 double lmin = lhs->Min();
689 double rmin = rhs->Min();
690 double lmax = lhs->Max();
691 double rmax = rhs->Max();
692 if ((lmin >= 0 && rmin >= 0) || (lmax < 0 && rmax < 0)) {
693 // Xor-ing negative or non-negative values results in a non-negative value.
694 return t->non_negative_signed32;
695 }
696 if ((lmax < 0 && rmin >= 0) || (lmin >= 0 && rmax < 0)) {
697 // Xor-ing a negative and a non-negative value results in a negative value.
698 return t->negative_signed32;
699 }
700 return Type::Signed32();
701 } 379 }
702 380
703 381
704 Type* Typer::Visitor::JSShiftLeftTyper(Type* lhs, Type* rhs, Typer* t) { 382 Bounds Typer::Visitor::TypeJSShiftLeft(Node* node) {
705 return Type::Signed32(); 383 return Bounds(Type::SignedSmall(zone()), Type::Signed32(zone()));
706 } 384 }
707 385
708 386
709 Type* Typer::Visitor::JSShiftRightTyper(Type* lhs, Type* rhs, Typer* t) { 387 Bounds Typer::Visitor::TypeJSShiftRight(Node* node) {
710 lhs = NumberToInt32(ToNumber(lhs, t), t); 388 return Bounds(Type::SignedSmall(zone()), Type::Signed32(zone()));
711 Factory* f = t->zone()->isolate()->factory();
712 if (lhs->Min() >= 0) {
713 // Right-shifting a non-negative value cannot make it negative, nor larger.
714 Handle<Object> min = f->NewNumber(0);
715 Handle<Object> max = f->NewNumber(lhs->Max());
716 return Type::Range(min, max, t->zone());
717 }
718 if (lhs->Max() < 0) {
719 // Right-shifting a negative value cannot make it non-negative, nor smaller.
720 Handle<Object> min = f->NewNumber(lhs->Min());
721 Handle<Object> max = f->NewNumber(-1);
722 return Type::Range(min, max, t->zone());
723 }
724 return Type::Signed32();
725 } 389 }
726 390
727 391
728 Type* Typer::Visitor::JSShiftRightLogicalTyper(Type* lhs, Type* rhs, Typer* t) { 392 Bounds Typer::Visitor::TypeJSShiftRightLogical(Node* node) {
729 lhs = NumberToUint32(ToNumber(lhs, t), t); 393 return Bounds(Type::UnsignedSmall(zone()), Type::Unsigned32(zone()));
730 Factory* f = t->zone()->isolate()->factory();
731 // Logical right-shifting any value cannot make it larger.
732 Handle<Object> min = f->NewNumber(0);
733 Handle<Object> max = f->NewNumber(lhs->Max());
734 return Type::Range(min, max, t->zone());
735 } 394 }
736 395
737 396
738 // JS arithmetic operators. 397 // JS arithmetic operators.
739 398
740 399 Bounds Typer::Visitor::TypeJSAdd(Node* node) {
741 Type* Typer::Visitor::JSAddTyper(Type* lhs, Type* rhs, Typer* t) { 400 Bounds left = OperandType(node, 0);
742 lhs = ToPrimitive(lhs, t); 401 Bounds right = OperandType(node, 1);
743 rhs = ToPrimitive(rhs, t); 402 Type* lower =
744 if (lhs->Maybe(Type::String()) || rhs->Maybe(Type::String())) { 403 left.lower->Is(Type::None()) || right.lower->Is(Type::None()) ?
745 if (lhs->Is(Type::String()) || rhs->Is(Type::String())) { 404 Type::None(zone()) :
746 return Type::String(); 405 left.lower->Is(Type::Number()) && right.lower->Is(Type::Number()) ?
747 } else { 406 Type::SignedSmall(zone()) :
748 return Type::NumberOrString(); 407 left.lower->Is(Type::String()) || right.lower->Is(Type::String()) ?
749 } 408 Type::String(zone()) : Type::None(zone());
750 } 409 Type* upper =
751 lhs = ToNumber(lhs, t); 410 left.upper->Is(Type::None()) && right.upper->Is(Type::None()) ?
752 rhs = ToNumber(rhs, t); 411 Type::None(zone()) :
753 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN(); 412 left.upper->Is(Type::Number()) && right.upper->Is(Type::Number()) ?
754 // TODO(neis): Do some analysis. 413 Type::Number(zone()) :
755 // TODO(neis): Deal with numeric bitsets here and elsewhere. 414 left.upper->Is(Type::String()) || right.upper->Is(Type::String()) ?
756 return Type::Number(); 415 Type::String(zone()) : Type::NumberOrString(zone());
416 return Bounds(lower, upper);
757 } 417 }
758 418
759 419
760 Type* Typer::Visitor::JSSubtractTyper(Type* lhs, Type* rhs, Typer* t) { 420 Bounds Typer::Visitor::TypeJSSubtract(Node* node) {
761 lhs = ToNumber(lhs, t); 421 return Bounds(Type::SignedSmall(zone()), Type::Number(zone()));
762 rhs = ToNumber(rhs, t);
763 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
764 // TODO(neis): Do some analysis.
765 return Type::Number();
766 } 422 }
767 423
768 424
769 Type* Typer::Visitor::JSMultiplyTyper(Type* lhs, Type* rhs, Typer* t) { 425 Bounds Typer::Visitor::TypeJSMultiply(Node* node) {
770 lhs = ToNumber(lhs, t); 426 return Bounds(Type::SignedSmall(zone()), Type::Number(zone()));
771 rhs = ToNumber(rhs, t);
772 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
773 // TODO(neis): Do some analysis.
774 return Type::Number();
775 } 427 }
776 428
777 429
778 Type* Typer::Visitor::JSDivideTyper(Type* lhs, Type* rhs, Typer* t) { 430 Bounds Typer::Visitor::TypeJSDivide(Node* node) {
779 lhs = ToNumber(lhs, t); 431 return Bounds(Type::SignedSmall(zone()), Type::Number(zone()));
780 rhs = ToNumber(rhs, t);
781 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
782 // TODO(neis): Do some analysis.
783 return Type::Number();
784 } 432 }
785 433
786 434
787 Type* Typer::Visitor::JSModulusTyper(Type* lhs, Type* rhs, Typer* t) { 435 Bounds Typer::Visitor::TypeJSModulus(Node* node) {
788 lhs = ToNumber(lhs, t); 436 return Bounds(Type::SignedSmall(zone()), Type::Number(zone()));
789 rhs = ToNumber(rhs, t);
790 if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
791 // TODO(neis): Do some analysis.
792 return Type::Number();
793 } 437 }
794 438
795 439
796 // JS unary operators. 440 // JS unary operators.
797 441
798
799 Type* Typer::Visitor::JSUnaryNotTyper(Type* type, Typer* t) {
800 return Invert(ToBoolean(type, t), t);
801 }
802
803
804 Bounds Typer::Visitor::TypeJSUnaryNot(Node* node) { 442 Bounds Typer::Visitor::TypeJSUnaryNot(Node* node) {
805 return TypeUnaryOp(node, JSUnaryNotTyper); 443 return Bounds(Type::Boolean(zone()));
806 } 444 }
807 445
808 446
809 Bounds Typer::Visitor::TypeJSTypeOf(Node* node) { 447 Bounds Typer::Visitor::TypeJSTypeOf(Node* node) {
810 return Bounds(Type::InternalizedString()); 448 return Bounds(Type::InternalizedString(zone()));
811 } 449 }
812 450
813 451
814 // JS conversion operators. 452 // JS conversion operators.
815 453
816
817 Bounds Typer::Visitor::TypeJSToBoolean(Node* node) { 454 Bounds Typer::Visitor::TypeJSToBoolean(Node* node) {
818 return TypeUnaryOp(node, ToBoolean); 455 return Bounds(Type::Boolean(zone()));
819 } 456 }
820 457
821 458
822 Bounds Typer::Visitor::TypeJSToNumber(Node* node) { 459 Bounds Typer::Visitor::TypeJSToNumber(Node* node) {
823 return TypeUnaryOp(node, ToNumber); 460 return Bounds(Type::SignedSmall(zone()), Type::Number(zone()));
824 } 461 }
825 462
826 463
827 Bounds Typer::Visitor::TypeJSToString(Node* node) { 464 Bounds Typer::Visitor::TypeJSToString(Node* node) {
828 return TypeUnaryOp(node, ToString); 465 return Bounds(Type::None(zone()), Type::String(zone()));
829 } 466 }
830 467
831 468
832 Bounds Typer::Visitor::TypeJSToName(Node* node) { 469 Bounds Typer::Visitor::TypeJSToName(Node* node) {
833 return Bounds(Type::None(), Type::Name()); 470 return Bounds(Type::None(zone()), Type::Name(zone()));
834 } 471 }
835 472
836 473
837 Bounds Typer::Visitor::TypeJSToObject(Node* node) { 474 Bounds Typer::Visitor::TypeJSToObject(Node* node) {
838 return Bounds(Type::None(), Type::Receiver()); 475 return Bounds(Type::None(zone()), Type::Receiver(zone()));
839 } 476 }
840 477
841 478
842 // JS object operators. 479 // JS object operators.
843 480
844
845 Bounds Typer::Visitor::TypeJSCreate(Node* node) { 481 Bounds Typer::Visitor::TypeJSCreate(Node* node) {
846 return Bounds(Type::None(), Type::Object()); 482 return Bounds(Type::None(zone()), Type::Object(zone()));
847 }
848
849
850 Type* Typer::Visitor::JSLoadPropertyTyper(Type* object, Type* name, Typer* t) {
851 // TODO(rossberg): Use range types and sized array types to filter undefined.
852 if (object->IsArray() && name->Is(Type::Integral32())) {
853 return Type::Union(
854 object->AsArray()->Element(), Type::Undefined(), t->zone());
855 }
856 return Type::Any();
857 } 483 }
858 484
859 485
860 Bounds Typer::Visitor::TypeJSLoadProperty(Node* node) { 486 Bounds Typer::Visitor::TypeJSLoadProperty(Node* node) {
861 return TypeBinaryOp(node, JSLoadPropertyTyper); 487 Bounds object = OperandType(node, 0);
488 Bounds name = OperandType(node, 1);
489 Bounds result = Bounds::Unbounded(zone());
490 // TODO(rossberg): Use range types and sized array types to filter undefined.
491 if (object.lower->IsArray() && name.lower->Is(Type::Integral32())) {
492 result.lower = Type::Union(
493 object.lower->AsArray()->Element(), Type::Undefined(zone()), zone());
494 }
495 if (object.upper->IsArray() && name.upper->Is(Type::Integral32())) {
496 result.upper = Type::Union(
497 object.upper->AsArray()->Element(), Type::Undefined(zone()), zone());
498 }
499 return result;
862 } 500 }
863 501
864 502
865 Bounds Typer::Visitor::TypeJSLoadNamed(Node* node) { 503 Bounds Typer::Visitor::TypeJSLoadNamed(Node* node) {
866 return Bounds::Unbounded(zone()); 504 return Bounds::Unbounded(zone());
867 } 505 }
868 506
869 507
870 Bounds Typer::Visitor::TypeJSStoreProperty(Node* node) { 508 Bounds Typer::Visitor::TypeJSStoreProperty(Node* node) {
871 UNREACHABLE(); 509 UNREACHABLE();
872 return Bounds(); 510 return Bounds();
873 } 511 }
874 512
875 513
876 Bounds Typer::Visitor::TypeJSStoreNamed(Node* node) { 514 Bounds Typer::Visitor::TypeJSStoreNamed(Node* node) {
877 UNREACHABLE(); 515 UNREACHABLE();
878 return Bounds(); 516 return Bounds();
879 } 517 }
880 518
881 519
882 Bounds Typer::Visitor::TypeJSDeleteProperty(Node* node) { 520 Bounds Typer::Visitor::TypeJSDeleteProperty(Node* node) {
883 return Bounds(Type::Boolean()); 521 return Bounds(Type::Boolean(zone()));
884 } 522 }
885 523
886 524
887 Bounds Typer::Visitor::TypeJSHasProperty(Node* node) { 525 Bounds Typer::Visitor::TypeJSHasProperty(Node* node) {
888 return Bounds(Type::Boolean()); 526 return Bounds(Type::Boolean(zone()));
889 } 527 }
890 528
891 529
892 Bounds Typer::Visitor::TypeJSInstanceOf(Node* node) { 530 Bounds Typer::Visitor::TypeJSInstanceOf(Node* node) {
893 return Bounds(Type::Boolean()); 531 return Bounds(Type::Boolean(zone()));
894 } 532 }
895 533
896 534
897 // JS context operators. 535 // JS context operators.
898 536
899
900 Bounds Typer::Visitor::TypeJSLoadContext(Node* node) { 537 Bounds Typer::Visitor::TypeJSLoadContext(Node* node) {
901 Bounds outer = OperandType(node, 0); 538 Bounds outer = OperandType(node, 0);
902 DCHECK(outer.upper->Maybe(Type::Internal())); 539 DCHECK(outer.upper->Maybe(Type::Internal()));
903 // TODO(rossberg): More precisely, instead of the above assertion, we should 540 // TODO(rossberg): More precisely, instead of the above assertion, we should
904 // back-propagate the constraint that it has to be a subtype of Internal. 541 // back-propagate the constraint that it has to be a subtype of Internal.
905 542
906 ContextAccess access = OpParameter<ContextAccess>(node); 543 ContextAccess access = OpParameter<ContextAccess>(node);
907 Type* context_type = outer.upper; 544 Type* context_type = outer.upper;
908 MaybeHandle<Context> context; 545 MaybeHandle<Context> context;
909 if (context_type->IsConstant()) { 546 if (context_type->IsConstant()) {
(...skipping 14 matching lines...) Expand all
924 context = handle(context.ToHandleChecked()->previous(), isolate()); 561 context = handle(context.ToHandleChecked()->previous(), isolate());
925 } 562 }
926 } 563 }
927 if (context.is_null()) { 564 if (context.is_null()) {
928 return Bounds::Unbounded(zone()); 565 return Bounds::Unbounded(zone());
929 } else { 566 } else {
930 Handle<Object> value = 567 Handle<Object> value =
931 handle(context.ToHandleChecked()->get(static_cast<int>(access.index())), 568 handle(context.ToHandleChecked()->get(static_cast<int>(access.index())),
932 isolate()); 569 isolate());
933 Type* lower = TypeConstant(value); 570 Type* lower = TypeConstant(value);
934 return Bounds(lower, Type::Any()); 571 return Bounds(lower, Type::Any(zone()));
935 } 572 }
936 } 573 }
937 574
938 575
939 Bounds Typer::Visitor::TypeJSStoreContext(Node* node) { 576 Bounds Typer::Visitor::TypeJSStoreContext(Node* node) {
940 UNREACHABLE(); 577 UNREACHABLE();
941 return Bounds(); 578 return Bounds();
942 } 579 }
943 580
944 581
(...skipping 29 matching lines...) Expand all
974 611
975 612
976 Bounds Typer::Visitor::TypeJSCreateGlobalContext(Node* node) { 613 Bounds Typer::Visitor::TypeJSCreateGlobalContext(Node* node) {
977 Type* outer = ContextType(node); 614 Type* outer = ContextType(node);
978 return Bounds(Type::Context(outer, zone())); 615 return Bounds(Type::Context(outer, zone()));
979 } 616 }
980 617
981 618
982 // JS other operators. 619 // JS other operators.
983 620
984
985 Bounds Typer::Visitor::TypeJSYield(Node* node) { 621 Bounds Typer::Visitor::TypeJSYield(Node* node) {
986 return Bounds::Unbounded(zone()); 622 return Bounds::Unbounded(zone());
987 } 623 }
988 624
989 625
990 Bounds Typer::Visitor::TypeJSCallConstruct(Node* node) { 626 Bounds Typer::Visitor::TypeJSCallConstruct(Node* node) {
991 return Bounds(Type::None(), Type::Receiver()); 627 return Bounds(Type::None(zone()), Type::Receiver(zone()));
992 }
993
994
995 Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
996 return fun->IsFunction() ? fun->AsFunction()->Result() : Type::Any();
997 } 628 }
998 629
999 630
1000 Bounds Typer::Visitor::TypeJSCallFunction(Node* node) { 631 Bounds Typer::Visitor::TypeJSCallFunction(Node* node) {
1001 return TypeUnaryOp(node, JSCallFunctionTyper); // We ignore argument types. 632 Bounds fun = OperandType(node, 0);
633 Type* lower = fun.lower->IsFunction()
634 ? fun.lower->AsFunction()->Result() : Type::None(zone());
635 Type* upper = fun.upper->IsFunction()
636 ? fun.upper->AsFunction()->Result() : Type::Any(zone());
637 return Bounds(lower, upper);
1002 } 638 }
1003 639
1004 640
1005 Bounds Typer::Visitor::TypeJSCallRuntime(Node* node) { 641 Bounds Typer::Visitor::TypeJSCallRuntime(Node* node) {
1006 return Bounds::Unbounded(zone()); 642 return Bounds::Unbounded(zone());
1007 } 643 }
1008 644
1009 645
1010 Bounds Typer::Visitor::TypeJSDebugger(Node* node) { 646 Bounds Typer::Visitor::TypeJSDebugger(Node* node) {
1011 return Bounds::Unbounded(zone()); 647 return Bounds::Unbounded(zone());
1012 } 648 }
1013 649
1014 650
1015 // Simplified operators. 651 // Simplified operators.
1016 652
653 Bounds Typer::Visitor::TypeBooleanNot(Node* node) {
654 return Bounds(Type::Boolean(zone()));
655 }
1017 656
1018 Bounds Typer::Visitor::TypeBooleanNot(Node* node) { 657
658 Bounds Typer::Visitor::TypeBooleanToNumber(Node* node) {
659 return Bounds(Type::Number(zone()));
660 }
661
662
663 Bounds Typer::Visitor::TypeNumberEqual(Node* node) {
664 return Bounds(Type::Boolean(zone()));
665 }
666
667
668 Bounds Typer::Visitor::TypeNumberLessThan(Node* node) {
669 return Bounds(Type::Boolean(zone()));
670 }
671
672
673 Bounds Typer::Visitor::TypeNumberLessThanOrEqual(Node* node) {
674 return Bounds(Type::Boolean(zone()));
675 }
676
677
678 Bounds Typer::Visitor::TypeNumberAdd(Node* node) {
679 return Bounds(Type::Number(zone()));
680 }
681
682
683 Bounds Typer::Visitor::TypeNumberSubtract(Node* node) {
684 return Bounds(Type::Number(zone()));
685 }
686
687
688 Bounds Typer::Visitor::TypeNumberMultiply(Node* node) {
689 return Bounds(Type::Number(zone()));
690 }
691
692
693 Bounds Typer::Visitor::TypeNumberDivide(Node* node) {
694 return Bounds(Type::Number(zone()));
695 }
696
697
698 Bounds Typer::Visitor::TypeNumberModulus(Node* node) {
699 return Bounds(Type::Number(zone()));
700 }
701
702
703 Bounds Typer::Visitor::TypeNumberToInt32(Node* node) {
704 Bounds arg = OperandType(node, 0);
705 Type* s32 = Type::Signed32(zone());
706 Type* lower = arg.lower->Is(s32) ? arg.lower : s32;
707 Type* upper = arg.upper->Is(s32) ? arg.upper : s32;
708 return Bounds(lower, upper);
709 }
710
711
712 Bounds Typer::Visitor::TypeNumberToUint32(Node* node) {
713 Bounds arg = OperandType(node, 0);
714 Type* u32 = Type::Unsigned32(zone());
715 Type* lower = arg.lower->Is(u32) ? arg.lower : u32;
716 Type* upper = arg.upper->Is(u32) ? arg.upper : u32;
717 return Bounds(lower, upper);
718 }
719
720
721 Bounds Typer::Visitor::TypeReferenceEqual(Node* node) {
722 return Bounds(Type::Boolean(zone()));
723 }
724
725
726 Bounds Typer::Visitor::TypeStringEqual(Node* node) {
727 return Bounds(Type::Boolean(zone()));
728 }
729
730
731 Bounds Typer::Visitor::TypeStringLessThan(Node* node) {
732 return Bounds(Type::Boolean(zone()));
733 }
734
735
736 Bounds Typer::Visitor::TypeStringLessThanOrEqual(Node* node) {
737 return Bounds(Type::Boolean(zone()));
738 }
739
740
741 Bounds Typer::Visitor::TypeStringAdd(Node* node) {
742 return Bounds(Type::String(zone()));
743 }
744
745
746 Bounds Typer::Visitor::TypeChangeTaggedToInt32(Node* node) {
747 // TODO(titzer): type is type of input, representation is Word32.
748 return Bounds(Type::Integral32());
749 }
750
751
752 Bounds Typer::Visitor::TypeChangeTaggedToUint32(Node* node) {
753 return Bounds(Type::Integral32()); // TODO(titzer): add appropriate rep
754 }
755
756
757 Bounds Typer::Visitor::TypeChangeTaggedToFloat64(Node* node) {
758 // TODO(titzer): type is type of input, representation is Float64.
759 return Bounds(Type::Number());
760 }
761
762
763 Bounds Typer::Visitor::TypeChangeInt32ToTagged(Node* node) {
764 // TODO(titzer): type is type of input, representation is Tagged.
765 return Bounds(Type::Integral32());
766 }
767
768
769 Bounds Typer::Visitor::TypeChangeUint32ToTagged(Node* node) {
770 // TODO(titzer): type is type of input, representation is Tagged.
771 return Bounds(Type::Unsigned32());
772 }
773
774
775 Bounds Typer::Visitor::TypeChangeFloat64ToTagged(Node* node) {
776 // TODO(titzer): type is type of input, representation is Tagged.
777 return Bounds(Type::Number());
778 }
779
780
781 Bounds Typer::Visitor::TypeChangeBoolToBit(Node* node) {
782 // TODO(titzer): type is type of input, representation is Bit.
1019 return Bounds(Type::Boolean()); 783 return Bounds(Type::Boolean());
1020 } 784 }
1021 785
1022 786
1023 Bounds Typer::Visitor::TypeBooleanToNumber(Node* node) { 787 Bounds Typer::Visitor::TypeChangeBitToBool(Node* node) {
1024 return Bounds(Type::Number()); 788 // TODO(titzer): type is type of input, representation is Tagged.
1025 }
1026
1027
1028 Bounds Typer::Visitor::TypeNumberEqual(Node* node) {
1029 return Bounds(Type::Boolean()); 789 return Bounds(Type::Boolean());
1030 } 790 }
1031 791
1032 792
1033 Bounds Typer::Visitor::TypeNumberLessThan(Node* node) {
1034 return Bounds(Type::Boolean());
1035 }
1036
1037
1038 Bounds Typer::Visitor::TypeNumberLessThanOrEqual(Node* node) {
1039 return Bounds(Type::Boolean());
1040 }
1041
1042
1043 Bounds Typer::Visitor::TypeNumberAdd(Node* node) {
1044 return Bounds(Type::Number());
1045 }
1046
1047
1048 Bounds Typer::Visitor::TypeNumberSubtract(Node* node) {
1049 return Bounds(Type::Number());
1050 }
1051
1052
1053 Bounds Typer::Visitor::TypeNumberMultiply(Node* node) {
1054 return Bounds(Type::Number());
1055 }
1056
1057
1058 Bounds Typer::Visitor::TypeNumberDivide(Node* node) {
1059 return Bounds(Type::Number());
1060 }
1061
1062
1063 Bounds Typer::Visitor::TypeNumberModulus(Node* node) {
1064 return Bounds(Type::Number());
1065 }
1066
1067
1068 Bounds Typer::Visitor::TypeNumberToInt32(Node* node) {
1069 return TypeUnaryOp(node, NumberToInt32);
1070 }
1071
1072
1073 Bounds Typer::Visitor::TypeNumberToUint32(Node* node) {
1074 return TypeUnaryOp(node, NumberToUint32);
1075 }
1076
1077
1078 Bounds Typer::Visitor::TypeReferenceEqual(Node* node) {
1079 return Bounds(Type::Boolean());
1080 }
1081
1082
1083 Bounds Typer::Visitor::TypeStringEqual(Node* node) {
1084 return Bounds(Type::Boolean());
1085 }
1086
1087
1088 Bounds Typer::Visitor::TypeStringLessThan(Node* node) {
1089 return Bounds(Type::Boolean());
1090 }
1091
1092
1093 Bounds Typer::Visitor::TypeStringLessThanOrEqual(Node* node) {
1094 return Bounds(Type::Boolean());
1095 }
1096
1097
1098 Bounds Typer::Visitor::TypeStringAdd(Node* node) {
1099 return Bounds(Type::String());
1100 }
1101
1102
1103 static Type* ChangeRepresentation(Type* type, Type* rep, Zone* zone) {
1104 // TODO(neis): Enable when expressible.
1105 /*
1106 return Type::Union(
1107 Type::Intersect(type, Type::Semantic(), zone),
1108 Type::Intersect(rep, Type::Representation(), zone), zone);
1109 */
1110 return type;
1111 }
1112
1113
1114 Bounds Typer::Visitor::TypeChangeTaggedToInt32(Node* node) {
1115 Bounds arg = OperandType(node, 0);
1116 // TODO(neis): DCHECK(arg.upper->Is(Type::Signed32()));
1117 return Bounds(
1118 ChangeRepresentation(arg.lower, Type::UntaggedInt32(), zone()),
1119 ChangeRepresentation(arg.upper, Type::UntaggedInt32(), zone()));
1120 }
1121
1122
1123 Bounds Typer::Visitor::TypeChangeTaggedToUint32(Node* node) {
1124 Bounds arg = OperandType(node, 0);
1125 // TODO(neis): DCHECK(arg.upper->Is(Type::Unsigned32()));
1126 return Bounds(
1127 ChangeRepresentation(arg.lower, Type::UntaggedInt32(), zone()),
1128 ChangeRepresentation(arg.upper, Type::UntaggedInt32(), zone()));
1129 }
1130
1131
1132 Bounds Typer::Visitor::TypeChangeTaggedToFloat64(Node* node) {
1133 Bounds arg = OperandType(node, 0);
1134 // TODO(neis): DCHECK(arg.upper->Is(Type::Number()));
1135 return Bounds(
1136 ChangeRepresentation(arg.lower, Type::UntaggedFloat64(), zone()),
1137 ChangeRepresentation(arg.upper, Type::UntaggedFloat64(), zone()));
1138 }
1139
1140
1141 Bounds Typer::Visitor::TypeChangeInt32ToTagged(Node* node) {
1142 Bounds arg = OperandType(node, 0);
1143 // TODO(neis): DCHECK(arg.upper->Is(Type::Signed32()));
1144 return Bounds(
1145 ChangeRepresentation(arg.lower, Type::Tagged(), zone()),
1146 ChangeRepresentation(arg.upper, Type::Tagged(), zone()));
1147 }
1148
1149
1150 Bounds Typer::Visitor::TypeChangeUint32ToTagged(Node* node) {
1151 Bounds arg = OperandType(node, 0);
1152 // TODO(neis): DCHECK(arg.upper->Is(Type::Unsigned32()));
1153 return Bounds(
1154 ChangeRepresentation(arg.lower, Type::Tagged(), zone()),
1155 ChangeRepresentation(arg.upper, Type::Tagged(), zone()));
1156 }
1157
1158
1159 Bounds Typer::Visitor::TypeChangeFloat64ToTagged(Node* node) {
1160 Bounds arg = OperandType(node, 0);
1161 // TODO(neis): CHECK(arg.upper->Is(Type::Number()));
1162 return Bounds(
1163 ChangeRepresentation(arg.lower, Type::Tagged(), zone()),
1164 ChangeRepresentation(arg.upper, Type::Tagged(), zone()));
1165 }
1166
1167
1168 Bounds Typer::Visitor::TypeChangeBoolToBit(Node* node) {
1169 Bounds arg = OperandType(node, 0);
1170 // TODO(neis): DCHECK(arg.upper->Is(Type::Boolean()));
1171 return Bounds(
1172 ChangeRepresentation(arg.lower, Type::UntaggedInt1(), zone()),
1173 ChangeRepresentation(arg.upper, Type::UntaggedInt1(), zone()));
1174 }
1175
1176
1177 Bounds Typer::Visitor::TypeChangeBitToBool(Node* node) {
1178 Bounds arg = OperandType(node, 0);
1179 // TODO(neis): DCHECK(arg.upper->Is(Type::Boolean()));
1180 return Bounds(
1181 ChangeRepresentation(arg.lower, Type::TaggedPtr(), zone()),
1182 ChangeRepresentation(arg.upper, Type::TaggedPtr(), zone()));
1183 }
1184
1185
1186 Bounds Typer::Visitor::TypeLoadField(Node* node) { 793 Bounds Typer::Visitor::TypeLoadField(Node* node) {
1187 return Bounds(FieldAccessOf(node->op()).type); 794 return Bounds(FieldAccessOf(node->op()).type);
1188 } 795 }
1189 796
1190 797
1191 Bounds Typer::Visitor::TypeLoadElement(Node* node) { 798 Bounds Typer::Visitor::TypeLoadElement(Node* node) {
1192 return Bounds(ElementAccessOf(node->op()).type); 799 return Bounds(ElementAccessOf(node->op()).type);
1193 } 800 }
1194 801
1195 802
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 } 1221 }
1615 1222
1616 1223
1617 void Typer::DecorateGraph(Graph* graph) { 1224 void Typer::DecorateGraph(Graph* graph) {
1618 graph->AddDecorator(new (zone()) TyperDecorator(this)); 1225 graph->AddDecorator(new (zone()) TyperDecorator(this));
1619 } 1226 }
1620 1227
1621 } 1228 }
1622 } 1229 }
1623 } // namespace v8::internal::compiler 1230 } // namespace v8::internal::compiler
OLDNEW
« no previous file with comments | « src/compiler/typer.h ('k') | src/types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698