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

Side by Side Diff: src/hydrogen.cc

Issue 300893003: Refactor HType to get rid of various hacks. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Skip representation axis in HType::FromType(). Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 "hydrogen.h" 5 #include "hydrogen.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "v8.h" 9 #include "v8.h"
10 #include "allocation-site-scopes.h" 10 #include "allocation-site-scopes.h"
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 boolean_value, \ 694 boolean_value, \
695 false, \ 695 false, \
696 ODDBALL_TYPE); \ 696 ODDBALL_TYPE); \
697 constant->InsertAfter(entry_block()->first()); \ 697 constant->InsertAfter(entry_block()->first()); \
698 constant_##name##_.set(constant); \ 698 constant_##name##_.set(constant); \
699 } \ 699 } \
700 return ReinsertConstantIfNecessary(constant_##name##_.get()); \ 700 return ReinsertConstantIfNecessary(constant_##name##_.get()); \
701 } 701 }
702 702
703 703
704 DEFINE_GET_CONSTANT(Undefined, undefined, undefined, HType::Tagged(), false) 704 DEFINE_GET_CONSTANT(Undefined, undefined, undefined, HType::Undefined(), false)
705 DEFINE_GET_CONSTANT(True, true, boolean, HType::Boolean(), true) 705 DEFINE_GET_CONSTANT(True, true, boolean, HType::Boolean(), true)
706 DEFINE_GET_CONSTANT(False, false, boolean, HType::Boolean(), false) 706 DEFINE_GET_CONSTANT(False, false, boolean, HType::Boolean(), false)
707 DEFINE_GET_CONSTANT(Hole, the_hole, the_hole, HType::Tagged(), false) 707 DEFINE_GET_CONSTANT(Hole, the_hole, the_hole, HType::None(), false)
708 DEFINE_GET_CONSTANT(Null, null, null, HType::Tagged(), false) 708 DEFINE_GET_CONSTANT(Null, null, null, HType::Null(), false)
709 709
710 710
711 #undef DEFINE_GET_CONSTANT 711 #undef DEFINE_GET_CONSTANT
712 712
713 #define DEFINE_IS_CONSTANT(Name, name) \ 713 #define DEFINE_IS_CONSTANT(Name, name) \
714 bool HGraph::IsConstant##Name(HConstant* constant) { \ 714 bool HGraph::IsConstant##Name(HConstant* constant) { \
715 return constant_##name##_.is_set() && constant == constant_##name##_.get(); \ 715 return constant_##name##_.is_set() && constant == constant_##name##_.get(); \
716 } 716 }
717 DEFINE_IS_CONSTANT(Undefined, undefined) 717 DEFINE_IS_CONSTANT(Undefined, undefined)
718 DEFINE_IS_CONSTANT(0, 0) 718 DEFINE_IS_CONSTANT(0, 0)
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 1546
1547 size = AddUncasted<HShl>(size, Add<HConstant>(kPointerSizeLog2)); 1547 size = AddUncasted<HShl>(size, Add<HConstant>(kPointerSizeLog2));
1548 size = AddUncasted<HAdd>(size, Add<HConstant>(kHeaderSize)); 1548 size = AddUncasted<HAdd>(size, Add<HConstant>(kHeaderSize));
1549 1549
1550 // Allocate the JSRegExpResult and the FixedArray in one step. 1550 // Allocate the JSRegExpResult and the FixedArray in one step.
1551 HValue* result = Add<HAllocate>( 1551 HValue* result = Add<HAllocate>(
1552 size, HType::JSArray(), NOT_TENURED, JS_ARRAY_TYPE); 1552 size, HType::JSArray(), NOT_TENURED, JS_ARRAY_TYPE);
1553 1553
1554 // Determine the elements FixedArray. 1554 // Determine the elements FixedArray.
1555 HValue* elements = Add<HInnerAllocatedObject>( 1555 HValue* elements = Add<HInnerAllocatedObject>(
1556 result, Add<HConstant>(JSRegExpResult::kSize)); 1556 result, Add<HConstant>(JSRegExpResult::kSize), HType::HeapObject());
1557 1557
1558 // Initialize the JSRegExpResult header. 1558 // Initialize the JSRegExpResult header.
1559 HValue* global_object = Add<HLoadNamedField>( 1559 HValue* global_object = Add<HLoadNamedField>(
1560 context(), static_cast<HValue*>(NULL), 1560 context(), static_cast<HValue*>(NULL),
1561 HObjectAccess::ForContextSlot(Context::GLOBAL_OBJECT_INDEX)); 1561 HObjectAccess::ForContextSlot(Context::GLOBAL_OBJECT_INDEX));
1562 HValue* native_context = Add<HLoadNamedField>( 1562 HValue* native_context = Add<HLoadNamedField>(
1563 global_object, static_cast<HValue*>(NULL), 1563 global_object, static_cast<HValue*>(NULL),
1564 HObjectAccess::ForGlobalObjectNativeContext()); 1564 HObjectAccess::ForGlobalObjectNativeContext());
1565 Add<HStoreNamedField>( 1565 Add<HStoreNamedField>(
1566 result, HObjectAccess::ForMap(), 1566 result, HObjectAccess::ForMap(),
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 } 2286 }
2287 2287
2288 HConstant* elements_size_value = Add<HConstant>(elements_size); 2288 HConstant* elements_size_value = Add<HConstant>(elements_size);
2289 HValue* mul = AddUncasted<HMul>(capacity, elements_size_value); 2289 HValue* mul = AddUncasted<HMul>(capacity, elements_size_value);
2290 mul->ClearFlag(HValue::kCanOverflow); 2290 mul->ClearFlag(HValue::kCanOverflow);
2291 2291
2292 HConstant* header_size = Add<HConstant>(FixedArray::kHeaderSize); 2292 HConstant* header_size = Add<HConstant>(FixedArray::kHeaderSize);
2293 HValue* total_size = AddUncasted<HAdd>(mul, header_size); 2293 HValue* total_size = AddUncasted<HAdd>(mul, header_size);
2294 total_size->ClearFlag(HValue::kCanOverflow); 2294 total_size->ClearFlag(HValue::kCanOverflow);
2295 2295
2296 return Add<HAllocate>(total_size, HType::NonPrimitive(), NOT_TENURED, 2296 return Add<HAllocate>(total_size, HType::HeapObject(), NOT_TENURED,
2297 instance_type); 2297 instance_type);
2298 } 2298 }
2299 2299
2300 2300
2301 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements, 2301 void HGraphBuilder::BuildInitializeElementsHeader(HValue* elements,
2302 ElementsKind kind, 2302 ElementsKind kind,
2303 HValue* capacity) { 2303 HValue* capacity) {
2304 Factory* factory = isolate()->factory(); 2304 Factory* factory = isolate()->factory();
2305 Handle<Map> map = IsFastDoubleElementsKind(kind) 2305 Handle<Map> map = IsFastDoubleElementsKind(kind)
2306 ? factory->fixed_double_array_map() 2306 ? factory->fixed_double_array_map()
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 BuildCreateAllocationMemento( 2345 BuildCreateAllocationMemento(
2346 array, Add<HConstant>(JSArray::kSize), allocation_site_payload); 2346 array, Add<HConstant>(JSArray::kSize), allocation_site_payload);
2347 } 2347 }
2348 2348
2349 int elements_location = JSArray::kSize; 2349 int elements_location = JSArray::kSize;
2350 if (mode == TRACK_ALLOCATION_SITE) { 2350 if (mode == TRACK_ALLOCATION_SITE) {
2351 elements_location += AllocationMemento::kSize; 2351 elements_location += AllocationMemento::kSize;
2352 } 2352 }
2353 2353
2354 HInnerAllocatedObject* elements = Add<HInnerAllocatedObject>( 2354 HInnerAllocatedObject* elements = Add<HInnerAllocatedObject>(
2355 array, Add<HConstant>(elements_location)); 2355 array, Add<HConstant>(elements_location), HType::HeapObject());
2356 Add<HStoreNamedField>(array, HObjectAccess::ForElementsPointer(), elements); 2356 Add<HStoreNamedField>(array, HObjectAccess::ForElementsPointer(), elements);
2357 return elements; 2357 return elements;
2358 } 2358 }
2359 2359
2360 2360
2361 HInstruction* HGraphBuilder::AddElementAccess( 2361 HInstruction* HGraphBuilder::AddElementAccess(
2362 HValue* elements, 2362 HValue* elements,
2363 HValue* checked_key, 2363 HValue* checked_key,
2364 HValue* val, 2364 HValue* val,
2365 HValue* dependency, 2365 HValue* dependency,
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 INITIALIZING_STORE); 2635 INITIALIZING_STORE);
2636 2636
2637 // Create an allocation site info if requested. 2637 // Create an allocation site info if requested.
2638 if (mode == TRACK_ALLOCATION_SITE) { 2638 if (mode == TRACK_ALLOCATION_SITE) {
2639 BuildCreateAllocationMemento( 2639 BuildCreateAllocationMemento(
2640 object, Add<HConstant>(JSArray::kSize), allocation_site); 2640 object, Add<HConstant>(JSArray::kSize), allocation_site);
2641 } 2641 }
2642 2642
2643 if (extra_size != NULL) { 2643 if (extra_size != NULL) {
2644 HValue* elements = Add<HInnerAllocatedObject>(object, 2644 HValue* elements = Add<HInnerAllocatedObject>(object,
2645 Add<HConstant>(array_size)); 2645 Add<HConstant>(array_size), HType::HeapObject());
2646 if (return_elements != NULL) *return_elements = elements; 2646 if (return_elements != NULL) *return_elements = elements;
2647 } 2647 }
2648 2648
2649 return object; 2649 return object;
2650 } 2650 }
2651 2651
2652 2652
2653 HValue* HGraphBuilder::BuildCloneShallowArrayCow(HValue* boilerplate, 2653 HValue* HGraphBuilder::BuildCloneShallowArrayCow(HValue* boilerplate,
2654 HValue* allocation_site, 2654 HValue* allocation_site,
2655 AllocationSiteMode mode, 2655 AllocationSiteMode mode,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 if_nil.CaptureContinuation(continuation); 2787 if_nil.CaptureContinuation(continuation);
2788 } 2788 }
2789 2789
2790 2790
2791 void HGraphBuilder::BuildCreateAllocationMemento( 2791 void HGraphBuilder::BuildCreateAllocationMemento(
2792 HValue* previous_object, 2792 HValue* previous_object,
2793 HValue* previous_object_size, 2793 HValue* previous_object_size,
2794 HValue* allocation_site) { 2794 HValue* allocation_site) {
2795 ASSERT(allocation_site != NULL); 2795 ASSERT(allocation_site != NULL);
2796 HInnerAllocatedObject* allocation_memento = Add<HInnerAllocatedObject>( 2796 HInnerAllocatedObject* allocation_memento = Add<HInnerAllocatedObject>(
2797 previous_object, previous_object_size); 2797 previous_object, previous_object_size, HType::HeapObject());
2798 AddStoreMapConstant( 2798 AddStoreMapConstant(
2799 allocation_memento, isolate()->factory()->allocation_memento_map()); 2799 allocation_memento, isolate()->factory()->allocation_memento_map());
2800 Add<HStoreNamedField>( 2800 Add<HStoreNamedField>(
2801 allocation_memento, 2801 allocation_memento,
2802 HObjectAccess::ForAllocationMementoSite(), 2802 HObjectAccess::ForAllocationMementoSite(),
2803 allocation_site); 2803 allocation_site);
2804 if (FLAG_allocation_site_pretenuring) { 2804 if (FLAG_allocation_site_pretenuring) {
2805 HValue* memento_create_count = Add<HLoadNamedField>( 2805 HValue* memento_create_count = Add<HLoadNamedField>(
2806 allocation_site, static_cast<HValue*>(NULL), 2806 allocation_site, static_cast<HValue*>(NULL),
2807 HObjectAccess::ForAllocationSiteOffset( 2807 HObjectAccess::ForAllocationSiteOffset(
(...skipping 2665 matching lines...) Expand 10 before | Expand all | Expand 10 after
5473 if (field_access.representation().IsDouble()) { 5473 if (field_access.representation().IsDouble()) {
5474 HObjectAccess heap_number_access = 5474 HObjectAccess heap_number_access =
5475 field_access.WithRepresentation(Representation::Tagged()); 5475 field_access.WithRepresentation(Representation::Tagged());
5476 if (transition_to_field) { 5476 if (transition_to_field) {
5477 // The store requires a mutable HeapNumber to be allocated. 5477 // The store requires a mutable HeapNumber to be allocated.
5478 NoObservableSideEffectsScope no_side_effects(this); 5478 NoObservableSideEffectsScope no_side_effects(this);
5479 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize); 5479 HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize);
5480 5480
5481 // TODO(hpayer): Allocation site pretenuring support. 5481 // TODO(hpayer): Allocation site pretenuring support.
5482 HInstruction* heap_number = Add<HAllocate>(heap_number_size, 5482 HInstruction* heap_number = Add<HAllocate>(heap_number_size,
5483 HType::Tagged(), 5483 HType::HeapObject(),
5484 NOT_TENURED, 5484 NOT_TENURED,
5485 HEAP_NUMBER_TYPE); 5485 HEAP_NUMBER_TYPE);
5486 AddStoreMapConstant(heap_number, isolate()->factory()->heap_number_map()); 5486 AddStoreMapConstant(heap_number, isolate()->factory()->heap_number_map());
5487 Add<HStoreNamedField>(heap_number, HObjectAccess::ForHeapNumberValue(), 5487 Add<HStoreNamedField>(heap_number, HObjectAccess::ForHeapNumberValue(),
5488 value); 5488 value);
5489 instr = New<HStoreNamedField>(checked_object->ActualValue(), 5489 instr = New<HStoreNamedField>(checked_object->ActualValue(),
5490 heap_number_access, 5490 heap_number_access,
5491 heap_number); 5491 heap_number);
5492 } else { 5492 } else {
5493 // Already holds a HeapNumber; load the box and write its value field. 5493 // Already holds a HeapNumber; load the box and write its value field.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
5661 field_maps_.Clear(); 5661 field_maps_.Clear();
5662 return; 5662 return;
5663 } 5663 }
5664 field_maps_.Add(field_map, zone()); 5664 field_maps_.Add(field_map, zone());
5665 it.Advance(); 5665 it.Advance();
5666 } 5666 }
5667 field_maps_.Sort(); 5667 field_maps_.Sort();
5668 ASSERT_EQ(num_field_maps, field_maps_.length()); 5668 ASSERT_EQ(num_field_maps, field_maps_.length());
5669 5669
5670 // Determine field HType from field HeapType. 5670 // Determine field HType from field HeapType.
5671 if (field_type->Is(HeapType::Number())) { 5671 field_type_ = HType::FromType<HeapType>(field_type);
5672 field_type_ = HType::HeapNumber(); 5672 ASSERT(field_type_.IsHeapObject());
5673 } else if (field_type->Is(HeapType::String())) {
5674 field_type_ = HType::String();
5675 } else if (field_type->Is(HeapType::Boolean())) {
5676 field_type_ = HType::Boolean();
5677 } else if (field_type->Is(HeapType::Array())) {
5678 field_type_ = HType::JSArray();
5679 } else if (field_type->Is(HeapType::Object())) {
5680 field_type_ = HType::JSObject();
5681 } else if (field_type->Is(HeapType::Null()) ||
5682 field_type->Is(HeapType::Undefined())) {
5683 field_type_ = HType::NonPrimitive();
5684 }
5685 5673
5686 // Add dependency on the map that introduced the field. 5674 // Add dependency on the map that introduced the field.
5687 Map::AddDependentCompilationInfo( 5675 Map::AddDependentCompilationInfo(
5688 handle(lookup_.GetFieldOwnerFromMap(*map), isolate()), 5676 handle(lookup_.GetFieldOwnerFromMap(*map), isolate()),
5689 DependentCode::kFieldTypeGroup, top_info()); 5677 DependentCode::kFieldTypeGroup, top_info());
5690 } 5678 }
5691 5679
5692 5680
5693 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() { 5681 bool HOptimizedGraphBuilder::PropertyAccessInfo::LookupInPrototypes() {
5694 Handle<Map> map = this->map(); 5682 Handle<Map> map = this->map();
(...skipping 3089 matching lines...) Expand 10 before | Expand all | Expand 10 after
8784 HValue* buffer, HValue* byte_offset, HValue* length) { 8772 HValue* buffer, HValue* byte_offset, HValue* length) {
8785 Handle<Map> external_array_map( 8773 Handle<Map> external_array_map(
8786 isolate()->heap()->MapForExternalArrayType(array_type)); 8774 isolate()->heap()->MapForExternalArrayType(array_type));
8787 8775
8788 // The HForceRepresentation is to prevent possible deopt on int-smi 8776 // The HForceRepresentation is to prevent possible deopt on int-smi
8789 // conversion after allocation but before the new object fields are set. 8777 // conversion after allocation but before the new object fields are set.
8790 length = AddUncasted<HForceRepresentation>(length, Representation::Smi()); 8778 length = AddUncasted<HForceRepresentation>(length, Representation::Smi());
8791 HValue* elements = 8779 HValue* elements =
8792 Add<HAllocate>( 8780 Add<HAllocate>(
8793 Add<HConstant>(ExternalArray::kAlignedSize), 8781 Add<HConstant>(ExternalArray::kAlignedSize),
8794 HType::NonPrimitive(), 8782 HType::HeapObject(),
8795 NOT_TENURED, 8783 NOT_TENURED,
8796 external_array_map->instance_type()); 8784 external_array_map->instance_type());
8797 8785
8798 AddStoreMapConstant(elements, external_array_map); 8786 AddStoreMapConstant(elements, external_array_map);
8799 Add<HStoreNamedField>(elements, 8787 Add<HStoreNamedField>(elements,
8800 HObjectAccess::ForFixedArrayLength(), length); 8788 HObjectAccess::ForFixedArrayLength(), length);
8801 8789
8802 HValue* backing_store = Add<HLoadNamedField>( 8790 HValue* backing_store = Add<HLoadNamedField>(
8803 buffer, static_cast<HValue*>(NULL), 8791 buffer, static_cast<HValue*>(NULL),
8804 HObjectAccess::ForJSArrayBufferBackingStore()); 8792 HObjectAccess::ForJSArrayBufferBackingStore());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
8841 Add<HConstant>(FixedTypedArrayBase::kHeaderSize)); 8829 Add<HConstant>(FixedTypedArrayBase::kHeaderSize));
8842 total_size->ClearFlag(HValue::kCanOverflow); 8830 total_size->ClearFlag(HValue::kCanOverflow);
8843 } 8831 }
8844 8832
8845 // The HForceRepresentation is to prevent possible deopt on int-smi 8833 // The HForceRepresentation is to prevent possible deopt on int-smi
8846 // conversion after allocation but before the new object fields are set. 8834 // conversion after allocation but before the new object fields are set.
8847 length = AddUncasted<HForceRepresentation>(length, Representation::Smi()); 8835 length = AddUncasted<HForceRepresentation>(length, Representation::Smi());
8848 Handle<Map> fixed_typed_array_map( 8836 Handle<Map> fixed_typed_array_map(
8849 isolate()->heap()->MapForFixedTypedArray(array_type)); 8837 isolate()->heap()->MapForFixedTypedArray(array_type));
8850 HValue* elements = 8838 HValue* elements =
8851 Add<HAllocate>(total_size, HType::NonPrimitive(), 8839 Add<HAllocate>(total_size, HType::HeapObject(),
8852 NOT_TENURED, fixed_typed_array_map->instance_type()); 8840 NOT_TENURED, fixed_typed_array_map->instance_type());
8853 AddStoreMapConstant(elements, fixed_typed_array_map); 8841 AddStoreMapConstant(elements, fixed_typed_array_map);
8854 8842
8855 Add<HStoreNamedField>(elements, 8843 Add<HStoreNamedField>(elements,
8856 HObjectAccess::ForFixedArrayLength(), 8844 HObjectAccess::ForFixedArrayLength(),
8857 length); 8845 length);
8858 8846
8859 HValue* filler = Add<HConstant>(static_cast<int32_t>(0)); 8847 HValue* filler = Add<HConstant>(static_cast<int32_t>(0));
8860 8848
8861 { 8849 {
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after
10274 Handle<FixedArray>::cast(elements))); 10262 Handle<FixedArray>::cast(elements)));
10275 boilerplate_object->set_elements(*elements); 10263 boilerplate_object->set_elements(*elements);
10276 } 10264 }
10277 10265
10278 HInstruction* object_elements = NULL; 10266 HInstruction* object_elements = NULL;
10279 if (elements_size > 0) { 10267 if (elements_size > 0) {
10280 HValue* object_elements_size = Add<HConstant>(elements_size); 10268 HValue* object_elements_size = Add<HConstant>(elements_size);
10281 InstanceType instance_type = boilerplate_object->HasFastDoubleElements() 10269 InstanceType instance_type = boilerplate_object->HasFastDoubleElements()
10282 ? FIXED_DOUBLE_ARRAY_TYPE : FIXED_ARRAY_TYPE; 10270 ? FIXED_DOUBLE_ARRAY_TYPE : FIXED_ARRAY_TYPE;
10283 object_elements = Add<HAllocate>( 10271 object_elements = Add<HAllocate>(
10284 object_elements_size, HType::NonPrimitive(), 10272 object_elements_size, HType::HeapObject(),
10285 pretenure_flag, instance_type, site_context->current()); 10273 pretenure_flag, instance_type, site_context->current());
10286 } 10274 }
10287 BuildInitElementsInObjectHeader(boilerplate_object, object, object_elements); 10275 BuildInitElementsInObjectHeader(boilerplate_object, object, object_elements);
10288 10276
10289 // Copy object elements if non-COW. 10277 // Copy object elements if non-COW.
10290 if (object_elements != NULL) { 10278 if (object_elements != NULL) {
10291 BuildEmitElements(boilerplate_object, elements, object_elements, 10279 BuildEmitElements(boilerplate_object, elements, object_elements,
10292 site_context); 10280 site_context);
10293 } 10281 }
10294 10282
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after
11795 if (ShouldProduceTraceOutput()) { 11783 if (ShouldProduceTraceOutput()) {
11796 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 11784 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
11797 } 11785 }
11798 11786
11799 #ifdef DEBUG 11787 #ifdef DEBUG
11800 graph_->Verify(false); // No full verify. 11788 graph_->Verify(false); // No full verify.
11801 #endif 11789 #endif
11802 } 11790 }
11803 11791
11804 } } // namespace v8::internal 11792 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698