Revision: 9640
Author: [email protected]
Date: Fri Oct 14 08:02:19 2011
Log: Revert r9612, it hits an assertion under special circumstances.
Problematic code is e.g.:
function typeofViaVariable() {
var foo = typeof({})
return foo === "undefined";
}
Review URL: http://codereview.chromium.org/8283036
http://code.google.com/p/v8/source/detail?r=9640
Modified:
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/hydrogen.h
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Fri Oct 14 05:26:29 2011
+++ /branches/bleeding_edge/src/hydrogen.cc Fri Oct 14 08:02:19 2011
@@ -5789,66 +5789,36 @@
void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr,
- HTypeof* typeof_expr,
+ Expression* sub_expr,
Handle<String> check) {
- HValue* value = typeof_expr->value();
+ CHECK_ALIVE(VisitForTypeOf(sub_expr));
+ HValue* value = Pop();
HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check);
instr->set_position(expr->position());
- ast_context()->ReturnControl(instr, expr->id());
- typeof_expr->DeleteAndReplaceWith(NULL);
+ return ast_context()->ReturnControl(instr, expr->id());
}
-static bool MatchLiteralCompareNil(HValue* left,
- Token::Value op,
- HValue* right,
- Handle<Object> nil,
- HValue** expr) {
- if (left->IsConstant() &&
- HConstant::cast(left)->handle().is_identical_to(nil) &&
- Token::IsEqualityOp(op)) {
- *expr = right;
+bool HGraphBuilder::TryLiteralCompare(CompareOperation* expr) {
+ Expression *sub_expr;
+ Handle<String> check;
+ if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) {
+ HandleLiteralCompareTypeof(expr, sub_expr, check);
return true;
}
- return false;
-}
-
-
-static bool MatchLiteralCompareTypeof(HValue* left,
- Token::Value op,
- HValue* right,
- HTypeof** typeof_expr,
- Handle<String>* check) {
- if (left->IsTypeof() &&
- Token::IsEqualityOp(op) &&
- right->IsConstant() &&
- HConstant::cast(right)->HasStringValue()) {
- *typeof_expr = HTypeof::cast(left);
- *check = Handle<String>::cast(HConstant::cast(right)->handle());
+
+ if (expr->IsLiteralCompareUndefined(&sub_expr)) {
+ HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue);
+ return true;
+ }
+
+ if (expr->IsLiteralCompareNull(&sub_expr)) {
+ HandleLiteralCompareNil(expr, sub_expr, kNullValue);
return true;
}
+
return false;
}
-
-
-static bool IsLiteralCompareTypeof(HValue* left,
- Token::Value op,
- HValue* right,
- HTypeof** typeof_expr,
- Handle<String>* check) {
- return MatchLiteralCompareTypeof(left, op, right, typeof_expr, check) ||
- MatchLiteralCompareTypeof(right, op, left, typeof_expr, check);
-}
-
-
-static bool IsLiteralCompareNil(HValue* left,
- Token::Value op,
- HValue* right,
- Handle<Object> nil,
- HValue** expr) {
- return MatchLiteralCompareNil(left, op, right, nil, expr) ||
- MatchLiteralCompareNil(right, op, left, nil, expr);
-}
void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
@@ -5867,10 +5837,12 @@
instr->set_position(expr->position());
return ast_context()->ReturnControl(instr, expr->id());
}
+
+ // Check for special cases that compare against literals.
+ if (TryLiteralCompare(expr)) return;
TypeInfo type_info = oracle()->CompareType(expr);
// 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 (type_info.IsUninitialized()) {
AddInstruction(new(zone()) HSoftDeoptimize);
current_block()->MarkAsDeoptimizing();
@@ -5884,20 +5856,6 @@
HValue* right = Pop();
HValue* left = Pop();
Token::Value op = expr->op();
-
- HTypeof* typeof_expr = NULL;
- Handle<String> check;
- if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) {
- return HandleLiteralCompareTypeof(expr, typeof_expr, check);
- }
- HValue* sub_expr = NULL;
- Factory* f = graph()->isolate()->factory();
- if (IsLiteralCompareNil(left, op, right, f->undefined_value(),
&sub_expr)) {
- return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue);
- }
- if (IsLiteralCompareNil(left, op, right, f->null_value(), &sub_expr)) {
- return HandleLiteralCompareNil(expr, sub_expr, kNullValue);
- }
if (op == Token::INSTANCEOF) {
// Check to see if the rhs of the instanceof is a global function not
@@ -5987,11 +5945,13 @@
void HGraphBuilder::HandleLiteralCompareNil(CompareOperation* expr,
- HValue* value,
+ Expression* sub_expr,
NilValue nil) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
ASSERT(current_block()->HasPredecessor());
+ CHECK_ALIVE(VisitForValue(sub_expr));
+ HValue* value = Pop();
EqualityKind kind =
expr->op() == Token::EQ_STRICT ? kStrictEquality :
kNonStrictEquality;
HIsNilAndBranch* instr = new(zone()) HIsNilAndBranch(value, kind, nil);
=======================================
--- /branches/bleeding_edge/src/hydrogen.h Thu Oct 13 08:07:28 2011
+++ /branches/bleeding_edge/src/hydrogen.h Fri Oct 14 08:02:19 2011
@@ -912,11 +912,12 @@
HValue* receiver,
SmallMapList* types,
Handle<String> name);
+ bool TryLiteralCompare(CompareOperation* expr);
void HandleLiteralCompareTypeof(CompareOperation* expr,
- HTypeof* typeof_expr,
+ Expression* sub_expr,
Handle<String> check);
void HandleLiteralCompareNil(CompareOperation* expr,
- HValue* value,
+ Expression* sub_expr,
NilValue nil);
HStringCharCodeAt* BuildStringCharCodeAt(HValue* context,
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev