From: dslomov@chromium.org Date: Fri, 22 Nov 2013 19:05:21 +0000 (+0000) Subject: Safe HGraphBuilder::Add<> and New<> X-Git-Tag: upstream/4.7.83~11574 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21dca31203c3efdca1a577214a534fb2dfacbce0;p=platform%2Fupstream%2Fv8.git Safe HGraphBuilder::Add<> and New<> R=danno@chromium.org Review URL: https://codereview.chromium.org/82943005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc index 3c90b5e..894c3d3 100644 --- a/src/code-stubs-hydrogen.cc +++ b/src/code-stubs-hydrogen.cc @@ -188,7 +188,7 @@ bool CodeStubGraphBuilderBase::BuildGraph() { if (!stack_parameter_count->IsConstant() && descriptor_->hint_stack_parameter_count_ < 0) { HInstruction* constant_one = graph()->GetConstant1(); - stack_pop_count = Add(stack_parameter_count, constant_one); + stack_pop_count = AddUncasted(stack_parameter_count, constant_one); stack_pop_count->ClearFlag(HValue::kCanOverflow); // TODO(mvstanton): verify that stack_parameter_count+1 really fits in a // smi. diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index f9524bc..fba23fa 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -1434,11 +1434,11 @@ class HGoto V8_FINAL : public HTemplateControlInstruction<1, 0> { class HDeoptimize V8_FINAL : public HTemplateControlInstruction<1, 0> { public: - static HInstruction* New(Zone* zone, - HValue* context, - const char* reason, - Deoptimizer::BailoutType type, - HBasicBlock* unreachable_continuation) { + static HDeoptimize* New(Zone* zone, + HValue* context, + const char* reason, + Deoptimizer::BailoutType type, + HBasicBlock* unreachable_continuation) { return new(zone) HDeoptimize(reason, type, unreachable_continuation); } diff --git a/src/hydrogen.cc b/src/hydrogen.cc index bd8b340..3e08b69 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -1195,7 +1195,7 @@ void HGraphBuilder::AddIncrementCounter(StatsCounter* counter) { HValue* reference = Add(ExternalReference(counter)); HValue* old_value = Add(reference, HObjectAccess::ForCounter()); - HValue* new_value = Add(old_value, graph()->GetConstant1()); + HValue* new_value = AddUncasted(old_value, graph()->GetConstant1()); new_value->ClearFlag(HValue::kCanOverflow); // Ignore counter overflow Add(reference, HObjectAccess::ForCounter(), new_value); @@ -1539,7 +1539,7 @@ HValue* HGraphBuilder::BuildUncheckedDictionaryElementLoad(HValue* receiver, static_cast(NULL), FAST_SMI_ELEMENTS); - HValue* mask = Add(capacity, graph()->GetConstant1()); + HValue* mask = AddUncasted(capacity, graph()->GetConstant1()); mask->ChangeRepresentation(Representation::Integer32()); mask->ClearFlag(HValue::kCanOverflow); @@ -1571,8 +1571,8 @@ HValue* HGraphBuilder::BuildNumberToString(HValue* object, // contains two elements (number and string) for each cache entry. HValue* mask = AddLoadFixedArrayLength(number_string_cache); mask->set_type(HType::Smi()); - mask = Add(mask, graph()->GetConstant1()); - mask = Add(mask, graph()->GetConstant1()); + mask = AddUncasted(mask, graph()->GetConstant1()); + mask = AddUncasted(mask, graph()->GetConstant1()); // Check whether object is a smi. IfBuilder if_objectissmi(this); @@ -1716,7 +1716,8 @@ void HGraphBuilder::BuildCopySeqStringChars(HValue* src, HValue* index = loop.BeginBody(graph()->GetConstant0(), length, Token::LT); { HValue* src_index = AddUncasted(src_offset, index); - HValue* value = Add(src_encoding, src, src_index); + HValue* value = + AddUncasted(src_encoding, src, src_index); HValue* dst_index = AddUncasted(dst_offset, index); Add(dst_encoding, dst, dst_index, value); } @@ -9853,7 +9854,8 @@ void HOptimizedGraphBuilder::GenerateStringAdd(CallRuntime* call) { CHECK_ALIVE(VisitForValue(call->arguments()->at(1))); HValue* right = Pop(); HValue* left = Pop(); - HInstruction* result = New(left, right, STRING_ADD_CHECK_BOTH); + HInstruction* result = + NewUncasted(left, right, STRING_ADD_CHECK_BOTH); return ast_context()->ReturnInstruction(result, call->id()); } @@ -9982,7 +9984,7 @@ void HOptimizedGraphBuilder::GenerateMathSqrt(CallRuntime* call) { ASSERT(call->arguments()->length() == 1); CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); HValue* value = Pop(); - HInstruction* result = New(value, kMathSqrt); + HInstruction* result = NewUncasted(value, kMathSqrt); return ast_context()->ReturnInstruction(result, call->id()); } diff --git a/src/hydrogen.h b/src/hydrogen.h index 441c413..e0c5066 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -1057,13 +1057,13 @@ class HGraphBuilder { HInstruction* NewUncasted() { return I::New(zone(), context()); } template - I* New() { return I::cast(NewUncasted()); } + I* New() { return I::New(zone(), context()); } template HInstruction* AddUncasted() { return AddInstruction(NewUncasted());} template - I* Add() { return I::cast(AddUncasted());} + I* Add() { return AddInstructionTyped(New());} template HInstruction* NewUncasted(P1 p1) { @@ -1071,7 +1071,7 @@ class HGraphBuilder { } template - I* New(P1 p1) { return I::cast(NewUncasted(p1)); } + I* New(P1 p1) { return I::New(zone(), context(), p1); } template HInstruction* AddUncasted(P1 p1) { @@ -1085,7 +1085,12 @@ class HGraphBuilder { template I* Add(P1 p1) { - return I::cast(AddUncasted(p1)); + I* result = AddInstructionTyped(New(p1)); + // Specializations must have their parameters properly casted + // to avoid landing here. + ASSERT(!result->IsReturn() && !result->IsSimulate() && + !result->IsDeoptimize()); + return result; } template @@ -1095,7 +1100,7 @@ class HGraphBuilder { template I* New(P1 p1, P2 p2) { - return I::cast(NewUncasted(p1, p2)); + return I::New(zone(), context(), p1, p2); } template @@ -1109,7 +1114,11 @@ class HGraphBuilder { template I* Add(P1 p1, P2 p2) { - return I::cast(AddUncasted(p1, p2)); + I* result = AddInstructionTyped(New(p1, p2)); + // Specializations must have their parameters properly casted + // to avoid landing here. + ASSERT(!result->IsSimulate()); + return result; } template @@ -1119,7 +1128,7 @@ class HGraphBuilder { template I* New(P1 p1, P2 p2, P3 p3) { - return I::cast(NewUncasted(p1, p2, p3)); + return I::New(zone(), context(), p1, p2, p3); } template @@ -1129,7 +1138,7 @@ class HGraphBuilder { template I* Add(P1 p1, P2 p2, P3 p3) { - return I::cast(AddUncasted(p1, p2, p3)); + return AddInstructionTyped(New(p1, p2, p3)); } template @@ -1139,7 +1148,7 @@ class HGraphBuilder { template I* New(P1 p1, P2 p2, P3 p3, P4 p4) { - return I::cast(NewUncasted(p1, p2, p3, p4)); + return I::New(zone(), context(), p1, p2, p3, p4); } template @@ -1149,7 +1158,7 @@ class HGraphBuilder { template I* Add(P1 p1, P2 p2, P3 p3, P4 p4) { - return I::cast(AddUncasted(p1, p2, p3, p4)); + return AddInstructionTyped(New(p1, p2, p3, p4)); } template @@ -1159,7 +1168,7 @@ class HGraphBuilder { template I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { - return I::cast(NewUncasted(p1, p2, p3, p4, p5)); + return I::New(zone(), context(), p1, p2, p3, p4, p5); } template @@ -1169,7 +1178,7 @@ class HGraphBuilder { template I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { - return I::cast(AddUncasted(p1, p2, p3, p4, p5)); + return AddInstructionTyped(New(p1, p2, p3, p4, p5)); } template @@ -1179,7 +1188,7 @@ class HGraphBuilder { template I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) { - return I::cast(NewUncasted(p1, p2, p3, p4, p5, p6)); + return I::New(zone(), context(), p1, p2, p3, p4, p5, p6); } template @@ -1189,7 +1198,7 @@ class HGraphBuilder { template I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) { - return I::cast(AddInstruction(NewUncasted(p1, p2, p3, p4, p5, p6))); + return AddInstructionTyped(New(p1, p2, p3, p4, p5, p6)); } template I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) { - return I::cast(NewUncasted(p1, p2, p3, p4, p5, p6, p7)); + return I::New(zone(), context(), p1, p2, p3, p4, p5, p6, p7); } template I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) { - return I::cast(AddInstruction(NewUncasted(p1, p2, p3, p4, - p5, p6, p7))); + return AddInstructionTyped(New(p1, p2, p3, p4, p5, p6, p7)); } template I* New(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) { - return I::cast(NewUncasted(p1, p2, p3, p4, p5, p6, p7, p8)); + return I::New(zone(), context(), p1, p2, p3, p4, p5, p6, p7, p8); } template I* Add(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) { - return I::cast( - AddInstruction(NewUncasted(p1, p2, p3, p4, p5, p6, p7, p8))); + return AddInstructionTyped(New(p1, p2, p3, p4, p5, p6, p7, p8)); } void AddSimulate(BailoutId id, RemovableSimulate removable = FIXED_SIMULATE); @@ -1742,6 +1749,11 @@ class HGraphBuilder { void PadEnvironmentForContinuation(HBasicBlock* from, HBasicBlock* continuation); + template + I* AddInstructionTyped(I* instr) { + return I::cast(AddInstruction(instr)); + } + CompilationInfo* info_; HGraph* graph_; HBasicBlock* current_block_; @@ -1750,7 +1762,7 @@ class HGraphBuilder { template<> -inline HInstruction* HGraphBuilder::AddUncasted( +inline HDeoptimize* HGraphBuilder::Add( const char* reason, Deoptimizer::BailoutType type) { if (type == Deoptimizer::SOFT) { isolate()->counters()->soft_deopts_requested()->Increment(); @@ -1770,14 +1782,14 @@ inline HInstruction* HGraphBuilder::AddUncasted( template<> -inline HDeoptimize* HGraphBuilder::Add( +inline HInstruction* HGraphBuilder::AddUncasted( const char* reason, Deoptimizer::BailoutType type) { - return static_cast(AddUncasted(reason, type)); + return Add(reason, type); } template<> -inline HInstruction* HGraphBuilder::AddUncasted( +inline HSimulate* HGraphBuilder::Add( BailoutId id, RemovableSimulate removable) { HSimulate* instr = current_block()->CreateSimulate(id, removable); @@ -1787,13 +1799,20 @@ inline HInstruction* HGraphBuilder::AddUncasted( template<> +inline HSimulate* HGraphBuilder::Add( + BailoutId id) { + return Add(id, FIXED_SIMULATE); +} + + +template<> inline HInstruction* HGraphBuilder::AddUncasted(BailoutId id) { - return AddUncasted(id, FIXED_SIMULATE); + return Add(id, FIXED_SIMULATE); } template<> -inline HInstruction* HGraphBuilder::AddUncasted(HValue* value) { +inline HReturn* HGraphBuilder::Add(HValue* value) { int num_parameters = graph()->info()->num_parameters(); HValue* params = AddUncasted(num_parameters); HReturn* return_instruction = New(value, params); @@ -1803,13 +1822,24 @@ inline HInstruction* HGraphBuilder::AddUncasted(HValue* value) { template<> +inline HReturn* HGraphBuilder::Add(HConstant* value) { + return Add(static_cast(value)); +} + +template<> +inline HInstruction* HGraphBuilder::AddUncasted(HValue* value) { + return Add(value); +} + + +template<> inline HInstruction* HGraphBuilder::AddUncasted(HConstant* value) { - return AddUncasted(static_cast(value)); + return Add(value); } template<> -inline HInstruction* HGraphBuilder::AddUncasted( +inline HCallRuntime* HGraphBuilder::Add( Handle name, const Runtime::Function* c_function, int argument_count) { @@ -1826,11 +1856,25 @@ inline HInstruction* HGraphBuilder::AddUncasted( template<> -inline HInstruction* HGraphBuilder::NewUncasted() { +inline HInstruction* HGraphBuilder::AddUncasted( + Handle name, + const Runtime::Function* c_function, + int argument_count) { + return Add(name, c_function, argument_count); +} + + +template<> +inline HContext* HGraphBuilder::New() { return HContext::New(zone()); } +template<> +inline HInstruction* HGraphBuilder::NewUncasted() { + return New(); +} + class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { public: // A class encapsulating (lazily-allocated) break and continue blocks for