OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_HYDROGEN_H_ | 5 #ifndef V8_HYDROGEN_H_ |
6 #define V8_HYDROGEN_H_ | 6 #define V8_HYDROGEN_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2275 template <class Instruction> HInstruction* PreProcessCall(Instruction* call); | 2275 template <class Instruction> HInstruction* PreProcessCall(Instruction* call); |
2276 void PushArgumentsFromEnvironment(int count); | 2276 void PushArgumentsFromEnvironment(int count); |
2277 | 2277 |
2278 void SetUpScope(Scope* scope); | 2278 void SetUpScope(Scope* scope); |
2279 void VisitStatements(ZoneList<Statement*>* statements) OVERRIDE; | 2279 void VisitStatements(ZoneList<Statement*>* statements) OVERRIDE; |
2280 | 2280 |
2281 #define DECLARE_VISIT(type) virtual void Visit##type(type* node) OVERRIDE; | 2281 #define DECLARE_VISIT(type) virtual void Visit##type(type* node) OVERRIDE; |
2282 AST_NODE_LIST(DECLARE_VISIT) | 2282 AST_NODE_LIST(DECLARE_VISIT) |
2283 #undef DECLARE_VISIT | 2283 #undef DECLARE_VISIT |
2284 | 2284 |
2285 Type* ToType(Handle<Map> map); | |
2286 | |
2287 private: | 2285 private: |
2288 // Helpers for flow graph construction. | 2286 // Helpers for flow graph construction. |
2289 enum GlobalPropertyAccess { | 2287 enum GlobalPropertyAccess { |
2290 kUseCell, | 2288 kUseCell, |
2291 kUseGeneric | 2289 kUseGeneric |
2292 }; | 2290 }; |
2293 GlobalPropertyAccess LookupGlobalProperty(Variable* var, LookupIterator* it, | 2291 GlobalPropertyAccess LookupGlobalProperty(Variable* var, LookupIterator* it, |
2294 PropertyAccessType access_type); | 2292 PropertyAccessType access_type); |
2295 | 2293 |
2296 void EnsureArgumentsArePushedForAccess(); | 2294 void EnsureArgumentsArePushedForAccess(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 return handle(isolate()->native_context()->array_function()); | 2425 return handle(isolate()->native_context()->array_function()); |
2428 } | 2426 } |
2429 | 2427 |
2430 bool IsCallArrayInlineable(int argument_count, Handle<AllocationSite> site); | 2428 bool IsCallArrayInlineable(int argument_count, Handle<AllocationSite> site); |
2431 void BuildInlinedCallArray(Expression* expression, int argument_count, | 2429 void BuildInlinedCallArray(Expression* expression, int argument_count, |
2432 Handle<AllocationSite> site); | 2430 Handle<AllocationSite> site); |
2433 | 2431 |
2434 class PropertyAccessInfo { | 2432 class PropertyAccessInfo { |
2435 public: | 2433 public: |
2436 PropertyAccessInfo(HOptimizedGraphBuilder* builder, | 2434 PropertyAccessInfo(HOptimizedGraphBuilder* builder, |
2437 PropertyAccessType access_type, | 2435 PropertyAccessType access_type, Handle<Map> map, |
2438 Type* type, | |
2439 Handle<String> name) | 2436 Handle<String> name) |
2440 : lookup_(builder->isolate()), | 2437 : lookup_(builder->isolate()), |
2441 builder_(builder), | 2438 builder_(builder), |
2442 access_type_(access_type), | 2439 access_type_(access_type), |
2443 type_(type), | 2440 map_(map), |
2444 name_(name), | 2441 name_(name), |
2445 field_type_(HType::Tagged()), | 2442 field_type_(HType::Tagged()), |
2446 access_(HObjectAccess::ForMap()) { } | 2443 access_(HObjectAccess::ForMap()) {} |
2447 | 2444 |
2448 // Checkes whether this PropertyAccessInfo can be handled as a monomorphic | 2445 // Checkes whether this PropertyAccessInfo can be handled as a monomorphic |
2449 // load named. It additionally fills in the fields necessary to generate the | 2446 // load named. It additionally fills in the fields necessary to generate the |
2450 // lookup code. | 2447 // lookup code. |
2451 bool CanAccessMonomorphic(); | 2448 bool CanAccessMonomorphic(); |
2452 | 2449 |
2453 // Checks whether all types behave uniform when loading name. If all maps | 2450 // Checks whether all types behave uniform when loading name. If all maps |
2454 // behave the same, a single monomorphic load instruction can be emitted, | 2451 // behave the same, a single monomorphic load instruction can be emitted, |
2455 // guarded by a single map-checks instruction that whether the receiver is | 2452 // guarded by a single map-checks instruction that whether the receiver is |
2456 // an instance of any of the types. | 2453 // an instance of any of the types. |
2457 // This method skips the first type in types, assuming that this | 2454 // This method skips the first type in types, assuming that this |
2458 // PropertyAccessInfo is built for types->first(). | 2455 // PropertyAccessInfo is built for types->first(). |
2459 bool CanAccessAsMonomorphic(SmallMapList* types); | 2456 bool CanAccessAsMonomorphic(SmallMapList* types); |
2460 | 2457 |
| 2458 bool NeedsWrappingFor(Handle<JSFunction> target) const; |
| 2459 |
2461 Handle<Map> map(); | 2460 Handle<Map> map(); |
2462 Type* type() const { return type_; } | |
2463 Handle<String> name() const { return name_; } | 2461 Handle<String> name() const { return name_; } |
2464 | 2462 |
2465 bool IsJSObjectFieldAccessor() { | 2463 bool IsJSObjectFieldAccessor() { |
2466 int offset; // unused | 2464 int offset; // unused |
2467 return Accessors::IsJSObjectFieldAccessor<Type>(type_, name_, &offset); | 2465 return Accessors::IsJSObjectFieldAccessor(map(), name_, &offset); |
2468 } | 2466 } |
2469 | 2467 |
2470 bool GetJSObjectFieldAccess(HObjectAccess* access) { | 2468 bool GetJSObjectFieldAccess(HObjectAccess* access) { |
2471 int offset; | 2469 int offset; |
2472 if (Accessors::IsJSObjectFieldAccessor<Type>(type_, name_, &offset)) { | 2470 if (Accessors::IsJSObjectFieldAccessor(map(), name_, &offset)) { |
2473 if (type_->Is(Type::String())) { | 2471 if (IsStringType()) { |
2474 DCHECK(String::Equals(isolate()->factory()->length_string(), name_)); | 2472 DCHECK(String::Equals(isolate()->factory()->length_string(), name_)); |
2475 *access = HObjectAccess::ForStringLength(); | 2473 *access = HObjectAccess::ForStringLength(); |
2476 } else if (type_->Is(Type::Array())) { | 2474 } else if (IsArrayType()) { |
2477 DCHECK(String::Equals(isolate()->factory()->length_string(), name_)); | 2475 DCHECK(String::Equals(isolate()->factory()->length_string(), name_)); |
2478 *access = HObjectAccess::ForArrayLength(map()->elements_kind()); | 2476 *access = HObjectAccess::ForArrayLength(map()->elements_kind()); |
2479 } else { | 2477 } else { |
2480 *access = HObjectAccess::ForMapAndOffset(map(), offset); | 2478 *access = HObjectAccess::ForMapAndOffset(map(), offset); |
2481 } | 2479 } |
2482 return true; | 2480 return true; |
2483 } | 2481 } |
2484 return false; | 2482 return false; |
2485 } | 2483 } |
2486 | 2484 |
(...skipping 12 matching lines...) Expand all Loading... |
2499 bool IsFound() const { return lookup_.IsFound(); } | 2497 bool IsFound() const { return lookup_.IsFound(); } |
2500 bool IsProperty() const { return lookup_.IsProperty(); } | 2498 bool IsProperty() const { return lookup_.IsProperty(); } |
2501 bool IsData() const { return lookup_.IsData(); } | 2499 bool IsData() const { return lookup_.IsData(); } |
2502 bool IsDataConstant() const { return lookup_.IsDataConstant(); } | 2500 bool IsDataConstant() const { return lookup_.IsDataConstant(); } |
2503 bool IsAccessorConstant() const { return lookup_.IsAccessorConstant(); } | 2501 bool IsAccessorConstant() const { return lookup_.IsAccessorConstant(); } |
2504 bool IsTransition() const { return lookup_.IsTransition(); } | 2502 bool IsTransition() const { return lookup_.IsTransition(); } |
2505 | 2503 |
2506 bool IsConfigurable() const { return lookup_.IsConfigurable(); } | 2504 bool IsConfigurable() const { return lookup_.IsConfigurable(); } |
2507 bool IsReadOnly() const { return lookup_.IsReadOnly(); } | 2505 bool IsReadOnly() const { return lookup_.IsReadOnly(); } |
2508 | 2506 |
| 2507 bool IsStringType() { return map_->instance_type() < FIRST_NONSTRING_TYPE; } |
| 2508 bool IsNumberType() { return map_->instance_type() == HEAP_NUMBER_TYPE; } |
| 2509 bool IsValueWrapped() { return IsStringType() || IsNumberType(); } |
| 2510 bool IsArrayType() { return map_->instance_type() == JS_ARRAY_TYPE; } |
| 2511 |
2509 private: | 2512 private: |
2510 Handle<Object> GetAccessorsFromMap(Handle<Map> map) const { | 2513 Handle<Object> GetAccessorsFromMap(Handle<Map> map) const { |
2511 return handle(lookup_.GetValueFromMap(*map), isolate()); | 2514 return handle(lookup_.GetValueFromMap(*map), isolate()); |
2512 } | 2515 } |
2513 Handle<Object> GetConstantFromMap(Handle<Map> map) const { | 2516 Handle<Object> GetConstantFromMap(Handle<Map> map) const { |
2514 return handle(lookup_.GetConstantFromMap(*map), isolate()); | 2517 return handle(lookup_.GetConstantFromMap(*map), isolate()); |
2515 } | 2518 } |
2516 Handle<HeapType> GetFieldTypeFromMap(Handle<Map> map) const { | 2519 Handle<HeapType> GetFieldTypeFromMap(Handle<Map> map) const { |
2517 return handle(lookup_.GetFieldTypeFromMap(*map), isolate()); | 2520 return handle(lookup_.GetFieldTypeFromMap(*map), isolate()); |
2518 } | 2521 } |
2519 Handle<Map> GetFieldOwnerFromMap(Handle<Map> map) const { | 2522 Handle<Map> GetFieldOwnerFromMap(Handle<Map> map) const { |
2520 return handle(lookup_.GetFieldOwnerFromMap(*map)); | 2523 return handle(lookup_.GetFieldOwnerFromMap(*map)); |
2521 } | 2524 } |
2522 int GetLocalFieldIndexFromMap(Handle<Map> map) const { | 2525 int GetLocalFieldIndexFromMap(Handle<Map> map) const { |
2523 return lookup_.GetLocalFieldIndexFromMap(*map); | 2526 return lookup_.GetLocalFieldIndexFromMap(*map); |
2524 } | 2527 } |
2525 Representation representation() const { return lookup_.representation(); } | 2528 Representation representation() const { return lookup_.representation(); } |
2526 | 2529 |
2527 Type* ToType(Handle<Map> map) { return builder_->ToType(map); } | |
2528 Zone* zone() { return builder_->zone(); } | 2530 Zone* zone() { return builder_->zone(); } |
2529 CompilationInfo* top_info() { return builder_->top_info(); } | 2531 CompilationInfo* top_info() { return builder_->top_info(); } |
2530 CompilationInfo* current_info() { return builder_->current_info(); } | 2532 CompilationInfo* current_info() { return builder_->current_info(); } |
2531 | 2533 |
2532 bool LoadResult(Handle<Map> map); | 2534 bool LoadResult(Handle<Map> map); |
2533 void LoadFieldMaps(Handle<Map> map); | 2535 void LoadFieldMaps(Handle<Map> map); |
2534 bool LookupDescriptor(); | 2536 bool LookupDescriptor(); |
2535 bool LookupInPrototypes(); | 2537 bool LookupInPrototypes(); |
2536 bool IsCompatible(PropertyAccessInfo* other); | 2538 bool IsCompatible(PropertyAccessInfo* other); |
2537 | 2539 |
2538 void GeneralizeRepresentation(Representation r) { | 2540 void GeneralizeRepresentation(Representation r) { |
2539 access_ = access_.WithRepresentation( | 2541 access_ = access_.WithRepresentation( |
2540 access_.representation().generalize(r)); | 2542 access_.representation().generalize(r)); |
2541 } | 2543 } |
2542 | 2544 |
2543 LookupResult lookup_; | 2545 LookupResult lookup_; |
2544 HOptimizedGraphBuilder* builder_; | 2546 HOptimizedGraphBuilder* builder_; |
2545 PropertyAccessType access_type_; | 2547 PropertyAccessType access_type_; |
2546 Type* type_; | 2548 Handle<Map> map_; |
2547 Handle<String> name_; | 2549 Handle<String> name_; |
2548 Handle<JSObject> holder_; | 2550 Handle<JSObject> holder_; |
2549 Handle<JSFunction> accessor_; | 2551 Handle<JSFunction> accessor_; |
2550 Handle<JSObject> api_holder_; | 2552 Handle<JSObject> api_holder_; |
2551 Handle<Object> constant_; | 2553 Handle<Object> constant_; |
2552 SmallMapList field_maps_; | 2554 SmallMapList field_maps_; |
2553 HType field_type_; | 2555 HType field_type_; |
2554 HObjectAccess access_; | 2556 HObjectAccess access_; |
2555 }; | 2557 }; |
2556 | 2558 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2915 } | 2917 } |
2916 | 2918 |
2917 private: | 2919 private: |
2918 HGraphBuilder* builder_; | 2920 HGraphBuilder* builder_; |
2919 }; | 2921 }; |
2920 | 2922 |
2921 | 2923 |
2922 } } // namespace v8::internal | 2924 } } // namespace v8::internal |
2923 | 2925 |
2924 #endif // V8_HYDROGEN_H_ | 2926 #endif // V8_HYDROGEN_H_ |
OLD | NEW |