Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index a0133e41c4b3dd5b0f17535956ef04b46c734bd3..163dfc0be55607892ec132a3f6eec9e6a7cbc696 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -1008,6 +1008,35 @@ 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); |
+} |
+ |
+ |
+// TODO(rossberg): this should die eventually. |
+Representation HGraphBuilder::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 HGraphBuilder::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(); |
+} |
+ |
+ |
HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { |
HBasicBlock* b = graph()->CreateBasicBlock(); |
b->SetInitialEnvironment(env); |
@@ -1678,6 +1707,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 = ToRepresentation(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, |
@@ -4663,15 +4726,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 +9085,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 +9095,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()); |
} |
@@ -9654,26 +9694,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) { |