Chromium Code Reviews| Index: src/hydrogen.h |
| diff --git a/src/hydrogen.h b/src/hydrogen.h |
| index 8484cd1eb65e6faf7aec09670a40de9345a04260..4384962775e2774205cb996532c790b9ccbeadc2 100644 |
| --- a/src/hydrogen.h |
| +++ b/src/hydrogen.h |
| @@ -583,7 +583,7 @@ class HEnvironment: public ZoneObject { |
| return result; |
| } |
| - HValue* LookupContext() const { |
| + HValue* context() const { |
| // Return first special. |
| return Lookup(parameter_count()); |
| } |
| @@ -990,57 +990,164 @@ class HGraphBuilder { |
| void Push(HValue* value) { environment()->Push(value); } |
| HValue* Pop() { return environment()->Pop(); } |
| + virtual HValue* context() = 0; |
| + |
| // Adding instructions. |
| HInstruction* AddInstruction(HInstruction* instr); |
| template<class I> |
| - I* Add() { return static_cast<I*>(AddInstruction(new(zone()) I())); } |
| + HInstruction* New() { return I::New(zone(), context()); } |
| + |
| + template<class I> |
| + I* NewAndCast() { return I::cast(New<I>()); } |
| + |
| + template<class I> |
| + HInstruction* Add() { return AddInstruction(New<I>());} |
| + |
| + template<class I> |
| + I* AddAndCast() { return I::cast(Add<I>());} |
| + |
| + template<class I, class P1> |
| + HInstruction* New(P1 p1) { |
| + return I::New(zone(), context(), p1); |
| + } |
| template<class I, class P1> |
| - I* Add(P1 p1) { |
| - return static_cast<I*>(AddInstruction(new(zone()) I(p1))); |
| + I* NewAndCast(P1 p1) { return I::cast(New<I>(p1)); } |
| + |
| + template<class I, class P1> |
| + HInstruction* Add(P1 p1) { |
| + HInstruction* result = AddInstruction(New<I>(p1)); |
| + // Specializations must have their parameters properly casted |
| + // to avoid landing here. |
| + ASSERT(!result->IsReturn() && !result->IsSimulate() && |
| + !result->IsDeoptimize()); |
| + return result; |
| + } |
| + |
| + template<class I, class P1> |
| + I* AddAndCast(P1 p1) { |
| + return I::cast(Add<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))); |
| + HInstruction* New(P1 p1, P2 p2) { return I::New(zone(), context(), p1, p2); } |
| + |
| + template<class I, class P1, class P2> |
| + I* NewAndCast(P1 p1, P2 p2) { return I::cast(New<I>(p1, p2)); } |
| + |
| + template<class I, class P1, class P2> |
| + HInstruction* Add(P1 p1, P2 p2) { |
| + HInstruction* result = AddInstruction(New<I>(p1, p2)); |
| + // Specializations must have their parameters properly casted |
| + // to avoid landing here. |
| + ASSERT(!result->IsSimulate()); |
| + return result; |
| + } |
| + |
| + template<class I, class P1, class P2> |
| + I* AddAndCast(P1 p1, P2 p2) { |
| + return static_cast<I*>(Add<I>(p1, p2)); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3> |
| + HInstruction* New(P1 p1, P2 p2, P3 p3) { |
| + return I::New(zone(), context(), p1, p2, p3); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3> |
| + I* NewAndCast(P1 p1, P2 p2, P3 p3) { |
| + return I::cast(New<I>(p1, p2, p3)); |
| } |
| 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))); |
| + HInstruction* Add(P1 p1, P2 p2, P3 p3) { |
| + return AddInstruction(New<I>(p1, p2, p3)); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3> |
| + I* AddAndCast(P1 p1, P2 p2, P3 p3) { |
| + return I::cast(Add<I>(p1, p2, p3)); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3, class P4> |
| + HInstruction* New(P1 p1, P2 p2, P3 p3, P4 p4) { |
| + return I::New(zone(), context(), p1, p2, p3, p4); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3, class P4> |
| + I* NewAndCast(P1 p1, P2 p2, P3 p3, P4 p4) { |
| + return I::cast(New<I>(p1, p2, p3, p4)); |
| } |
| 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))); |
| + HInstruction* Add(P1 p1, P2 p2, P3 p3, P4 p4) { |
| + return AddInstruction(New<I>(p1, p2, p3, p4)); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3, class P4> |
| + I* AddAndCast(P1 p1, P2 p2, P3 p3, P4 p4) { |
| + return I::cast(Add<I>(p1, p2, p3, p4)); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3, class P4, class P5> |
| + HInstruction* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { |
| + return I::New(zone(), context(), p1, p2, p3, p4, p5); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3, class P4, class P5> |
| + I* NewAndCast(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { |
| + return I::cast(New<I>(p1, p2, p3, p4, p5)); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3, class P4, class P5> |
| + HInstruction* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { |
| + return AddInstruction(New<I>(p1, p2, p3, p4, p5)); |
| } |
| 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))); |
| + I* AddAndCast(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { |
| + return I::cast(Add<I>(p1, p2, p3, p4, p5)); |
| + } |
| + |
| + template<class I, class P1, class P2, class P3, class P4, class P5, class P6> |
| + HInstruction* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) { |
| + return 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> |
| - 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))); |
| + I* AddAndCast(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) { |
| + return I::cast(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))); |
| + HInstruction* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) { |
| + return 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> |
| + I* AddAndCast(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) { |
| + return I::cast(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))); |
| + HInstruction* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) { |
| + return AddInstruction(new(zone()) I(p1, p2, p3, p4, p5, p6, p7, p8)); |
| } |
| + template<class I, class P1, class P2, class P3, class P4, |
| + class P5, class P6, class P7, class P8> |
| + I* AddAndCast(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) { |
| + return I::cast( |
| + AddInstruction(new(zone()) I(p1, p2, p3, p4, p5, p6, p7, p8))); |
| + } |
| + |
| + void AddSimulate(BailoutId id, |
| + RemovableSimulate removable = FIXED_SIMULATE); |
| + |
| void IncrementInNoSideEffectsScope() { |
| no_side_effects_scope_count_++; |
| } |
| @@ -1089,15 +1196,9 @@ class HGraphBuilder { |
| LoadKeyedHoleMode load_mode, |
| KeyedAccessStoreMode store_mode); |
| - HLoadNamedField* AddLoad( |
| - HValue *object, |
| - HObjectAccess access, |
| - HValue *typecheck = NULL); |
| - |
| HLoadNamedField* BuildLoadNamedField( |
| HValue* object, |
| - HObjectAccess access, |
| - Representation representation); |
| + HObjectAccess access); |
| HInstruction* AddExternalArrayElementAccess( |
| HValue* external_elements, |
| @@ -1117,13 +1218,11 @@ class HGraphBuilder { |
| LoadKeyedHoleMode load_mode, |
| KeyedAccessStoreMode store_mode); |
| - HLoadNamedField* BuildLoadNamedField(HValue* object, HObjectAccess access); |
| - HStoreNamedField* AddStore(HValue *object, HObjectAccess access, HValue *val); |
| HStoreNamedField* AddStoreMapConstant(HValue *object, Handle<Map>); |
| HLoadNamedField* AddLoadElements(HValue *object, HValue *typecheck = NULL); |
| HLoadNamedField* AddLoadFixedArrayLength(HValue *object); |
| - HValue* AddLoadJSBuiltin(Builtins::JavaScript builtin, HValue* context); |
| + HValue* AddLoadJSBuiltin(Builtins::JavaScript builtin); |
| HValue* TruncateToNumber(HValue* value, Handle<Type>* expected); |
| @@ -1314,8 +1413,7 @@ class HGraphBuilder { |
| HGraphBuilder* builder_; |
| }; |
| - HValue* BuildNewElementsCapacity(HValue* context, |
| - HValue* old_capacity); |
| + HValue* BuildNewElementsCapacity(HValue* old_capacity); |
| void BuildNewSpaceArrayCheck(HValue* length, |
| ElementsKind kind); |
| @@ -1349,7 +1447,7 @@ class HGraphBuilder { |
| return JSArray::kPreallocatedArrayElements; |
| } |
| - HValue* EmitMapCode(HValue* context); |
| + HValue* EmitMapCode(); |
| HValue* EmitInternalMapCode(); |
| HValue* EstablishEmptyArrayAllocationSize(); |
| HValue* EstablishAllocationSize(HValue* length_node); |
| @@ -1364,16 +1462,14 @@ class HGraphBuilder { |
| HInnerAllocatedObject* elements_location_; |
| }; |
| - HValue* BuildAllocateElements(HValue* context, |
| - ElementsKind kind, |
| + HValue* BuildAllocateElements(ElementsKind kind, |
| HValue* capacity); |
| void BuildInitializeElementsHeader(HValue* elements, |
| ElementsKind kind, |
| HValue* capacity); |
| - HValue* BuildAllocateElementsAndInitializeElementsHeader(HValue* context, |
| - ElementsKind kind, |
| + HValue* BuildAllocateElementsAndInitializeElementsHeader(ElementsKind kind, |
| HValue* capacity); |
| // array must have been allocated with enough room for |
| @@ -1394,27 +1490,26 @@ class HGraphBuilder { |
| HValue* length, |
| HValue* new_capacity); |
| - void BuildFillElementsWithHole(HValue* context, |
| - HValue* elements, |
| + void BuildFillElementsWithHole(HValue* elements, |
| ElementsKind elements_kind, |
| HValue* from, |
| HValue* to); |
| - void BuildCopyElements(HValue* context, |
| - HValue* from_elements, |
| + void BuildCopyElements(HValue* from_elements, |
| ElementsKind from_elements_kind, |
| HValue* to_elements, |
| ElementsKind to_elements_kind, |
| HValue* length, |
| HValue* capacity); |
| - HValue* BuildCloneShallowArray(HContext* context, |
| - HValue* boilerplate, |
| + HValue* BuildCloneShallowArray(HValue* boilerplate, |
| HValue* allocation_site, |
| AllocationSiteMode mode, |
| ElementsKind kind, |
| int length); |
| + HValue* BuildKeyHash(HValue* key); |
|
Toon Verwaest
2013/07/31 12:56:37
Left-over declaration from a different CL?
danno
2013/07/31 14:10:09
Done.
|
| + |
| HInstruction* BuildUnaryMathOp( |
| HValue* value, Handle<Type> type, Token::Value token); |
| @@ -1428,8 +1523,8 @@ class HGraphBuilder { |
| int previous_object_size, |
| HValue* payload); |
| - HInstruction* BuildGetNativeContext(HValue* context); |
| - HInstruction* BuildGetArrayFunction(HValue* context); |
| + HInstruction* BuildGetNativeContext(); |
| + HInstruction* BuildGetArrayFunction(); |
| private: |
| HGraphBuilder(); |
| @@ -1445,13 +1540,14 @@ class HGraphBuilder { |
| template<> |
| -inline HDeoptimize* HGraphBuilder::Add(Deoptimizer::BailoutType type) { |
| +inline HInstruction* HGraphBuilder::Add<HDeoptimize>( |
| + Deoptimizer::BailoutType type) { |
| if (type == Deoptimizer::SOFT) { |
| isolate()->counters()->soft_deopts_requested()->Increment(); |
| if (FLAG_always_opt) return NULL; |
| } |
| if (current_block()->IsDeoptimizing()) return NULL; |
| - HDeoptimize* instr = new(zone()) HDeoptimize(type); |
| + HDeoptimize* instr = NewAndCast<HDeoptimize>(type); |
| AddInstruction(instr); |
| if (type == Deoptimizer::SOFT) { |
| isolate()->counters()->soft_deopts_inserted()->Increment(); |
| @@ -1463,8 +1559,9 @@ inline HDeoptimize* HGraphBuilder::Add(Deoptimizer::BailoutType type) { |
| template<> |
| -inline HSimulate* HGraphBuilder::Add(BailoutId id, |
| - RemovableSimulate removable) { |
| +inline HInstruction* HGraphBuilder::Add<HSimulate>( |
| + BailoutId id, |
| + RemovableSimulate removable) { |
| HSimulate* instr = current_block()->CreateSimulate(id, removable); |
| AddInstruction(instr); |
| return instr; |
| @@ -1472,26 +1569,44 @@ inline HSimulate* HGraphBuilder::Add(BailoutId id, |
| template<> |
| -inline HSimulate* HGraphBuilder::Add(BailoutId id) { |
| +inline HInstruction* HGraphBuilder::New<HLoadNamedField>( |
| + HValue* object, HObjectAccess access) { |
| + return New<HLoadNamedField>(object, access, static_cast<HValue*>(NULL)); |
| +} |
| + |
| + |
| +template<> |
| +inline HInstruction* HGraphBuilder::Add<HLoadNamedField>( |
| + HValue* object, HObjectAccess access) { |
| + return Add<HLoadNamedField>(object, access, static_cast<HValue*>(NULL)); |
| +} |
| + |
| + |
| +template<> |
| +inline HInstruction* HGraphBuilder::Add<HSimulate>(BailoutId id) { |
| return Add<HSimulate>(id, FIXED_SIMULATE); |
| } |
| template<> |
| -inline HReturn* HGraphBuilder::Add(HValue* value) { |
| - HValue* context = environment()->LookupContext(); |
| +inline HInstruction* HGraphBuilder::Add<HReturn>(HValue* value) { |
| int num_parameters = graph()->info()->num_parameters(); |
| HValue* params = Add<HConstant>(num_parameters); |
| - HReturn* return_instruction = new(graph()->zone()) |
| - HReturn(value, context, params); |
| + HReturn* return_instruction = NewAndCast<HReturn>(value, params); |
| current_block()->FinishExit(return_instruction); |
| return return_instruction; |
| } |
| template<> |
| -inline HReturn* HGraphBuilder::Add(HConstant* p1) { |
| - return Add<HReturn>(static_cast<HValue*>(p1)); |
| +inline HInstruction* HGraphBuilder::Add<HReturn>(HConstant* value) { |
| + return Add<HReturn>(static_cast<HValue*>(value)); |
| +} |
| + |
| + |
| +template<> |
| +inline HInstruction* HGraphBuilder::New<HContext>() { |
| + return HContext::New(zone()); |
| } |
| @@ -1560,6 +1675,8 @@ class HOptimizedGraphBuilder: public HGraphBuilder, public AstVisitor { |
| bool inline_bailout() { return inline_bailout_; } |
| + HValue* context() { return environment()->context(); } |
| + |
| void Bailout(const char* reason); |
| HBasicBlock* CreateJoin(HBasicBlock* first, |
| @@ -1835,8 +1952,7 @@ class HOptimizedGraphBuilder: public HGraphBuilder, public AstVisitor { |
| Expression* sub_expr, |
| NilValue nil); |
| - HInstruction* BuildStringCharCodeAt(HValue* context, |
| - HValue* string, |
| + HInstruction* BuildStringCharCodeAt(HValue* string, |
| HValue* index); |
| HInstruction* BuildBinaryOperation(BinaryOperation* expr, |
| HValue* left, |