Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | #include "src/compiler/typer.h" |
| 6 | |
| 7 | #include "src/base/flags.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include "src/bootstrapper.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include "src/compilation-dependencies.h" |
| 10 | #include "src/compiler/common-operator.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 11 | #include "src/compiler/graph-reducer.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 12 | #include "src/compiler/js-operator.h" |
| 13 | #include "src/compiler/node.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | #include "src/compiler/node-properties.h" |
| 15 | #include "src/compiler/simplified-operator.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 16 | #include "src/objects-inl.h" |
| 17 | #include "src/type-cache.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 18 | |
| 19 | namespace v8 { |
| 20 | namespace internal { |
| 21 | namespace compiler { |
| 22 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 23 | class Typer::Decorator final : public GraphDecorator { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 24 | public: |
| 25 | explicit Decorator(Typer* typer) : typer_(typer) {} |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | void Decorate(Node* node) final; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 27 | |
| 28 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 29 | Typer* const typer_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 30 | }; |
| 31 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 32 | Typer::Typer(Isolate* isolate, Graph* graph, Flags flags, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 33 | CompilationDependencies* dependencies, FunctionType* function_type) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | : isolate_(isolate), |
| 35 | graph_(graph), |
| 36 | flags_(flags), |
| 37 | dependencies_(dependencies), |
| 38 | function_type_(function_type), |
| 39 | decorator_(nullptr), |
| 40 | cache_(TypeCache::Get()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 41 | Zone* zone = this->zone(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 42 | Factory* const factory = isolate->factory(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 43 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | Type* infinity = Type::Constant(factory->infinity_value(), zone); |
| 45 | Type* minus_infinity = Type::Constant(factory->minus_infinity_value(), zone); |
| 46 | // TODO(neis): Unfortunately, the infinities created in other places might |
| 47 | // be different ones (eg the result of NewNumber in TypeNumberConstant). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 48 | Type* truncating_to_zero = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 49 | Type::Union(Type::Union(infinity, minus_infinity, zone), |
| 50 | Type::MinusZeroOrNaN(), zone); |
| 51 | DCHECK(!truncating_to_zero->Maybe(Type::Integral32())); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 52 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | singleton_false_ = Type::Constant(factory->false_value(), zone); |
| 54 | singleton_true_ = Type::Constant(factory->true_value(), zone); |
| 55 | singleton_the_hole_ = Type::Constant(factory->the_hole_value(), zone); |
| 56 | signed32ish_ = Type::Union(Type::Signed32(), truncating_to_zero, zone); |
| 57 | unsigned32ish_ = Type::Union(Type::Unsigned32(), truncating_to_zero, zone); |
| 58 | falsish_ = Type::Union( |
| 59 | Type::Undetectable(), |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 60 | Type::Union(Type::Union(singleton_false_, cache_.kZeroish, zone), |
| 61 | singleton_the_hole_, zone), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 62 | zone); |
| 63 | truish_ = Type::Union( |
| 64 | singleton_true_, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 65 | Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone), zone); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 66 | |
| 67 | decorator_ = new (zone) Decorator(this); |
| 68 | graph_->AddDecorator(decorator_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 72 | Typer::~Typer() { |
| 73 | graph_->RemoveDecorator(decorator_); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | class Typer::Visitor : public Reducer { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 78 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 79 | explicit Visitor(Typer* typer) |
| 80 | : typer_(typer), weakened_nodes_(typer->zone()) {} |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 81 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 82 | Reduction Reduce(Node* node) override { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 83 | if (node->op()->ValueOutputCount() == 0) return NoChange(); |
| 84 | switch (node->opcode()) { |
| 85 | #define DECLARE_CASE(x) \ |
| 86 | case IrOpcode::k##x: \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 87 | return UpdateType(node, TypeBinaryOp(node, x##Typer)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 88 | JS_SIMPLE_BINOP_LIST(DECLARE_CASE) |
| 89 | #undef DECLARE_CASE |
| 90 | |
| 91 | #define DECLARE_CASE(x) \ |
| 92 | case IrOpcode::k##x: \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 93 | return UpdateType(node, Type##x(node)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 94 | DECLARE_CASE(Start) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 | DECLARE_CASE(IfException) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 96 | // VALUE_OP_LIST without JS_SIMPLE_BINOP_LIST: |
| 97 | COMMON_OP_LIST(DECLARE_CASE) |
| 98 | SIMPLIFIED_OP_LIST(DECLARE_CASE) |
| 99 | MACHINE_OP_LIST(DECLARE_CASE) |
| 100 | JS_SIMPLE_UNOP_LIST(DECLARE_CASE) |
| 101 | JS_OBJECT_OP_LIST(DECLARE_CASE) |
| 102 | JS_CONTEXT_OP_LIST(DECLARE_CASE) |
| 103 | JS_OTHER_OP_LIST(DECLARE_CASE) |
| 104 | #undef DECLARE_CASE |
| 105 | |
| 106 | #define DECLARE_CASE(x) case IrOpcode::k##x: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 107 | DECLARE_CASE(Loop) |
| 108 | DECLARE_CASE(Branch) |
| 109 | DECLARE_CASE(IfTrue) |
| 110 | DECLARE_CASE(IfFalse) |
| 111 | DECLARE_CASE(IfSuccess) |
| 112 | DECLARE_CASE(Switch) |
| 113 | DECLARE_CASE(IfValue) |
| 114 | DECLARE_CASE(IfDefault) |
| 115 | DECLARE_CASE(Merge) |
| 116 | DECLARE_CASE(Deoptimize) |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 117 | DECLARE_CASE(DeoptimizeIf) |
| 118 | DECLARE_CASE(DeoptimizeUnless) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 119 | DECLARE_CASE(Return) |
| 120 | DECLARE_CASE(TailCall) |
| 121 | DECLARE_CASE(Terminate) |
| 122 | DECLARE_CASE(OsrNormalEntry) |
| 123 | DECLARE_CASE(OsrLoopEntry) |
| 124 | DECLARE_CASE(Throw) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 125 | DECLARE_CASE(End) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 126 | #undef DECLARE_CASE |
| 127 | break; |
| 128 | } |
| 129 | return NoChange(); |
| 130 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 131 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 132 | Type* TypeNode(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | switch (node->opcode()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 134 | #define DECLARE_CASE(x) \ |
| 135 | case IrOpcode::k##x: return TypeBinaryOp(node, x##Typer); |
| 136 | JS_SIMPLE_BINOP_LIST(DECLARE_CASE) |
| 137 | #undef DECLARE_CASE |
| 138 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 139 | #define DECLARE_CASE(x) case IrOpcode::k##x: return Type##x(node); |
| 140 | DECLARE_CASE(Start) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 141 | DECLARE_CASE(IfException) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 142 | // VALUE_OP_LIST without JS_SIMPLE_BINOP_LIST: |
| 143 | COMMON_OP_LIST(DECLARE_CASE) |
| 144 | SIMPLIFIED_OP_LIST(DECLARE_CASE) |
| 145 | MACHINE_OP_LIST(DECLARE_CASE) |
| 146 | JS_SIMPLE_UNOP_LIST(DECLARE_CASE) |
| 147 | JS_OBJECT_OP_LIST(DECLARE_CASE) |
| 148 | JS_CONTEXT_OP_LIST(DECLARE_CASE) |
| 149 | JS_OTHER_OP_LIST(DECLARE_CASE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | #undef DECLARE_CASE |
| 151 | |
| 152 | #define DECLARE_CASE(x) case IrOpcode::k##x: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 153 | DECLARE_CASE(Loop) |
| 154 | DECLARE_CASE(Branch) |
| 155 | DECLARE_CASE(IfTrue) |
| 156 | DECLARE_CASE(IfFalse) |
| 157 | DECLARE_CASE(IfSuccess) |
| 158 | DECLARE_CASE(Switch) |
| 159 | DECLARE_CASE(IfValue) |
| 160 | DECLARE_CASE(IfDefault) |
| 161 | DECLARE_CASE(Merge) |
| 162 | DECLARE_CASE(Deoptimize) |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 163 | DECLARE_CASE(DeoptimizeIf) |
| 164 | DECLARE_CASE(DeoptimizeUnless) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 165 | DECLARE_CASE(Return) |
| 166 | DECLARE_CASE(TailCall) |
| 167 | DECLARE_CASE(Terminate) |
| 168 | DECLARE_CASE(OsrNormalEntry) |
| 169 | DECLARE_CASE(OsrLoopEntry) |
| 170 | DECLARE_CASE(Throw) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 171 | DECLARE_CASE(End) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | #undef DECLARE_CASE |
| 173 | break; |
| 174 | } |
| 175 | UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 176 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | Type* TypeConstant(Handle<Object> value); |
| 180 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 181 | private: |
| 182 | Typer* typer_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 183 | ZoneSet<NodeId> weakened_nodes_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 184 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 185 | #define DECLARE_METHOD(x) inline Type* Type##x(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | DECLARE_METHOD(Start) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 187 | DECLARE_METHOD(IfException) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 188 | VALUE_OP_LIST(DECLARE_METHOD) |
| 189 | #undef DECLARE_METHOD |
| 190 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 191 | Type* TypeOrNone(Node* node) { |
| 192 | return NodeProperties::IsTyped(node) ? NodeProperties::GetType(node) |
| 193 | : Type::None(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 196 | Type* Operand(Node* node, int i) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 197 | Node* operand_node = NodeProperties::GetValueInput(node, i); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 198 | return TypeOrNone(operand_node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 199 | } |
| 200 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 201 | Type* WrapContextTypeForInput(Node* node); |
| 202 | Type* Weaken(Node* node, Type* current_type, Type* previous_type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 203 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 204 | Zone* zone() { return typer_->zone(); } |
| 205 | Isolate* isolate() { return typer_->isolate(); } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 206 | Graph* graph() { return typer_->graph(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 207 | Typer::Flags flags() const { return typer_->flags(); } |
| 208 | CompilationDependencies* dependencies() const { |
| 209 | return typer_->dependencies(); |
| 210 | } |
| 211 | |
| 212 | void SetWeakened(NodeId node_id) { weakened_nodes_.insert(node_id); } |
| 213 | bool IsWeakened(NodeId node_id) { |
| 214 | return weakened_nodes_.find(node_id) != weakened_nodes_.end(); |
| 215 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 216 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 217 | typedef Type* (*UnaryTyperFun)(Type*, Typer* t); |
| 218 | typedef Type* (*BinaryTyperFun)(Type*, Type*, Typer* t); |
| 219 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 220 | Type* TypeUnaryOp(Node* node, UnaryTyperFun); |
| 221 | Type* TypeBinaryOp(Node* node, BinaryTyperFun); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 222 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 223 | enum ComparisonOutcomeFlags { |
| 224 | kComparisonTrue = 1, |
| 225 | kComparisonFalse = 2, |
| 226 | kComparisonUndefined = 4 |
| 227 | }; |
| 228 | typedef base::Flags<ComparisonOutcomeFlags> ComparisonOutcome; |
| 229 | |
| 230 | static ComparisonOutcome Invert(ComparisonOutcome, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 231 | static Type* Invert(Type*, Typer*); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 232 | static Type* FalsifyUndefined(ComparisonOutcome, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 233 | static Type* Rangify(Type*, Typer*); |
| 234 | |
| 235 | static Type* ToPrimitive(Type*, Typer*); |
| 236 | static Type* ToBoolean(Type*, Typer*); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 237 | static Type* ToInteger(Type*, Typer*); |
| 238 | static Type* ToLength(Type*, Typer*); |
| 239 | static Type* ToName(Type*, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 240 | static Type* ToNumber(Type*, Typer*); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 241 | static Type* ToObject(Type*, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 242 | static Type* ToString(Type*, Typer*); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 243 | static Type* NumberCeil(Type*, Typer*); |
| 244 | static Type* NumberFloor(Type*, Typer*); |
| 245 | static Type* NumberRound(Type*, Typer*); |
| 246 | static Type* NumberTrunc(Type*, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 247 | static Type* NumberToInt32(Type*, Typer*); |
| 248 | static Type* NumberToUint32(Type*, Typer*); |
| 249 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 250 | static Type* ObjectIsNumber(Type*, Typer*); |
| 251 | static Type* ObjectIsReceiver(Type*, Typer*); |
| 252 | static Type* ObjectIsSmi(Type*, Typer*); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 253 | static Type* ObjectIsUndetectable(Type*, Typer*); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 254 | |
| 255 | static Type* JSAddRanger(RangeType*, RangeType*, Typer*); |
| 256 | static Type* JSSubtractRanger(RangeType*, RangeType*, Typer*); |
| 257 | static Type* JSDivideRanger(RangeType*, RangeType*, Typer*); |
| 258 | static Type* JSModulusRanger(RangeType*, RangeType*, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 259 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 260 | static ComparisonOutcome JSCompareTyper(Type*, Type*, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 261 | |
| 262 | #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); |
| 263 | JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) |
| 264 | #undef DECLARE_METHOD |
| 265 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 266 | static Type* JSTypeOfTyper(Type*, Typer*); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 267 | static Type* JSLoadPropertyTyper(Type*, Type*, Typer*); |
| 268 | static Type* JSCallFunctionTyper(Type*, Typer*); |
| 269 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 270 | static Type* ReferenceEqualTyper(Type*, Type*, Typer*); |
| 271 | |
| 272 | Reduction UpdateType(Node* node, Type* current) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 273 | if (NodeProperties::IsTyped(node)) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 274 | // Widen the type of a previously typed node. |
| 275 | Type* previous = NodeProperties::GetType(node); |
| 276 | if (node->opcode() == IrOpcode::kPhi) { |
| 277 | // Speed up termination in the presence of range types: |
| 278 | current = Weaken(node, current, previous); |
| 279 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 280 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 281 | CHECK(previous->Is(current)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 282 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 283 | NodeProperties::SetType(node, current); |
| 284 | if (!current->Is(previous)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 285 | // If something changed, revisit all uses. |
| 286 | return Changed(node); |
| 287 | } |
| 288 | return NoChange(); |
| 289 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 290 | // No previous type, simply update the type. |
| 291 | NodeProperties::SetType(node, current); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 292 | return Changed(node); |
| 293 | } |
| 294 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 295 | }; |
| 296 | |
| 297 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 298 | void Typer::Run() { Run(NodeVector(zone())); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 299 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 300 | |
| 301 | void Typer::Run(const NodeVector& roots) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 302 | Visitor visitor(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 303 | GraphReducer graph_reducer(zone(), graph()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 304 | graph_reducer.AddReducer(&visitor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 305 | for (Node* const root : roots) graph_reducer.ReduceNode(root); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 306 | graph_reducer.ReduceGraph(); |
| 307 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | |
| 309 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 310 | void Typer::Decorator::Decorate(Node* node) { |
| 311 | if (node->op()->ValueOutputCount() > 0) { |
| 312 | // Only eagerly type-decorate nodes with known input types. |
| 313 | // Other cases will generally require a proper fixpoint iteration with Run. |
| 314 | bool is_typed = NodeProperties::IsTyped(node); |
| 315 | if (is_typed || NodeProperties::AllValueInputsAreTyped(node)) { |
| 316 | Visitor typing(typer_); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 317 | Type* type = typing.TypeNode(node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 318 | if (is_typed) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 319 | type = Type::Intersect(type, NodeProperties::GetType(node), |
| 320 | typer_->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 321 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 322 | NodeProperties::SetType(node, type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 328 | // ----------------------------------------------------------------------------- |
| 329 | |
| 330 | // Helper functions that lift a function f on types to a function on bounds, |
| 331 | // and uses that to type the given node. Note that f is never called with None |
| 332 | // as an argument. |
| 333 | |
| 334 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 335 | Type* Typer::Visitor::TypeUnaryOp(Node* node, UnaryTyperFun f) { |
| 336 | Type* input = Operand(node, 0); |
| 337 | return input->IsInhabited() ? f(input, typer_) : Type::None(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 341 | Type* Typer::Visitor::TypeBinaryOp(Node* node, BinaryTyperFun f) { |
| 342 | Type* left = Operand(node, 0); |
| 343 | Type* right = Operand(node, 1); |
| 344 | return left->IsInhabited() && right->IsInhabited() ? f(left, right, typer_) |
| 345 | : Type::None(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 349 | Type* Typer::Visitor::Invert(Type* type, Typer* t) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 350 | DCHECK(type->Is(Type::Boolean())); |
| 351 | DCHECK(type->IsInhabited()); |
| 352 | if (type->Is(t->singleton_false_)) return t->singleton_true_; |
| 353 | if (type->Is(t->singleton_true_)) return t->singleton_false_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 354 | return type; |
| 355 | } |
| 356 | |
| 357 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 358 | Typer::Visitor::ComparisonOutcome Typer::Visitor::Invert( |
| 359 | ComparisonOutcome outcome, Typer* t) { |
| 360 | ComparisonOutcome result(0); |
| 361 | if ((outcome & kComparisonUndefined) != 0) result |= kComparisonUndefined; |
| 362 | if ((outcome & kComparisonTrue) != 0) result |= kComparisonFalse; |
| 363 | if ((outcome & kComparisonFalse) != 0) result |= kComparisonTrue; |
| 364 | return result; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | Type* Typer::Visitor::FalsifyUndefined(ComparisonOutcome outcome, Typer* t) { |
| 369 | if ((outcome & kComparisonFalse) != 0 || |
| 370 | (outcome & kComparisonUndefined) != 0) { |
| 371 | return (outcome & kComparisonTrue) != 0 ? Type::Boolean() |
| 372 | : t->singleton_false_; |
| 373 | } |
| 374 | // Type should be non empty, so we know it should be true. |
| 375 | DCHECK((outcome & kComparisonTrue) != 0); |
| 376 | return t->singleton_true_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
| 380 | Type* Typer::Visitor::Rangify(Type* type, Typer* t) { |
| 381 | if (type->IsRange()) return type; // Shortcut. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 382 | if (!type->Is(t->cache_.kInteger)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 383 | return type; // Give up on non-integer types. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 384 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 385 | double min = type->Min(); |
| 386 | double max = type->Max(); |
| 387 | // Handle the degenerate case of empty bitset types (such as |
| 388 | // OtherUnsigned31 and OtherSigned32 on 64-bit architectures). |
| 389 | if (std::isnan(min)) { |
| 390 | DCHECK(std::isnan(max)); |
| 391 | return type; |
| 392 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 393 | return Type::Range(min, max, t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | |
| 397 | // Type conversion. |
| 398 | |
| 399 | |
| 400 | Type* Typer::Visitor::ToPrimitive(Type* type, Typer* t) { |
| 401 | if (type->Is(Type::Primitive()) && !type->Maybe(Type::Receiver())) { |
| 402 | return type; |
| 403 | } |
| 404 | return Type::Primitive(); |
| 405 | } |
| 406 | |
| 407 | |
| 408 | Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) { |
| 409 | if (type->Is(Type::Boolean())) return type; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 410 | if (type->Is(t->falsish_)) return t->singleton_false_; |
| 411 | if (type->Is(t->truish_)) return t->singleton_true_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 412 | if (type->Is(Type::PlainNumber()) && (type->Max() < 0 || 0 < type->Min())) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 413 | return t->singleton_true_; // Ruled out nan, -0 and +0. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 414 | } |
| 415 | return Type::Boolean(); |
| 416 | } |
| 417 | |
| 418 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 419 | // static |
| 420 | Type* Typer::Visitor::ToInteger(Type* type, Typer* t) { |
| 421 | // ES6 section 7.1.4 ToInteger ( argument ) |
| 422 | type = ToNumber(type, t); |
| 423 | if (type->Is(t->cache_.kIntegerOrMinusZero)) return type; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 424 | if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) { |
| 425 | return Type::Union( |
| 426 | Type::Intersect(type, t->cache_.kIntegerOrMinusZero, t->zone()), |
| 427 | t->cache_.kSingletonZero, t->zone()); |
| 428 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 429 | return t->cache_.kIntegerOrMinusZero; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | // static |
| 434 | Type* Typer::Visitor::ToLength(Type* type, Typer* t) { |
| 435 | // ES6 section 7.1.15 ToLength ( argument ) |
| 436 | type = ToInteger(type, t); |
| 437 | double min = type->Min(); |
| 438 | double max = type->Max(); |
| 439 | if (min <= 0.0) min = 0.0; |
| 440 | if (max > kMaxSafeInteger) max = kMaxSafeInteger; |
| 441 | if (max <= min) max = min; |
| 442 | return Type::Range(min, max, t->zone()); |
| 443 | } |
| 444 | |
| 445 | |
| 446 | // static |
| 447 | Type* Typer::Visitor::ToName(Type* type, Typer* t) { |
| 448 | // ES6 section 7.1.14 ToPropertyKey ( argument ) |
| 449 | type = ToPrimitive(type, t); |
| 450 | if (type->Is(Type::Name())) return type; |
| 451 | if (type->Maybe(Type::Symbol())) return Type::Name(); |
| 452 | return ToString(type, t); |
| 453 | } |
| 454 | |
| 455 | |
| 456 | // static |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 457 | Type* Typer::Visitor::ToNumber(Type* type, Typer* t) { |
| 458 | if (type->Is(Type::Number())) return type; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 459 | if (type->Is(Type::NullOrUndefined())) { |
| 460 | if (type->Is(Type::Null())) return t->cache_.kSingletonZero; |
| 461 | if (type->Is(Type::Undefined())) return Type::NaN(); |
| 462 | return Type::Union(Type::NaN(), t->cache_.kSingletonZero, t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 463 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 464 | if (type->Is(Type::NumberOrUndefined())) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 465 | return Type::Union(Type::Intersect(type, Type::Number(), t->zone()), |
| 466 | Type::NaN(), t->zone()); |
| 467 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 468 | if (type->Is(t->singleton_false_)) return t->cache_.kSingletonZero; |
| 469 | if (type->Is(t->singleton_true_)) return t->cache_.kSingletonOne; |
| 470 | if (type->Is(Type::Boolean())) return t->cache_.kZeroOrOne; |
| 471 | if (type->Is(Type::BooleanOrNumber())) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 472 | return Type::Union(Type::Intersect(type, Type::Number(), t->zone()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 473 | t->cache_.kZeroOrOne, t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 474 | } |
| 475 | return Type::Number(); |
| 476 | } |
| 477 | |
| 478 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 479 | // static |
| 480 | Type* Typer::Visitor::ToObject(Type* type, Typer* t) { |
| 481 | // ES6 section 7.1.13 ToObject ( argument ) |
| 482 | if (type->Is(Type::Receiver())) return type; |
| 483 | if (type->Is(Type::Primitive())) return Type::OtherObject(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 484 | if (!type->Maybe(Type::OtherUndetectable())) { |
| 485 | return Type::DetectableReceiver(); |
| 486 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 487 | return Type::Receiver(); |
| 488 | } |
| 489 | |
| 490 | |
| 491 | // static |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 492 | Type* Typer::Visitor::ToString(Type* type, Typer* t) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 493 | // ES6 section 7.1.12 ToString ( argument ) |
| 494 | type = ToPrimitive(type, t); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 495 | if (type->Is(Type::String())) return type; |
| 496 | return Type::String(); |
| 497 | } |
| 498 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 499 | // static |
| 500 | Type* Typer::Visitor::NumberCeil(Type* type, Typer* t) { |
| 501 | DCHECK(type->Is(Type::Number())); |
| 502 | if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 503 | // TODO(bmeurer): We could infer a more precise type here. |
| 504 | return t->cache_.kIntegerOrMinusZeroOrNaN; |
| 505 | } |
| 506 | |
| 507 | // static |
| 508 | Type* Typer::Visitor::NumberFloor(Type* type, Typer* t) { |
| 509 | DCHECK(type->Is(Type::Number())); |
| 510 | if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 511 | // TODO(bmeurer): We could infer a more precise type here. |
| 512 | return t->cache_.kIntegerOrMinusZeroOrNaN; |
| 513 | } |
| 514 | |
| 515 | // static |
| 516 | Type* Typer::Visitor::NumberRound(Type* type, Typer* t) { |
| 517 | DCHECK(type->Is(Type::Number())); |
| 518 | if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 519 | // TODO(bmeurer): We could infer a more precise type here. |
| 520 | return t->cache_.kIntegerOrMinusZeroOrNaN; |
| 521 | } |
| 522 | |
| 523 | // static |
| 524 | Type* Typer::Visitor::NumberTrunc(Type* type, Typer* t) { |
| 525 | DCHECK(type->Is(Type::Number())); |
| 526 | if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; |
| 527 | // TODO(bmeurer): We could infer a more precise type here. |
| 528 | return t->cache_.kIntegerOrMinusZeroOrNaN; |
| 529 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 530 | |
| 531 | Type* Typer::Visitor::NumberToInt32(Type* type, Typer* t) { |
| 532 | // TODO(neis): DCHECK(type->Is(Type::Number())); |
| 533 | if (type->Is(Type::Signed32())) return type; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 534 | if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero; |
| 535 | if (type->Is(t->signed32ish_)) { |
| 536 | return Type::Intersect( |
| 537 | Type::Union(type, t->cache_.kSingletonZero, t->zone()), |
| 538 | Type::Signed32(), t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 539 | } |
| 540 | return Type::Signed32(); |
| 541 | } |
| 542 | |
| 543 | |
| 544 | Type* Typer::Visitor::NumberToUint32(Type* type, Typer* t) { |
| 545 | // TODO(neis): DCHECK(type->Is(Type::Number())); |
| 546 | if (type->Is(Type::Unsigned32())) return type; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 547 | if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero; |
| 548 | if (type->Is(t->unsigned32ish_)) { |
| 549 | return Type::Intersect( |
| 550 | Type::Union(type, t->cache_.kSingletonZero, t->zone()), |
| 551 | Type::Unsigned32(), t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 552 | } |
| 553 | return Type::Unsigned32(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 557 | // Type checks. |
| 558 | |
| 559 | |
| 560 | Type* Typer::Visitor::ObjectIsNumber(Type* type, Typer* t) { |
| 561 | if (type->Is(Type::Number())) return t->singleton_true_; |
| 562 | if (!type->Maybe(Type::Number())) return t->singleton_false_; |
| 563 | return Type::Boolean(); |
| 564 | } |
| 565 | |
| 566 | |
| 567 | Type* Typer::Visitor::ObjectIsReceiver(Type* type, Typer* t) { |
| 568 | if (type->Is(Type::Receiver())) return t->singleton_true_; |
| 569 | if (!type->Maybe(Type::Receiver())) return t->singleton_false_; |
| 570 | return Type::Boolean(); |
| 571 | } |
| 572 | |
| 573 | |
| 574 | Type* Typer::Visitor::ObjectIsSmi(Type* type, Typer* t) { |
| 575 | if (type->Is(Type::TaggedSigned())) return t->singleton_true_; |
| 576 | if (type->Is(Type::TaggedPointer())) return t->singleton_false_; |
| 577 | return Type::Boolean(); |
| 578 | } |
| 579 | |
| 580 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 581 | Type* Typer::Visitor::ObjectIsUndetectable(Type* type, Typer* t) { |
| 582 | if (type->Is(Type::Undetectable())) return t->singleton_true_; |
| 583 | if (!type->Maybe(Type::Undetectable())) return t->singleton_false_; |
| 584 | return Type::Boolean(); |
| 585 | } |
| 586 | |
| 587 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 588 | // ----------------------------------------------------------------------------- |
| 589 | |
| 590 | |
| 591 | // Control operators. |
| 592 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 593 | Type* Typer::Visitor::TypeStart(Node* node) { return Type::Internal(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 594 | |
| 595 | Type* Typer::Visitor::TypeIfException(Node* node) { return Type::Any(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 596 | |
| 597 | |
| 598 | // Common operators. |
| 599 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 600 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 601 | Type* Typer::Visitor::TypeParameter(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 602 | if (FunctionType* function_type = typer_->function_type()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 603 | int const index = ParameterIndexOf(node->op()); |
| 604 | if (index >= 0 && index < function_type->Arity()) { |
| 605 | return function_type->Parameter(index); |
| 606 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 607 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 608 | return Type::Any(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 612 | Type* Typer::Visitor::TypeOsrValue(Node* node) { return Type::Any(); } |
| 613 | |
| 614 | |
| 615 | Type* Typer::Visitor::TypeInt32Constant(Node* node) { |
| 616 | double number = OpParameter<int32_t>(node); |
| 617 | return Type::Intersect(Type::Range(number, number, zone()), |
| 618 | Type::UntaggedIntegral32(), zone()); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | Type* Typer::Visitor::TypeInt64Constant(Node* node) { |
| 623 | // TODO(rossberg): This actually seems to be a PointerConstant so far... |
| 624 | return Type::Internal(); // TODO(rossberg): Add int64 bitset type? |
| 625 | } |
| 626 | |
| 627 | |
| 628 | Type* Typer::Visitor::TypeFloat32Constant(Node* node) { |
| 629 | return Type::Intersect(Type::Of(OpParameter<float>(node), zone()), |
| 630 | Type::UntaggedFloat32(), zone()); |
| 631 | } |
| 632 | |
| 633 | |
| 634 | Type* Typer::Visitor::TypeFloat64Constant(Node* node) { |
| 635 | return Type::Intersect(Type::Of(OpParameter<double>(node), zone()), |
| 636 | Type::UntaggedFloat64(), zone()); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | Type* Typer::Visitor::TypeNumberConstant(Node* node) { |
| 641 | Factory* f = isolate()->factory(); |
| 642 | double number = OpParameter<double>(node); |
| 643 | if (Type::IsInteger(number)) { |
| 644 | return Type::Range(number, number, zone()); |
| 645 | } |
| 646 | return Type::Constant(f->NewNumber(number), zone()); |
| 647 | } |
| 648 | |
| 649 | |
| 650 | Type* Typer::Visitor::TypeHeapConstant(Node* node) { |
| 651 | return TypeConstant(OpParameter<Handle<HeapObject>>(node)); |
| 652 | } |
| 653 | |
| 654 | |
| 655 | Type* Typer::Visitor::TypeExternalConstant(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 656 | return Type::Internal(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | Type* Typer::Visitor::TypeSelect(Node* node) { |
| 661 | return Type::Union(Operand(node, 1), Operand(node, 2), zone()); |
| 662 | } |
| 663 | |
| 664 | |
| 665 | Type* Typer::Visitor::TypePhi(Node* node) { |
| 666 | int arity = node->op()->ValueInputCount(); |
| 667 | Type* type = Operand(node, 0); |
| 668 | for (int i = 1; i < arity; ++i) { |
| 669 | type = Type::Union(type, Operand(node, i), zone()); |
| 670 | } |
| 671 | return type; |
| 672 | } |
| 673 | |
| 674 | |
| 675 | Type* Typer::Visitor::TypeEffectPhi(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 676 | UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 677 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 681 | Type* Typer::Visitor::TypeEffectSet(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 682 | UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 683 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 687 | Type* Typer::Visitor::TypeGuard(Node* node) { |
| 688 | Type* input_type = Operand(node, 0); |
| 689 | Type* guard_type = OpParameter<Type*>(node); |
| 690 | return Type::Intersect(input_type, guard_type, zone()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 694 | Type* Typer::Visitor::TypeBeginRegion(Node* node) { |
| 695 | UNREACHABLE(); |
| 696 | return nullptr; |
| 697 | } |
| 698 | |
| 699 | |
| 700 | Type* Typer::Visitor::TypeFinishRegion(Node* node) { return Operand(node, 0); } |
| 701 | |
| 702 | |
| 703 | Type* Typer::Visitor::TypeFrameState(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 704 | // TODO(rossberg): Ideally FrameState wouldn't have a value output. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 705 | return Type::Internal(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 708 | Type* Typer::Visitor::TypeStateValues(Node* node) { return Type::Internal(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 709 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 710 | Type* Typer::Visitor::TypeObjectState(Node* node) { return Type::Internal(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 711 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 712 | Type* Typer::Visitor::TypeTypedStateValues(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 713 | return Type::Internal(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
| 717 | Type* Typer::Visitor::TypeCall(Node* node) { return Type::Any(); } |
| 718 | |
| 719 | |
| 720 | Type* Typer::Visitor::TypeProjection(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 721 | Type* const type = Operand(node, 0); |
| 722 | if (type->Is(Type::None())) return Type::None(); |
| 723 | int const index = static_cast<int>(ProjectionIndexOf(node->op())); |
| 724 | if (type->IsTuple() && index < type->AsTuple()->Arity()) { |
| 725 | return type->AsTuple()->Element(index); |
| 726 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 727 | return Type::Any(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 731 | Type* Typer::Visitor::TypeDead(Node* node) { return Type::Any(); } |
| 732 | |
| 733 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 734 | // JS comparison operators. |
| 735 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 736 | |
| 737 | Type* Typer::Visitor::JSEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 738 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false_; |
| 739 | if (lhs->Is(Type::NullOrUndefined()) && rhs->Is(Type::NullOrUndefined())) { |
| 740 | return t->singleton_true_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 741 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 742 | if (lhs->Is(Type::Number()) && rhs->Is(Type::Number()) && |
| 743 | (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 744 | return t->singleton_false_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 745 | } |
| 746 | if (lhs->IsConstant() && rhs->Is(lhs)) { |
| 747 | // Types are equal and are inhabited only by a single semantic value, |
| 748 | // which is not nan due to the earlier check. |
| 749 | // TODO(neis): Extend this to Range(x,x), MinusZero, ...? |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 750 | return t->singleton_true_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 751 | } |
| 752 | return Type::Boolean(); |
| 753 | } |
| 754 | |
| 755 | |
| 756 | Type* Typer::Visitor::JSNotEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
| 757 | return Invert(JSEqualTyper(lhs, rhs, t), t); |
| 758 | } |
| 759 | |
| 760 | |
| 761 | static Type* JSType(Type* type) { |
| 762 | if (type->Is(Type::Boolean())) return Type::Boolean(); |
| 763 | if (type->Is(Type::String())) return Type::String(); |
| 764 | if (type->Is(Type::Number())) return Type::Number(); |
| 765 | if (type->Is(Type::Undefined())) return Type::Undefined(); |
| 766 | if (type->Is(Type::Null())) return Type::Null(); |
| 767 | if (type->Is(Type::Symbol())) return Type::Symbol(); |
| 768 | if (type->Is(Type::Receiver())) return Type::Receiver(); // JS "Object" |
| 769 | return Type::Any(); |
| 770 | } |
| 771 | |
| 772 | |
| 773 | Type* Typer::Visitor::JSStrictEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 774 | if (!JSType(lhs)->Maybe(JSType(rhs))) return t->singleton_false_; |
| 775 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return t->singleton_false_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 776 | if (lhs->Is(Type::Number()) && rhs->Is(Type::Number()) && |
| 777 | (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 778 | return t->singleton_false_; |
| 779 | } |
| 780 | if ((lhs->Is(t->singleton_the_hole_) || rhs->Is(t->singleton_the_hole_)) && |
| 781 | !lhs->Maybe(rhs)) { |
| 782 | return t->singleton_false_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 783 | } |
| 784 | if (lhs->IsConstant() && rhs->Is(lhs)) { |
| 785 | // Types are equal and are inhabited only by a single semantic value, |
| 786 | // which is not nan due to the earlier check. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 787 | return t->singleton_true_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 788 | } |
| 789 | return Type::Boolean(); |
| 790 | } |
| 791 | |
| 792 | |
| 793 | Type* Typer::Visitor::JSStrictNotEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
| 794 | return Invert(JSStrictEqualTyper(lhs, rhs, t), t); |
| 795 | } |
| 796 | |
| 797 | |
| 798 | // The EcmaScript specification defines the four relational comparison operators |
| 799 | // (<, <=, >=, >) with the help of a single abstract one. It behaves like < |
| 800 | // but returns undefined when the inputs cannot be compared. |
| 801 | // We implement the typing analogously. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 802 | Typer::Visitor::ComparisonOutcome Typer::Visitor::JSCompareTyper(Type* lhs, |
| 803 | Type* rhs, |
| 804 | Typer* t) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 805 | lhs = ToPrimitive(lhs, t); |
| 806 | rhs = ToPrimitive(rhs, t); |
| 807 | if (lhs->Maybe(Type::String()) && rhs->Maybe(Type::String())) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 808 | return ComparisonOutcome(kComparisonTrue) | |
| 809 | ComparisonOutcome(kComparisonFalse); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 810 | } |
| 811 | lhs = ToNumber(lhs, t); |
| 812 | rhs = ToNumber(rhs, t); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 813 | |
| 814 | // Shortcut for NaNs. |
| 815 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return kComparisonUndefined; |
| 816 | |
| 817 | ComparisonOutcome result; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 818 | if (lhs->IsConstant() && rhs->Is(lhs)) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 819 | // Types are equal and are inhabited only by a single semantic value. |
| 820 | result = kComparisonFalse; |
| 821 | } else if (lhs->Min() >= rhs->Max()) { |
| 822 | result = kComparisonFalse; |
| 823 | } else if (lhs->Max() < rhs->Min()) { |
| 824 | result = kComparisonTrue; |
| 825 | } else { |
| 826 | // We cannot figure out the result, return both true and false. (We do not |
| 827 | // have to return undefined because that cannot affect the result of |
| 828 | // FalsifyUndefined.) |
| 829 | return ComparisonOutcome(kComparisonTrue) | |
| 830 | ComparisonOutcome(kComparisonFalse); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 831 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 832 | // Add the undefined if we could see NaN. |
| 833 | if (lhs->Maybe(Type::NaN()) || rhs->Maybe(Type::NaN())) { |
| 834 | result |= kComparisonUndefined; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 835 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 836 | return result; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | |
| 840 | Type* Typer::Visitor::JSLessThanTyper(Type* lhs, Type* rhs, Typer* t) { |
| 841 | return FalsifyUndefined(JSCompareTyper(lhs, rhs, t), t); |
| 842 | } |
| 843 | |
| 844 | |
| 845 | Type* Typer::Visitor::JSGreaterThanTyper(Type* lhs, Type* rhs, Typer* t) { |
| 846 | return FalsifyUndefined(JSCompareTyper(rhs, lhs, t), t); |
| 847 | } |
| 848 | |
| 849 | |
| 850 | Type* Typer::Visitor::JSLessThanOrEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
| 851 | return FalsifyUndefined(Invert(JSCompareTyper(rhs, lhs, t), t), t); |
| 852 | } |
| 853 | |
| 854 | |
| 855 | Type* Typer::Visitor::JSGreaterThanOrEqualTyper( |
| 856 | Type* lhs, Type* rhs, Typer* t) { |
| 857 | return FalsifyUndefined(Invert(JSCompareTyper(lhs, rhs, t), t), t); |
| 858 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 859 | |
| 860 | |
| 861 | // JS bitwise operators. |
| 862 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 863 | |
| 864 | Type* Typer::Visitor::JSBitwiseOrTyper(Type* lhs, Type* rhs, Typer* t) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 865 | lhs = NumberToInt32(ToNumber(lhs, t), t); |
| 866 | rhs = NumberToInt32(ToNumber(rhs, t), t); |
| 867 | double lmin = lhs->Min(); |
| 868 | double rmin = rhs->Min(); |
| 869 | double lmax = lhs->Max(); |
| 870 | double rmax = rhs->Max(); |
| 871 | // Or-ing any two values results in a value no smaller than their minimum. |
| 872 | // Even no smaller than their maximum if both values are non-negative. |
| 873 | double min = |
| 874 | lmin >= 0 && rmin >= 0 ? std::max(lmin, rmin) : std::min(lmin, rmin); |
| 875 | double max = Type::Signed32()->Max(); |
| 876 | |
| 877 | // Or-ing with 0 is essentially a conversion to int32. |
| 878 | if (rmin == 0 && rmax == 0) { |
| 879 | min = lmin; |
| 880 | max = lmax; |
| 881 | } |
| 882 | if (lmin == 0 && lmax == 0) { |
| 883 | min = rmin; |
| 884 | max = rmax; |
| 885 | } |
| 886 | |
| 887 | if (lmax < 0 || rmax < 0) { |
| 888 | // Or-ing two values of which at least one is negative results in a negative |
| 889 | // value. |
| 890 | max = std::min(max, -1.0); |
| 891 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 892 | return Type::Range(min, max, t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 893 | // TODO(neis): Be precise for singleton inputs, here and elsewhere. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 897 | Type* Typer::Visitor::JSBitwiseAndTyper(Type* lhs, Type* rhs, Typer* t) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 898 | lhs = NumberToInt32(ToNumber(lhs, t), t); |
| 899 | rhs = NumberToInt32(ToNumber(rhs, t), t); |
| 900 | double lmin = lhs->Min(); |
| 901 | double rmin = rhs->Min(); |
| 902 | double lmax = lhs->Max(); |
| 903 | double rmax = rhs->Max(); |
| 904 | double min = Type::Signed32()->Min(); |
| 905 | // And-ing any two values results in a value no larger than their maximum. |
| 906 | // Even no larger than their minimum if both values are non-negative. |
| 907 | double max = |
| 908 | lmin >= 0 && rmin >= 0 ? std::min(lmax, rmax) : std::max(lmax, rmax); |
| 909 | // And-ing with a non-negative value x causes the result to be between |
| 910 | // zero and x. |
| 911 | if (lmin >= 0) { |
| 912 | min = 0; |
| 913 | max = std::min(max, lmax); |
| 914 | } |
| 915 | if (rmin >= 0) { |
| 916 | min = 0; |
| 917 | max = std::min(max, rmax); |
| 918 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 919 | return Type::Range(min, max, t->zone()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 923 | Type* Typer::Visitor::JSBitwiseXorTyper(Type* lhs, Type* rhs, Typer* t) { |
| 924 | lhs = NumberToInt32(ToNumber(lhs, t), t); |
| 925 | rhs = NumberToInt32(ToNumber(rhs, t), t); |
| 926 | double lmin = lhs->Min(); |
| 927 | double rmin = rhs->Min(); |
| 928 | double lmax = lhs->Max(); |
| 929 | double rmax = rhs->Max(); |
| 930 | if ((lmin >= 0 && rmin >= 0) || (lmax < 0 && rmax < 0)) { |
| 931 | // Xor-ing negative or non-negative values results in a non-negative value. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 932 | return Type::Unsigned31(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 933 | } |
| 934 | if ((lmax < 0 && rmin >= 0) || (lmin >= 0 && rmax < 0)) { |
| 935 | // Xor-ing a negative and a non-negative value results in a negative value. |
| 936 | // TODO(jarin) Use a range here. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 937 | return Type::Negative32(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 938 | } |
| 939 | return Type::Signed32(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 943 | Type* Typer::Visitor::JSShiftLeftTyper(Type* lhs, Type* rhs, Typer* t) { |
| 944 | return Type::Signed32(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 948 | Type* Typer::Visitor::JSShiftRightTyper(Type* lhs, Type* rhs, Typer* t) { |
| 949 | lhs = NumberToInt32(ToNumber(lhs, t), t); |
| 950 | rhs = NumberToUint32(ToNumber(rhs, t), t); |
| 951 | double min = kMinInt; |
| 952 | double max = kMaxInt; |
| 953 | if (lhs->Min() >= 0) { |
| 954 | // Right-shifting a non-negative value cannot make it negative, nor larger. |
| 955 | min = std::max(min, 0.0); |
| 956 | max = std::min(max, lhs->Max()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 957 | if (rhs->Min() > 0 && rhs->Max() <= 31) { |
| 958 | max = static_cast<int>(max) >> static_cast<int>(rhs->Min()); |
| 959 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 960 | } |
| 961 | if (lhs->Max() < 0) { |
| 962 | // Right-shifting a negative value cannot make it non-negative, nor smaller. |
| 963 | min = std::max(min, lhs->Min()); |
| 964 | max = std::min(max, -1.0); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 965 | if (rhs->Min() > 0 && rhs->Max() <= 31) { |
| 966 | min = static_cast<int>(min) >> static_cast<int>(rhs->Min()); |
| 967 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 968 | } |
| 969 | if (rhs->Min() > 0 && rhs->Max() <= 31) { |
| 970 | // Right-shifting by a positive value yields a small integer value. |
| 971 | double shift_min = kMinInt >> static_cast<int>(rhs->Min()); |
| 972 | double shift_max = kMaxInt >> static_cast<int>(rhs->Min()); |
| 973 | min = std::max(min, shift_min); |
| 974 | max = std::min(max, shift_max); |
| 975 | } |
| 976 | // TODO(jarin) Ideally, the following micro-optimization should be performed |
| 977 | // by the type constructor. |
| 978 | if (max != Type::Signed32()->Max() || min != Type::Signed32()->Min()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 979 | return Type::Range(min, max, t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 980 | } |
| 981 | return Type::Signed32(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 985 | Type* Typer::Visitor::JSShiftRightLogicalTyper(Type* lhs, Type* rhs, Typer* t) { |
| 986 | lhs = NumberToUint32(ToNumber(lhs, t), t); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 987 | // Logical right-shifting any value cannot make it larger. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 988 | return Type::Range(0.0, lhs->Max(), t->zone()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | |
| 992 | // JS arithmetic operators. |
| 993 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 994 | |
| 995 | // Returns the array's least element, ignoring NaN. |
| 996 | // There must be at least one non-NaN element. |
| 997 | // Any -0 is converted to 0. |
| 998 | static double array_min(double a[], size_t n) { |
| 999 | DCHECK(n != 0); |
| 1000 | double x = +V8_INFINITY; |
| 1001 | for (size_t i = 0; i < n; ++i) { |
| 1002 | if (!std::isnan(a[i])) { |
| 1003 | x = std::min(a[i], x); |
| 1004 | } |
| 1005 | } |
| 1006 | DCHECK(!std::isnan(x)); |
| 1007 | return x == 0 ? 0 : x; // -0 -> 0 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1011 | // Returns the array's greatest element, ignoring NaN. |
| 1012 | // There must be at least one non-NaN element. |
| 1013 | // Any -0 is converted to 0. |
| 1014 | static double array_max(double a[], size_t n) { |
| 1015 | DCHECK(n != 0); |
| 1016 | double x = -V8_INFINITY; |
| 1017 | for (size_t i = 0; i < n; ++i) { |
| 1018 | if (!std::isnan(a[i])) { |
| 1019 | x = std::max(a[i], x); |
| 1020 | } |
| 1021 | } |
| 1022 | DCHECK(!std::isnan(x)); |
| 1023 | return x == 0 ? 0 : x; // -0 -> 0 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1026 | Type* Typer::Visitor::JSAddRanger(RangeType* lhs, RangeType* rhs, Typer* t) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1027 | double results[4]; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1028 | results[0] = lhs->Min() + rhs->Min(); |
| 1029 | results[1] = lhs->Min() + rhs->Max(); |
| 1030 | results[2] = lhs->Max() + rhs->Min(); |
| 1031 | results[3] = lhs->Max() + rhs->Max(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1032 | // Since none of the inputs can be -0, the result cannot be -0 either. |
| 1033 | // However, it can be nan (the sum of two infinities of opposite sign). |
| 1034 | // On the other hand, if none of the "results" above is nan, then the actual |
| 1035 | // result cannot be nan either. |
| 1036 | int nans = 0; |
| 1037 | for (int i = 0; i < 4; ++i) { |
| 1038 | if (std::isnan(results[i])) ++nans; |
| 1039 | } |
| 1040 | if (nans == 4) return Type::NaN(); // [-inf..-inf] + [inf..inf] or vice versa |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1041 | Type* range = |
| 1042 | Type::Range(array_min(results, 4), array_max(results, 4), t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1043 | return nans == 0 ? range : Type::Union(range, Type::NaN(), t->zone()); |
| 1044 | // Examples: |
| 1045 | // [-inf, -inf] + [+inf, +inf] = NaN |
| 1046 | // [-inf, -inf] + [n, +inf] = [-inf, -inf] \/ NaN |
| 1047 | // [-inf, +inf] + [n, +inf] = [-inf, +inf] \/ NaN |
| 1048 | // [-inf, m] + [n, +inf] = [-inf, +inf] \/ NaN |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1052 | Type* Typer::Visitor::JSAddTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1053 | lhs = ToPrimitive(lhs, t); |
| 1054 | rhs = ToPrimitive(rhs, t); |
| 1055 | if (lhs->Maybe(Type::String()) || rhs->Maybe(Type::String())) { |
| 1056 | if (lhs->Is(Type::String()) || rhs->Is(Type::String())) { |
| 1057 | return Type::String(); |
| 1058 | } else { |
| 1059 | return Type::NumberOrString(); |
| 1060 | } |
| 1061 | } |
| 1062 | lhs = Rangify(ToNumber(lhs, t), t); |
| 1063 | rhs = Rangify(ToNumber(rhs, t), t); |
| 1064 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN(); |
| 1065 | if (lhs->IsRange() && rhs->IsRange()) { |
| 1066 | return JSAddRanger(lhs->AsRange(), rhs->AsRange(), t); |
| 1067 | } |
| 1068 | // TODO(neis): Deal with numeric bitsets here and elsewhere. |
| 1069 | return Type::Number(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1072 | Type* Typer::Visitor::JSSubtractRanger(RangeType* lhs, RangeType* rhs, |
| 1073 | Typer* t) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1074 | double results[4]; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1075 | results[0] = lhs->Min() - rhs->Min(); |
| 1076 | results[1] = lhs->Min() - rhs->Max(); |
| 1077 | results[2] = lhs->Max() - rhs->Min(); |
| 1078 | results[3] = lhs->Max() - rhs->Max(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1079 | // Since none of the inputs can be -0, the result cannot be -0. |
| 1080 | // However, it can be nan (the subtraction of two infinities of same sign). |
| 1081 | // On the other hand, if none of the "results" above is nan, then the actual |
| 1082 | // result cannot be nan either. |
| 1083 | int nans = 0; |
| 1084 | for (int i = 0; i < 4; ++i) { |
| 1085 | if (std::isnan(results[i])) ++nans; |
| 1086 | } |
| 1087 | if (nans == 4) return Type::NaN(); // [inf..inf] - [inf..inf] (all same sign) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1088 | Type* range = |
| 1089 | Type::Range(array_min(results, 4), array_max(results, 4), t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1090 | return nans == 0 ? range : Type::Union(range, Type::NaN(), t->zone()); |
| 1091 | // Examples: |
| 1092 | // [-inf, +inf] - [-inf, +inf] = [-inf, +inf] \/ NaN |
| 1093 | // [-inf, -inf] - [-inf, -inf] = NaN |
| 1094 | // [-inf, -inf] - [n, +inf] = [-inf, -inf] \/ NaN |
| 1095 | // [m, +inf] - [-inf, n] = [-inf, +inf] \/ NaN |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | Type* Typer::Visitor::JSSubtractTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1100 | lhs = Rangify(ToNumber(lhs, t), t); |
| 1101 | rhs = Rangify(ToNumber(rhs, t), t); |
| 1102 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN(); |
| 1103 | if (lhs->IsRange() && rhs->IsRange()) { |
| 1104 | return JSSubtractRanger(lhs->AsRange(), rhs->AsRange(), t); |
| 1105 | } |
| 1106 | return Type::Number(); |
| 1107 | } |
| 1108 | |
| 1109 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1110 | Type* Typer::Visitor::JSMultiplyTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1111 | lhs = Rangify(ToNumber(lhs, t), t); |
| 1112 | rhs = Rangify(ToNumber(rhs, t), t); |
| 1113 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN(); |
| 1114 | if (lhs->IsRange() && rhs->IsRange()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1115 | double results[4]; |
| 1116 | double lmin = lhs->AsRange()->Min(); |
| 1117 | double lmax = lhs->AsRange()->Max(); |
| 1118 | double rmin = rhs->AsRange()->Min(); |
| 1119 | double rmax = rhs->AsRange()->Max(); |
| 1120 | results[0] = lmin * rmin; |
| 1121 | results[1] = lmin * rmax; |
| 1122 | results[2] = lmax * rmin; |
| 1123 | results[3] = lmax * rmax; |
| 1124 | // If the result may be nan, we give up on calculating a precise type, |
| 1125 | // because |
| 1126 | // the discontinuity makes it too complicated. Note that even if none of |
| 1127 | // the |
| 1128 | // "results" above is nan, the actual result may still be, so we have to do |
| 1129 | // a |
| 1130 | // different check: |
| 1131 | bool maybe_nan = (lhs->Maybe(t->cache_.kSingletonZero) && |
| 1132 | (rmin == -V8_INFINITY || rmax == +V8_INFINITY)) || |
| 1133 | (rhs->Maybe(t->cache_.kSingletonZero) && |
| 1134 | (lmin == -V8_INFINITY || lmax == +V8_INFINITY)); |
| 1135 | if (maybe_nan) return t->cache_.kIntegerOrMinusZeroOrNaN; // Giving up. |
| 1136 | bool maybe_minuszero = (lhs->Maybe(t->cache_.kSingletonZero) && rmin < 0) || |
| 1137 | (rhs->Maybe(t->cache_.kSingletonZero) && lmin < 0); |
| 1138 | Type* range = |
| 1139 | Type::Range(array_min(results, 4), array_max(results, 4), t->zone()); |
| 1140 | return maybe_minuszero ? Type::Union(range, Type::MinusZero(), t->zone()) |
| 1141 | : range; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1142 | } |
| 1143 | return Type::Number(); |
| 1144 | } |
| 1145 | |
| 1146 | |
| 1147 | Type* Typer::Visitor::JSDivideTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1148 | lhs = ToNumber(lhs, t); |
| 1149 | rhs = ToNumber(rhs, t); |
| 1150 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN(); |
| 1151 | // Division is tricky, so all we do is try ruling out nan. |
| 1152 | // TODO(neis): try ruling out -0 as well? |
| 1153 | bool maybe_nan = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1154 | lhs->Maybe(Type::NaN()) || rhs->Maybe(t->cache_.kZeroish) || |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1155 | ((lhs->Min() == -V8_INFINITY || lhs->Max() == +V8_INFINITY) && |
| 1156 | (rhs->Min() == -V8_INFINITY || rhs->Max() == +V8_INFINITY)); |
| 1157 | return maybe_nan ? Type::Number() : Type::OrderedNumber(); |
| 1158 | } |
| 1159 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1160 | Type* Typer::Visitor::JSModulusRanger(RangeType* lhs, RangeType* rhs, |
| 1161 | Typer* t) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1162 | double lmin = lhs->Min(); |
| 1163 | double lmax = lhs->Max(); |
| 1164 | double rmin = rhs->Min(); |
| 1165 | double rmax = rhs->Max(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1166 | |
| 1167 | double labs = std::max(std::abs(lmin), std::abs(lmax)); |
| 1168 | double rabs = std::max(std::abs(rmin), std::abs(rmax)) - 1; |
| 1169 | double abs = std::min(labs, rabs); |
| 1170 | bool maybe_minus_zero = false; |
| 1171 | double omin = 0; |
| 1172 | double omax = 0; |
| 1173 | if (lmin >= 0) { // {lhs} positive. |
| 1174 | omin = 0; |
| 1175 | omax = abs; |
| 1176 | } else if (lmax <= 0) { // {lhs} negative. |
| 1177 | omin = 0 - abs; |
| 1178 | omax = 0; |
| 1179 | maybe_minus_zero = true; |
| 1180 | } else { |
| 1181 | omin = 0 - abs; |
| 1182 | omax = abs; |
| 1183 | maybe_minus_zero = true; |
| 1184 | } |
| 1185 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1186 | Type* result = Type::Range(omin, omax, t->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1187 | if (maybe_minus_zero) |
| 1188 | result = Type::Union(result, Type::MinusZero(), t->zone()); |
| 1189 | return result; |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | Type* Typer::Visitor::JSModulusTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1194 | lhs = ToNumber(lhs, t); |
| 1195 | rhs = ToNumber(rhs, t); |
| 1196 | if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN(); |
| 1197 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1198 | if (lhs->Maybe(Type::NaN()) || rhs->Maybe(t->cache_.kZeroish) || |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1199 | lhs->Min() == -V8_INFINITY || lhs->Max() == +V8_INFINITY) { |
| 1200 | // Result maybe NaN. |
| 1201 | return Type::Number(); |
| 1202 | } |
| 1203 | |
| 1204 | lhs = Rangify(lhs, t); |
| 1205 | rhs = Rangify(rhs, t); |
| 1206 | if (lhs->IsRange() && rhs->IsRange()) { |
| 1207 | return JSModulusRanger(lhs->AsRange(), rhs->AsRange(), t); |
| 1208 | } |
| 1209 | return Type::OrderedNumber(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | // JS unary operators. |
| 1214 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1215 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1216 | Type* Typer::Visitor::JSTypeOfTyper(Type* type, Typer* t) { |
| 1217 | Factory* const f = t->isolate()->factory(); |
| 1218 | if (type->Is(Type::Boolean())) { |
| 1219 | return Type::Constant(f->boolean_string(), t->zone()); |
| 1220 | } else if (type->Is(Type::Number())) { |
| 1221 | return Type::Constant(f->number_string(), t->zone()); |
| 1222 | } else if (type->Is(Type::String())) { |
| 1223 | return Type::Constant(f->string_string(), t->zone()); |
| 1224 | } else if (type->Is(Type::Symbol())) { |
| 1225 | return Type::Constant(f->symbol_string(), t->zone()); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1226 | } else if (type->Is(Type::Union(Type::Undefined(), Type::OtherUndetectable(), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1227 | t->zone()))) { |
| 1228 | return Type::Constant(f->undefined_string(), t->zone()); |
| 1229 | } else if (type->Is(Type::Null())) { |
| 1230 | return Type::Constant(f->object_string(), t->zone()); |
| 1231 | } else if (type->Is(Type::Function())) { |
| 1232 | return Type::Constant(f->function_string(), t->zone()); |
| 1233 | } else if (type->IsConstant()) { |
| 1234 | return Type::Constant( |
| 1235 | Object::TypeOf(t->isolate(), type->AsConstant()->Value()), t->zone()); |
| 1236 | } |
| 1237 | return Type::InternalizedString(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1241 | Type* Typer::Visitor::TypeJSTypeOf(Node* node) { |
| 1242 | return TypeUnaryOp(node, JSTypeOfTyper); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | // JS conversion operators. |
| 1247 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1248 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1249 | Type* Typer::Visitor::TypeJSToBoolean(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1250 | return TypeUnaryOp(node, ToBoolean); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1253 | Type* Typer::Visitor::TypeJSToInteger(Node* node) { |
| 1254 | return TypeUnaryOp(node, ToInteger); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1257 | Type* Typer::Visitor::TypeJSToLength(Node* node) { |
| 1258 | return TypeUnaryOp(node, ToLength); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1261 | Type* Typer::Visitor::TypeJSToName(Node* node) { |
| 1262 | return TypeUnaryOp(node, ToName); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1265 | Type* Typer::Visitor::TypeJSToNumber(Node* node) { |
| 1266 | return TypeUnaryOp(node, ToNumber); |
| 1267 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1268 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1269 | Type* Typer::Visitor::TypeJSToObject(Node* node) { |
| 1270 | return TypeUnaryOp(node, ToObject); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1273 | Type* Typer::Visitor::TypeJSToString(Node* node) { |
| 1274 | return TypeUnaryOp(node, ToString); |
| 1275 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1276 | |
| 1277 | // JS object operators. |
| 1278 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1279 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1280 | Type* Typer::Visitor::TypeJSCreate(Node* node) { return Type::Object(); } |
| 1281 | |
| 1282 | |
| 1283 | Type* Typer::Visitor::TypeJSCreateArguments(Node* node) { |
| 1284 | return Type::OtherObject(); |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | Type* Typer::Visitor::TypeJSCreateArray(Node* node) { |
| 1289 | return Type::OtherObject(); |
| 1290 | } |
| 1291 | |
| 1292 | |
| 1293 | Type* Typer::Visitor::TypeJSCreateClosure(Node* node) { |
| 1294 | return Type::Function(); |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | Type* Typer::Visitor::TypeJSCreateIterResultObject(Node* node) { |
| 1299 | return Type::OtherObject(); |
| 1300 | } |
| 1301 | |
| 1302 | |
| 1303 | Type* Typer::Visitor::TypeJSCreateLiteralArray(Node* node) { |
| 1304 | return Type::OtherObject(); |
| 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | Type* Typer::Visitor::TypeJSCreateLiteralObject(Node* node) { |
| 1309 | return Type::OtherObject(); |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | Type* Typer::Visitor::TypeJSCreateLiteralRegExp(Node* node) { |
| 1314 | return Type::OtherObject(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | Type* Typer::Visitor::JSLoadPropertyTyper(Type* object, Type* name, Typer* t) { |
| 1319 | // TODO(rossberg): Use range types and sized array types to filter undefined. |
| 1320 | if (object->IsArray() && name->Is(Type::Integral32())) { |
| 1321 | return Type::Union( |
| 1322 | object->AsArray()->Element(), Type::Undefined(), t->zone()); |
| 1323 | } |
| 1324 | return Type::Any(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1328 | Type* Typer::Visitor::TypeJSLoadProperty(Node* node) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1329 | return TypeBinaryOp(node, JSLoadPropertyTyper); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1333 | Type* Typer::Visitor::TypeJSLoadNamed(Node* node) { |
| 1334 | Factory* const f = isolate()->factory(); |
| 1335 | Handle<Name> name = NamedAccessOf(node->op()).name(); |
| 1336 | if (name.is_identical_to(f->prototype_string())) { |
| 1337 | Type* receiver = Operand(node, 0); |
| 1338 | if (receiver->Is(Type::None())) return Type::None(); |
| 1339 | if (receiver->IsConstant() && |
| 1340 | receiver->AsConstant()->Value()->IsJSFunction()) { |
| 1341 | Handle<JSFunction> function = |
| 1342 | Handle<JSFunction>::cast(receiver->AsConstant()->Value()); |
| 1343 | if (function->has_prototype()) { |
| 1344 | // We need to add a code dependency on the initial map of the {function} |
| 1345 | // in order to be notified about changes to "prototype" of {function}, |
| 1346 | // so we can only infer a constant type if deoptimization is enabled. |
| 1347 | if (flags() & kDeoptimizationEnabled) { |
| 1348 | JSFunction::EnsureHasInitialMap(function); |
| 1349 | Handle<Map> initial_map(function->initial_map(), isolate()); |
| 1350 | dependencies()->AssumeInitialMapCantChange(initial_map); |
| 1351 | return Type::Constant(handle(initial_map->prototype(), isolate()), |
| 1352 | zone()); |
| 1353 | } |
| 1354 | } |
| 1355 | } else if (receiver->IsClass() && |
| 1356 | receiver->AsClass()->Map()->IsJSFunctionMap()) { |
| 1357 | Handle<Map> map = receiver->AsClass()->Map(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1358 | return map->has_non_instance_prototype() ? Type::Primitive() |
| 1359 | : Type::Receiver(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | return Type::Any(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1366 | Type* Typer::Visitor::TypeJSLoadGlobal(Node* node) { return Type::Any(); } |
| 1367 | |
| 1368 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1369 | // Returns a somewhat larger range if we previously assigned |
| 1370 | // a (smaller) range to this node. This is used to speed up |
| 1371 | // the fixpoint calculation in case there appears to be a loop |
| 1372 | // in the graph. In the current implementation, we are |
| 1373 | // increasing the limits to the closest power of two. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1374 | Type* Typer::Visitor::Weaken(Node* node, Type* current_type, |
| 1375 | Type* previous_type) { |
| 1376 | static const double kWeakenMinLimits[] = { |
| 1377 | 0.0, -1073741824.0, -2147483648.0, -4294967296.0, -8589934592.0, |
| 1378 | -17179869184.0, -34359738368.0, -68719476736.0, -137438953472.0, |
| 1379 | -274877906944.0, -549755813888.0, -1099511627776.0, -2199023255552.0, |
| 1380 | -4398046511104.0, -8796093022208.0, -17592186044416.0, -35184372088832.0, |
| 1381 | -70368744177664.0, -140737488355328.0, -281474976710656.0, |
| 1382 | -562949953421312.0}; |
| 1383 | static const double kWeakenMaxLimits[] = { |
| 1384 | 0.0, 1073741823.0, 2147483647.0, 4294967295.0, 8589934591.0, |
| 1385 | 17179869183.0, 34359738367.0, 68719476735.0, 137438953471.0, |
| 1386 | 274877906943.0, 549755813887.0, 1099511627775.0, 2199023255551.0, |
| 1387 | 4398046511103.0, 8796093022207.0, 17592186044415.0, 35184372088831.0, |
| 1388 | 70368744177663.0, 140737488355327.0, 281474976710655.0, |
| 1389 | 562949953421311.0}; |
| 1390 | STATIC_ASSERT(arraysize(kWeakenMinLimits) == arraysize(kWeakenMaxLimits)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1391 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1392 | // If the types have nothing to do with integers, return the types. |
| 1393 | Type* const integer = typer_->cache_.kInteger; |
| 1394 | if (!previous_type->Maybe(integer)) { |
| 1395 | return current_type; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1396 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1397 | DCHECK(current_type->Maybe(integer)); |
| 1398 | |
| 1399 | Type* current_integer = Type::Intersect(current_type, integer, zone()); |
| 1400 | Type* previous_integer = Type::Intersect(previous_type, integer, zone()); |
| 1401 | |
| 1402 | // Once we start weakening a node, we should always weaken. |
| 1403 | if (!IsWeakened(node->id())) { |
| 1404 | // Only weaken if there is range involved; we should converge quickly |
| 1405 | // for all other types (the exception is a union of many constants, |
| 1406 | // but we currently do not increase the number of constants in unions). |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1407 | Type* previous = previous_integer->GetRange(); |
| 1408 | Type* current = current_integer->GetRange(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1409 | if (current == nullptr || previous == nullptr) { |
| 1410 | return current_type; |
| 1411 | } |
| 1412 | // Range is involved => we are weakening. |
| 1413 | SetWeakened(node->id()); |
| 1414 | } |
| 1415 | |
| 1416 | double current_min = current_integer->Min(); |
| 1417 | double new_min = current_min; |
| 1418 | // Find the closest lower entry in the list of allowed |
| 1419 | // minima (or negative infinity if there is no such entry). |
| 1420 | if (current_min != previous_integer->Min()) { |
| 1421 | new_min = -V8_INFINITY; |
| 1422 | for (double const min : kWeakenMinLimits) { |
| 1423 | if (min <= current_min) { |
| 1424 | new_min = min; |
| 1425 | break; |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | double current_max = current_integer->Max(); |
| 1431 | double new_max = current_max; |
| 1432 | // Find the closest greater entry in the list of allowed |
| 1433 | // maxima (or infinity if there is no such entry). |
| 1434 | if (current_max != previous_integer->Max()) { |
| 1435 | new_max = V8_INFINITY; |
| 1436 | for (double const max : kWeakenMaxLimits) { |
| 1437 | if (max >= current_max) { |
| 1438 | new_max = max; |
| 1439 | break; |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | return Type::Union(current_type, |
| 1445 | Type::Range(new_min, new_max, typer_->zone()), |
| 1446 | typer_->zone()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1450 | Type* Typer::Visitor::TypeJSStoreProperty(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1451 | UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1452 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1456 | Type* Typer::Visitor::TypeJSStoreNamed(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1457 | UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1458 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1462 | Type* Typer::Visitor::TypeJSStoreGlobal(Node* node) { |
| 1463 | UNREACHABLE(); |
| 1464 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1468 | Type* Typer::Visitor::TypeJSDeleteProperty(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1469 | return Type::Boolean(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1472 | Type* Typer::Visitor::TypeJSHasProperty(Node* node) { return Type::Boolean(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1473 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1474 | Type* Typer::Visitor::TypeJSInstanceOf(Node* node) { return Type::Boolean(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1475 | |
| 1476 | // JS context operators. |
| 1477 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1478 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1479 | Type* Typer::Visitor::TypeJSLoadContext(Node* node) { |
| 1480 | ContextAccess const& access = ContextAccessOf(node->op()); |
| 1481 | if (access.index() == Context::EXTENSION_INDEX) { |
| 1482 | return Type::TaggedPointer(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1483 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1484 | // Since contexts are mutable, we just return the top. |
| 1485 | return Type::Any(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1489 | Type* Typer::Visitor::TypeJSStoreContext(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1490 | UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1491 | return nullptr; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1495 | Type* Typer::Visitor::WrapContextTypeForInput(Node* node) { |
| 1496 | Type* outer = TypeOrNone(NodeProperties::GetContextInput(node)); |
| 1497 | if (outer->Is(Type::None())) { |
| 1498 | return Type::None(); |
| 1499 | } else { |
| 1500 | DCHECK(outer->Maybe(Type::Internal())); |
| 1501 | return Type::Context(outer, zone()); |
| 1502 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1506 | Type* Typer::Visitor::TypeJSCreateFunctionContext(Node* node) { |
| 1507 | return WrapContextTypeForInput(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1511 | Type* Typer::Visitor::TypeJSCreateCatchContext(Node* node) { |
| 1512 | return WrapContextTypeForInput(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1516 | Type* Typer::Visitor::TypeJSCreateWithContext(Node* node) { |
| 1517 | return WrapContextTypeForInput(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1521 | Type* Typer::Visitor::TypeJSCreateBlockContext(Node* node) { |
| 1522 | return WrapContextTypeForInput(node); |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | Type* Typer::Visitor::TypeJSCreateModuleContext(Node* node) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1527 | // TODO(rossberg): this is probably incorrect |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1528 | return WrapContextTypeForInput(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1532 | Type* Typer::Visitor::TypeJSCreateScriptContext(Node* node) { |
| 1533 | return WrapContextTypeForInput(node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | |
| 1537 | // JS other operators. |
| 1538 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1539 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1540 | Type* Typer::Visitor::TypeJSYield(Node* node) { return Type::Any(); } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1541 | |
| 1542 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1543 | Type* Typer::Visitor::TypeJSCallConstruct(Node* node) { |
| 1544 | return Type::Receiver(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | |
| 1548 | Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1549 | if (fun->IsFunction()) { |
| 1550 | return fun->AsFunction()->Result(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1551 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1552 | if (fun->IsConstant() && fun->AsConstant()->Value()->IsJSFunction()) { |
| 1553 | Handle<JSFunction> function = |
| 1554 | Handle<JSFunction>::cast(fun->AsConstant()->Value()); |
| 1555 | if (function->shared()->HasBuiltinFunctionId()) { |
| 1556 | switch (function->shared()->builtin_function_id()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1557 | case kMathRandom: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1558 | return Type::OrderedNumber(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1559 | case kMathFloor: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1560 | case kMathCeil: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1561 | case kMathRound: |
| 1562 | case kMathTrunc: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1563 | return t->cache_.kIntegerOrMinusZeroOrNaN; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1564 | // Unary math functions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1565 | case kMathAbs: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1566 | case kMathLog: |
| 1567 | case kMathExp: |
| 1568 | case kMathSqrt: |
| 1569 | case kMathCos: |
| 1570 | case kMathSin: |
| 1571 | case kMathTan: |
| 1572 | case kMathAcos: |
| 1573 | case kMathAsin: |
| 1574 | case kMathAtan: |
| 1575 | case kMathFround: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1576 | return Type::Number(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1577 | // Binary math functions. |
| 1578 | case kMathAtan2: |
| 1579 | case kMathPow: |
| 1580 | case kMathMax: |
| 1581 | case kMathMin: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1582 | return Type::Number(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1583 | case kMathImul: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1584 | return Type::Signed32(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1585 | case kMathClz32: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1586 | return t->cache_.kZeroToThirtyTwo; |
| 1587 | // String functions. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1588 | case kStringCharCodeAt: |
| 1589 | return Type::Union(Type::Range(0, kMaxUInt16, t->zone()), Type::NaN(), |
| 1590 | t->zone()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1591 | case kStringCharAt: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1592 | case kStringConcat: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1593 | case kStringFromCharCode: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1594 | case kStringToLowerCase: |
| 1595 | case kStringToUpperCase: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1596 | return Type::String(); |
| 1597 | // Array functions. |
| 1598 | case kArrayIndexOf: |
| 1599 | case kArrayLastIndexOf: |
| 1600 | return Type::Number(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1601 | default: |
| 1602 | break; |
| 1603 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1604 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1605 | } |
| 1606 | return Type::Any(); |
| 1607 | } |
| 1608 | |
| 1609 | |
| 1610 | Type* Typer::Visitor::TypeJSCallFunction(Node* node) { |
| 1611 | // TODO(bmeurer): We could infer better types if we wouldn't ignore the |
| 1612 | // argument types for the JSCallFunctionTyper above. |
| 1613 | return TypeUnaryOp(node, JSCallFunctionTyper); |
| 1614 | } |
| 1615 | |
| 1616 | |
| 1617 | Type* Typer::Visitor::TypeJSCallRuntime(Node* node) { |
| 1618 | switch (CallRuntimeParametersOf(node->op()).id()) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1619 | case Runtime::kInlineIsJSReceiver: |
| 1620 | return TypeUnaryOp(node, ObjectIsReceiver); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1621 | case Runtime::kInlineIsSmi: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1622 | return TypeUnaryOp(node, ObjectIsSmi); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1623 | case Runtime::kInlineIsArray: |
| 1624 | case Runtime::kInlineIsDate: |
| 1625 | case Runtime::kInlineIsTypedArray: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1626 | case Runtime::kInlineIsRegExp: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1627 | return Type::Boolean(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1628 | case Runtime::kInlineDoubleLo: |
| 1629 | case Runtime::kInlineDoubleHi: |
| 1630 | return Type::Signed32(); |
| 1631 | case Runtime::kInlineConstructDouble: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1632 | case Runtime::kInlineMathAtan2: |
| 1633 | return Type::Number(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1634 | case Runtime::kInlineCreateIterResultObject: |
| 1635 | case Runtime::kInlineRegExpConstructResult: |
| 1636 | return Type::OtherObject(); |
| 1637 | case Runtime::kInlineSubString: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1638 | case Runtime::kInlineStringCharFromCode: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1639 | return Type::String(); |
| 1640 | case Runtime::kInlineToInteger: |
| 1641 | return TypeUnaryOp(node, ToInteger); |
| 1642 | case Runtime::kInlineToLength: |
| 1643 | return TypeUnaryOp(node, ToLength); |
| 1644 | case Runtime::kInlineToName: |
| 1645 | return TypeUnaryOp(node, ToName); |
| 1646 | case Runtime::kInlineToNumber: |
| 1647 | return TypeUnaryOp(node, ToNumber); |
| 1648 | case Runtime::kInlineToObject: |
| 1649 | return TypeUnaryOp(node, ToObject); |
| 1650 | case Runtime::kInlineToPrimitive: |
| 1651 | case Runtime::kInlineToPrimitive_Number: |
| 1652 | case Runtime::kInlineToPrimitive_String: |
| 1653 | return TypeUnaryOp(node, ToPrimitive); |
| 1654 | case Runtime::kInlineToString: |
| 1655 | return TypeUnaryOp(node, ToString); |
| 1656 | case Runtime::kHasInPrototypeChain: |
| 1657 | return Type::Boolean(); |
| 1658 | default: |
| 1659 | break; |
| 1660 | } |
| 1661 | return Type::Any(); |
| 1662 | } |
| 1663 | |
| 1664 | |
| 1665 | Type* Typer::Visitor::TypeJSConvertReceiver(Node* node) { |
| 1666 | return Type::Receiver(); |
| 1667 | } |
| 1668 | |
| 1669 | |
| 1670 | Type* Typer::Visitor::TypeJSForInNext(Node* node) { |
| 1671 | return Type::Union(Type::Name(), Type::Undefined(), zone()); |
| 1672 | } |
| 1673 | |
| 1674 | |
| 1675 | Type* Typer::Visitor::TypeJSForInPrepare(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1676 | STATIC_ASSERT(Map::EnumLengthBits::kMax <= FixedArray::kMaxLength); |
| 1677 | Factory* const f = isolate()->factory(); |
| 1678 | Type* const cache_type = Type::Union( |
| 1679 | typer_->cache_.kSmi, Type::Class(f->meta_map(), zone()), zone()); |
| 1680 | Type* const cache_array = Type::Class(f->fixed_array_map(), zone()); |
| 1681 | Type* const cache_length = typer_->cache_.kFixedArrayLengthType; |
| 1682 | return Type::Tuple(cache_type, cache_array, cache_length, zone()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1685 | Type* Typer::Visitor::TypeJSForInDone(Node* node) { return Type::Boolean(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1686 | |
| 1687 | Type* Typer::Visitor::TypeJSForInStep(Node* node) { |
| 1688 | STATIC_ASSERT(Map::EnumLengthBits::kMax <= FixedArray::kMaxLength); |
| 1689 | return Type::Range(1, FixedArray::kMaxLength + 1, zone()); |
| 1690 | } |
| 1691 | |
| 1692 | |
| 1693 | Type* Typer::Visitor::TypeJSLoadMessage(Node* node) { return Type::Any(); } |
| 1694 | |
| 1695 | |
| 1696 | Type* Typer::Visitor::TypeJSStoreMessage(Node* node) { |
| 1697 | UNREACHABLE(); |
| 1698 | return nullptr; |
| 1699 | } |
| 1700 | |
| 1701 | |
| 1702 | Type* Typer::Visitor::TypeJSStackCheck(Node* node) { return Type::Any(); } |
| 1703 | |
| 1704 | |
| 1705 | // Simplified operators. |
| 1706 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1707 | Type* Typer::Visitor::TypeBooleanNot(Node* node) { return Type::Boolean(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1708 | |
| 1709 | Type* Typer::Visitor::TypeBooleanToNumber(Node* node) { |
| 1710 | return TypeUnaryOp(node, ToNumber); |
| 1711 | } |
| 1712 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1713 | Type* Typer::Visitor::TypeNumberEqual(Node* node) { return Type::Boolean(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1714 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1715 | Type* Typer::Visitor::TypeNumberLessThan(Node* node) { return Type::Boolean(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1716 | |
| 1717 | Type* Typer::Visitor::TypeNumberLessThanOrEqual(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1718 | return Type::Boolean(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1721 | Type* Typer::Visitor::TypeNumberAdd(Node* node) { return Type::Number(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1722 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1723 | Type* Typer::Visitor::TypeNumberSubtract(Node* node) { return Type::Number(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1724 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1725 | Type* Typer::Visitor::TypeNumberMultiply(Node* node) { return Type::Number(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1726 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1727 | Type* Typer::Visitor::TypeNumberDivide(Node* node) { return Type::Number(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1728 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1729 | Type* Typer::Visitor::TypeNumberModulus(Node* node) { return Type::Number(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1730 | |
| 1731 | Type* Typer::Visitor::TypeNumberBitwiseOr(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1732 | return Type::Signed32(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | Type* Typer::Visitor::TypeNumberBitwiseXor(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1737 | return Type::Signed32(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | Type* Typer::Visitor::TypeNumberBitwiseAnd(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1742 | return Type::Signed32(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | |
| 1746 | Type* Typer::Visitor::TypeNumberShiftLeft(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1747 | return Type::Signed32(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | |
| 1751 | Type* Typer::Visitor::TypeNumberShiftRight(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1752 | return Type::Signed32(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | |
| 1756 | Type* Typer::Visitor::TypeNumberShiftRightLogical(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1757 | return Type::Unsigned32(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1760 | Type* Typer::Visitor::TypeNumberImul(Node* node) { return Type::Signed32(); } |
| 1761 | |
| 1762 | Type* Typer::Visitor::TypeNumberClz32(Node* node) { |
| 1763 | return typer_->cache_.kZeroToThirtyTwo; |
| 1764 | } |
| 1765 | |
| 1766 | Type* Typer::Visitor::TypeNumberCeil(Node* node) { |
| 1767 | return TypeUnaryOp(node, NumberCeil); |
| 1768 | } |
| 1769 | |
| 1770 | Type* Typer::Visitor::TypeNumberFloor(Node* node) { |
| 1771 | return TypeUnaryOp(node, NumberFloor); |
| 1772 | } |
| 1773 | |
| 1774 | Type* Typer::Visitor::TypeNumberRound(Node* node) { |
| 1775 | return TypeUnaryOp(node, NumberRound); |
| 1776 | } |
| 1777 | |
| 1778 | Type* Typer::Visitor::TypeNumberTrunc(Node* node) { |
| 1779 | return TypeUnaryOp(node, NumberTrunc); |
| 1780 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1781 | |
| 1782 | Type* Typer::Visitor::TypeNumberToInt32(Node* node) { |
| 1783 | return TypeUnaryOp(node, NumberToInt32); |
| 1784 | } |
| 1785 | |
| 1786 | |
| 1787 | Type* Typer::Visitor::TypeNumberToUint32(Node* node) { |
| 1788 | return TypeUnaryOp(node, NumberToUint32); |
| 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | Type* Typer::Visitor::TypeNumberIsHoleNaN(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1793 | return Type::Boolean(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | |
| 1797 | Type* Typer::Visitor::TypePlainPrimitiveToNumber(Node* node) { |
| 1798 | return TypeUnaryOp(node, ToNumber); |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | // static |
| 1803 | Type* Typer::Visitor::ReferenceEqualTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1804 | if (lhs->IsConstant() && rhs->Is(lhs)) { |
| 1805 | return t->singleton_true_; |
| 1806 | } |
| 1807 | return Type::Boolean(); |
| 1808 | } |
| 1809 | |
| 1810 | |
| 1811 | Type* Typer::Visitor::TypeReferenceEqual(Node* node) { |
| 1812 | return TypeBinaryOp(node, ReferenceEqualTyper); |
| 1813 | } |
| 1814 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1815 | Type* Typer::Visitor::TypeStringEqual(Node* node) { return Type::Boolean(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1816 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1817 | Type* Typer::Visitor::TypeStringLessThan(Node* node) { return Type::Boolean(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1818 | |
| 1819 | Type* Typer::Visitor::TypeStringLessThanOrEqual(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1820 | return Type::Boolean(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1823 | Type* Typer::Visitor::TypeStringToNumber(Node* node) { |
| 1824 | return TypeUnaryOp(node, ToNumber); |
| 1825 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1826 | |
| 1827 | namespace { |
| 1828 | |
| 1829 | Type* ChangeRepresentation(Type* type, Type* rep, Zone* zone) { |
| 1830 | return Type::Union(Type::Semantic(type, zone), |
| 1831 | Type::Representation(rep, zone), zone); |
| 1832 | } |
| 1833 | |
| 1834 | } // namespace |
| 1835 | |
| 1836 | |
| 1837 | Type* Typer::Visitor::TypeChangeTaggedToInt32(Node* node) { |
| 1838 | Type* arg = Operand(node, 0); |
| 1839 | // TODO(neis): DCHECK(arg->Is(Type::Signed32())); |
| 1840 | return ChangeRepresentation(arg, Type::UntaggedIntegral32(), zone()); |
| 1841 | } |
| 1842 | |
| 1843 | |
| 1844 | Type* Typer::Visitor::TypeChangeTaggedToUint32(Node* node) { |
| 1845 | Type* arg = Operand(node, 0); |
| 1846 | // TODO(neis): DCHECK(arg->Is(Type::Unsigned32())); |
| 1847 | return ChangeRepresentation(arg, Type::UntaggedIntegral32(), zone()); |
| 1848 | } |
| 1849 | |
| 1850 | |
| 1851 | Type* Typer::Visitor::TypeChangeTaggedToFloat64(Node* node) { |
| 1852 | Type* arg = Operand(node, 0); |
| 1853 | // TODO(neis): DCHECK(arg->Is(Type::Number())); |
| 1854 | return ChangeRepresentation(arg, Type::UntaggedFloat64(), zone()); |
| 1855 | } |
| 1856 | |
| 1857 | |
| 1858 | Type* Typer::Visitor::TypeChangeInt32ToTagged(Node* node) { |
| 1859 | Type* arg = Operand(node, 0); |
| 1860 | // TODO(neis): DCHECK(arg->Is(Type::Signed32())); |
| 1861 | Type* rep = |
| 1862 | arg->Is(Type::SignedSmall()) ? Type::TaggedSigned() : Type::Tagged(); |
| 1863 | return ChangeRepresentation(arg, rep, zone()); |
| 1864 | } |
| 1865 | |
| 1866 | |
| 1867 | Type* Typer::Visitor::TypeChangeUint32ToTagged(Node* node) { |
| 1868 | Type* arg = Operand(node, 0); |
| 1869 | // TODO(neis): DCHECK(arg->Is(Type::Unsigned32())); |
| 1870 | return ChangeRepresentation(arg, Type::Tagged(), zone()); |
| 1871 | } |
| 1872 | |
| 1873 | |
| 1874 | Type* Typer::Visitor::TypeChangeFloat64ToTagged(Node* node) { |
| 1875 | Type* arg = Operand(node, 0); |
| 1876 | // TODO(neis): CHECK(arg.upper->Is(Type::Number())); |
| 1877 | return ChangeRepresentation(arg, Type::Tagged(), zone()); |
| 1878 | } |
| 1879 | |
| 1880 | |
| 1881 | Type* Typer::Visitor::TypeChangeBoolToBit(Node* node) { |
| 1882 | Type* arg = Operand(node, 0); |
| 1883 | // TODO(neis): DCHECK(arg.upper->Is(Type::Boolean())); |
| 1884 | return ChangeRepresentation(arg, Type::UntaggedBit(), zone()); |
| 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | Type* Typer::Visitor::TypeChangeBitToBool(Node* node) { |
| 1889 | Type* arg = Operand(node, 0); |
| 1890 | // TODO(neis): DCHECK(arg.upper->Is(Type::Boolean())); |
| 1891 | return ChangeRepresentation(arg, Type::TaggedPointer(), zone()); |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | Type* Typer::Visitor::TypeAllocate(Node* node) { return Type::TaggedPointer(); } |
| 1896 | |
| 1897 | |
| 1898 | namespace { |
| 1899 | |
| 1900 | MaybeHandle<Map> GetStableMapFromObjectType(Type* object_type) { |
| 1901 | if (object_type->IsConstant() && |
| 1902 | object_type->AsConstant()->Value()->IsHeapObject()) { |
| 1903 | Handle<Map> object_map( |
| 1904 | Handle<HeapObject>::cast(object_type->AsConstant()->Value())->map()); |
| 1905 | if (object_map->is_stable()) return object_map; |
| 1906 | } else if (object_type->IsClass()) { |
| 1907 | Handle<Map> object_map = object_type->AsClass()->Map(); |
| 1908 | if (object_map->is_stable()) return object_map; |
| 1909 | } |
| 1910 | return MaybeHandle<Map>(); |
| 1911 | } |
| 1912 | |
| 1913 | } // namespace |
| 1914 | |
| 1915 | |
| 1916 | Type* Typer::Visitor::TypeLoadField(Node* node) { |
| 1917 | FieldAccess const& access = FieldAccessOf(node->op()); |
| 1918 | if (access.base_is_tagged == kTaggedBase && |
| 1919 | access.offset == HeapObject::kMapOffset) { |
| 1920 | // The type of LoadField[Map](o) is Constant(map) if map is stable and |
| 1921 | // either |
| 1922 | // (a) o has type Constant(object) and map == object->map, or |
| 1923 | // (b) o has type Class(map), |
| 1924 | // and either |
| 1925 | // (1) map cannot transition further, or |
| 1926 | // (2) deoptimization is enabled and we can add a code dependency on the |
| 1927 | // stability of map (to guard the Constant type information). |
| 1928 | Type* const object = Operand(node, 0); |
| 1929 | if (object->Is(Type::None())) return Type::None(); |
| 1930 | Handle<Map> object_map; |
| 1931 | if (GetStableMapFromObjectType(object).ToHandle(&object_map)) { |
| 1932 | if (object_map->CanTransition()) { |
| 1933 | if (flags() & kDeoptimizationEnabled) { |
| 1934 | dependencies()->AssumeMapStable(object_map); |
| 1935 | } else { |
| 1936 | return access.type; |
| 1937 | } |
| 1938 | } |
| 1939 | Type* object_map_type = Type::Constant(object_map, zone()); |
| 1940 | DCHECK(object_map_type->Is(access.type)); |
| 1941 | return object_map_type; |
| 1942 | } |
| 1943 | } |
| 1944 | return access.type; |
| 1945 | } |
| 1946 | |
| 1947 | |
| 1948 | Type* Typer::Visitor::TypeLoadBuffer(Node* node) { |
| 1949 | // TODO(bmeurer): This typing is not yet correct. Since we can still access |
| 1950 | // out of bounds, the type in the general case has to include Undefined. |
| 1951 | switch (BufferAccessOf(node->op()).external_array_type()) { |
| 1952 | #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
| 1953 | case kExternal##Type##Array: \ |
| 1954 | return typer_->cache_.k##Type; |
| 1955 | TYPED_ARRAYS(TYPED_ARRAY_CASE) |
| 1956 | #undef TYPED_ARRAY_CASE |
| 1957 | } |
| 1958 | UNREACHABLE(); |
| 1959 | return nullptr; |
| 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | Type* Typer::Visitor::TypeLoadElement(Node* node) { |
| 1964 | return ElementAccessOf(node->op()).type; |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | Type* Typer::Visitor::TypeStoreField(Node* node) { |
| 1969 | UNREACHABLE(); |
| 1970 | return nullptr; |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | Type* Typer::Visitor::TypeStoreBuffer(Node* node) { |
| 1975 | UNREACHABLE(); |
| 1976 | return nullptr; |
| 1977 | } |
| 1978 | |
| 1979 | |
| 1980 | Type* Typer::Visitor::TypeStoreElement(Node* node) { |
| 1981 | UNREACHABLE(); |
| 1982 | return nullptr; |
| 1983 | } |
| 1984 | |
| 1985 | |
| 1986 | Type* Typer::Visitor::TypeObjectIsNumber(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1987 | return TypeUnaryOp(node, ObjectIsNumber); |
| 1988 | } |
| 1989 | |
| 1990 | |
| 1991 | Type* Typer::Visitor::TypeObjectIsReceiver(Node* node) { |
| 1992 | return TypeUnaryOp(node, ObjectIsReceiver); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | |
| 1996 | Type* Typer::Visitor::TypeObjectIsSmi(Node* node) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1997 | return TypeUnaryOp(node, ObjectIsSmi); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2001 | Type* Typer::Visitor::TypeObjectIsUndetectable(Node* node) { |
| 2002 | return TypeUnaryOp(node, ObjectIsUndetectable); |
| 2003 | } |
| 2004 | |
| 2005 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2006 | // Machine operators. |
| 2007 | |
| 2008 | Type* Typer::Visitor::TypeLoad(Node* node) { return Type::Any(); } |
| 2009 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2010 | Type* Typer::Visitor::TypeStackSlot(Node* node) { return Type::Any(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2011 | |
| 2012 | Type* Typer::Visitor::TypeStore(Node* node) { |
| 2013 | UNREACHABLE(); |
| 2014 | return nullptr; |
| 2015 | } |
| 2016 | |
| 2017 | |
| 2018 | Type* Typer::Visitor::TypeWord32And(Node* node) { return Type::Integral32(); } |
| 2019 | |
| 2020 | |
| 2021 | Type* Typer::Visitor::TypeWord32Or(Node* node) { return Type::Integral32(); } |
| 2022 | |
| 2023 | |
| 2024 | Type* Typer::Visitor::TypeWord32Xor(Node* node) { return Type::Integral32(); } |
| 2025 | |
| 2026 | |
| 2027 | Type* Typer::Visitor::TypeWord32Shl(Node* node) { return Type::Integral32(); } |
| 2028 | |
| 2029 | |
| 2030 | Type* Typer::Visitor::TypeWord32Shr(Node* node) { return Type::Integral32(); } |
| 2031 | |
| 2032 | |
| 2033 | Type* Typer::Visitor::TypeWord32Sar(Node* node) { return Type::Integral32(); } |
| 2034 | |
| 2035 | |
| 2036 | Type* Typer::Visitor::TypeWord32Ror(Node* node) { return Type::Integral32(); } |
| 2037 | |
| 2038 | |
| 2039 | Type* Typer::Visitor::TypeWord32Equal(Node* node) { return Type::Boolean(); } |
| 2040 | |
| 2041 | |
| 2042 | Type* Typer::Visitor::TypeWord32Clz(Node* node) { return Type::Integral32(); } |
| 2043 | |
| 2044 | |
| 2045 | Type* Typer::Visitor::TypeWord32Ctz(Node* node) { return Type::Integral32(); } |
| 2046 | |
| 2047 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2048 | Type* Typer::Visitor::TypeWord32ReverseBits(Node* node) { |
| 2049 | return Type::Integral32(); |
| 2050 | } |
| 2051 | |
| 2052 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2053 | Type* Typer::Visitor::TypeWord32Popcnt(Node* node) { |
| 2054 | return Type::Integral32(); |
| 2055 | } |
| 2056 | |
| 2057 | |
| 2058 | Type* Typer::Visitor::TypeWord64And(Node* node) { return Type::Internal(); } |
| 2059 | |
| 2060 | |
| 2061 | Type* Typer::Visitor::TypeWord64Or(Node* node) { return Type::Internal(); } |
| 2062 | |
| 2063 | |
| 2064 | Type* Typer::Visitor::TypeWord64Xor(Node* node) { return Type::Internal(); } |
| 2065 | |
| 2066 | |
| 2067 | Type* Typer::Visitor::TypeWord64Shl(Node* node) { return Type::Internal(); } |
| 2068 | |
| 2069 | |
| 2070 | Type* Typer::Visitor::TypeWord64Shr(Node* node) { return Type::Internal(); } |
| 2071 | |
| 2072 | |
| 2073 | Type* Typer::Visitor::TypeWord64Sar(Node* node) { return Type::Internal(); } |
| 2074 | |
| 2075 | |
| 2076 | Type* Typer::Visitor::TypeWord64Ror(Node* node) { return Type::Internal(); } |
| 2077 | |
| 2078 | |
| 2079 | Type* Typer::Visitor::TypeWord64Clz(Node* node) { return Type::Internal(); } |
| 2080 | |
| 2081 | |
| 2082 | Type* Typer::Visitor::TypeWord64Ctz(Node* node) { return Type::Internal(); } |
| 2083 | |
| 2084 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2085 | Type* Typer::Visitor::TypeWord64ReverseBits(Node* node) { |
| 2086 | return Type::Internal(); |
| 2087 | } |
| 2088 | |
| 2089 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2090 | Type* Typer::Visitor::TypeWord64Popcnt(Node* node) { return Type::Internal(); } |
| 2091 | |
| 2092 | |
| 2093 | Type* Typer::Visitor::TypeWord64Equal(Node* node) { return Type::Boolean(); } |
| 2094 | |
| 2095 | |
| 2096 | Type* Typer::Visitor::TypeInt32Add(Node* node) { return Type::Integral32(); } |
| 2097 | |
| 2098 | |
| 2099 | Type* Typer::Visitor::TypeInt32AddWithOverflow(Node* node) { |
| 2100 | return Type::Internal(); |
| 2101 | } |
| 2102 | |
| 2103 | |
| 2104 | Type* Typer::Visitor::TypeInt32Sub(Node* node) { return Type::Integral32(); } |
| 2105 | |
| 2106 | |
| 2107 | Type* Typer::Visitor::TypeInt32SubWithOverflow(Node* node) { |
| 2108 | return Type::Internal(); |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | Type* Typer::Visitor::TypeInt32Mul(Node* node) { return Type::Integral32(); } |
| 2113 | |
| 2114 | |
| 2115 | Type* Typer::Visitor::TypeInt32MulHigh(Node* node) { return Type::Signed32(); } |
| 2116 | |
| 2117 | |
| 2118 | Type* Typer::Visitor::TypeInt32Div(Node* node) { return Type::Integral32(); } |
| 2119 | |
| 2120 | |
| 2121 | Type* Typer::Visitor::TypeInt32Mod(Node* node) { return Type::Integral32(); } |
| 2122 | |
| 2123 | |
| 2124 | Type* Typer::Visitor::TypeInt32LessThan(Node* node) { return Type::Boolean(); } |
| 2125 | |
| 2126 | |
| 2127 | Type* Typer::Visitor::TypeInt32LessThanOrEqual(Node* node) { |
| 2128 | return Type::Boolean(); |
| 2129 | } |
| 2130 | |
| 2131 | |
| 2132 | Type* Typer::Visitor::TypeUint32Div(Node* node) { return Type::Unsigned32(); } |
| 2133 | |
| 2134 | |
| 2135 | Type* Typer::Visitor::TypeUint32LessThan(Node* node) { return Type::Boolean(); } |
| 2136 | |
| 2137 | |
| 2138 | Type* Typer::Visitor::TypeUint32LessThanOrEqual(Node* node) { |
| 2139 | return Type::Boolean(); |
| 2140 | } |
| 2141 | |
| 2142 | |
| 2143 | Type* Typer::Visitor::TypeUint32Mod(Node* node) { return Type::Unsigned32(); } |
| 2144 | |
| 2145 | |
| 2146 | Type* Typer::Visitor::TypeUint32MulHigh(Node* node) { |
| 2147 | return Type::Unsigned32(); |
| 2148 | } |
| 2149 | |
| 2150 | |
| 2151 | Type* Typer::Visitor::TypeInt64Add(Node* node) { return Type::Internal(); } |
| 2152 | |
| 2153 | |
| 2154 | Type* Typer::Visitor::TypeInt64AddWithOverflow(Node* node) { |
| 2155 | return Type::Internal(); |
| 2156 | } |
| 2157 | |
| 2158 | |
| 2159 | Type* Typer::Visitor::TypeInt64Sub(Node* node) { return Type::Internal(); } |
| 2160 | |
| 2161 | |
| 2162 | Type* Typer::Visitor::TypeInt64SubWithOverflow(Node* node) { |
| 2163 | return Type::Internal(); |
| 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | Type* Typer::Visitor::TypeInt64Mul(Node* node) { return Type::Internal(); } |
| 2168 | |
| 2169 | |
| 2170 | Type* Typer::Visitor::TypeInt64Div(Node* node) { return Type::Internal(); } |
| 2171 | |
| 2172 | |
| 2173 | Type* Typer::Visitor::TypeInt64Mod(Node* node) { return Type::Internal(); } |
| 2174 | |
| 2175 | |
| 2176 | Type* Typer::Visitor::TypeInt64LessThan(Node* node) { return Type::Boolean(); } |
| 2177 | |
| 2178 | |
| 2179 | Type* Typer::Visitor::TypeInt64LessThanOrEqual(Node* node) { |
| 2180 | return Type::Boolean(); |
| 2181 | } |
| 2182 | |
| 2183 | |
| 2184 | Type* Typer::Visitor::TypeUint64Div(Node* node) { return Type::Internal(); } |
| 2185 | |
| 2186 | |
| 2187 | Type* Typer::Visitor::TypeUint64LessThan(Node* node) { return Type::Boolean(); } |
| 2188 | |
| 2189 | |
| 2190 | Type* Typer::Visitor::TypeUint64LessThanOrEqual(Node* node) { |
| 2191 | return Type::Boolean(); |
| 2192 | } |
| 2193 | |
| 2194 | |
| 2195 | Type* Typer::Visitor::TypeUint64Mod(Node* node) { return Type::Internal(); } |
| 2196 | |
| 2197 | |
| 2198 | Type* Typer::Visitor::TypeChangeFloat32ToFloat64(Node* node) { |
| 2199 | return Type::Intersect(Type::Number(), Type::UntaggedFloat64(), zone()); |
| 2200 | } |
| 2201 | |
| 2202 | |
| 2203 | Type* Typer::Visitor::TypeChangeFloat64ToInt32(Node* node) { |
| 2204 | return Type::Intersect(Type::Signed32(), Type::UntaggedIntegral32(), zone()); |
| 2205 | } |
| 2206 | |
| 2207 | |
| 2208 | Type* Typer::Visitor::TypeChangeFloat64ToUint32(Node* node) { |
| 2209 | return Type::Intersect(Type::Unsigned32(), Type::UntaggedIntegral32(), |
| 2210 | zone()); |
| 2211 | } |
| 2212 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2213 | Type* Typer::Visitor::TypeTruncateFloat64ToUint32(Node* node) { |
| 2214 | return Type::Intersect(Type::Unsigned32(), Type::UntaggedIntegral32(), |
| 2215 | zone()); |
| 2216 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2217 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2218 | Type* Typer::Visitor::TypeTruncateFloat32ToInt32(Node* node) { |
| 2219 | return Type::Intersect(Type::Signed32(), Type::UntaggedIntegral32(), zone()); |
| 2220 | } |
| 2221 | |
| 2222 | |
| 2223 | Type* Typer::Visitor::TypeTruncateFloat32ToUint32(Node* node) { |
| 2224 | return Type::Intersect(Type::Unsigned32(), Type::UntaggedIntegral32(), |
| 2225 | zone()); |
| 2226 | } |
| 2227 | |
| 2228 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2229 | Type* Typer::Visitor::TypeTryTruncateFloat32ToInt64(Node* node) { |
| 2230 | return Type::Internal(); |
| 2231 | } |
| 2232 | |
| 2233 | |
| 2234 | Type* Typer::Visitor::TypeTryTruncateFloat64ToInt64(Node* node) { |
| 2235 | return Type::Internal(); |
| 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | Type* Typer::Visitor::TypeTryTruncateFloat32ToUint64(Node* node) { |
| 2240 | return Type::Internal(); |
| 2241 | } |
| 2242 | |
| 2243 | |
| 2244 | Type* Typer::Visitor::TypeTryTruncateFloat64ToUint64(Node* node) { |
| 2245 | return Type::Internal(); |
| 2246 | } |
| 2247 | |
| 2248 | |
| 2249 | Type* Typer::Visitor::TypeChangeInt32ToFloat64(Node* node) { |
| 2250 | return Type::Intersect(Type::Signed32(), Type::UntaggedFloat64(), zone()); |
| 2251 | } |
| 2252 | |
| 2253 | |
| 2254 | Type* Typer::Visitor::TypeChangeInt32ToInt64(Node* node) { |
| 2255 | return Type::Internal(); |
| 2256 | } |
| 2257 | |
| 2258 | |
| 2259 | Type* Typer::Visitor::TypeChangeUint32ToFloat64(Node* node) { |
| 2260 | return Type::Intersect(Type::Unsigned32(), Type::UntaggedFloat64(), zone()); |
| 2261 | } |
| 2262 | |
| 2263 | |
| 2264 | Type* Typer::Visitor::TypeChangeUint32ToUint64(Node* node) { |
| 2265 | return Type::Internal(); |
| 2266 | } |
| 2267 | |
| 2268 | |
| 2269 | Type* Typer::Visitor::TypeTruncateFloat64ToFloat32(Node* node) { |
| 2270 | return Type::Intersect(Type::Number(), Type::UntaggedFloat32(), zone()); |
| 2271 | } |
| 2272 | |
| 2273 | |
| 2274 | Type* Typer::Visitor::TypeTruncateFloat64ToInt32(Node* node) { |
| 2275 | return Type::Intersect(Type::Signed32(), Type::UntaggedIntegral32(), zone()); |
| 2276 | } |
| 2277 | |
| 2278 | |
| 2279 | Type* Typer::Visitor::TypeTruncateInt64ToInt32(Node* node) { |
| 2280 | return Type::Intersect(Type::Signed32(), Type::UntaggedIntegral32(), zone()); |
| 2281 | } |
| 2282 | |
| 2283 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2284 | Type* Typer::Visitor::TypeRoundInt32ToFloat32(Node* node) { |
| 2285 | return Type::Intersect(Type::PlainNumber(), Type::UntaggedFloat32(), zone()); |
| 2286 | } |
| 2287 | |
| 2288 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2289 | Type* Typer::Visitor::TypeRoundInt64ToFloat32(Node* node) { |
| 2290 | return Type::Intersect(Type::PlainNumber(), Type::UntaggedFloat32(), zone()); |
| 2291 | } |
| 2292 | |
| 2293 | |
| 2294 | Type* Typer::Visitor::TypeRoundInt64ToFloat64(Node* node) { |
| 2295 | return Type::Intersect(Type::PlainNumber(), Type::UntaggedFloat64(), zone()); |
| 2296 | } |
| 2297 | |
| 2298 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2299 | Type* Typer::Visitor::TypeRoundUint32ToFloat32(Node* node) { |
| 2300 | return Type::Intersect(Type::PlainNumber(), Type::UntaggedFloat32(), zone()); |
| 2301 | } |
| 2302 | |
| 2303 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2304 | Type* Typer::Visitor::TypeRoundUint64ToFloat32(Node* node) { |
| 2305 | return Type::Intersect(Type::PlainNumber(), Type::UntaggedFloat32(), zone()); |
| 2306 | } |
| 2307 | |
| 2308 | |
| 2309 | Type* Typer::Visitor::TypeRoundUint64ToFloat64(Node* node) { |
| 2310 | return Type::Intersect(Type::PlainNumber(), Type::UntaggedFloat64(), zone()); |
| 2311 | } |
| 2312 | |
| 2313 | |
| 2314 | Type* Typer::Visitor::TypeBitcastFloat32ToInt32(Node* node) { |
| 2315 | return Type::Number(); |
| 2316 | } |
| 2317 | |
| 2318 | |
| 2319 | Type* Typer::Visitor::TypeBitcastFloat64ToInt64(Node* node) { |
| 2320 | return Type::Number(); |
| 2321 | } |
| 2322 | |
| 2323 | |
| 2324 | Type* Typer::Visitor::TypeBitcastInt32ToFloat32(Node* node) { |
| 2325 | return Type::Number(); |
| 2326 | } |
| 2327 | |
| 2328 | |
| 2329 | Type* Typer::Visitor::TypeBitcastInt64ToFloat64(Node* node) { |
| 2330 | return Type::Number(); |
| 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | Type* Typer::Visitor::TypeFloat32Add(Node* node) { return Type::Number(); } |
| 2335 | |
| 2336 | |
| 2337 | Type* Typer::Visitor::TypeFloat32Sub(Node* node) { return Type::Number(); } |
| 2338 | |
| 2339 | |
| 2340 | Type* Typer::Visitor::TypeFloat32Mul(Node* node) { return Type::Number(); } |
| 2341 | |
| 2342 | |
| 2343 | Type* Typer::Visitor::TypeFloat32Div(Node* node) { return Type::Number(); } |
| 2344 | |
| 2345 | |
| 2346 | Type* Typer::Visitor::TypeFloat32Max(Node* node) { return Type::Number(); } |
| 2347 | |
| 2348 | |
| 2349 | Type* Typer::Visitor::TypeFloat32Min(Node* node) { return Type::Number(); } |
| 2350 | |
| 2351 | |
| 2352 | Type* Typer::Visitor::TypeFloat32Abs(Node* node) { |
| 2353 | // TODO(turbofan): We should be able to infer a better type here. |
| 2354 | return Type::Number(); |
| 2355 | } |
| 2356 | |
| 2357 | |
| 2358 | Type* Typer::Visitor::TypeFloat32Sqrt(Node* node) { return Type::Number(); } |
| 2359 | |
| 2360 | |
| 2361 | Type* Typer::Visitor::TypeFloat32Equal(Node* node) { return Type::Boolean(); } |
| 2362 | |
| 2363 | |
| 2364 | Type* Typer::Visitor::TypeFloat32LessThan(Node* node) { |
| 2365 | return Type::Boolean(); |
| 2366 | } |
| 2367 | |
| 2368 | |
| 2369 | Type* Typer::Visitor::TypeFloat32LessThanOrEqual(Node* node) { |
| 2370 | return Type::Boolean(); |
| 2371 | } |
| 2372 | |
| 2373 | |
| 2374 | Type* Typer::Visitor::TypeFloat64Add(Node* node) { return Type::Number(); } |
| 2375 | |
| 2376 | |
| 2377 | Type* Typer::Visitor::TypeFloat64Sub(Node* node) { return Type::Number(); } |
| 2378 | |
| 2379 | |
| 2380 | Type* Typer::Visitor::TypeFloat64Mul(Node* node) { return Type::Number(); } |
| 2381 | |
| 2382 | |
| 2383 | Type* Typer::Visitor::TypeFloat64Div(Node* node) { return Type::Number(); } |
| 2384 | |
| 2385 | |
| 2386 | Type* Typer::Visitor::TypeFloat64Mod(Node* node) { return Type::Number(); } |
| 2387 | |
| 2388 | |
| 2389 | Type* Typer::Visitor::TypeFloat64Max(Node* node) { return Type::Number(); } |
| 2390 | |
| 2391 | |
| 2392 | Type* Typer::Visitor::TypeFloat64Min(Node* node) { return Type::Number(); } |
| 2393 | |
| 2394 | |
| 2395 | Type* Typer::Visitor::TypeFloat64Abs(Node* node) { |
| 2396 | // TODO(turbofan): We should be able to infer a better type here. |
| 2397 | return Type::Number(); |
| 2398 | } |
| 2399 | |
| 2400 | |
| 2401 | Type* Typer::Visitor::TypeFloat64Sqrt(Node* node) { return Type::Number(); } |
| 2402 | |
| 2403 | |
| 2404 | Type* Typer::Visitor::TypeFloat64Equal(Node* node) { return Type::Boolean(); } |
| 2405 | |
| 2406 | |
| 2407 | Type* Typer::Visitor::TypeFloat64LessThan(Node* node) { |
| 2408 | return Type::Boolean(); |
| 2409 | } |
| 2410 | |
| 2411 | |
| 2412 | Type* Typer::Visitor::TypeFloat64LessThanOrEqual(Node* node) { |
| 2413 | return Type::Boolean(); |
| 2414 | } |
| 2415 | |
| 2416 | |
| 2417 | Type* Typer::Visitor::TypeFloat32RoundDown(Node* node) { |
| 2418 | // TODO(sigurds): We could have a tighter bound here. |
| 2419 | return Type::Number(); |
| 2420 | } |
| 2421 | |
| 2422 | |
| 2423 | Type* Typer::Visitor::TypeFloat64RoundDown(Node* node) { |
| 2424 | // TODO(sigurds): We could have a tighter bound here. |
| 2425 | return Type::Number(); |
| 2426 | } |
| 2427 | |
| 2428 | |
| 2429 | Type* Typer::Visitor::TypeFloat32RoundUp(Node* node) { |
| 2430 | // TODO(sigurds): We could have a tighter bound here. |
| 2431 | return Type::Number(); |
| 2432 | } |
| 2433 | |
| 2434 | |
| 2435 | Type* Typer::Visitor::TypeFloat64RoundUp(Node* node) { |
| 2436 | // TODO(sigurds): We could have a tighter bound here. |
| 2437 | return Type::Number(); |
| 2438 | } |
| 2439 | |
| 2440 | |
| 2441 | Type* Typer::Visitor::TypeFloat32RoundTruncate(Node* node) { |
| 2442 | // TODO(sigurds): We could have a tighter bound here. |
| 2443 | return Type::Number(); |
| 2444 | } |
| 2445 | |
| 2446 | |
| 2447 | Type* Typer::Visitor::TypeFloat64RoundTruncate(Node* node) { |
| 2448 | // TODO(sigurds): We could have a tighter bound here. |
| 2449 | return Type::Number(); |
| 2450 | } |
| 2451 | |
| 2452 | |
| 2453 | Type* Typer::Visitor::TypeFloat64RoundTiesAway(Node* node) { |
| 2454 | // TODO(sigurds): We could have a tighter bound here. |
| 2455 | return Type::Number(); |
| 2456 | } |
| 2457 | |
| 2458 | |
| 2459 | Type* Typer::Visitor::TypeFloat32RoundTiesEven(Node* node) { |
| 2460 | // TODO(sigurds): We could have a tighter bound here. |
| 2461 | return Type::Number(); |
| 2462 | } |
| 2463 | |
| 2464 | |
| 2465 | Type* Typer::Visitor::TypeFloat64RoundTiesEven(Node* node) { |
| 2466 | // TODO(sigurds): We could have a tighter bound here. |
| 2467 | return Type::Number(); |
| 2468 | } |
| 2469 | |
| 2470 | |
| 2471 | Type* Typer::Visitor::TypeFloat64ExtractLowWord32(Node* node) { |
| 2472 | return Type::Signed32(); |
| 2473 | } |
| 2474 | |
| 2475 | |
| 2476 | Type* Typer::Visitor::TypeFloat64ExtractHighWord32(Node* node) { |
| 2477 | return Type::Signed32(); |
| 2478 | } |
| 2479 | |
| 2480 | |
| 2481 | Type* Typer::Visitor::TypeFloat64InsertLowWord32(Node* node) { |
| 2482 | return Type::Number(); |
| 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | Type* Typer::Visitor::TypeFloat64InsertHighWord32(Node* node) { |
| 2487 | return Type::Number(); |
| 2488 | } |
| 2489 | |
| 2490 | |
| 2491 | Type* Typer::Visitor::TypeLoadStackPointer(Node* node) { |
| 2492 | return Type::Internal(); |
| 2493 | } |
| 2494 | |
| 2495 | |
| 2496 | Type* Typer::Visitor::TypeLoadFramePointer(Node* node) { |
| 2497 | return Type::Internal(); |
| 2498 | } |
| 2499 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2500 | Type* Typer::Visitor::TypeLoadParentFramePointer(Node* node) { |
| 2501 | return Type::Internal(); |
| 2502 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2503 | |
| 2504 | Type* Typer::Visitor::TypeCheckedLoad(Node* node) { return Type::Any(); } |
| 2505 | |
| 2506 | |
| 2507 | Type* Typer::Visitor::TypeCheckedStore(Node* node) { |
| 2508 | UNREACHABLE(); |
| 2509 | return nullptr; |
| 2510 | } |
| 2511 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2512 | Type* Typer::Visitor::TypeInt32PairAdd(Node* node) { return Type::Internal(); } |
| 2513 | |
| 2514 | Type* Typer::Visitor::TypeInt32PairSub(Node* node) { return Type::Internal(); } |
| 2515 | |
| 2516 | Type* Typer::Visitor::TypeInt32PairMul(Node* node) { return Type::Internal(); } |
| 2517 | |
| 2518 | Type* Typer::Visitor::TypeWord32PairShl(Node* node) { return Type::Internal(); } |
| 2519 | |
| 2520 | Type* Typer::Visitor::TypeWord32PairShr(Node* node) { return Type::Internal(); } |
| 2521 | |
| 2522 | Type* Typer::Visitor::TypeWord32PairSar(Node* node) { return Type::Internal(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2523 | |
| 2524 | // Heap constants. |
| 2525 | |
| 2526 | |
| 2527 | Type* Typer::Visitor::TypeConstant(Handle<Object> value) { |
| 2528 | if (value->IsJSTypedArray()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2529 | switch (JSTypedArray::cast(*value)->type()) { |
| 2530 | #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
| 2531 | case kExternal##Type##Array: \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2532 | return typer_->cache_.k##Type##Array; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2533 | TYPED_ARRAYS(TYPED_ARRAY_CASE) |
| 2534 | #undef TYPED_ARRAY_CASE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2535 | } |
| 2536 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2537 | if (Type::IsInteger(*value)) { |
| 2538 | return Type::Range(value->Number(), value->Number(), zone()); |
| 2539 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2540 | return Type::Constant(value, zone()); |
| 2541 | } |
| 2542 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2543 | } // namespace compiler |
| 2544 | } // namespace internal |
| 2545 | } // namespace v8 |