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