From fe2074f58038c7cf6d989758775adf71c8927706 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Fri, 13 May 2011 13:29:02 +0000 Subject: [PATCH] Removed a "feature envy" bad smell: Moved AssumeRepresentation method to where it belongs. Review URL: http://codereview.chromium.org/7015039 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7890 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen-instructions.cc | 10 ++++++++++ src/hydrogen-instructions.h | 1 + src/hydrogen.cc | 16 +++------------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 5aa5dd0bf..ccc3c182e 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -67,6 +67,16 @@ const char* Representation::Mnemonic() const { } +void HValue::AssumeRepresentation(Representation r) { + if (CheckFlag(kFlexibleRepresentation)) { + ChangeRepresentation(r); + // The representation of the value is dictated by type feedback and + // will not be changed later. + ClearFlag(kFlexibleRepresentation); + } +} + + static int32_t ConvertAndSetOverflow(int64_t result, bool* overflow) { if (result > kMaxInt) { *overflow = true; diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index 03ff00751..88ce87dbc 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -557,6 +557,7 @@ class HValue: public ZoneObject { RepresentationChanged(r); representation_ = r; } + void AssumeRepresentation(Representation r); virtual bool IsConvertibleToInteger() const { return true; } diff --git a/src/hydrogen.cc b/src/hydrogen.cc index eb6cbe0c9..18d77f339 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -4636,7 +4636,7 @@ void HGraphBuilder::VisitSub(UnaryOperation* expr) { TypeInfo info = oracle()->UnaryType(expr); Representation rep = ToRepresentation(info); TraceRepresentation(expr->op(), info, instr, rep); - AssumeRepresentation(instr, rep); + instr->AssumeRepresentation(rep); ast_context()->ReturnInstruction(instr, expr->id()); } @@ -4707,7 +4707,7 @@ HInstruction* HGraphBuilder::BuildIncrement(HValue* value, rep = Representation::Integer32(); } TraceRepresentation(expr->op(), info, instr, rep); - AssumeRepresentation(instr, rep); + instr->AssumeRepresentation(rep); return instr; } @@ -4885,7 +4885,7 @@ HInstruction* HGraphBuilder::BuildBinaryOperation(BinaryOperation* expr, rep = Representation::Integer32(); } TraceRepresentation(expr->op(), info, instr, rep); - AssumeRepresentation(instr, rep); + instr->AssumeRepresentation(rep); return instr; } @@ -5073,16 +5073,6 @@ void HGraphBuilder::TraceRepresentation(Token::Value op, } -void HGraphBuilder::AssumeRepresentation(HValue* value, Representation rep) { - if (value->CheckFlag(HValue::kFlexibleRepresentation)) { - value->ChangeRepresentation(rep); - // The representation of the value is dictated by type feedback and - // will not be changed later. - value->ClearFlag(HValue::kFlexibleRepresentation); - } -} - - Representation HGraphBuilder::ToRepresentation(TypeInfo info) { if (info.IsSmi()) return Representation::Integer32(); if (info.IsInteger32()) return Representation::Integer32(); -- 2.34.1