Commit f95ddc88 authored by danno@chromium.org's avatar danno@chromium.org

Add templatized convienience functions for adding hydrogen instructions

R=bmeurer@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15360 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3b60d6de
...@@ -599,7 +599,7 @@ HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor( ...@@ -599,7 +599,7 @@ HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor(
HConstant* initial_capacity_node = new(zone()) HConstant(initial_capacity); HConstant* initial_capacity_node = new(zone()) HConstant(initial_capacity);
AddInstruction(initial_capacity_node); AddInstruction(initial_capacity_node);
HBoundsCheck* checked_arg = AddBoundsCheck(argument, max_alloc_length); HBoundsCheck* checked_arg = Add<HBoundsCheck>(argument, max_alloc_length);
IfBuilder if_builder(this); IfBuilder if_builder(this);
if_builder.IfCompare(checked_arg, constant_zero, Token::EQ); if_builder.IfCompare(checked_arg, constant_zero, Token::EQ);
if_builder.Then(); if_builder.Then();
......
...@@ -989,13 +989,6 @@ void HGraphBuilder::AddSimulate(BailoutId id, ...@@ -989,13 +989,6 @@ void HGraphBuilder::AddSimulate(BailoutId id,
} }
HBoundsCheck* HGraphBuilder::AddBoundsCheck(HValue* index, HValue* length) {
HBoundsCheck* result = new(graph()->zone()) HBoundsCheck(index, length);
AddInstruction(result);
return result;
}
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();
...@@ -1175,7 +1168,7 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow(HValue* object, ...@@ -1175,7 +1168,7 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow(HValue* object,
length_checker.Else(); length_checker.Else();
AddBoundsCheck(key, length); Add<HBoundsCheck>(key, length);
environment()->Push(elements); environment()->Push(elements);
length_checker.End(); length_checker.End();
...@@ -1280,7 +1273,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1280,7 +1273,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
return result; return result;
} else { } else {
ASSERT(store_mode == STANDARD_STORE); ASSERT(store_mode == STANDARD_STORE);
checked_key = AddBoundsCheck(key, length); checked_key = Add<HBoundsCheck>(key, length);
HLoadExternalArrayPointer* external_elements = HLoadExternalArrayPointer* external_elements =
new(zone) HLoadExternalArrayPointer(elements); new(zone) HLoadExternalArrayPointer(elements);
AddInstruction(external_elements); AddInstruction(external_elements);
...@@ -1308,7 +1301,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -1308,7 +1301,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
length, key, is_js_array); length, key, is_js_array);
checked_key = key; checked_key = key;
} else { } else {
checked_key = AddBoundsCheck(key, length); checked_key = Add<HBoundsCheck>(key, length);
if (is_store && (fast_elements || fast_smi_only_elements)) { if (is_store && (fast_elements || fast_smi_only_elements)) {
if (store_mode == STORE_NO_TRANSITION_HANDLE_COW) { if (store_mode == STORE_NO_TRANSITION_HANDLE_COW) {
...@@ -7274,7 +7267,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -7274,7 +7267,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
&& todo_external_array) { && todo_external_array) {
HInstruction* length = HInstruction* length =
AddInstruction(new(zone()) HFixedArrayBaseLength(elements)); AddInstruction(new(zone()) HFixedArrayBaseLength(elements));
checked_key = AddBoundsCheck(key, length); checked_key = Add<HBoundsCheck>(key, length);
external_elements = new(zone()) HLoadExternalArrayPointer(elements); external_elements = new(zone()) HLoadExternalArrayPointer(elements);
AddInstruction(external_elements); AddInstruction(external_elements);
} }
...@@ -7317,7 +7310,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -7317,7 +7310,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
typecheck, Representation::Smi()); typecheck, Representation::Smi());
length->set_type(HType::Smi()); length->set_type(HType::Smi());
checked_key = AddBoundsCheck(key, length); checked_key = Add<HBoundsCheck>(key, length);
access = AddInstruction(BuildFastElementAccess( access = AddInstruction(BuildFastElementAccess(
elements, checked_key, val, elements_kind_branch, elements, checked_key, val, elements_kind_branch,
elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE)); elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE));
...@@ -7335,7 +7328,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess( ...@@ -7335,7 +7328,7 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
set_current_block(if_fastobject); set_current_block(if_fastobject);
length = AddInstruction(new(zone()) HFixedArrayBaseLength(elements)); length = AddInstruction(new(zone()) HFixedArrayBaseLength(elements));
checked_key = AddBoundsCheck(key, length); checked_key = Add<HBoundsCheck>(key, length);
access = AddInstruction(BuildFastElementAccess( access = AddInstruction(BuildFastElementAccess(
elements, checked_key, val, elements_kind_branch, elements, checked_key, val, elements_kind_branch,
elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE)); elements_kind, is_store, NEVER_RETURN_HOLE, STANDARD_STORE));
...@@ -7487,7 +7480,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) { ...@@ -7487,7 +7480,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) {
new(zone()) HArgumentsElements(false)); new(zone()) HArgumentsElements(false));
HInstruction* length = AddInstruction( HInstruction* length = AddInstruction(
new(zone()) HArgumentsLength(elements)); new(zone()) HArgumentsLength(elements));
HInstruction* checked_key = AddBoundsCheck(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 {
EnsureArgumentsArePushedForAccess(); EnsureArgumentsArePushedForAccess();
...@@ -7498,7 +7491,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) { ...@@ -7498,7 +7491,7 @@ bool HOptimizedGraphBuilder::TryArgumentsAccess(Property* expr) {
arguments_environment()->parameter_count() - 1; arguments_environment()->parameter_count() - 1;
HInstruction* length = AddInstruction(new(zone()) HConstant( HInstruction* length = AddInstruction(new(zone()) HConstant(
argument_count)); argument_count));
HInstruction* checked_key = AddBoundsCheck(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);
} }
} }
...@@ -9323,7 +9316,7 @@ HInstruction* HOptimizedGraphBuilder::BuildStringCharCodeAt( ...@@ -9323,7 +9316,7 @@ HInstruction* HOptimizedGraphBuilder::BuildStringCharCodeAt(
AddInstruction(HCheckInstanceType::NewIsString(string, zone())); AddInstruction(HCheckInstanceType::NewIsString(string, zone()));
HInstruction* length = HStringLength::New(zone(), string); HInstruction* length = HStringLength::New(zone(), string);
AddInstruction(length); AddInstruction(length);
HInstruction* checked_index = AddBoundsCheck(index, length); HInstruction* checked_index = Add<HBoundsCheck>(index, length);
return new(zone()) HStringCharCodeAt(context, string, checked_index); return new(zone()) HStringCharCodeAt(context, string, checked_index);
} }
...@@ -10537,7 +10530,7 @@ void HOptimizedGraphBuilder::GenerateArguments(CallRuntime* call) { ...@@ -10537,7 +10530,7 @@ void HOptimizedGraphBuilder::GenerateArguments(CallRuntime* call) {
HInstruction* elements = AddInstruction( HInstruction* elements = AddInstruction(
new(zone()) HArgumentsElements(false)); new(zone()) HArgumentsElements(false));
HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements)); HInstruction* length = AddInstruction(new(zone()) HArgumentsLength(elements));
HInstruction* checked_index = AddBoundsCheck(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);
return ast_context()->ReturnInstruction(result, call->id()); return ast_context()->ReturnInstruction(result, call->id());
......
...@@ -994,9 +994,27 @@ class HGraphBuilder { ...@@ -994,9 +994,27 @@ class HGraphBuilder {
// Adding instructions. // Adding instructions.
HInstruction* AddInstruction(HInstruction* instr); HInstruction* AddInstruction(HInstruction* instr);
template<class I>
I* Add() { return static_cast<I*>(AddInstruction(new(zone()) I())); }
template<class I, class P1>
I* Add(P1 p1) {
return static_cast<I*>(AddInstruction(new(zone()) I(p1)));
}
template<class I, class P1, class P2>
I* Add(P1 p1, P2 p2) {
return static_cast<I*>(AddInstruction(new(zone()) I(p1, p2)));
}
template<class I, class P1, class P2, class P3>
I* Add(P1 p1, P2 p2, P3 p3) {
return static_cast<I*>(AddInstruction(new(zone()) I(p1, p2, p3)));
}
void AddSimulate(BailoutId id, void AddSimulate(BailoutId id,
RemovableSimulate removable = FIXED_SIMULATE); RemovableSimulate removable = FIXED_SIMULATE);
HBoundsCheck* AddBoundsCheck(HValue* index, HValue* length);
HReturn* AddReturn(HValue* value); HReturn* AddReturn(HValue* value);
......
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