f1ec44e2f5
This CL adds support to optimize for..in in fast enum-cache mode to the same degree that it was optimized in Crankshaft, without adding the same deoptimization loop that Crankshaft had with missing enum cache indices. That means code like for (var k in o) { var v = o[k]; // ... } and code like for (var k in o) { if (Object.prototype.hasOwnProperty.call(o, k)) { var v = o[k]; // ... } } which follows the https://eslint.org/docs/rules/guard-for-in linter rule, can now utilize the enum cache indices if o has only fast properties on the receiver, which speeds up the access o[k] significantly and reduces the pollution of the global megamorphic stub cache. For example the micro-benchmark in the tracking bug v8:6702 now runs faster than ever before: forIn: 1516 ms. forInHasOwnProperty: 1674 ms. forInHasOwnPropertySafe: 1595 ms. forInSum: 2051 ms. forInSumSafe: 2215 ms. Compared to numbers from V8 5.8 which is the last version running with Crankshaft forIn: 1641 ms. forInHasOwnProperty: 1719 ms. forInHasOwnPropertySafe: 1802 ms. forInSum: 2226 ms. forInSumSafe: 2409 ms. and V8 6.0 which is the current stable version with TurboFan: forIn: 1713 ms. forInHasOwnProperty: 5417 ms. forInHasOwnPropertySafe: 5324 ms. forInSum: 7556 ms. forInSumSafe: 11067 ms. It also improves the throughput on the string-fasta benchmark by around 7-10%, and there seems to be a ~5% improvement on the Speedometer/React benchmark locally. For this to work, the ForInPrepare bytecode was split into ForInEnumerate and ForInPrepare, which is very similar to how it was handled in Fullcodegen initially. In TurboFan we introduce a new operator LoadFieldByIndex that does the dynamic property load. This also removes the CheckMapValue operator again in favor of just using LoadField, ReferenceEqual and CheckIf, which work automatically with the EscapeAnalysis and the BranchConditionElimination. Bug: v8:6702 Change-Id: I91235413eea478ba77ace7bd14bb2f62e155dd9a Reviewed-on: https://chromium-review.googlesource.com/645949 Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/master@{#47768}
179 lines
5.0 KiB
C++
179 lines
5.0 KiB
C++
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/type-hints.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
std::ostream& operator<<(std::ostream& os, BinaryOperationHint hint) {
|
|
switch (hint) {
|
|
case BinaryOperationHint::kNone:
|
|
return os << "None";
|
|
case BinaryOperationHint::kSignedSmall:
|
|
return os << "SignedSmall";
|
|
case BinaryOperationHint::kSignedSmallInputs:
|
|
return os << "SignedSmallInputs";
|
|
case BinaryOperationHint::kSigned32:
|
|
return os << "Signed32";
|
|
case BinaryOperationHint::kNumber:
|
|
return os << "Number";
|
|
case BinaryOperationHint::kNumberOrOddball:
|
|
return os << "NumberOrOddball";
|
|
case BinaryOperationHint::kString:
|
|
return os << "String";
|
|
case BinaryOperationHint::kAny:
|
|
return os << "Any";
|
|
}
|
|
UNREACHABLE();
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, CompareOperationHint hint) {
|
|
switch (hint) {
|
|
case CompareOperationHint::kNone:
|
|
return os << "None";
|
|
case CompareOperationHint::kSignedSmall:
|
|
return os << "SignedSmall";
|
|
case CompareOperationHint::kNumber:
|
|
return os << "Number";
|
|
case CompareOperationHint::kNumberOrOddball:
|
|
return os << "NumberOrOddball";
|
|
case CompareOperationHint::kInternalizedString:
|
|
return os << "InternalizedString";
|
|
case CompareOperationHint::kString:
|
|
return os << "String";
|
|
case CompareOperationHint::kSymbol:
|
|
return os << "Symbol";
|
|
case CompareOperationHint::kReceiver:
|
|
return os << "Receiver";
|
|
case CompareOperationHint::kAny:
|
|
return os << "Any";
|
|
}
|
|
UNREACHABLE();
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, ForInHint hint) {
|
|
switch (hint) {
|
|
case ForInHint::kNone:
|
|
return os << "None";
|
|
case ForInHint::kEnumCacheKeys:
|
|
return os << "EnumCacheKeys";
|
|
case ForInHint::kEnumCacheKeysAndIndices:
|
|
return os << "EnumCacheKeysAndIndices";
|
|
case ForInHint::kAny:
|
|
return os << "Any";
|
|
}
|
|
UNREACHABLE();
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, ToBooleanHint hint) {
|
|
switch (hint) {
|
|
case ToBooleanHint::kNone:
|
|
return os << "None";
|
|
case ToBooleanHint::kUndefined:
|
|
return os << "Undefined";
|
|
case ToBooleanHint::kBoolean:
|
|
return os << "Boolean";
|
|
case ToBooleanHint::kNull:
|
|
return os << "Null";
|
|
case ToBooleanHint::kSmallInteger:
|
|
return os << "SmallInteger";
|
|
case ToBooleanHint::kReceiver:
|
|
return os << "Receiver";
|
|
case ToBooleanHint::kString:
|
|
return os << "String";
|
|
case ToBooleanHint::kSymbol:
|
|
return os << "Symbol";
|
|
case ToBooleanHint::kHeapNumber:
|
|
return os << "HeapNumber";
|
|
case ToBooleanHint::kAny:
|
|
return os << "Any";
|
|
case ToBooleanHint::kNeedsMap:
|
|
return os << "NeedsMap";
|
|
}
|
|
UNREACHABLE();
|
|
}
|
|
|
|
std::string ToString(ToBooleanHint hint) {
|
|
switch (hint) {
|
|
case ToBooleanHint::kNone:
|
|
return "None";
|
|
case ToBooleanHint::kUndefined:
|
|
return "Undefined";
|
|
case ToBooleanHint::kBoolean:
|
|
return "Boolean";
|
|
case ToBooleanHint::kNull:
|
|
return "Null";
|
|
case ToBooleanHint::kSmallInteger:
|
|
return "SmallInteger";
|
|
case ToBooleanHint::kReceiver:
|
|
return "Receiver";
|
|
case ToBooleanHint::kString:
|
|
return "String";
|
|
case ToBooleanHint::kSymbol:
|
|
return "Symbol";
|
|
case ToBooleanHint::kHeapNumber:
|
|
return "HeapNumber";
|
|
case ToBooleanHint::kAny:
|
|
return "Any";
|
|
case ToBooleanHint::kNeedsMap:
|
|
return "NeedsMap";
|
|
}
|
|
UNREACHABLE();
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, ToBooleanHints hints) {
|
|
if (hints == ToBooleanHint::kAny) return os << "Any";
|
|
if (hints == ToBooleanHint::kNone) return os << "None";
|
|
bool first = true;
|
|
for (ToBooleanHints::mask_type i = 0; i < sizeof(i) * 8; ++i) {
|
|
ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i);
|
|
if (hints & hint) {
|
|
if (!first) os << "|";
|
|
first = false;
|
|
os << hint;
|
|
}
|
|
}
|
|
return os;
|
|
}
|
|
|
|
std::string ToString(ToBooleanHints hints) {
|
|
if (hints == ToBooleanHint::kAny) return "Any";
|
|
if (hints == ToBooleanHint::kNone) return "None";
|
|
std::string ret;
|
|
bool first = true;
|
|
for (ToBooleanHints::mask_type i = 0; i < sizeof(i) * 8; ++i) {
|
|
ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i);
|
|
if (hints & hint) {
|
|
if (!first) ret += "|";
|
|
first = false;
|
|
ret += ToString(hint);
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags) {
|
|
switch (flags) {
|
|
case STRING_ADD_CHECK_NONE:
|
|
return os << "CheckNone";
|
|
case STRING_ADD_CHECK_LEFT:
|
|
return os << "CheckLeft";
|
|
case STRING_ADD_CHECK_RIGHT:
|
|
return os << "CheckRight";
|
|
case STRING_ADD_CHECK_BOTH:
|
|
return os << "CheckBoth";
|
|
case STRING_ADD_CONVERT_LEFT:
|
|
return os << "ConvertLeft";
|
|
case STRING_ADD_CONVERT_RIGHT:
|
|
return os << "ConvertRight";
|
|
case STRING_ADD_CONVERT:
|
|
break;
|
|
}
|
|
UNREACHABLE();
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|