Commit 382ec92f authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Make use of templatized convienience functions for adding Hydrogen instructions.

Building on the previous changes from https://codereview.chromium.org/18050004/
this patch makes even more use of the templatized functions for adding
Hydrogen instructions.

R=danno@chromium.org
BUG=

Review URL: https://codereview.chromium.org/18051010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15379 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 85d7a36e
...@@ -993,8 +993,7 @@ void HGraphBuilder::AddSimulate(BailoutId id, ...@@ -993,8 +993,7 @@ void HGraphBuilder::AddSimulate(BailoutId id,
HReturn* HGraphBuilder::AddReturn(HValue* value) { HReturn* HGraphBuilder::AddReturn(HValue* value) {
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
int num_parameters = graph()->info()->num_parameters(); int num_parameters = graph()->info()->num_parameters();
HValue* params = AddInstruction(new(graph()->zone()) HValue* params = Add<HConstant>(num_parameters);
HConstant(num_parameters));
HReturn* return_instruction = new(graph()->zone()) HReturn* return_instruction = new(graph()->zone())
HReturn(value, context, params); HReturn(value, context, params);
current_block()->FinishExit(return_instruction); current_block()->FinishExit(return_instruction);
...@@ -1020,9 +1019,7 @@ HBasicBlock* HGraphBuilder::CreateLoopHeaderBlock() { ...@@ -1020,9 +1019,7 @@ HBasicBlock* HGraphBuilder::CreateLoopHeaderBlock() {
HValue* HGraphBuilder::BuildCheckHeapObject(HValue* obj) { HValue* HGraphBuilder::BuildCheckHeapObject(HValue* obj) {
if (obj->type().IsHeapObject()) return obj; if (obj->type().IsHeapObject()) return obj;
HCheckHeapObject* check = new(zone()) HCheckHeapObject(obj); return Add<HCheckHeapObject>(obj);
AddInstruction(check);
return check;
} }
...@@ -1046,7 +1043,7 @@ HInstruction* HGraphBuilder::BuildExternalArrayElementAccess( ...@@ -1046,7 +1043,7 @@ HInstruction* HGraphBuilder::BuildExternalArrayElementAccess(
ASSERT(val != NULL); ASSERT(val != NULL);
switch (elements_kind) { switch (elements_kind) {
case EXTERNAL_PIXEL_ELEMENTS: { case EXTERNAL_PIXEL_ELEMENTS: {
val = AddInstruction(new(zone) HClampToUint8(val)); val = Add<HClampToUint8>(val);
break; break;
} }
case EXTERNAL_BYTE_ELEMENTS: case EXTERNAL_BYTE_ELEMENTS:
...@@ -1133,8 +1130,7 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow(HValue* object, ...@@ -1133,8 +1130,7 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow(HValue* object,
length_checker.IfCompare(length, key, Token::EQ); length_checker.IfCompare(length, key, Token::EQ);
length_checker.Then(); length_checker.Then();
HValue* current_capacity = HValue* current_capacity = Add<HFixedArrayBaseLength>(elements);
AddInstruction(new(zone) HFixedArrayBaseLength(elements));
IfBuilder capacity_checker(this); IfBuilder capacity_checker(this);
...@@ -1182,7 +1178,6 @@ HValue* HGraphBuilder::BuildCopyElementsOnWrite(HValue* object, ...@@ -1182,7 +1178,6 @@ HValue* HGraphBuilder::BuildCopyElementsOnWrite(HValue* object,
HValue* elements, HValue* elements,
ElementsKind kind, ElementsKind kind,
HValue* length) { HValue* length) {
Zone* zone = this->zone();
Heap* heap = isolate()->heap(); Heap* heap = isolate()->heap();
IfBuilder cow_checker(this); IfBuilder cow_checker(this);
...@@ -1191,8 +1186,7 @@ HValue* HGraphBuilder::BuildCopyElementsOnWrite(HValue* object, ...@@ -1191,8 +1186,7 @@ HValue* HGraphBuilder::BuildCopyElementsOnWrite(HValue* object,
Handle<Map>(heap->fixed_cow_array_map())); Handle<Map>(heap->fixed_cow_array_map()));
cow_checker.Then(); cow_checker.Then();
HValue* capacity = HValue* capacity = Add<HFixedArrayBaseLength>(elements);
AddInstruction(new(zone) HFixedArrayBaseLength(elements));
HValue* new_elements = BuildGrowElementsCapacity(object, elements, HValue* new_elements = BuildGrowElementsCapacity(object, elements,
kind, length, capacity); kind, length, capacity);
...@@ -1249,15 +1243,14 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1249,15 +1243,14 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
Representation::Smi()); Representation::Smi());
length->set_type(HType::Smi()); length->set_type(HType::Smi());
} else { } else {
length = AddInstruction(new(zone) HFixedArrayBaseLength(elements)); length = Add<HFixedArrayBaseLength>(elements);
} }
HValue* checked_key = NULL; HValue* checked_key = NULL;
if (IsExternalArrayElementsKind(elements_kind)) { if (IsExternalArrayElementsKind(elements_kind)) {
if (store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) { if (store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) {
NoObservableSideEffectsScope no_effects(this); NoObservableSideEffectsScope no_effects(this);
HLoadExternalArrayPointer* external_elements = HLoadExternalArrayPointer* external_elements =
new(zone) HLoadExternalArrayPointer(elements); Add<HLoadExternalArrayPointer>(elements);
AddInstruction(external_elements);
IfBuilder length_checker(this); IfBuilder length_checker(this);
length_checker.IfCompare(key, length, Token::LT); length_checker.IfCompare(key, length, Token::LT);
length_checker.Then(); length_checker.Then();
...@@ -1276,8 +1269,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1276,8 +1269,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
ASSERT(store_mode == STANDARD_STORE); ASSERT(store_mode == STANDARD_STORE);
checked_key = Add<HBoundsCheck>(key, length); checked_key = Add<HBoundsCheck>(key, length);
HLoadExternalArrayPointer* external_elements = HLoadExternalArrayPointer* external_elements =
new(zone) HLoadExternalArrayPointer(elements); Add<HLoadExternalArrayPointer>(elements);
AddInstruction(external_elements);
return AddInstruction(BuildExternalArrayElementAccess( return AddInstruction(BuildExternalArrayElementAccess(
external_elements, checked_key, val, mapcheck, external_elements, checked_key, val, mapcheck,
elements_kind, is_store)); elements_kind, is_store));
...@@ -1292,8 +1284,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1292,8 +1284,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
// deopt, leaving the backing store in an invalid state. // deopt, leaving the backing store in an invalid state.
if (is_store && IsFastSmiElementsKind(elements_kind) && if (is_store && IsFastSmiElementsKind(elements_kind) &&
!val->type().IsSmi()) { !val->type().IsSmi()) {
val = AddInstruction(new(zone) HForceRepresentation( val = Add<HForceRepresentation>(val, Representation::Smi());
val, Representation::Smi()));
} }
if (IsGrowStoreMode(store_mode)) { if (IsGrowStoreMode(store_mode)) {
...@@ -1331,14 +1322,12 @@ HValue* HGraphBuilder::BuildAllocateElements(HValue* context, ...@@ -1331,14 +1322,12 @@ HValue* HGraphBuilder::BuildAllocateElements(HValue* context,
int elements_size = IsFastDoubleElementsKind(kind) int elements_size = IsFastDoubleElementsKind(kind)
? kDoubleSize : kPointerSize; ? kDoubleSize : kPointerSize;
HConstant* elements_size_value = new(zone) HConstant(elements_size); HConstant* elements_size_value = Add<HConstant>(elements_size);
AddInstruction(elements_size_value);
HValue* mul = AddInstruction( HValue* mul = AddInstruction(
HMul::New(zone, context, capacity, elements_size_value)); HMul::New(zone, context, capacity, elements_size_value));
mul->ClearFlag(HValue::kCanOverflow); mul->ClearFlag(HValue::kCanOverflow);
HConstant* header_size = new(zone) HConstant(FixedArray::kHeaderSize); HConstant* header_size = Add<HConstant>(FixedArray::kHeaderSize);
AddInstruction(header_size);
HValue* total_size = AddInstruction( HValue* total_size = AddInstruction(
HAdd::New(zone, context, mul, header_size)); HAdd::New(zone, context, mul, header_size));
total_size->ClearFlag(HValue::kCanOverflow); total_size->ClearFlag(HValue::kCanOverflow);
...@@ -1356,10 +1345,7 @@ HValue* HGraphBuilder::BuildAllocateElements(HValue* context, ...@@ -1356,10 +1345,7 @@ HValue* HGraphBuilder::BuildAllocateElements(HValue* context,
} }
} }
HValue* elements = return Add<HAllocate>(context, total_size, HType::JSArray(), flags);
AddInstruction(new(zone) HAllocate(context, total_size,
HType::JSArray(), flags));
return elements;
} }
...@@ -1398,8 +1384,7 @@ HInnerAllocatedObject* HGraphBuilder::BuildJSArrayHeader(HValue* array, ...@@ -1398,8 +1384,7 @@ HInnerAllocatedObject* HGraphBuilder::BuildJSArrayHeader(HValue* array,
AddStore(array, HObjectAccess::ForMap(), array_map); AddStore(array, HObjectAccess::ForMap(), array_map);
HConstant* empty_fixed_array = HConstant* empty_fixed_array =
new(zone()) HConstant(isolate()->factory()->empty_fixed_array()); Add<HConstant>(isolate()->factory()->empty_fixed_array());
AddInstruction(empty_fixed_array);
HObjectAccess access = HObjectAccess::ForPropertiesPointer(); HObjectAccess access = HObjectAccess::ForPropertiesPointer();
AddStore(array, access, empty_fixed_array); AddStore(array, access, empty_fixed_array);
...@@ -1416,10 +1401,8 @@ HInnerAllocatedObject* HGraphBuilder::BuildJSArrayHeader(HValue* array, ...@@ -1416,10 +1401,8 @@ HInnerAllocatedObject* HGraphBuilder::BuildJSArrayHeader(HValue* array,
elements_location += AllocationSiteInfo::kSize; elements_location += AllocationSiteInfo::kSize;
} }
HInnerAllocatedObject* elements = new(zone()) HInnerAllocatedObject( HInnerAllocatedObject* elements =
array, elements_location); Add<HInnerAllocatedObject>(array, elements_location);
AddInstruction(elements);
AddStore(array, HObjectAccess::ForElementsPointer(), elements); AddStore(array, HObjectAccess::ForElementsPointer(), elements);
return elements; return elements;
} }
...@@ -1443,7 +1426,7 @@ HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context, ...@@ -1443,7 +1426,7 @@ HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context,
HAdd::New(zone, context, half_old_capacity, old_capacity)); HAdd::New(zone, context, half_old_capacity, old_capacity));
new_capacity->ClearFlag(HValue::kCanOverflow); new_capacity->ClearFlag(HValue::kCanOverflow);
HValue* min_growth = AddInstruction(new(zone) HConstant(16)); HValue* min_growth = Add<HConstant>(16);
new_capacity = AddInstruction( new_capacity = AddInstruction(
HAdd::New(zone, context, new_capacity, min_growth)); HAdd::New(zone, context, new_capacity, min_growth));
...@@ -1454,17 +1437,15 @@ HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context, ...@@ -1454,17 +1437,15 @@ HValue* HGraphBuilder::BuildNewElementsCapacity(HValue* context,
void HGraphBuilder::BuildNewSpaceArrayCheck(HValue* length, ElementsKind kind) { void HGraphBuilder::BuildNewSpaceArrayCheck(HValue* length, ElementsKind kind) {
Zone* zone = this->zone();
Heap* heap = isolate()->heap(); Heap* heap = isolate()->heap();
int element_size = IsFastDoubleElementsKind(kind) ? kDoubleSize int element_size = IsFastDoubleElementsKind(kind) ? kDoubleSize
: kPointerSize; : kPointerSize;
int max_size = heap->MaxRegularSpaceAllocationSize() / element_size; int max_size = heap->MaxRegularSpaceAllocationSize() / element_size;
max_size -= JSArray::kSize / element_size; max_size -= JSArray::kSize / element_size;
HConstant* max_size_constant = new(zone) HConstant(max_size); HConstant* max_size_constant = Add<HConstant>(max_size);
AddInstruction(max_size_constant);
// Since we're forcing Integer32 representation for this HBoundsCheck, // Since we're forcing Integer32 representation for this HBoundsCheck,
// there's no need to Smi-check the index. // there's no need to Smi-check the index.
AddInstruction(new(zone) HBoundsCheck(length, max_size_constant)); Add<HBoundsCheck>(length, max_size_constant);
} }
...@@ -1500,10 +1481,9 @@ void HGraphBuilder::BuildFillElementsWithHole(HValue* context, ...@@ -1500,10 +1481,9 @@ void HGraphBuilder::BuildFillElementsWithHole(HValue* context,
Factory* factory = isolate()->factory(); Factory* factory = isolate()->factory();
double nan_double = FixedDoubleArray::hole_nan_as_double(); double nan_double = FixedDoubleArray::hole_nan_as_double();
Zone* zone = this->zone();
HValue* hole = IsFastSmiOrObjectElementsKind(elements_kind) HValue* hole = IsFastSmiOrObjectElementsKind(elements_kind)
? AddInstruction(new(zone) HConstant(factory->the_hole_value())) ? Add<HConstant>(factory->the_hole_value())
: AddInstruction(new(zone) HConstant(nan_double)); : Add<HConstant>(nan_double);
// Special loop unfolding case // Special loop unfolding case
static const int kLoopUnfoldLimit = 4; static const int kLoopUnfoldLimit = 4;
...@@ -1530,15 +1510,15 @@ void HGraphBuilder::BuildFillElementsWithHole(HValue* context, ...@@ -1530,15 +1510,15 @@ void HGraphBuilder::BuildFillElementsWithHole(HValue* context,
if (unfold_loop) { if (unfold_loop) {
for (int i = 0; i < initial_capacity; i++) { for (int i = 0; i < initial_capacity; i++) {
HInstruction* key = AddInstruction(new(zone) HConstant(i)); HInstruction* key = Add<HConstant>(i);
AddInstruction(new(zone) HStoreKeyed(elements, key, hole, elements_kind)); Add<HStoreKeyed>(elements, key, hole, elements_kind);
} }
} else { } else {
LoopBuilder builder(this, context, LoopBuilder::kPostIncrement); LoopBuilder builder(this, context, LoopBuilder::kPostIncrement);
HValue* key = builder.BeginBody(from, to, Token::LT); HValue* key = builder.BeginBody(from, to, Token::LT);
AddInstruction(new(zone) HStoreKeyed(elements, key, hole, elements_kind)); Add<HStoreKeyed>(elements, key, hole, elements_kind);
builder.EndBody(); builder.EndBody();
} }
...@@ -1568,15 +1548,15 @@ void HGraphBuilder::BuildCopyElements(HValue* context, ...@@ -1568,15 +1548,15 @@ void HGraphBuilder::BuildCopyElements(HValue* context,
HValue* key = builder.BeginBody(graph()->GetConstant0(), length, Token::LT); HValue* key = builder.BeginBody(graph()->GetConstant0(), length, Token::LT);
HValue* element = HValue* element = Add<HLoadKeyed>(from_elements, key,
AddInstruction(new(zone()) HLoadKeyed(from_elements, key, NULL, static_cast<HValue*>(NULL),
from_elements_kind, from_elements_kind,
ALLOW_RETURN_HOLE)); ALLOW_RETURN_HOLE);
ElementsKind holey_kind = IsFastSmiElementsKind(to_elements_kind) ElementsKind holey_kind = IsFastSmiElementsKind(to_elements_kind)
? FAST_HOLEY_ELEMENTS : to_elements_kind; ? FAST_HOLEY_ELEMENTS : to_elements_kind;
HInstruction* holey_store = AddInstruction( HInstruction* holey_store = Add<HStoreKeyed>(to_elements, key,
new(zone()) HStoreKeyed(to_elements, key, element, holey_kind)); element, holey_kind);
// Allow NaN hole values to converted to their tagged counterparts. // Allow NaN hole values to converted to their tagged counterparts.
if (IsFastHoleyElementsKind(to_elements_kind)) { if (IsFastHoleyElementsKind(to_elements_kind)) {
holey_store->SetFlag(HValue::kAllowUndefinedAsNaN); holey_store->SetFlag(HValue::kAllowUndefinedAsNaN);
...@@ -1597,8 +1577,6 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context, ...@@ -1597,8 +1577,6 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
AllocationSiteMode mode, AllocationSiteMode mode,
ElementsKind kind, ElementsKind kind,
int length) { int length) {
Zone* zone = this->zone();
NoObservableSideEffectsScope no_effects(this); NoObservableSideEffectsScope no_effects(this);
// All sizes here are multiples of kPointerSize. // All sizes here are multiples of kPointerSize.
...@@ -1616,12 +1594,11 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context, ...@@ -1616,12 +1594,11 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
HAllocate::Flags allocate_flags = HAllocate::DefaultFlags(kind); HAllocate::Flags allocate_flags = HAllocate::DefaultFlags(kind);
// Allocate both the JS array and the elements array in one big // Allocate both the JS array and the elements array in one big
// allocation. This avoids multiple limit checks. // allocation. This avoids multiple limit checks.
HValue* size_in_bytes = AddInstruction(new(zone) HConstant(size)); HValue* size_in_bytes = Add<HConstant>(size);
HInstruction* object = HInstruction* object = Add<HAllocate>(context,
AddInstruction(new(zone) HAllocate(context, size_in_bytes,
size_in_bytes, HType::JSObject(),
HType::JSObject(), allocate_flags);
allocate_flags));
// Copy the JS array part. // Copy the JS array part.
for (int i = 0; i < JSArray::kSize; i += kPointerSize) { for (int i = 0; i < JSArray::kSize; i += kPointerSize) {
...@@ -1640,8 +1617,7 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context, ...@@ -1640,8 +1617,7 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
// Get hold of the elements array of the boilerplate and setup the // Get hold of the elements array of the boilerplate and setup the
// elements pointer in the resulting object. // elements pointer in the resulting object.
HValue* boilerplate_elements = AddLoadElements(boilerplate); HValue* boilerplate_elements = AddLoadElements(boilerplate);
HValue* object_elements = HValue* object_elements = Add<HInnerAllocatedObject>(object, elems_offset);
AddInstruction(new(zone) HInnerAllocatedObject(object, elems_offset));
AddStore(object, HObjectAccess::ForElementsPointer(), object_elements); AddStore(object, HObjectAccess::ForElementsPointer(), object_elements);
// Copy the elements array header. // Copy the elements array header.
...@@ -1655,16 +1631,10 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context, ...@@ -1655,16 +1631,10 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context,
// copying loops with constant length up to a given boundary and use this // copying loops with constant length up to a given boundary and use this
// helper here instead. // helper here instead.
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
HValue* key_constant = AddInstruction(new(zone) HConstant(i)); HValue* key_constant = Add<HConstant>(i);
HInstruction* value = HInstruction* value = Add<HLoadKeyed>(boilerplate_elements, key_constant,
AddInstruction(new(zone) HLoadKeyed(boilerplate_elements, static_cast<HValue*>(NULL), kind);
key_constant, Add<HStoreKeyed>(object_elements, key_constant, value, kind);
NULL,
kind));
AddInstruction(new(zone) HStoreKeyed(object_elements,
key_constant,
value,
kind));
} }
} }
...@@ -1715,9 +1685,8 @@ void HGraphBuilder::BuildCompareNil( ...@@ -1715,9 +1685,8 @@ void HGraphBuilder::BuildCompareNil(
HValue* HGraphBuilder::BuildCreateAllocationSiteInfo(HValue* previous_object, HValue* HGraphBuilder::BuildCreateAllocationSiteInfo(HValue* previous_object,
int previous_object_size, int previous_object_size,
HValue* payload) { HValue* payload) {
HInnerAllocatedObject* alloc_site = new(zone()) HInnerAllocatedObject* alloc_site = Add<HInnerAllocatedObject>(
HInnerAllocatedObject(previous_object, previous_object_size); previous_object, previous_object_size);
AddInstruction(alloc_site);
Handle<Map> alloc_site_map(isolate()->heap()->allocation_site_info_map()); Handle<Map> alloc_site_map(isolate()->heap()->allocation_site_info_map());
AddStoreMapConstant(alloc_site, alloc_site_map); AddStoreMapConstant(alloc_site, alloc_site_map);
HObjectAccess access = HObjectAccess::ForAllocationSitePayload(); HObjectAccess access = HObjectAccess::ForAllocationSitePayload();
...@@ -1728,8 +1697,7 @@ HValue* HGraphBuilder::BuildCreateAllocationSiteInfo(HValue* previous_object, ...@@ -1728,8 +1697,7 @@ HValue* HGraphBuilder::BuildCreateAllocationSiteInfo(HValue* previous_object,
HInstruction* HGraphBuilder::BuildGetNativeContext(HValue* context) { HInstruction* HGraphBuilder::BuildGetNativeContext(HValue* context) {
// Get the global context, then the native context // Get the global context, then the native context
HInstruction* global_object = AddInstruction(new(zone()) HInstruction* global_object = Add<HGlobalObject>(context);
HGlobalObject(context));
HObjectAccess access = HObjectAccess::ForJSObjectOffset( HObjectAccess access = HObjectAccess::ForJSObjectOffset(
GlobalObject::kNativeContextOffset); GlobalObject::kNativeContextOffset);
return AddLoad(global_object, access); return AddLoad(global_object, access);
...@@ -1738,11 +1706,9 @@ HInstruction* HGraphBuilder::BuildGetNativeContext(HValue* context) { ...@@ -1738,11 +1706,9 @@ HInstruction* HGraphBuilder::BuildGetNativeContext(HValue* context) {
HInstruction* HGraphBuilder::BuildGetArrayFunction(HValue* context) { HInstruction* HGraphBuilder::BuildGetArrayFunction(HValue* context) {
HInstruction* native_context = BuildGetNativeContext(context); HInstruction* native_context = BuildGetNativeContext(context);
HInstruction* index = AddInstruction(new(zone()) HInstruction* index = Add<HConstant>(Context::ARRAY_FUNCTION_INDEX);
HConstant(Context::ARRAY_FUNCTION_INDEX)); return Add<HLoadKeyed>(
native_context, index, static_cast<HValue*>(NULL), FAST_ELEMENTS);
return AddInstruction(new (zone())
HLoadKeyed(native_context, index, NULL, FAST_ELEMENTS));
} }
...@@ -1774,24 +1740,22 @@ HGraphBuilder::JSArrayBuilder::JSArrayBuilder(HGraphBuilder* builder, ...@@ -1774,24 +1740,22 @@ HGraphBuilder::JSArrayBuilder::JSArrayBuilder(HGraphBuilder* builder,
HValue* HGraphBuilder::JSArrayBuilder::EmitMapCode(HValue* context) { HValue* HGraphBuilder::JSArrayBuilder::EmitMapCode(HValue* context) {
HInstruction* native_context = builder()->BuildGetNativeContext(context); HInstruction* native_context = builder()->BuildGetNativeContext(context);
HInstruction* index = builder()->AddInstruction(new(zone()) HInstruction* index = builder()->Add<HConstant>(Context::JS_ARRAY_MAPS_INDEX);
HConstant(Context::JS_ARRAY_MAPS_INDEX));
HInstruction* map_array = builder()->AddInstruction(new(zone()) HInstruction* map_array = builder()->Add<HLoadKeyed>(
HLoadKeyed(native_context, index, NULL, FAST_ELEMENTS)); native_context, index, static_cast<HValue*>(NULL), FAST_ELEMENTS);
HInstruction* kind_index = builder()->AddInstruction(new(zone()) HInstruction* kind_index = builder()->Add<HConstant>(kind_);
HConstant(kind_));
return builder()->AddInstruction(new(zone()) return builder()->Add<HLoadKeyed>(
HLoadKeyed(map_array, kind_index, NULL, FAST_ELEMENTS)); map_array, kind_index, static_cast<HValue*>(NULL), FAST_ELEMENTS);
} }
HValue* HGraphBuilder::JSArrayBuilder::EmitInternalMapCode() { HValue* HGraphBuilder::JSArrayBuilder::EmitInternalMapCode() {
// Find the map near the constructor function // Find the map near the constructor function
HObjectAccess access = HObjectAccess::ForPrototypeOrInitialMap(); HObjectAccess access = HObjectAccess::ForPrototypeOrInitialMap();
return AddInstruction( return builder()->AddInstruction(
builder()->BuildLoadNamedField(constructor_function_, builder()->BuildLoadNamedField(constructor_function_,
access, access,
Representation::Tagged())); Representation::Tagged()));
...@@ -1814,18 +1778,17 @@ HValue* HGraphBuilder::JSArrayBuilder::EstablishAllocationSize( ...@@ -1814,18 +1778,17 @@ HValue* HGraphBuilder::JSArrayBuilder::EstablishAllocationSize(
base_size += FixedArray::kHeaderSize; base_size += FixedArray::kHeaderSize;
} }
HInstruction* elements_size_value = new(zone()) HConstant(elements_size()); HInstruction* elements_size_value =
AddInstruction(elements_size_value); builder()->Add<HConstant>(elements_size());
HInstruction* mul = HMul::New(zone(), context, length_node, HInstruction* mul = HMul::New(zone(), context, length_node,
elements_size_value); elements_size_value);
mul->ClearFlag(HValue::kCanOverflow); mul->ClearFlag(HValue::kCanOverflow);
AddInstruction(mul); builder()->AddInstruction(mul);
HInstruction* base = new(zone()) HConstant(base_size); HInstruction* base = builder()->Add<HConstant>(base_size);
AddInstruction(base);
HInstruction* total_size = HAdd::New(zone(), context, base, mul); HInstruction* total_size = HAdd::New(zone(), context, base, mul);
total_size->ClearFlag(HValue::kCanOverflow); total_size->ClearFlag(HValue::kCanOverflow);
AddInstruction(total_size); builder()->AddInstruction(total_size);
return total_size; return total_size;
} }
...@@ -1840,16 +1803,13 @@ HValue* HGraphBuilder::JSArrayBuilder::EstablishEmptyArrayAllocationSize() { ...@@ -1840,16 +1803,13 @@ HValue* HGraphBuilder::JSArrayBuilder::EstablishEmptyArrayAllocationSize() {
? FixedDoubleArray::SizeFor(initial_capacity()) ? FixedDoubleArray::SizeFor(initial_capacity())
: FixedArray::SizeFor(initial_capacity()); : FixedArray::SizeFor(initial_capacity());
HConstant* array_size = new(zone()) HConstant(base_size); return builder()->Add<HConstant>(base_size);
AddInstruction(array_size);
return array_size;
} }
HValue* HGraphBuilder::JSArrayBuilder::AllocateEmptyArray() { HValue* HGraphBuilder::JSArrayBuilder::AllocateEmptyArray() {
HValue* size_in_bytes = EstablishEmptyArrayAllocationSize(); HValue* size_in_bytes = EstablishEmptyArrayAllocationSize();
HConstant* capacity = new(zone()) HConstant(initial_capacity()); HConstant* capacity = builder()->Add<HConstant>(initial_capacity());
AddInstruction(capacity);
return AllocateArray(size_in_bytes, return AllocateArray(size_in_bytes,
capacity, capacity,
builder()->graph()->GetConstant0(), builder()->graph()->GetConstant0(),
...@@ -1873,9 +1833,8 @@ HValue* HGraphBuilder::JSArrayBuilder::AllocateArray(HValue* size_in_bytes, ...@@ -1873,9 +1833,8 @@ HValue* HGraphBuilder::JSArrayBuilder::AllocateArray(HValue* size_in_bytes,
// Allocate (dealing with failure appropriately) // Allocate (dealing with failure appropriately)
HAllocate::Flags flags = HAllocate::DefaultFlags(kind_); HAllocate::Flags flags = HAllocate::DefaultFlags(kind_);
HAllocate* new_object = new(zone()) HAllocate(context, size_in_bytes, HAllocate* new_object = builder()->Add<HAllocate>(context, size_in_bytes,
HType::JSArray(), flags); HType::JSArray(), flags);
AddInstruction(new_object);
// Fill in the fields: map, properties, length // Fill in the fields: map, properties, length
HValue* map; HValue* map;
...@@ -1906,10 +1865,7 @@ HStoreNamedField* HGraphBuilder::AddStore(HValue *object, ...@@ -1906,10 +1865,7 @@ HStoreNamedField* HGraphBuilder::AddStore(HValue *object,
HObjectAccess access, HObjectAccess access,
HValue *val, HValue *val,
Representation representation) { Representation representation) {
HStoreNamedField *instr = new(zone()) return Add<HStoreNamedField>(object, access, val, representation);
HStoreNamedField(object, access, val, representation);
AddInstruction(instr);
return instr;
} }
...@@ -1917,20 +1873,14 @@ HLoadNamedField* HGraphBuilder::AddLoad(HValue *object, ...@@ -1917,20 +1873,14 @@ HLoadNamedField* HGraphBuilder::AddLoad(HValue *object,
HObjectAccess access, HObjectAccess access,
HValue *typecheck, HValue *typecheck,
Representation representation) { Representation representation) {
HLoadNamedField *instr = return Add<HLoadNamedField>(object, access, typecheck, representation);
new(zone()) HLoadNamedField(object, access, typecheck, representation);
AddInstruction(instr);
return instr;
} }
HStoreNamedField* HGraphBuilder::AddStoreMapConstant(HValue *object, HStoreNamedField* HGraphBuilder::AddStoreMapConstant(HValue *object,
Handle<Map> map) { Handle<Map> map) {
HValue* constant = AddInstruction(new(zone()) HConstant(map)); return Add<HStoreNamedField>(object, HObjectAccess::ForMap(),
HStoreNamedField *instr = Add<HConstant>(map));
new(zone()) HStoreNamedField(object, HObjectAccess::ForMap(), constant);
AddInstruction(instr);
return instr;
} }
...@@ -3702,7 +3652,7 @@ void HOptimizedGraphBuilder::VisitForControl(Expression* expr, ...@@ -3702,7 +3652,7 @@ void HOptimizedGraphBuilder::VisitForControl(Expression* expr,
void HOptimizedGraphBuilder::VisitArgument(Expression* expr) { void HOptimizedGraphBuilder::VisitArgument(Expression* expr) {
CHECK_ALIVE(VisitForValue(expr)); CHECK_ALIVE(VisitForValue(expr));
Push(AddInstruction(new(zone()) HPushArgument(Pop()))); Push(Add<HPushArgument>(Pop()));
} }
...@@ -3768,8 +3718,7 @@ bool HOptimizedGraphBuilder::BuildGraph() { ...@@ -3768,8 +3718,7 @@ bool HOptimizedGraphBuilder::BuildGraph() {
AddSimulate(BailoutId::Declarations()); AddSimulate(BailoutId::Declarations());
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
AddInstruction( Add<HStackCheck>(context, HStackCheck::kFunctionEntry);
new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry));
VisitStatements(current_info()->function()->body()); VisitStatements(current_info()->function()->body());
if (HasStackOverflow()) return false; if (HasStackOverflow()) return false;
...@@ -4495,7 +4444,7 @@ void HOptimizedGraphBuilder::AddSoftDeoptimize() { ...@@ -4495,7 +4444,7 @@ void HOptimizedGraphBuilder::AddSoftDeoptimize() {
isolate()->counters()->soft_deopts_requested()->Increment(); isolate()->counters()->soft_deopts_requested()->Increment();
if (FLAG_always_opt) return; if (FLAG_always_opt) return;
if (current_block()->IsDeoptimizing()) return; if (current_block()->IsDeoptimizing()) return;
AddInstruction(new(zone()) HSoftDeoptimize()); Add<HSoftDeoptimize>();
isolate()->counters()->soft_deopts_inserted()->Increment(); isolate()->counters()->soft_deopts_inserted()->Increment();
current_block()->MarkAsDeoptimizing(); current_block()->MarkAsDeoptimizing();
graph()->set_has_soft_deoptimize(true); graph()->set_has_soft_deoptimize(true);
...@@ -4511,16 +4460,15 @@ HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { ...@@ -4511,16 +4460,15 @@ HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) {
} }
while (!arguments.is_empty()) { while (!arguments.is_empty()) {
AddInstruction(new(zone()) HPushArgument(arguments.RemoveLast())); Add<HPushArgument>(arguments.RemoveLast());
} }
return call; return call;
} }
void HOptimizedGraphBuilder::SetUpScope(Scope* scope) { void HOptimizedGraphBuilder::SetUpScope(Scope* scope) {
HConstant* undefined_constant = new(zone()) HConstant( HConstant* undefined_constant = Add<HConstant>(
isolate()->factory()->undefined_value()); isolate()->factory()->undefined_value());
AddInstruction(undefined_constant);
graph()->set_undefined_constant(undefined_constant); graph()->set_undefined_constant(undefined_constant);
// Create an arguments object containing the initial parameters. Set the // Create an arguments object containing the initial parameters. Set the
...@@ -4529,7 +4477,7 @@ void HOptimizedGraphBuilder::SetUpScope(Scope* scope) { ...@@ -4529,7 +4477,7 @@ void HOptimizedGraphBuilder::SetUpScope(Scope* scope) {
HArgumentsObject* arguments_object = HArgumentsObject* arguments_object =
new(zone()) HArgumentsObject(environment()->parameter_count(), zone()); new(zone()) HArgumentsObject(environment()->parameter_count(), zone());
for (int i = 0; i < environment()->parameter_count(); ++i) { for (int i = 0; i < environment()->parameter_count(); ++i) {
HInstruction* parameter = AddInstruction(new(zone()) HParameter(i)); HInstruction* parameter = Add<HParameter>(i);
arguments_object->AddArgument(parameter, zone()); arguments_object->AddArgument(parameter, zone());
environment()->Bind(i, parameter); environment()->Bind(i, parameter);
} }
...@@ -4537,7 +4485,7 @@ void HOptimizedGraphBuilder::SetUpScope(Scope* scope) { ...@@ -4537,7 +4485,7 @@ void HOptimizedGraphBuilder::SetUpScope(Scope* scope) {
graph()->SetArgumentsObject(arguments_object); graph()->SetArgumentsObject(arguments_object);
// First special is HContext. // First special is HContext.
HInstruction* context = AddInstruction(new(zone()) HContext); HInstruction* context = Add<HContext>();
environment()->BindContext(context); environment()->BindContext(context);
// Initialize specials and locals to undefined. // Initialize specials and locals to undefined.
...@@ -4976,8 +4924,7 @@ bool HOptimizedGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) { ...@@ -4976,8 +4924,7 @@ bool HOptimizedGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) {
new(zone()) ZoneList<HUnknownOSRValue*>(length, zone()); new(zone()) ZoneList<HUnknownOSRValue*>(length, zone());
for (int i = 0; i < first_expression_index; ++i) { for (int i = 0; i < first_expression_index; ++i) {
HUnknownOSRValue* osr_value = new(zone()) HUnknownOSRValue; HUnknownOSRValue* osr_value = Add<HUnknownOSRValue>();
AddInstruction(osr_value);
environment()->Bind(i, osr_value); environment()->Bind(i, osr_value);
osr_values->Add(osr_value, zone()); osr_values->Add(osr_value, zone());
} }
...@@ -4985,8 +4932,7 @@ bool HOptimizedGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) { ...@@ -4985,8 +4932,7 @@ bool HOptimizedGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) {
if (first_expression_index != length) { if (first_expression_index != length) {
environment()->Drop(length - first_expression_index); environment()->Drop(length - first_expression_index);
for (int i = first_expression_index; i < length; ++i) { for (int i = first_expression_index; i < length; ++i) {
HUnknownOSRValue* osr_value = new(zone()) HUnknownOSRValue; HUnknownOSRValue* osr_value = Add<HUnknownOSRValue>();
AddInstruction(osr_value);
environment()->Push(osr_value); environment()->Push(osr_value);
osr_values->Add(osr_value, zone()); osr_values->Add(osr_value, zone());
} }
...@@ -4995,9 +4941,8 @@ bool HOptimizedGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) { ...@@ -4995,9 +4941,8 @@ bool HOptimizedGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) {
graph()->set_osr_values(osr_values); graph()->set_osr_values(osr_values);
AddSimulate(osr_entry_id); AddSimulate(osr_entry_id);
AddInstruction(new(zone()) HOsrEntry(osr_entry_id)); Add<HOsrEntry>(osr_entry_id);
HContext* context = new(zone()) HContext; HContext* context = Add<HContext>();
AddInstruction(context);
environment()->BindContext(context); environment()->BindContext(context);
current_block()->Goto(loop_predecessor); current_block()->Goto(loop_predecessor);
loop_predecessor->SetJoinId(statement->EntryId()); loop_predecessor->SetJoinId(statement->EntryId());
...@@ -5012,9 +4957,8 @@ void HOptimizedGraphBuilder::VisitLoopBody(IterationStatement* stmt, ...@@ -5012,9 +4957,8 @@ void HOptimizedGraphBuilder::VisitLoopBody(IterationStatement* stmt,
BreakAndContinueScope push(break_info, this); BreakAndContinueScope push(break_info, this);
AddSimulate(stmt->StackCheckId()); AddSimulate(stmt->StackCheckId());
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HStackCheck* stack_check = HStackCheck* stack_check = Add<HStackCheck>(
new(zone()) HStackCheck(context, HStackCheck::kBackwardsBranch); context, HStackCheck::kBackwardsBranch);
AddInstruction(stack_check);
ASSERT(loop_entry->IsLoopHeader()); ASSERT(loop_entry->IsLoopHeader());
loop_entry->loop_information()->set_stack_check(stack_check); loop_entry->loop_information()->set_stack_check(stack_check);
CHECK_BAILOUT(Visit(stmt->body())); CHECK_BAILOUT(Visit(stmt->body()));
...@@ -5183,30 +5127,24 @@ void HOptimizedGraphBuilder::VisitForInStatement(ForInStatement* stmt) { ...@@ -5183,30 +5127,24 @@ void HOptimizedGraphBuilder::VisitForInStatement(ForInStatement* stmt) {
CHECK_ALIVE(VisitForValue(stmt->enumerable())); CHECK_ALIVE(VisitForValue(stmt->enumerable()));
HValue* enumerable = Top(); // Leave enumerable at the top. HValue* enumerable = Top(); // Leave enumerable at the top.
HInstruction* map = AddInstruction(new(zone()) HForInPrepareMap( HInstruction* map = Add<HForInPrepareMap>(
environment()->LookupContext(), enumerable)); environment()->LookupContext(), enumerable);
AddSimulate(stmt->PrepareId()); AddSimulate(stmt->PrepareId());
HInstruction* array = AddInstruction( HInstruction* array = Add<HForInCacheArray>(
new(zone()) HForInCacheArray( enumerable, map, DescriptorArray::kEnumCacheBridgeCacheIndex);
enumerable,
map,
DescriptorArray::kEnumCacheBridgeCacheIndex));
HInstruction* enum_length = AddInstruction(new(zone()) HMapEnumLength(map)); HInstruction* enum_length = Add<HMapEnumLength>(map);
HInstruction* start_index = AddInstruction(new(zone()) HConstant(0)); HInstruction* start_index = Add<HConstant>(0);
Push(map); Push(map);
Push(array); Push(array);
Push(enum_length); Push(enum_length);
Push(start_index); Push(start_index);
HInstruction* index_cache = AddInstruction( HInstruction* index_cache = Add<HForInCacheArray>(
new(zone()) HForInCacheArray( enumerable, map, DescriptorArray::kEnumCacheBridgeIndicesCacheIndex);
enumerable,
map,
DescriptorArray::kEnumCacheBridgeIndicesCacheIndex));
HForInCacheArray::cast(array)->set_index_cache( HForInCacheArray::cast(array)->set_index_cache(
HForInCacheArray::cast(index_cache)); HForInCacheArray::cast(index_cache));
...@@ -5237,18 +5175,16 @@ void HOptimizedGraphBuilder::VisitForInStatement(ForInStatement* stmt) { ...@@ -5237,18 +5175,16 @@ void HOptimizedGraphBuilder::VisitForInStatement(ForInStatement* stmt) {
set_current_block(loop_body); set_current_block(loop_body);
HValue* key = AddInstruction( HValue* key = Add<HLoadKeyed>(
new(zone()) HLoadKeyed( environment()->ExpressionStackAt(2), // Enum cache.
environment()->ExpressionStackAt(2), // Enum cache. environment()->ExpressionStackAt(0), // Iteration index.
environment()->ExpressionStackAt(0), // Iteration index. environment()->ExpressionStackAt(0),
environment()->ExpressionStackAt(0), FAST_ELEMENTS);
FAST_ELEMENTS));
// Check if the expected map still matches that of the enumerable. // Check if the expected map still matches that of the enumerable.
// If not just deoptimize. // If not just deoptimize.
AddInstruction(new(zone()) HCheckMapValue( Add<HCheckMapValue>(environment()->ExpressionStackAt(4),
environment()->ExpressionStackAt(4), environment()->ExpressionStackAt(3));
environment()->ExpressionStackAt(3)));
Bind(each_var, key); Bind(each_var, key);
...@@ -5421,9 +5357,7 @@ HValue* HOptimizedGraphBuilder::BuildContextChainWalk(Variable* var) { ...@@ -5421,9 +5357,7 @@ HValue* HOptimizedGraphBuilder::BuildContextChainWalk(Variable* var) {
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
int length = current_info()->scope()->ContextChainLength(var->scope()); int length = current_info()->scope()->ContextChainLength(var->scope());
while (length-- > 0) { while (length-- > 0) {
HInstruction* context_instruction = new(zone()) HOuterContext(context); context = Add<HOuterContext>(context);
AddInstruction(context_instruction);
context = context_instruction;
} }
return context; return context;
} }
...@@ -5729,23 +5663,18 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -5729,23 +5663,18 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
flags |= expr->has_function() flags |= expr->has_function()
? ObjectLiteral::kHasFunction : ObjectLiteral::kNoFlags; ? ObjectLiteral::kHasFunction : ObjectLiteral::kNoFlags;
AddInstruction(new(zone()) HPushArgument(AddInstruction( Add<HPushArgument>(Add<HConstant>(closure_literals));
new(zone()) HConstant(closure_literals)))); Add<HPushArgument>(Add<HConstant>(literal_index));
AddInstruction(new(zone()) HPushArgument(AddInstruction( Add<HPushArgument>(Add<HConstant>(constant_properties));
new(zone()) HConstant(literal_index)))); Add<HPushArgument>(Add<HConstant>(flags));
AddInstruction(new(zone()) HPushArgument(AddInstruction(
new(zone()) HConstant(constant_properties))));
AddInstruction(new(zone()) HPushArgument(AddInstruction(
new(zone()) HConstant(flags))));
Runtime::FunctionId function_id = Runtime::FunctionId function_id =
(expr->depth() > 1 || expr->may_store_doubles()) (expr->depth() > 1 || expr->may_store_doubles())
? Runtime::kCreateObjectLiteral : Runtime::kCreateObjectLiteralShallow; ? Runtime::kCreateObjectLiteral : Runtime::kCreateObjectLiteralShallow;
literal = AddInstruction( literal = Add<HCallRuntime>(context,
new(zone()) HCallRuntime(context, isolate()->factory()->empty_string(),
isolate()->factory()->empty_string(), Runtime::FunctionForId(function_id),
Runtime::FunctionForId(function_id), 4);
4));
} }
// The object is expected in the bailout environment during computation // The object is expected in the bailout environment during computation
...@@ -5811,8 +5740,7 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -5811,8 +5740,7 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
// of the object. This makes sure that the original object won't // of the object. This makes sure that the original object won't
// be used by other optimized code before it is transformed // be used by other optimized code before it is transformed
// (e.g. because of code motion). // (e.g. because of code motion).
HToFastProperties* result = new(zone()) HToFastProperties(Pop()); HToFastProperties* result = Add<HToFastProperties>(Pop());
AddInstruction(result);
return ast_context()->ReturnValue(result); return ast_context()->ReturnValue(result);
} else { } else {
return ast_context()->ReturnValue(Pop()); return ast_context()->ReturnValue(Pop());
...@@ -5884,20 +5812,16 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -5884,20 +5812,16 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
Handle<FixedArray> constants = isolate()->factory()->empty_fixed_array(); Handle<FixedArray> constants = isolate()->factory()->empty_fixed_array();
int literal_index = expr->literal_index(); int literal_index = expr->literal_index();
AddInstruction(new(zone()) HPushArgument(AddInstruction( Add<HPushArgument>(Add<HConstant>(literals));
new(zone()) HConstant(literals)))); Add<HPushArgument>(Add<HConstant>(literal_index));
AddInstruction(new(zone()) HPushArgument(AddInstruction( Add<HPushArgument>(Add<HConstant>(constants));
new(zone()) HConstant(literal_index))));
AddInstruction(new(zone()) HPushArgument(AddInstruction(
new(zone()) HConstant(constants))));
Runtime::FunctionId function_id = (expr->depth() > 1) Runtime::FunctionId function_id = (expr->depth() > 1)
? Runtime::kCreateArrayLiteral : Runtime::kCreateArrayLiteralShallow; ? Runtime::kCreateArrayLiteral : Runtime::kCreateArrayLiteralShallow;
literal = AddInstruction( literal = Add<HCallRuntime>(context,
new(zone()) HCallRuntime(context, isolate()->factory()->empty_string(),
isolate()->factory()->empty_string(), Runtime::FunctionForId(function_id),
Runtime::FunctionForId(function_id), 3);
3));
// De-opt if elements kind changed from boilerplate_elements_kind. // De-opt if elements kind changed from boilerplate_elements_kind.
Handle<Map> map = Handle<Map>(original_boilerplate_object->map(), Handle<Map> map = Handle<Map>(original_boilerplate_object->map(),
...@@ -5909,7 +5833,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -5909,7 +5833,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
// of the property values and is the value of the entire expression. // of the property values and is the value of the entire expression.
Push(literal); Push(literal);
// The literal index is on the stack, too. // The literal index is on the stack, too.
Push(AddInstruction(new(zone()) HConstant(expr->literal_index()))); Push(Add<HConstant>(expr->literal_index()));
HInstruction* elements = NULL; HInstruction* elements = NULL;
...@@ -5925,7 +5849,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -5925,7 +5849,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
elements = AddLoadElements(literal); elements = AddLoadElements(literal);
HValue* key = AddInstruction(new(zone()) HConstant(i)); HValue* key = Add<HConstant>(i);
switch (boilerplate_elements_kind) { switch (boilerplate_elements_kind) {
case FAST_SMI_ELEMENTS: case FAST_SMI_ELEMENTS:
...@@ -5934,11 +5858,8 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -5934,11 +5858,8 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
case FAST_HOLEY_ELEMENTS: case FAST_HOLEY_ELEMENTS:
case FAST_DOUBLE_ELEMENTS: case FAST_DOUBLE_ELEMENTS:
case FAST_HOLEY_DOUBLE_ELEMENTS: case FAST_HOLEY_DOUBLE_ELEMENTS:
AddInstruction(new(zone()) HStoreKeyed( Add<HStoreKeyed>(elements, key, value,
elements, boilerplate_elements_kind);
key,
value,
boilerplate_elements_kind));
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -6035,11 +5956,9 @@ HInstruction* HOptimizedGraphBuilder::BuildStoreNamedField( ...@@ -6035,11 +5956,9 @@ HInstruction* HOptimizedGraphBuilder::BuildStoreNamedField(
ASSERT(proto->GetPrototype(isolate())->IsNull()); ASSERT(proto->GetPrototype(isolate())->IsNull());
} }
ASSERT(proto->IsJSObject()); ASSERT(proto->IsJSObject());
AddInstruction(new(zone()) HCheckPrototypeMaps( Add<HCheckPrototypeMaps>(Handle<JSObject>(JSObject::cast(map->prototype())),
Handle<JSObject>(JSObject::cast(map->prototype())), Handle<JSObject>(JSObject::cast(proto)),
Handle<JSObject>(JSObject::cast(proto)), zone(), top_info());
zone(),
top_info()));
} }
HObjectAccess field_access = HObjectAccess::ForField(map, lookup, name); HObjectAccess field_access = HObjectAccess::ForField(map, lookup, name);
...@@ -6051,11 +5970,10 @@ HInstruction* HOptimizedGraphBuilder::BuildStoreNamedField( ...@@ -6051,11 +5970,10 @@ HInstruction* HOptimizedGraphBuilder::BuildStoreNamedField(
if (transition_to_field) { if (transition_to_field) {
// The store requires a mutable HeapNumber to be allocated. // The store requires a mutable HeapNumber to be allocated.
NoObservableSideEffectsScope no_side_effects(this); NoObservableSideEffectsScope no_side_effects(this);
HInstruction* heap_number_size = AddInstruction(new(zone()) HConstant( HInstruction* heap_number_size = Add<HConstant>(HeapNumber::kSize);
HeapNumber::kSize)); HInstruction* double_box = Add<HAllocate>(
HInstruction* double_box = AddInstruction(new(zone()) HAllocate(
environment()->LookupContext(), heap_number_size, environment()->LookupContext(), heap_number_size,
HType::HeapNumber(), HAllocate::CAN_ALLOCATE_IN_NEW_SPACE)); HType::HeapNumber(), HAllocate::CAN_ALLOCATE_IN_NEW_SPACE);
AddStoreMapConstant(double_box, isolate()->factory()->heap_number_map()); AddStoreMapConstant(double_box, isolate()->factory()->heap_number_map());
AddStore(double_box, HObjectAccess::ForHeapNumberValue(), AddStore(double_box, HObjectAccess::ForHeapNumberValue(),
value, Representation::Double()); value, Representation::Double());
...@@ -6105,8 +6023,8 @@ HInstruction* HOptimizedGraphBuilder::BuildCallSetter( ...@@ -6105,8 +6023,8 @@ HInstruction* HOptimizedGraphBuilder::BuildCallSetter(
Handle<JSFunction> setter, Handle<JSFunction> setter,
Handle<JSObject> holder) { Handle<JSObject> holder) {
AddCheckConstantFunction(holder, object, map); AddCheckConstantFunction(holder, object, map);
AddInstruction(new(zone()) HPushArgument(object)); Add<HPushArgument>(object);
AddInstruction(new(zone()) HPushArgument(value)); Add<HPushArgument>(value);
return new(zone()) HCallConstantFunction(setter, 2); return new(zone()) HCallConstantFunction(setter, 2);
} }
...@@ -6386,25 +6304,19 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment( ...@@ -6386,25 +6304,19 @@ void HOptimizedGraphBuilder::HandleGlobalVariableAssignment(
if (type == kUseCell) { if (type == kUseCell) {
Handle<GlobalObject> global(current_info()->global_object()); Handle<GlobalObject> global(current_info()->global_object());
Handle<PropertyCell> cell(global->GetPropertyCell(&lookup)); Handle<PropertyCell> cell(global->GetPropertyCell(&lookup));
HInstruction* instr = HInstruction* instr = Add<HStoreGlobalCell>(value, cell,
new(zone()) HStoreGlobalCell(value, cell, lookup.GetPropertyDetails()); lookup.GetPropertyDetails());
instr->set_position(position); instr->set_position(position);
AddInstruction(instr);
if (instr->HasObservableSideEffects()) { if (instr->HasObservableSideEffects()) {
AddSimulate(ast_id, REMOVABLE_SIMULATE); AddSimulate(ast_id, REMOVABLE_SIMULATE);
} }
} else { } else {
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = Add<HGlobalObject>(context);
AddInstruction(global_object);
HStoreGlobalGeneric* instr = HStoreGlobalGeneric* instr =
new(zone()) HStoreGlobalGeneric(context, Add<HStoreGlobalGeneric>(context, global_object, var->name(),
global_object, value, function_strict_mode_flag());
var->name(),
value,
function_strict_mode_flag());
instr->set_position(position); instr->set_position(position);
AddInstruction(instr);
ASSERT(instr->HasObservableSideEffects()); ASSERT(instr->HasObservableSideEffects());
AddSimulate(ast_id, REMOVABLE_SIMULATE); AddSimulate(ast_id, REMOVABLE_SIMULATE);
} }
...@@ -6440,8 +6352,8 @@ void HOptimizedGraphBuilder::BuildStoreNamed(Expression* expr, ...@@ -6440,8 +6352,8 @@ void HOptimizedGraphBuilder::BuildStoreNamed(Expression* expr,
return; return;
} }
Drop(2); Drop(2);
AddInstruction(new(zone()) HPushArgument(object)); Add<HPushArgument>(object);
AddInstruction(new(zone()) HPushArgument(value)); Add<HPushArgument>(value);
instr = new(zone()) HCallConstantFunction(setter, 2); instr = new(zone()) HCallConstantFunction(setter, 2);
} else { } else {
Drop(2); Drop(2);
...@@ -6538,9 +6450,8 @@ void HOptimizedGraphBuilder::HandleCompoundAssignment(Assignment* expr) { ...@@ -6538,9 +6450,8 @@ void HOptimizedGraphBuilder::HandleCompoundAssignment(Assignment* expr) {
} }
HValue* context = BuildContextChainWalk(var); HValue* context = BuildContextChainWalk(var);
HStoreContextSlot* instr = HStoreContextSlot* instr = Add<HStoreContextSlot>(context, var->index(),
new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); mode, Top());
AddInstruction(instr);
if (instr->HasObservableSideEffects()) { if (instr->HasObservableSideEffects()) {
AddSimulate(expr->AssignmentId(), REMOVABLE_SIMULATE); AddSimulate(expr->AssignmentId(), REMOVABLE_SIMULATE);
} }
...@@ -6670,7 +6581,7 @@ void HOptimizedGraphBuilder::VisitAssignment(Assignment* expr) { ...@@ -6670,7 +6581,7 @@ void HOptimizedGraphBuilder::VisitAssignment(Assignment* expr) {
// We insert a use of the old value to detect unsupported uses of const // We insert a use of the old value to detect unsupported uses of const
// variables (e.g. initialization inside a loop). // variables (e.g. initialization inside a loop).
HValue* old_value = environment()->Lookup(var); HValue* old_value = environment()->Lookup(var);
AddInstruction(new(zone()) HUseConst(old_value)); Add<HUseConst>(old_value);
} }
} else if (var->mode() == CONST_HARMONY) { } else if (var->mode() == CONST_HARMONY) {
if (expr->op() != Token::INIT_CONST_HARMONY) { if (expr->op() != Token::INIT_CONST_HARMONY) {
...@@ -6751,9 +6662,8 @@ void HOptimizedGraphBuilder::VisitAssignment(Assignment* expr) { ...@@ -6751,9 +6662,8 @@ void HOptimizedGraphBuilder::VisitAssignment(Assignment* expr) {
} }
HValue* context = BuildContextChainWalk(var); HValue* context = BuildContextChainWalk(var);
HStoreContextSlot* instr = new(zone()) HStoreContextSlot( HStoreContextSlot* instr = Add<HStoreContextSlot>(context, var->index(),
context, var->index(), mode, Top()); mode, Top());
AddInstruction(instr);
if (instr->HasObservableSideEffects()) { if (instr->HasObservableSideEffects()) {
AddSimulate(expr->AssignmentId(), REMOVABLE_SIMULATE); AddSimulate(expr->AssignmentId(), REMOVABLE_SIMULATE);
} }
...@@ -6787,9 +6697,8 @@ void HOptimizedGraphBuilder::VisitThrow(Throw* expr) { ...@@ -6787,9 +6697,8 @@ void HOptimizedGraphBuilder::VisitThrow(Throw* expr) {
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HValue* value = environment()->Pop(); HValue* value = environment()->Pop();
HThrow* instr = new(zone()) HThrow(context, value); HThrow* instr = Add<HThrow>(context, value);
instr->set_position(expr->position()); instr->set_position(expr->position());
AddInstruction(instr);
AddSimulate(expr->id()); AddSimulate(expr->id());
current_block()->FinishExit(new(zone()) HAbnormalExit); current_block()->FinishExit(new(zone()) HAbnormalExit);
set_current_block(NULL); set_current_block(NULL);
...@@ -6835,7 +6744,7 @@ HInstruction* HOptimizedGraphBuilder::BuildCallGetter( ...@@ -6835,7 +6744,7 @@ HInstruction* HOptimizedGraphBuilder::BuildCallGetter(
Handle<JSFunction> getter, Handle<JSFunction> getter,
Handle<JSObject> holder) { Handle<JSObject> holder) {
AddCheckConstantFunction(holder, object, map); AddCheckConstantFunction(holder, object, map);
AddInstruction(new(zone()) HPushArgument(object)); Add<HPushArgument>(object);
return new(zone()) HCallConstantFunction(getter, 1); return new(zone()) HCallConstantFunction(getter, 1);
} }
...@@ -6880,9 +6789,8 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedMonomorphic( ...@@ -6880,9 +6789,8 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedMonomorphic(
Handle<JSObject> holder(lookup.holder()); Handle<JSObject> holder(lookup.holder());
Handle<Map> holder_map(holder->map()); Handle<Map> holder_map(holder->map());
AddCheckMap(object, map); AddCheckMap(object, map);
AddInstruction(new(zone()) HCheckPrototypeMaps( Add<HCheckPrototypeMaps>(prototype, holder, zone(), top_info());
prototype, holder, zone(), top_info())); HValue* holder_value = Add<HConstant>(holder);
HValue* holder_value = AddInstruction(new(zone()) HConstant(holder));
return BuildLoadNamedField(holder_value, return BuildLoadNamedField(holder_value,
HObjectAccess::ForField(holder_map, &lookup, name), HObjectAccess::ForField(holder_map, &lookup, name),
ComputeLoadStoreRepresentation(map, &lookup)); ComputeLoadStoreRepresentation(map, &lookup));
...@@ -6894,8 +6802,7 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedMonomorphic( ...@@ -6894,8 +6802,7 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedMonomorphic(
Handle<JSObject> holder(lookup.holder()); Handle<JSObject> holder(lookup.holder());
Handle<Map> holder_map(holder->map()); Handle<Map> holder_map(holder->map());
AddCheckMap(object, map); AddCheckMap(object, map);
AddInstruction(new(zone()) HCheckPrototypeMaps( Add<HCheckPrototypeMaps>(prototype, holder, zone(), top_info());
prototype, holder, zone(), top_info()));
Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*holder_map)); Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*holder_map));
return new(zone()) HConstant(function); return new(zone()) HConstant(function);
} }
...@@ -6932,8 +6839,7 @@ HInstruction* HOptimizedGraphBuilder::BuildMonomorphicElementAccess( ...@@ -6932,8 +6839,7 @@ HInstruction* HOptimizedGraphBuilder::BuildMonomorphicElementAccess(
isolate()->IsFastArrayConstructorPrototypeChainIntact()) { isolate()->IsFastArrayConstructorPrototypeChainIntact()) {
Handle<JSObject> prototype(JSObject::cast(map->prototype()), isolate()); Handle<JSObject> prototype(JSObject::cast(map->prototype()), isolate());
Handle<JSObject> object_prototype = isolate()->initial_object_prototype(); Handle<JSObject> object_prototype = isolate()->initial_object_prototype();
AddInstruction(new(zone()) HCheckPrototypeMaps( Add<HCheckPrototypeMaps>(prototype, object_prototype, zone(), top_info());
prototype, object_prototype, zone(), top_info()));
load_mode = ALLOW_RETURN_HOLE; load_mode = ALLOW_RETURN_HOLE;
graph()->MarkDependsOnEmptyArrayProtoElements(); graph()->MarkDependsOnEmptyArrayProtoElements();
} }
...@@ -7065,9 +6971,8 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -7065,9 +6971,8 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
map->elements_kind(), map->elements_kind(),
transition_target.at(i)->elements_kind())); transition_target.at(i)->elements_kind()));
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
transition = new(zone()) HTransitionElementsKind( transition = Add<HTransitionElementsKind>(context, object, map,
context, object, map, transition_target.at(i)); transition_target.at(i));
AddInstruction(transition);
} else { } else {
type_todo[map->elements_kind()] = true; type_todo[map->elements_kind()] = true;
if (IsExternalArrayElementsKind(map->elements_kind())) { if (IsExternalArrayElementsKind(map->elements_kind())) {
...@@ -7100,8 +7005,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -7100,8 +7005,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
AddInstruction(HCheckInstanceType::NewIsSpecObject(object, zone())); AddInstruction(HCheckInstanceType::NewIsSpecObject(object, zone()));
HBasicBlock* join = graph()->CreateBasicBlock(); HBasicBlock* join = graph()->CreateBasicBlock();
HInstruction* elements_kind_instr = HInstruction* elements_kind_instr = Add<HElementsKind>(object);
AddInstruction(new(zone()) HElementsKind(object));
HInstruction* elements = AddLoadElements(object, checkspec); HInstruction* elements = AddLoadElements(object, checkspec);
HLoadExternalArrayPointer* external_elements = NULL; HLoadExternalArrayPointer* external_elements = NULL;
HInstruction* checked_key = NULL; HInstruction* checked_key = NULL;
...@@ -7122,11 +7026,9 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -7122,11 +7026,9 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
LAST_ELEMENTS_KIND); LAST_ELEMENTS_KIND);
if (elements_kind == FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND if (elements_kind == FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND
&& todo_external_array) { && todo_external_array) {
HInstruction* length = HInstruction* length = Add<HFixedArrayBaseLength>(elements);
AddInstruction(new(zone()) HFixedArrayBaseLength(elements));
checked_key = Add<HBoundsCheck>(key, length); checked_key = Add<HBoundsCheck>(key, length);
external_elements = new(zone()) HLoadExternalArrayPointer(elements); external_elements = Add<HLoadExternalArrayPointer>(elements);
AddInstruction(external_elements);
} }
if (type_todo[elements_kind]) { if (type_todo[elements_kind]) {
HBasicBlock* if_true = graph()->CreateBasicBlock(); HBasicBlock* if_true = graph()->CreateBasicBlock();
...@@ -7317,8 +7219,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) { ...@@ -7317,8 +7219,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) {
if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("length"))) return false; if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("length"))) return false;
if (function_state()->outer() == NULL) { if (function_state()->outer() == NULL) {
HInstruction* elements = AddInstruction( HInstruction* elements = Add<HArgumentsElements>(false);
new(zone()) HArgumentsElements(false));
result = new(zone()) HArgumentsLength(elements); result = new(zone()) HArgumentsLength(elements);
} else { } else {
// Number of arguments without receiver. // Number of arguments without receiver.
...@@ -7333,10 +7234,8 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) { ...@@ -7333,10 +7234,8 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) {
HValue* key = Pop(); HValue* key = Pop();
Drop(1); // Arguments object. Drop(1); // Arguments object.
if (function_state()->outer() == NULL) { if (function_state()->outer() == NULL) {
HInstruction* elements = AddInstruction( HInstruction* elements = Add<HArgumentsElements>(false);
new(zone()) HArgumentsElements(false)); HInstruction* length = Add<HArgumentsLength>(elements);
HInstruction* length = AddInstruction(
new(zone()) HArgumentsLength(elements));
HInstruction* checked_key = Add<HBoundsCheck>(key, length); HInstruction* checked_key = Add<HBoundsCheck>(key, length);
result = new(zone()) HAccessArgumentsAt(elements, length, checked_key); result = new(zone()) HAccessArgumentsAt(elements, length, checked_key);
} else { } else {
...@@ -7346,8 +7245,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) { ...@@ -7346,8 +7245,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) {
HInstruction* elements = function_state()->arguments_elements(); HInstruction* elements = function_state()->arguments_elements();
int argument_count = environment()-> int argument_count = environment()->
arguments_environment()->parameter_count() - 1; arguments_environment()->parameter_count() - 1;
HInstruction* length = AddInstruction(new(zone()) HConstant( HInstruction* length = Add<HConstant>(argument_count);
argument_count));
HInstruction* checked_key = Add<HBoundsCheck>(key, length); HInstruction* checked_key = Add<HBoundsCheck>(key, length);
result = new(zone()) HAccessArgumentsAt(elements, length, checked_key); result = new(zone()) HAccessArgumentsAt(elements, length, checked_key);
} }
...@@ -7407,7 +7305,7 @@ void HOptimizedGraphBuilder::VisitProperty(Property* expr) { ...@@ -7407,7 +7305,7 @@ void HOptimizedGraphBuilder::VisitProperty(Property* expr) {
if (LookupGetter(map, name, &getter, &holder)) { if (LookupGetter(map, name, &getter, &holder)) {
AddCheckConstantFunction(holder, Top(), map); AddCheckConstantFunction(holder, Top(), map);
if (FLAG_inline_accessors && TryInlineGetter(getter, expr)) return; if (FLAG_inline_accessors && TryInlineGetter(getter, expr)) return;
AddInstruction(new(zone()) HPushArgument(Pop())); Add<HPushArgument>(Pop());
instr = new(zone()) HCallConstantFunction(getter, 1); instr = new(zone()) HCallConstantFunction(getter, 1);
} else { } else {
instr = BuildLoadNamedMonomorphic(Pop(), name, expr, map); instr = BuildLoadNamedMonomorphic(Pop(), name, expr, map);
...@@ -7449,8 +7347,7 @@ void HOptimizedGraphBuilder::AddCheckPrototypeMaps(Handle<JSObject> holder, ...@@ -7449,8 +7347,7 @@ void HOptimizedGraphBuilder::AddCheckPrototypeMaps(Handle<JSObject> holder,
Handle<Map> receiver_map) { Handle<Map> receiver_map) {
if (!holder.is_null()) { if (!holder.is_null()) {
Handle<JSObject> prototype(JSObject::cast(receiver_map->prototype())); Handle<JSObject> prototype(JSObject::cast(receiver_map->prototype()));
AddInstruction(new(zone()) HCheckPrototypeMaps( Add<HCheckPrototypeMaps>(prototype, holder, zone(), top_info());
prototype, holder, zone(), top_info()));
} }
} }
...@@ -7877,9 +7774,7 @@ bool HOptimizedGraphBuilder::TryInline(CallKind call_kind, ...@@ -7877,9 +7774,7 @@ bool HOptimizedGraphBuilder::TryInline(CallKind call_kind,
// //
// TODO(kmillikin): implement the same inlining on other platforms so we // TODO(kmillikin): implement the same inlining on other platforms so we
// can remove the unsightly ifdefs in this function. // can remove the unsightly ifdefs in this function.
HConstant* context = HConstant* context = Add<HConstant>(Handle<Context>(target->context()));
new(zone()) HConstant(Handle<Context>(target->context()));
AddInstruction(context);
inner_env->BindContext(context); inner_env->BindContext(context);
#endif #endif
...@@ -7893,25 +7788,19 @@ bool HOptimizedGraphBuilder::TryInline(CallKind call_kind, ...@@ -7893,25 +7788,19 @@ bool HOptimizedGraphBuilder::TryInline(CallKind call_kind,
ASSERT(function->scope()->arguments()->IsStackAllocated()); ASSERT(function->scope()->arguments()->IsStackAllocated());
HEnvironment* arguments_env = inner_env->arguments_environment(); HEnvironment* arguments_env = inner_env->arguments_environment();
int arguments_count = arguments_env->parameter_count(); int arguments_count = arguments_env->parameter_count();
arguments_object = new(zone()) HArgumentsObject(arguments_count, zone()); arguments_object = Add<HArgumentsObject>(arguments_count, zone());
inner_env->Bind(function->scope()->arguments(), arguments_object); inner_env->Bind(function->scope()->arguments(), arguments_object);
for (int i = 0; i < arguments_count; i++) { for (int i = 0; i < arguments_count; i++) {
arguments_object->AddArgument(arguments_env->Lookup(i), zone()); arguments_object->AddArgument(arguments_env->Lookup(i), zone());
} }
AddInstruction(arguments_object);
} }
HEnterInlined* enter_inlined = HEnterInlined* enter_inlined =
new(zone()) HEnterInlined(target, Add<HEnterInlined>(target, arguments_count, function,
arguments_count, function_state()->inlining_kind(),
function, function->scope()->arguments(),
function_state()->inlining_kind(), arguments_object, undefined_receiver, zone());
function->scope()->arguments(),
arguments_object,
undefined_receiver,
zone());
function_state()->set_entry(enter_inlined); function_state()->set_entry(enter_inlined);
AddInstruction(enter_inlined);
VisitDeclarations(target_info.scope()->declarations()); VisitDeclarations(target_info.scope()->declarations());
VisitStatements(function->body()); VisitStatements(function->body());
...@@ -8149,12 +8038,9 @@ bool HOptimizedGraphBuilder::TryInlineBuiltinMethodCall( ...@@ -8149,12 +8038,9 @@ bool HOptimizedGraphBuilder::TryInlineBuiltinMethodCall(
HValue* string = Pop(); HValue* string = Pop();
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
ASSERT(!expr->holder().is_null()); ASSERT(!expr->holder().is_null());
AddInstruction(new(zone()) HCheckPrototypeMaps( Add<HCheckPrototypeMaps>(Call::GetPrototypeForPrimitiveCheck(
Call::GetPrototypeForPrimitiveCheck(STRING_CHECK, STRING_CHECK, expr->holder()->GetIsolate()),
expr->holder()->GetIsolate()), expr->holder(), zone(), top_info());
expr->holder(),
zone(),
top_info()));
HInstruction* char_code = HInstruction* char_code =
BuildStringCharCodeAt(context, string, index); BuildStringCharCodeAt(context, string, index);
if (id == kStringCharCodeAt) { if (id == kStringCharCodeAt) {
...@@ -8245,8 +8131,7 @@ bool HOptimizedGraphBuilder::TryInlineBuiltinMethodCall( ...@@ -8245,8 +8131,7 @@ bool HOptimizedGraphBuilder::TryInlineBuiltinMethodCall(
AddCheckConstantFunction(expr->holder(), receiver, receiver_map); AddCheckConstantFunction(expr->holder(), receiver, receiver_map);
Drop(1); // Receiver. Drop(1); // Receiver.
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = Add<HGlobalObject>(context);
AddInstruction(global_object);
HRandom* result = new(zone()) HRandom(global_object); HRandom* result = new(zone()) HRandom(global_object);
ast_context()->ReturnInstruction(result, expr->id()); ast_context()->ReturnInstruction(result, expr->id());
return true; return true;
...@@ -8325,12 +8210,9 @@ bool HOptimizedGraphBuilder::TryCallApply(Call* expr) { ...@@ -8325,12 +8210,9 @@ bool HOptimizedGraphBuilder::TryCallApply(Call* expr) {
HValue* receiver = Pop(); HValue* receiver = Pop();
if (function_state()->outer() == NULL) { if (function_state()->outer() == NULL) {
HInstruction* elements = AddInstruction( HInstruction* elements = Add<HArgumentsElements>(false);
new(zone()) HArgumentsElements(false)); HInstruction* length = Add<HArgumentsLength>(elements);
HInstruction* length = HValue* wrapped_receiver = Add<HWrapReceiver>(receiver, function);
AddInstruction(new(zone()) HArgumentsLength(elements));
HValue* wrapped_receiver =
AddInstruction(new(zone()) HWrapReceiver(receiver, function));
HInstruction* result = HInstruction* result =
new(zone()) HApplyArguments(function, new(zone()) HApplyArguments(function,
wrapped_receiver, wrapped_receiver,
...@@ -8555,14 +8437,12 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) { ...@@ -8555,14 +8437,12 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) {
CHECK_ALIVE(VisitForValue(expr->expression())); CHECK_ALIVE(VisitForValue(expr->expression()));
HValue* function = Pop(); HValue* function = Pop();
AddInstruction(new(zone()) HCheckFunction(function, expr->target())); Add<HCheckFunction>(function, expr->target());
// Replace the global object with the global receiver. // Replace the global object with the global receiver.
HGlobalReceiver* global_receiver = HGlobalReceiver* global_receiver = Add<HGlobalReceiver>(global_object);
new(zone()) HGlobalReceiver(global_object);
// Index of the receiver from the top of the expression stack. // Index of the receiver from the top of the expression stack.
const int receiver_index = argument_count - 1; const int receiver_index = argument_count - 1;
AddInstruction(global_receiver);
ASSERT(environment()->ExpressionStackAt(receiver_index)-> ASSERT(environment()->ExpressionStackAt(receiver_index)->
IsGlobalObject()); IsGlobalObject());
environment()->SetExpressionStackAt(receiver_index, global_receiver); environment()->SetExpressionStackAt(receiver_index, global_receiver);
...@@ -8593,8 +8473,7 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) { ...@@ -8593,8 +8473,7 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) {
} }
} else { } else {
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HGlobalObject* receiver = new(zone()) HGlobalObject(context); HGlobalObject* receiver = Add<HGlobalObject>(context);
AddInstruction(receiver);
PushAndAdd(new(zone()) HPushArgument(receiver)); PushAndAdd(new(zone()) HPushArgument(receiver));
CHECK_ALIVE(VisitArgumentList(expr->arguments())); CHECK_ALIVE(VisitArgumentList(expr->arguments()));
...@@ -8608,12 +8487,11 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) { ...@@ -8608,12 +8487,11 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) {
CHECK_ALIVE(VisitForValue(expr->expression())); CHECK_ALIVE(VisitForValue(expr->expression()));
HValue* function = Top(); HValue* function = Top();
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HGlobalObject* global = new(zone()) HGlobalObject(context); HGlobalObject* global = Add<HGlobalObject>(context);
AddInstruction(global);
HGlobalReceiver* receiver = new(zone()) HGlobalReceiver(global); HGlobalReceiver* receiver = new(zone()) HGlobalReceiver(global);
PushAndAdd(receiver); PushAndAdd(receiver);
CHECK_ALIVE(VisitExpressions(expr->arguments())); CHECK_ALIVE(VisitExpressions(expr->arguments()));
AddInstruction(new(zone()) HCheckFunction(function, expr->target())); Add<HCheckFunction>(function, expr->target());
if (TryInlineBuiltinFunctionCall(expr, true)) { // Drop the function. if (TryInlineBuiltinFunctionCall(expr, true)) { // Drop the function.
if (FLAG_trace_inlining) { if (FLAG_trace_inlining) {
...@@ -8639,10 +8517,8 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) { ...@@ -8639,10 +8517,8 @@ void HOptimizedGraphBuilder::VisitCall(Call* expr) {
CHECK_ALIVE(VisitForValue(expr->expression())); CHECK_ALIVE(VisitForValue(expr->expression()));
HValue* function = Top(); HValue* function = Top();
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = Add<HGlobalObject>(context);
AddInstruction(global_object); HGlobalReceiver* receiver = Add<HGlobalReceiver>(global_object);
HGlobalReceiver* receiver = new(zone()) HGlobalReceiver(global_object);
AddInstruction(receiver);
PushAndAdd(new(zone()) HPushArgument(receiver)); PushAndAdd(new(zone()) HPushArgument(receiver));
CHECK_ALIVE(VisitArgumentList(expr->arguments())); CHECK_ALIVE(VisitArgumentList(expr->arguments()));
...@@ -8680,8 +8556,7 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) { ...@@ -8680,8 +8556,7 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) {
HValue* function = Top(); HValue* function = Top();
CHECK_ALIVE(VisitExpressions(expr->arguments())); CHECK_ALIVE(VisitExpressions(expr->arguments()));
Handle<JSFunction> constructor = expr->target(); Handle<JSFunction> constructor = expr->target();
HValue* check = AddInstruction( HValue* check = Add<HCheckFunction>(function, constructor);
new(zone()) HCheckFunction(function, constructor));
// Force completion of inobject slack tracking before generating // Force completion of inobject slack tracking before generating
// allocation code to finalize instance size. // allocation code to finalize instance size.
...@@ -8690,10 +8565,9 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) { ...@@ -8690,10 +8565,9 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) {
} }
// Replace the constructor function with a newly allocated receiver. // Replace the constructor function with a newly allocated receiver.
HInstruction* receiver = new(zone()) HAllocateObject(context, constructor); HInstruction* receiver = Add<HAllocateObject>(context, constructor);
// Index of the receiver from the top of the expression stack. // Index of the receiver from the top of the expression stack.
const int receiver_index = argument_count - 1; const int receiver_index = argument_count - 1;
AddInstruction(receiver);
ASSERT(environment()->ExpressionStackAt(receiver_index) == function); ASSERT(environment()->ExpressionStackAt(receiver_index) == function);
environment()->SetExpressionStackAt(receiver_index, receiver); environment()->SetExpressionStackAt(receiver_index, receiver);
...@@ -8721,7 +8595,7 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) { ...@@ -8721,7 +8595,7 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) {
HCallNew* call; HCallNew* call;
if (expr->target().is_identical_to(array_function)) { if (expr->target().is_identical_to(array_function)) {
Handle<Cell> cell = expr->allocation_info_cell(); Handle<Cell> cell = expr->allocation_info_cell();
AddInstruction(new(zone()) HCheckFunction(constructor, array_function)); Add<HCheckFunction>(constructor, array_function);
call = new(zone()) HCallNewArray(context, constructor, argument_count, call = new(zone()) HCallNewArray(context, constructor, argument_count,
cell, expr->elements_kind()); cell, expr->elements_kind());
} else { } else {
...@@ -8944,12 +8818,11 @@ HInstruction* HOptimizedGraphBuilder::BuildIncrement( ...@@ -8944,12 +8818,11 @@ HInstruction* HOptimizedGraphBuilder::BuildIncrement(
// actual HChange instruction we need is (sometimes) added in a later // actual HChange instruction we need is (sometimes) added in a later
// phase, so it is not available now to be used as an input to HAdd and // phase, so it is not available now to be used as an input to HAdd and
// as the return value. // as the return value.
HInstruction* number_input = new(zone()) HForceRepresentation(Pop(), rep); HInstruction* number_input = Add<HForceRepresentation>(Pop(), rep);
if (!rep.IsDouble()) { if (!rep.IsDouble()) {
number_input->SetFlag(HInstruction::kFlexibleRepresentation); number_input->SetFlag(HInstruction::kFlexibleRepresentation);
number_input->SetFlag(HInstruction::kCannotBeTagged); number_input->SetFlag(HInstruction::kCannotBeTagged);
} }
AddInstruction(number_input);
Push(number_input); Push(number_input);
} }
...@@ -9032,9 +8905,8 @@ void HOptimizedGraphBuilder::VisitCountOperation(CountOperation* expr) { ...@@ -9032,9 +8905,8 @@ void HOptimizedGraphBuilder::VisitCountOperation(CountOperation* expr) {
HValue* context = BuildContextChainWalk(var); HValue* context = BuildContextChainWalk(var);
HStoreContextSlot::Mode mode = IsLexicalVariableMode(var->mode()) HStoreContextSlot::Mode mode = IsLexicalVariableMode(var->mode())
? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck; ? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck;
HStoreContextSlot* instr = HStoreContextSlot* instr = Add<HStoreContextSlot>(context, var->index(),
new(zone()) HStoreContextSlot(context, var->index(), mode, after); mode, after);
AddInstruction(instr);
if (instr->HasObservableSideEffects()) { if (instr->HasObservableSideEffects()) {
AddSimulate(expr->AssignmentId(), REMOVABLE_SIMULATE); AddSimulate(expr->AssignmentId(), REMOVABLE_SIMULATE);
} }
...@@ -9655,7 +9527,7 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) { ...@@ -9655,7 +9527,7 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
result->set_position(expr->position()); result->set_position(expr->position());
return ast_context()->ReturnInstruction(result, expr->id()); return ast_context()->ReturnInstruction(result, expr->id());
} else { } else {
AddInstruction(new(zone()) HCheckFunction(right, target)); Add<HCheckFunction>(right, target);
HInstanceOfKnownGlobal* result = HInstanceOfKnownGlobal* result =
new(zone()) HInstanceOfKnownGlobal(context, left, target); new(zone()) HInstanceOfKnownGlobal(context, left, target);
result->set_position(expr->position()); result->set_position(expr->position());
...@@ -9769,7 +9641,6 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral( ...@@ -9769,7 +9641,6 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
int data_size, int data_size,
int pointer_size, int pointer_size,
AllocationSiteMode mode) { AllocationSiteMode mode) {
Zone* zone = this->zone();
NoObservableSideEffectsScope no_effects(this); NoObservableSideEffectsScope no_effects(this);
HInstruction* target = NULL; HInstruction* target = NULL;
...@@ -9782,9 +9653,9 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral( ...@@ -9782,9 +9653,9 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
HAllocate::Flags data_flags = HAllocate::Flags data_flags =
static_cast<HAllocate::Flags>(HAllocate::DefaultFlags() | static_cast<HAllocate::Flags>(HAllocate::DefaultFlags() |
HAllocate::CAN_ALLOCATE_IN_OLD_DATA_SPACE); HAllocate::CAN_ALLOCATE_IN_OLD_DATA_SPACE);
HValue* size_in_bytes = AddInstruction(new(zone) HConstant(data_size)); HValue* size_in_bytes = Add<HConstant>(data_size);
data_target = AddInstruction(new(zone) HAllocate( data_target = Add<HAllocate>(context, size_in_bytes,
context, size_in_bytes, HType::JSObject(), data_flags)); HType::JSObject(), data_flags);
Handle<Map> free_space_map = isolate()->factory()->free_space_map(); Handle<Map> free_space_map = isolate()->factory()->free_space_map();
AddStoreMapConstant(data_target, free_space_map); AddStoreMapConstant(data_target, free_space_map);
HObjectAccess access = HObjectAccess access =
...@@ -9794,15 +9665,12 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral( ...@@ -9794,15 +9665,12 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
if (pointer_size != 0) { if (pointer_size != 0) {
flags = static_cast<HAllocate::Flags>( flags = static_cast<HAllocate::Flags>(
flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE); flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
HValue* size_in_bytes = AddInstruction(new(zone) HConstant(pointer_size)); HValue* size_in_bytes = Add<HConstant>(pointer_size);
target = AddInstruction(new(zone) HAllocate(context, target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), flags);
size_in_bytes, HType::JSObject(), flags));
} }
} else { } else {
HValue* size_in_bytes = HValue* size_in_bytes = Add<HConstant>(data_size + pointer_size);
AddInstruction(new(zone) HConstant(data_size + pointer_size)); target = Add<HAllocate>(context, size_in_bytes, HType::JSObject(), flags);
target = AddInstruction(new(zone) HAllocate(context, size_in_bytes,
HType::JSObject(), flags));
} }
int offset = 0; int offset = 0;
...@@ -9821,8 +9689,6 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy( ...@@ -9821,8 +9689,6 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy(
HInstruction* data_target, HInstruction* data_target,
int* data_offset, int* data_offset,
AllocationSiteMode mode) { AllocationSiteMode mode) {
Zone* zone = this->zone();
Handle<FixedArrayBase> elements(boilerplate_object->elements()); Handle<FixedArrayBase> elements(boilerplate_object->elements());
Handle<FixedArrayBase> original_elements( Handle<FixedArrayBase> original_elements(
original_boilerplate_object->elements()); original_boilerplate_object->elements());
...@@ -9858,7 +9724,7 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy( ...@@ -9858,7 +9724,7 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy(
// Copy in-object properties. // Copy in-object properties.
if (boilerplate_object->map()->NumberOfFields() != 0) { if (boilerplate_object->map()->NumberOfFields() != 0) {
HValue* object_properties = HValue* object_properties =
AddInstruction(new(zone) HInnerAllocatedObject(target, object_offset)); Add<HInnerAllocatedObject>(target, object_offset);
BuildEmitInObjectProperties(boilerplate_object, original_boilerplate_object, BuildEmitInObjectProperties(boilerplate_object, original_boilerplate_object,
object_properties, target, offset, data_target, data_offset); object_properties, target, offset, data_target, data_offset);
} }
...@@ -9868,8 +9734,8 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy( ...@@ -9868,8 +9734,8 @@ void HOptimizedGraphBuilder::BuildEmitDeepCopy(
boilerplate_object->map()->CanTrackAllocationSite()) { boilerplate_object->map()->CanTrackAllocationSite()) {
elements_offset += AllocationSiteInfo::kSize; elements_offset += AllocationSiteInfo::kSize;
*offset += AllocationSiteInfo::kSize; *offset += AllocationSiteInfo::kSize;
HInstruction* original_boilerplate = AddInstruction(new(zone) HConstant( HInstruction* original_boilerplate =
original_boilerplate_object)); Add<HConstant>(original_boilerplate_object);
BuildCreateAllocationSiteInfo(target, JSArray::kSize, original_boilerplate); BuildCreateAllocationSiteInfo(target, JSArray::kSize, original_boilerplate);
} }
} }
...@@ -9883,11 +9749,9 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader( ...@@ -9883,11 +9749,9 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader(
int elements_offset, int elements_offset,
int elements_size) { int elements_size) {
ASSERT(boilerplate_object->properties()->length() == 0); ASSERT(boilerplate_object->properties()->length() == 0);
Zone* zone = this->zone();
HValue* result = NULL; HValue* result = NULL;
HValue* object_header = HValue* object_header = Add<HInnerAllocatedObject>(target, object_offset);
AddInstruction(new(zone) HInnerAllocatedObject(target, object_offset));
Handle<Map> boilerplate_object_map(boilerplate_object->map()); Handle<Map> boilerplate_object_map(boilerplate_object->map());
AddStoreMapConstant(object_header, boilerplate_object_map); AddStoreMapConstant(object_header, boilerplate_object_map);
...@@ -9895,14 +9759,12 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader( ...@@ -9895,14 +9759,12 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader(
if (elements_size == 0) { if (elements_size == 0) {
Handle<Object> elements_field = Handle<Object> elements_field =
Handle<Object>(boilerplate_object->elements(), isolate()); Handle<Object>(boilerplate_object->elements(), isolate());
elements = AddInstruction(new(zone) HConstant(elements_field)); elements = Add<HConstant>(elements_field);
} else { } else {
if (data_target != NULL && boilerplate_object->HasFastDoubleElements()) { if (data_target != NULL && boilerplate_object->HasFastDoubleElements()) {
elements = AddInstruction(new(zone) HInnerAllocatedObject( elements = Add<HInnerAllocatedObject>(data_target, elements_offset);
data_target, elements_offset));
} else { } else {
elements = AddInstruction(new(zone) HInnerAllocatedObject( elements = Add<HInnerAllocatedObject>(target, elements_offset);
target, elements_offset));
} }
result = elements; result = elements;
} }
...@@ -9911,8 +9773,7 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader( ...@@ -9911,8 +9773,7 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader(
Handle<Object> properties_field = Handle<Object> properties_field =
Handle<Object>(boilerplate_object->properties(), isolate()); Handle<Object>(boilerplate_object->properties(), isolate());
ASSERT(*properties_field == isolate()->heap()->empty_fixed_array()); ASSERT(*properties_field == isolate()->heap()->empty_fixed_array());
HInstruction* properties = AddInstruction(new(zone) HConstant( HInstruction* properties = Add<HConstant>(properties_field);
properties_field));
HObjectAccess access = HObjectAccess::ForPropertiesPointer(); HObjectAccess access = HObjectAccess::ForPropertiesPointer();
AddStore(object_header, access, properties); AddStore(object_header, access, properties);
...@@ -9921,7 +9782,7 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader( ...@@ -9921,7 +9782,7 @@ HValue* HOptimizedGraphBuilder::BuildEmitObjectHeader(
Handle<JSArray>::cast(boilerplate_object); Handle<JSArray>::cast(boilerplate_object);
Handle<Object> length_field = Handle<Object> length_field =
Handle<Object>(boilerplate_array->length(), isolate()); Handle<Object>(boilerplate_array->length(), isolate());
HInstruction* length = AddInstruction(new(zone) HConstant(length_field)); HInstruction* length = Add<HConstant>(length_field);
ASSERT(boilerplate_array->length()->IsSmi()); ASSERT(boilerplate_array->length()->IsSmi());
Representation representation = Representation representation =
...@@ -9943,7 +9804,6 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties( ...@@ -9943,7 +9804,6 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
int* offset, int* offset,
HInstruction* data_target, HInstruction* data_target,
int* data_offset) { int* data_offset) {
Zone* zone = this->zone();
Handle<DescriptorArray> descriptors( Handle<DescriptorArray> descriptors(
boilerplate_object->map()->instance_descriptors()); boilerplate_object->map()->instance_descriptors());
int limit = boilerplate_object->map()->NumberOfOwnDescriptors(); int limit = boilerplate_object->map()->NumberOfOwnDescriptors();
...@@ -9970,8 +9830,8 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties( ...@@ -9970,8 +9830,8 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
Handle<JSObject> original_value_object = Handle<JSObject>::cast( Handle<JSObject> original_value_object = Handle<JSObject>::cast(
Handle<Object>(original_boilerplate_object->InObjectPropertyAt(index), Handle<Object>(original_boilerplate_object->InObjectPropertyAt(index),
isolate())); isolate()));
HInstruction* value_instruction = HInstruction* value_instruction = Add<HInnerAllocatedObject>(target,
AddInstruction(new(zone) HInnerAllocatedObject(target, *offset)); *offset);
AddStore(object_properties, access, value_instruction); AddStore(object_properties, access, value_instruction);
...@@ -9979,19 +9839,16 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties( ...@@ -9979,19 +9839,16 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
offset, data_target, data_offset, DONT_TRACK_ALLOCATION_SITE); offset, data_target, data_offset, DONT_TRACK_ALLOCATION_SITE);
} else { } else {
Representation representation = details.representation(); Representation representation = details.representation();
HInstruction* value_instruction = HInstruction* value_instruction = Add<HConstant>(value);
AddInstruction(new(zone) HConstant(value));
if (representation.IsDouble()) { if (representation.IsDouble()) {
// Allocate a HeapNumber box and store the value into it. // Allocate a HeapNumber box and store the value into it.
HInstruction* double_box; HInstruction* double_box;
if (data_target != NULL) { if (data_target != NULL) {
double_box = AddInstruction(new(zone) HInnerAllocatedObject( double_box = Add<HInnerAllocatedObject>(data_target, *data_offset);
data_target, *data_offset));
*data_offset += HeapNumber::kSize; *data_offset += HeapNumber::kSize;
} else { } else {
double_box = AddInstruction(new(zone) HInnerAllocatedObject( double_box = Add<HInnerAllocatedObject>(target, *offset);
target, *offset));
*offset += HeapNumber::kSize; *offset += HeapNumber::kSize;
} }
AddStoreMapConstant(double_box, AddStoreMapConstant(double_box,
...@@ -10006,8 +9863,8 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties( ...@@ -10006,8 +9863,8 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
} }
int inobject_properties = boilerplate_object->map()->inobject_properties(); int inobject_properties = boilerplate_object->map()->inobject_properties();
HInstruction* value_instruction = AddInstruction(new(zone) HInstruction* value_instruction =
HConstant(isolate()->factory()->one_pointer_filler_map())); Add<HConstant>(isolate()->factory()->one_pointer_filler_map());
for (int i = copied_fields; i < inobject_properties; i++) { for (int i = copied_fields; i < inobject_properties; i++) {
ASSERT(boilerplate_object->IsJSObject()); ASSERT(boilerplate_object->IsJSObject());
int property_offset = boilerplate_object->GetInObjectPropertyOffset(i); int property_offset = boilerplate_object->GetInObjectPropertyOffset(i);
...@@ -10026,11 +9883,8 @@ void HOptimizedGraphBuilder::BuildEmitElements( ...@@ -10026,11 +9883,8 @@ void HOptimizedGraphBuilder::BuildEmitElements(
int* offset, int* offset,
HInstruction* data_target, HInstruction* data_target,
int* data_offset) { int* data_offset) {
Zone* zone = this->zone();
int elements_length = elements->length(); int elements_length = elements->length();
HValue* object_elements_length = HValue* object_elements_length = Add<HConstant>(elements_length);
AddInstruction(new(zone) HConstant(elements_length));
BuildInitializeElementsHeader(object_elements, kind, object_elements_length); BuildInitializeElementsHeader(object_elements, kind, object_elements_length);
...@@ -10050,17 +9904,16 @@ void HOptimizedGraphBuilder::BuildEmitFixedDoubleArray( ...@@ -10050,17 +9904,16 @@ void HOptimizedGraphBuilder::BuildEmitFixedDoubleArray(
Handle<FixedArrayBase> elements, Handle<FixedArrayBase> elements,
ElementsKind kind, ElementsKind kind,
HValue* object_elements) { HValue* object_elements) {
Zone* zone = this->zone(); HInstruction* boilerplate_elements = Add<HConstant>(elements);
HInstruction* boilerplate_elements =
AddInstruction(new(zone) HConstant(elements));
int elements_length = elements->length(); int elements_length = elements->length();
for (int i = 0; i < elements_length; i++) { for (int i = 0; i < elements_length; i++) {
HValue* key_constant = AddInstruction(new(zone) HConstant(i)); HValue* key_constant = Add<HConstant>(i);
HInstruction* value_instruction = HInstruction* value_instruction =
AddInstruction(new(zone) HLoadKeyed( Add<HLoadKeyed>(boilerplate_elements, key_constant,
boilerplate_elements, key_constant, NULL, kind, ALLOW_RETURN_HOLE)); static_cast<HValue*>(NULL), kind,
HInstruction* store = AddInstruction(new(zone) HStoreKeyed( ALLOW_RETURN_HOLE);
object_elements, key_constant, value_instruction, kind)); HInstruction* store = Add<HStoreKeyed>(object_elements, key_constant,
value_instruction, kind);
store->SetFlag(HValue::kAllowUndefinedAsNaN); store->SetFlag(HValue::kAllowUndefinedAsNaN);
} }
} }
...@@ -10075,33 +9928,29 @@ void HOptimizedGraphBuilder::BuildEmitFixedArray( ...@@ -10075,33 +9928,29 @@ void HOptimizedGraphBuilder::BuildEmitFixedArray(
int* offset, int* offset,
HInstruction* data_target, HInstruction* data_target,
int* data_offset) { int* data_offset) {
Zone* zone = this->zone(); HInstruction* boilerplate_elements = Add<HConstant>(elements);
HInstruction* boilerplate_elements =
AddInstruction(new(zone) HConstant(elements));
int elements_length = elements->length(); int elements_length = elements->length();
Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements); Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
Handle<FixedArray> original_fast_elements = Handle<FixedArray> original_fast_elements =
Handle<FixedArray>::cast(original_elements); Handle<FixedArray>::cast(original_elements);
for (int i = 0; i < elements_length; i++) { for (int i = 0; i < elements_length; i++) {
Handle<Object> value(fast_elements->get(i), isolate()); Handle<Object> value(fast_elements->get(i), isolate());
HValue* key_constant = AddInstruction(new(zone) HConstant(i)); HValue* key_constant = Add<HConstant>(i);
if (value->IsJSObject()) { if (value->IsJSObject()) {
Handle<JSObject> value_object = Handle<JSObject>::cast(value); Handle<JSObject> value_object = Handle<JSObject>::cast(value);
Handle<JSObject> original_value_object = Handle<JSObject>::cast( Handle<JSObject> original_value_object = Handle<JSObject>::cast(
Handle<Object>(original_fast_elements->get(i), isolate())); Handle<Object>(original_fast_elements->get(i), isolate()));
HInstruction* value_instruction = HInstruction* value_instruction = Add<HInnerAllocatedObject>(target,
AddInstruction(new(zone) HInnerAllocatedObject(target, *offset)); *offset);
AddInstruction(new(zone) HStoreKeyed( Add<HStoreKeyed>(object_elements, key_constant, value_instruction, kind);
object_elements, key_constant, value_instruction, kind));
BuildEmitDeepCopy(value_object, original_value_object, target, BuildEmitDeepCopy(value_object, original_value_object, target,
offset, data_target, data_offset, DONT_TRACK_ALLOCATION_SITE); offset, data_target, data_offset, DONT_TRACK_ALLOCATION_SITE);
} else { } else {
HInstruction* value_instruction = HInstruction* value_instruction =
AddInstruction(new(zone) HLoadKeyed( Add<HLoadKeyed>(boilerplate_elements, key_constant,
boilerplate_elements, key_constant, NULL, kind, static_cast<HValue*>(NULL), kind,
ALLOW_RETURN_HOLE)); ALLOW_RETURN_HOLE);
AddInstruction(new(zone) HStoreKeyed( Add<HStoreKeyed>(object_elements, key_constant, value_instruction, kind);
object_elements, key_constant, value_instruction, kind));
} }
} }
} }
...@@ -10126,9 +9975,7 @@ void HOptimizedGraphBuilder::VisitDeclarations( ...@@ -10126,9 +9975,7 @@ void HOptimizedGraphBuilder::VisitDeclarations(
int flags = DeclareGlobalsEvalFlag::encode(current_info()->is_eval()) | int flags = DeclareGlobalsEvalFlag::encode(current_info()->is_eval()) |
DeclareGlobalsNativeFlag::encode(current_info()->is_native()) | DeclareGlobalsNativeFlag::encode(current_info()->is_native()) |
DeclareGlobalsLanguageMode::encode(current_info()->language_mode()); DeclareGlobalsLanguageMode::encode(current_info()->language_mode());
HInstruction* result = new(zone()) HDeclareGlobals( Add<HDeclareGlobals>(environment()->LookupContext(), array, flags);
environment()->LookupContext(), array, flags);
AddInstruction(result);
globals_.Clear(); globals_.Clear();
} }
} }
...@@ -10158,9 +10005,8 @@ void HOptimizedGraphBuilder::VisitVariableDeclaration( ...@@ -10158,9 +10005,8 @@ void HOptimizedGraphBuilder::VisitVariableDeclaration(
if (hole_init) { if (hole_init) {
HValue* value = graph()->GetConstantHole(); HValue* value = graph()->GetConstantHole();
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HStoreContextSlot* store = new(zone()) HStoreContextSlot( HStoreContextSlot* store = Add<HStoreContextSlot>(
context, variable->index(), HStoreContextSlot::kNoCheck, value); context, variable->index(), HStoreContextSlot::kNoCheck, value);
AddInstruction(store);
if (store->HasObservableSideEffects()) { if (store->HasObservableSideEffects()) {
AddSimulate(proxy->id(), REMOVABLE_SIMULATE); AddSimulate(proxy->id(), REMOVABLE_SIMULATE);
} }
...@@ -10197,9 +10043,8 @@ void HOptimizedGraphBuilder::VisitFunctionDeclaration( ...@@ -10197,9 +10043,8 @@ void HOptimizedGraphBuilder::VisitFunctionDeclaration(
CHECK_ALIVE(VisitForValue(declaration->fun())); CHECK_ALIVE(VisitForValue(declaration->fun()));
HValue* value = Pop(); HValue* value = Pop();
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HStoreContextSlot* store = new(zone()) HStoreContextSlot( HStoreContextSlot* store = Add<HStoreContextSlot>(
context, variable->index(), HStoreContextSlot::kNoCheck, value); context, variable->index(), HStoreContextSlot::kNoCheck, value);
AddInstruction(store);
if (store->HasObservableSideEffects()) { if (store->HasObservableSideEffects()) {
AddSimulate(proxy->id(), REMOVABLE_SIMULATE); AddSimulate(proxy->id(), REMOVABLE_SIMULATE);
} }
...@@ -10371,8 +10216,7 @@ void HOptimizedGraphBuilder::GenerateArgumentsLength(CallRuntime* call) { ...@@ -10371,8 +10216,7 @@ void HOptimizedGraphBuilder::GenerateArgumentsLength(CallRuntime* call) {
// function is blacklisted by AstNode::IsInlineable. // function is blacklisted by AstNode::IsInlineable.
ASSERT(function_state()->outer() == NULL); ASSERT(function_state()->outer() == NULL);
ASSERT(call->arguments()->length() == 0); ASSERT(call->arguments()->length() == 0);
HInstruction* elements = AddInstruction( HInstruction* elements = Add<HArgumentsElements>(false);
new(zone()) HArgumentsElements(false));
HArgumentsLength* result = new(zone()) HArgumentsLength(elements); HArgumentsLength* result = new(zone()) HArgumentsLength(elements);
return ast_context()->ReturnInstruction(result, call->id()); return ast_context()->ReturnInstruction(result, call->id());
} }
...@@ -10386,9 +10230,8 @@ void HOptimizedGraphBuilder::GenerateArguments(CallRuntime* call) { ...@@ -10386,9 +10230,8 @@ void HOptimizedGraphBuilder::GenerateArguments(CallRuntime* call) {
ASSERT(call->arguments()->length() == 1); ASSERT(call->arguments()->length() == 1);
CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
HValue* index = Pop(); HValue* index = Pop();
HInstruction* elements = AddInstruction( HInstruction* elements = Add<HArgumentsElements>(false);
new(zone()) HArgumentsElements(false)); HInstruction* length = Add<HArgumentsLength>(elements);
HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements));
HInstruction* checked_index = Add<HBoundsCheck>(index, length); HInstruction* checked_index = Add<HBoundsCheck>(index, length);
HAccessArgumentsAt* result = HAccessArgumentsAt* result =
new(zone()) HAccessArgumentsAt(elements, length, checked_index); new(zone()) HAccessArgumentsAt(elements, length, checked_index);
...@@ -10553,8 +10396,7 @@ void HOptimizedGraphBuilder::GenerateLog(CallRuntime* call) { ...@@ -10553,8 +10396,7 @@ void HOptimizedGraphBuilder::GenerateLog(CallRuntime* call) {
// Fast support for Math.random(). // Fast support for Math.random().
void HOptimizedGraphBuilder::GenerateRandomHeapNumber(CallRuntime* call) { void HOptimizedGraphBuilder::GenerateRandomHeapNumber(CallRuntime* call) {
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HGlobalObject* global_object = new(zone()) HGlobalObject(context); HGlobalObject* global_object = Add<HGlobalObject>(context);
AddInstruction(global_object);
HRandom* result = new(zone()) HRandom(global_object); HRandom* result = new(zone()) HRandom(global_object);
return ast_context()->ReturnInstruction(result, call->id()); return ast_context()->ReturnInstruction(result, call->id());
} }
...@@ -10660,15 +10502,14 @@ void HOptimizedGraphBuilder::GenerateCallFunction(CallRuntime* call) { ...@@ -10660,15 +10502,14 @@ void HOptimizedGraphBuilder::GenerateCallFunction(CallRuntime* call) {
current_block()->Finish(typecheck); current_block()->Finish(typecheck);
set_current_block(if_jsfunction); set_current_block(if_jsfunction);
HInstruction* invoke_result = AddInstruction( HInstruction* invoke_result =
new(zone()) HInvokeFunction(context, function, arg_count)); Add<HInvokeFunction>(context, function, arg_count);
Drop(arg_count); Drop(arg_count);
Push(invoke_result); Push(invoke_result);
if_jsfunction->Goto(join); if_jsfunction->Goto(join);
set_current_block(if_nonfunction); set_current_block(if_nonfunction);
HInstruction* call_result = AddInstruction( HInstruction* call_result = Add<HCallFunction>(context, function, arg_count);
new(zone()) HCallFunction(context, function, arg_count));
Drop(arg_count); Drop(arg_count);
Push(call_result); Push(call_result);
if_nonfunction->Goto(join); if_nonfunction->Goto(join);
......
...@@ -997,6 +997,36 @@ class HGraphBuilder { ...@@ -997,6 +997,36 @@ class HGraphBuilder {
return static_cast<I*>(AddInstruction(new(zone()) I(p1, p2, p3))); return static_cast<I*>(AddInstruction(new(zone()) I(p1, p2, p3)));
} }
template<class I, class P1, class P2, class P3, class P4>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4) {
return static_cast<I*>(AddInstruction(new(zone()) I(p1, p2, p3, p4)));
}
template<class I, class P1, class P2, class P3, class P4, class P5>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
return static_cast<I*>(AddInstruction(new(zone()) I(p1, p2, p3, p4, p5)));
}
template<class I, class P1, class P2, class P3, class P4, class P5, class P6>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) {
return static_cast<I*>(AddInstruction(
new(zone()) I(p1, p2, p3, p4, p5, p6)));
}
template<class I, class P1, class P2, class P3,
class P4, class P5, class P6, class P7>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) {
return static_cast<I*>(AddInstruction(
new(zone()) I(p1, p2, p3, p4, p5, p6, p7)));
}
template<class I, class P1, class P2, class P3, class P4,
class P5, class P6, class P7, class P8>
I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) {
return static_cast<I*>(AddInstruction(
new(zone()) I(p1, p2, p3, p4, p5, p6, p7, p8)));
}
void AddSimulate(BailoutId id, void AddSimulate(BailoutId id,
RemovableSimulate removable = FIXED_SIMULATE); RemovableSimulate removable = FIXED_SIMULATE);
...@@ -1291,9 +1321,6 @@ class HGraphBuilder { ...@@ -1291,9 +1321,6 @@ class HGraphBuilder {
int elements_size() const { int elements_size() const {
return IsFastDoubleElementsKind(kind_) ? kDoubleSize : kPointerSize; return IsFastDoubleElementsKind(kind_) ? kDoubleSize : kPointerSize;
} }
HInstruction* AddInstruction(HInstruction* instr) {
return builder_->AddInstruction(instr);
}
HGraphBuilder* builder() { return builder_; } HGraphBuilder* builder() { return builder_; }
HGraph* graph() { return builder_->graph(); } HGraph* graph() { return builder_->graph(); }
int initial_capacity() { int initial_capacity() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment