OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/typer.h" | 5 #include "src/compiler/typer.h" |
6 | 6 |
7 #include "src/base/flags.h" | 7 #include "src/base/flags.h" |
8 #include "src/base/lazy-instance.h" | 8 #include "src/base/lazy-instance.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/compiler/graph-reducer.h" | 10 #include "src/compiler/graph-reducer.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 Type::Any(), zone()); | 58 Type::Any(), zone()); |
59 Type* const kNumberFunc0 = Type::Function(Type::Number(), zone()); | 59 Type* const kNumberFunc0 = Type::Function(Type::Number(), zone()); |
60 Type* const kNumberFunc1 = | 60 Type* const kNumberFunc1 = |
61 Type::Function(Type::Number(), Type::Number(), zone()); | 61 Type::Function(Type::Number(), Type::Number(), zone()); |
62 Type* const kNumberFunc2 = | 62 Type* const kNumberFunc2 = |
63 Type::Function(Type::Number(), Type::Number(), Type::Number(), zone()); | 63 Type::Function(Type::Number(), Type::Number(), Type::Number(), zone()); |
64 Type* const kImulFunc = Type::Function(Type::Signed32(), Type::Integral32(), | 64 Type* const kImulFunc = Type::Function(Type::Signed32(), Type::Integral32(), |
65 Type::Integral32(), zone()); | 65 Type::Integral32(), zone()); |
66 Type* const kClz32Func = | 66 Type* const kClz32Func = |
67 Type::Function(CreateRange(0, 32), Type::Number(), zone()); | 67 Type::Function(CreateRange(0, 32), Type::Number(), zone()); |
68 Type* const kArrayBufferFunc = | |
69 Type::Function(Type::Object(zone()), Type::Unsigned32(), zone()); | |
70 | 68 |
71 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ | 69 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ |
72 Type* const k##TypeName##Array = CreateArray(k##TypeName); \ | 70 Type* const k##TypeName##Array = CreateArray(k##TypeName); |
73 Type* const k##TypeName##ArrayFunc = CreateArrayFunction(k##TypeName##Array); | |
74 TYPED_ARRAYS(TYPED_ARRAY) | 71 TYPED_ARRAYS(TYPED_ARRAY) |
75 #undef TYPED_ARRAY | 72 #undef TYPED_ARRAY |
76 | 73 |
77 private: | 74 private: |
78 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } | 75 Type* CreateArray(Type* element) { return Type::Array(element, zone()); } |
79 | 76 |
80 Type* CreateArrayFunction(Type* array) { | 77 Type* CreateArrayFunction(Type* array) { |
81 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); | 78 Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone()); |
82 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); | 79 Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone()); |
83 Type* arg3 = arg2; | 80 Type* arg3 = arg2; |
(...skipping 28 matching lines...) Expand all Loading... |
112 class Typer::Decorator final : public GraphDecorator { | 109 class Typer::Decorator final : public GraphDecorator { |
113 public: | 110 public: |
114 explicit Decorator(Typer* typer) : typer_(typer) {} | 111 explicit Decorator(Typer* typer) : typer_(typer) {} |
115 void Decorate(Node* node) final; | 112 void Decorate(Node* node) final; |
116 | 113 |
117 private: | 114 private: |
118 Typer* const typer_; | 115 Typer* const typer_; |
119 }; | 116 }; |
120 | 117 |
121 | 118 |
122 Typer::Typer(Isolate* isolate, Graph* graph, Type::FunctionType* function_type, | 119 Typer::Typer(Isolate* isolate, Graph* graph, Type::FunctionType* function_type) |
123 MaybeHandle<Context> context) | |
124 : isolate_(isolate), | 120 : isolate_(isolate), |
125 graph_(graph), | 121 graph_(graph), |
126 function_type_(function_type), | 122 function_type_(function_type), |
127 context_(context), | |
128 decorator_(nullptr), | 123 decorator_(nullptr), |
129 cache_(kCache.Get()) { | 124 cache_(kCache.Get()) { |
130 Zone* zone = this->zone(); | 125 Zone* zone = this->zone(); |
131 Factory* const factory = isolate->factory(); | 126 Factory* const factory = isolate->factory(); |
132 | 127 |
133 Type* infinity = Type::Constant(factory->infinity_value(), zone); | 128 Type* infinity = Type::Constant(factory->infinity_value(), zone); |
134 Type* minus_infinity = Type::Constant(factory->minus_infinity_value(), zone); | 129 Type* minus_infinity = Type::Constant(factory->minus_infinity_value(), zone); |
135 Type* truncating_to_zero = | 130 Type* truncating_to_zero = |
136 Type::Union(Type::Union(infinity, minus_infinity, zone), | 131 Type::Union(Type::Union(infinity, minus_infinity, zone), |
137 Type::MinusZeroOrNaN(), zone); | 132 Type::MinusZeroOrNaN(), zone); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 break; | 249 break; |
255 } | 250 } |
256 UNREACHABLE(); | 251 UNREACHABLE(); |
257 return Bounds(); | 252 return Bounds(); |
258 } | 253 } |
259 | 254 |
260 Type* TypeConstant(Handle<Object> value); | 255 Type* TypeConstant(Handle<Object> value); |
261 | 256 |
262 private: | 257 private: |
263 Typer* typer_; | 258 Typer* typer_; |
264 MaybeHandle<Context> context_; | |
265 ZoneSet<NodeId> weakened_nodes_; | 259 ZoneSet<NodeId> weakened_nodes_; |
266 | 260 |
267 #define DECLARE_METHOD(x) inline Bounds Type##x(Node* node); | 261 #define DECLARE_METHOD(x) inline Bounds Type##x(Node* node); |
268 DECLARE_METHOD(Start) | 262 DECLARE_METHOD(Start) |
269 DECLARE_METHOD(IfException) | 263 DECLARE_METHOD(IfException) |
270 VALUE_OP_LIST(DECLARE_METHOD) | 264 VALUE_OP_LIST(DECLARE_METHOD) |
271 #undef DECLARE_METHOD | 265 #undef DECLARE_METHOD |
272 | 266 |
273 Bounds BoundsOrNone(Node* node) { | 267 Bounds BoundsOrNone(Node* node) { |
274 return NodeProperties::IsTyped(node) ? NodeProperties::GetBounds(node) | 268 return NodeProperties::IsTyped(node) ? NodeProperties::GetBounds(node) |
275 : Bounds(Type::None()); | 269 : Bounds(Type::None()); |
276 } | 270 } |
277 | 271 |
278 Bounds Operand(Node* node, int i) { | 272 Bounds Operand(Node* node, int i) { |
279 Node* operand_node = NodeProperties::GetValueInput(node, i); | 273 Node* operand_node = NodeProperties::GetValueInput(node, i); |
280 return BoundsOrNone(operand_node); | 274 return BoundsOrNone(operand_node); |
281 } | 275 } |
282 | 276 |
283 Bounds WrapContextBoundsForInput(Node* node); | 277 Bounds WrapContextBoundsForInput(Node* node); |
284 Type* Weaken(Node* node, Type* current_type, Type* previous_type); | 278 Type* Weaken(Node* node, Type* current_type, Type* previous_type); |
285 | 279 |
286 Zone* zone() { return typer_->zone(); } | 280 Zone* zone() { return typer_->zone(); } |
287 Isolate* isolate() { return typer_->isolate(); } | 281 Isolate* isolate() { return typer_->isolate(); } |
288 Graph* graph() { return typer_->graph(); } | 282 Graph* graph() { return typer_->graph(); } |
289 MaybeHandle<Context> context() { return typer_->context(); } | |
290 | 283 |
291 void SetWeakened(NodeId node_id) { weakened_nodes_.insert(node_id); } | 284 void SetWeakened(NodeId node_id) { weakened_nodes_.insert(node_id); } |
292 bool IsWeakened(NodeId node_id) { | 285 bool IsWeakened(NodeId node_id) { |
293 return weakened_nodes_.find(node_id) != weakened_nodes_.end(); | 286 return weakened_nodes_.find(node_id) != weakened_nodes_.end(); |
294 } | 287 } |
295 | 288 |
296 typedef Type* (*UnaryTyperFun)(Type*, Typer* t); | 289 typedef Type* (*UnaryTyperFun)(Type*, Typer* t); |
297 typedef Type* (*BinaryTyperFun)(Type*, Type*, Typer* t); | 290 typedef Type* (*BinaryTyperFun)(Type*, Type*, Typer* t); |
298 | 291 |
299 Bounds TypeUnaryOp(Node* node, UnaryTyperFun); | 292 Bounds TypeUnaryOp(Node* node, UnaryTyperFun); |
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2330 case kMathMax: | 2323 case kMathMax: |
2331 case kMathMin: | 2324 case kMathMin: |
2332 return typer_->cache_.kNumberFunc2; | 2325 return typer_->cache_.kNumberFunc2; |
2333 case kMathImul: | 2326 case kMathImul: |
2334 return typer_->cache_.kImulFunc; | 2327 return typer_->cache_.kImulFunc; |
2335 case kMathClz32: | 2328 case kMathClz32: |
2336 return typer_->cache_.kClz32Func; | 2329 return typer_->cache_.kClz32Func; |
2337 default: | 2330 default: |
2338 break; | 2331 break; |
2339 } | 2332 } |
2340 } else if (JSFunction::cast(*value)->IsBuiltin() && !context().is_null()) { | |
2341 Handle<Context> native = | |
2342 handle(context().ToHandleChecked()->native_context(), isolate()); | |
2343 if (*value == native->array_buffer_fun()) { | |
2344 return typer_->cache_.kArrayBufferFunc; | |
2345 } else if (*value == native->int8_array_fun()) { | |
2346 return typer_->cache_.kInt8ArrayFunc; | |
2347 } else if (*value == native->int16_array_fun()) { | |
2348 return typer_->cache_.kInt16ArrayFunc; | |
2349 } else if (*value == native->int32_array_fun()) { | |
2350 return typer_->cache_.kInt32ArrayFunc; | |
2351 } else if (*value == native->uint8_array_fun()) { | |
2352 return typer_->cache_.kUint8ArrayFunc; | |
2353 } else if (*value == native->uint16_array_fun()) { | |
2354 return typer_->cache_.kUint16ArrayFunc; | |
2355 } else if (*value == native->uint32_array_fun()) { | |
2356 return typer_->cache_.kUint32ArrayFunc; | |
2357 } else if (*value == native->float32_array_fun()) { | |
2358 return typer_->cache_.kFloat32ArrayFunc; | |
2359 } else if (*value == native->float64_array_fun()) { | |
2360 return typer_->cache_.kFloat64ArrayFunc; | |
2361 } | |
2362 } | 2333 } |
2363 int const arity = | 2334 int const arity = |
2364 JSFunction::cast(*value)->shared()->internal_formal_parameter_count(); | 2335 JSFunction::cast(*value)->shared()->internal_formal_parameter_count(); |
2365 switch (arity) { | 2336 switch (arity) { |
2366 case SharedFunctionInfo::kDontAdaptArgumentsSentinel: | 2337 case SharedFunctionInfo::kDontAdaptArgumentsSentinel: |
2367 // Some smart optimization at work... &%$!&@+$! | 2338 // Some smart optimization at work... &%$!&@+$! |
2368 return Type::Any(zone()); | 2339 return Type::Any(zone()); |
2369 case 0: | 2340 case 0: |
2370 return typer_->cache_.kAnyFunc0; | 2341 return typer_->cache_.kAnyFunc0; |
2371 case 1: | 2342 case 1: |
(...skipping 17 matching lines...) Expand all Loading... |
2389 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 2360 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
2390 #undef TYPED_ARRAY_CASE | 2361 #undef TYPED_ARRAY_CASE |
2391 } | 2362 } |
2392 } | 2363 } |
2393 return Type::Constant(value, zone()); | 2364 return Type::Constant(value, zone()); |
2394 } | 2365 } |
2395 | 2366 |
2396 } // namespace compiler | 2367 } // namespace compiler |
2397 } // namespace internal | 2368 } // namespace internal |
2398 } // namespace v8 | 2369 } // namespace v8 |
OLD | NEW |