Chromium Code Reviews| Index: src/hydrogen.cc |
| diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
| index a0133e41c4b3dd5b0f17535956ef04b46c734bd3..be9e7eceec538149480817d5e6ca3ca6c0c0638d 100644 |
| --- a/src/hydrogen.cc |
| +++ b/src/hydrogen.cc |
| @@ -1008,6 +1008,15 @@ HReturn* HGraphBuilder::AddReturn(HValue* value) { |
| } |
| +void HGraphBuilder::AddSoftDeoptimize() { |
| + if (FLAG_always_opt) return; |
| + if (current_block()->IsDeoptimizing()) return; |
| + AddInstruction(new(zone()) HSoftDeoptimize()); |
| + current_block()->MarkAsDeoptimizing(); |
| + graph()->set_has_soft_deoptimize(true); |
| +} |
| + |
| + |
| HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { |
| HBasicBlock* b = graph()->CreateBasicBlock(); |
| b->SetInitialEnvironment(env); |
| @@ -1678,6 +1687,40 @@ HValue* HGraphBuilder::BuildCloneShallowArray(HContext* context, |
| } |
| +HInstruction* HGraphBuilder::BuildUnaryMathOp( |
| + HValue* input, Handle<Type> type, Token::Value operation) { |
| + // We only handle the numeric cases here |
| + type = handle( |
| + Type::Intersect(type, handle(Type::Number(), isolate())), isolate()); |
| + |
| + switch (operation) { |
| + default: |
| + UNREACHABLE(); |
| + case Token::SUB: { |
| + HInstruction* instr = |
| + HMul::New(zone(), environment()->LookupContext(), |
| + input, graph()->GetConstantMinus1()); |
| + Representation rep = Representation::FromType(type); |
| + if (type->Is(Type::None())) { |
| + AddSoftDeoptimize(); |
| + type = handle(Type::Any(), isolate()); |
| + } |
| + if (instr->IsBinaryOperation()) { |
| + HBinaryOperation* binop = HBinaryOperation::cast(instr); |
| + binop->set_observed_input_representation(1, rep); |
| + binop->set_observed_input_representation(2, rep); |
| + } |
| + return instr; |
| + } |
| + case Token::BIT_NOT: |
| + if (type->Is(Type::None())) { |
| + AddSoftDeoptimize(); |
| + } |
| + return new(zone()) HBitNot(input); |
| + } |
| +} |
| + |
| + |
| void HGraphBuilder::BuildCompareNil( |
| HValue* value, |
| Handle<Type> type, |
| @@ -1940,6 +1983,19 @@ HStoreNamedField* HGraphBuilder::AddStoreMapConstant(HValue *object, |
| } |
| +HValue* HGraphBuilder::LoadJSBuiltin(Builtins::JavaScript builtin, |
|
danno
2013/07/05 08:25:48
nit: one space after HValue*, and perhaps call thi
|
| + HContext* context) { |
| + HGlobalObject* global_object = new(zone()) HGlobalObject(context); |
| + AddInstruction(global_object); |
|
danno
2013/07/05 08:25:48
Instead of
HGlobalObject* global_object = new(zon
|
| + HObjectAccess access = HObjectAccess::ForJSObjectOffset( |
| + GlobalObject::kBuiltinsOffset); |
| + HValue* builtins = AddLoad(global_object, access); |
| + HObjectAccess function_access = HObjectAccess::ForJSObjectOffset( |
| + JSBuiltinsObject::OffsetOfFunctionWithId(builtin)); |
| + return AddLoad(builtins, function_access); |
| +} |
| + |
| + |
| HOptimizedGraphBuilder::HOptimizedGraphBuilder(CompilationInfo* info) |
| : HGraphBuilder(info), |
| function_state_(NULL), |
| @@ -4663,15 +4719,6 @@ void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) { |
| } |
| -void HOptimizedGraphBuilder::AddSoftDeoptimize() { |
| - if (FLAG_always_opt) return; |
| - if (current_block()->IsDeoptimizing()) return; |
| - AddInstruction(new(zone()) HSoftDeoptimize()); |
| - current_block()->MarkAsDeoptimizing(); |
| - graph()->set_has_soft_deoptimize(true); |
| -} |
| - |
| - |
| template <class Instruction> |
| HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { |
| int count = call->argument_count(); |
| @@ -9031,19 +9078,8 @@ void HOptimizedGraphBuilder::VisitTypeof(UnaryOperation* expr) { |
| void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) { |
| CHECK_ALIVE(VisitForValue(expr->expression())); |
| HValue* value = Pop(); |
| - HValue* context = environment()->LookupContext(); |
| - HInstruction* instr = |
| - HMul::New(zone(), context, value, graph()->GetConstantMinus1()); |
| Handle<Type> type = expr->type(); |
| - Representation rep = ToRepresentation(type); |
| - if (type->Is(Type::None())) { |
| - AddSoftDeoptimize(); |
| - type = handle(Type::Any(), isolate()); |
| - } |
| - if (instr->IsBinaryOperation()) { |
| - HBinaryOperation::cast(instr)->set_observed_input_representation(1, rep); |
| - HBinaryOperation::cast(instr)->set_observed_input_representation(2, rep); |
| - } |
| + HInstruction* instr = BuildUnaryMathOp(value, type, Token::SUB); |
| return ast_context()->ReturnInstruction(instr, expr->id()); |
| } |
| @@ -9052,10 +9088,7 @@ void HOptimizedGraphBuilder::VisitBitNot(UnaryOperation* expr) { |
| CHECK_ALIVE(VisitForValue(expr->expression())); |
| HValue* value = Pop(); |
| Handle<Type> info = expr->type(); |
| - if (info->Is(Type::None())) { |
| - AddSoftDeoptimize(); |
| - } |
| - HInstruction* instr = new(zone()) HBitNot(value); |
| + HInstruction* instr = BuildUnaryMathOp(value, info, Token::BIT_NOT); |
| return ast_context()->ReturnInstruction(instr, expr->id()); |
| } |
| @@ -9109,7 +9142,7 @@ HInstruction* HOptimizedGraphBuilder::BuildIncrement( |
| CountOperation* expr) { |
| // The input to the count operation is on top of the expression stack. |
| TypeInfo info = expr->type(); |
| - Representation rep = ToRepresentation(info); |
| + Representation rep = Representation::FromType(info); |
| if (rep.IsNone() || rep.IsTagged()) { |
| rep = Representation::Smi(); |
| } |
| @@ -9420,9 +9453,9 @@ HInstruction* HOptimizedGraphBuilder::BuildBinaryOperation( |
| Handle<Type> result_type = expr->result_type(); |
| bool has_fixed_right_arg = expr->has_fixed_right_arg(); |
| int fixed_right_arg_value = expr->fixed_right_arg_value(); |
| - Representation left_rep = ToRepresentation(left_type); |
| - Representation right_rep = ToRepresentation(right_type); |
| - Representation result_rep = ToRepresentation(result_type); |
| + Representation left_rep = Representation::FromType(left_type); |
| + Representation right_rep = Representation::FromType(right_type); |
| + Representation result_rep = Representation::FromType(result_type); |
| if (left_type->Is(Type::None())) { |
| AddSoftDeoptimize(); |
| left_type = handle(Type::Any(), isolate()); |
| @@ -9654,26 +9687,6 @@ void HOptimizedGraphBuilder::VisitArithmeticExpression(BinaryOperation* expr) { |
| } |
| -// TODO(rossberg): this should die eventually. |
| -Representation HOptimizedGraphBuilder::ToRepresentation(TypeInfo info) { |
| - if (info.IsUninitialized()) return Representation::None(); |
| - // TODO(verwaest): Return Smi rather than Integer32. |
| - if (info.IsSmi()) return Representation::Integer32(); |
| - if (info.IsInteger32()) return Representation::Integer32(); |
| - if (info.IsDouble()) return Representation::Double(); |
| - if (info.IsNumber()) return Representation::Double(); |
| - return Representation::Tagged(); |
| -} |
| - |
| - |
| -Representation HOptimizedGraphBuilder::ToRepresentation(Handle<Type> type) { |
| - if (type->Is(Type::None())) return Representation::None(); |
| - if (type->Is(Type::Integer32())) return Representation::Integer32(); |
| - if (type->Is(Type::Number())) return Representation::Double(); |
| - return Representation::Tagged(); |
| -} |
| - |
| - |
| void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, |
| HTypeof* typeof_expr, |
| Handle<String> check) { |
| @@ -9766,9 +9779,9 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) { |
| Handle<Type> left_type = expr->left_type(); |
| Handle<Type> right_type = expr->right_type(); |
| Handle<Type> overall_type = expr->overall_type(); |
| - Representation combined_rep = ToRepresentation(overall_type); |
| - Representation left_rep = ToRepresentation(left_type); |
| - Representation right_rep = ToRepresentation(right_type); |
| + Representation combined_rep = Representation::FromType(overall_type); |
| + Representation left_rep = Representation::FromType(left_type); |
| + Representation right_rep = Representation::FromType(right_type); |
| // Check if this expression was ever executed according to type feedback. |
| // Note that for the special typeof/null/undefined cases we get unknown here. |
| if (overall_type->Is(Type::None())) { |
| @@ -9891,8 +9904,8 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) { |
| result->set_position(expr->position()); |
| return ast_context()->ReturnInstruction(result, expr->id()); |
| } else { |
| - // TODO(verwaest): Remove once ToRepresentation properly returns Smi when |
| - // the IC measures Smi. |
| + // TODO(verwaest): Remove once Representation::FromType properly |
| + // returns Smi when the IC measures Smi. |
| if (left_type->Is(Type::Integer31())) left_rep = Representation::Smi(); |
| if (right_type->Is(Type::Integer31())) right_rep = Representation::Smi(); |
| HCompareIDAndBranch* result = |