Commit d1fb8384 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Introduce Oddball::to_number_raw and use it for change lowering.

The Oddball::to_number_raw field contains the actual double value of the
Oddball converted to a number, and is located at the same offset as the
HeapNumber::value field, so for lowering changes we don't need to check
for undefined (or any other oddball explicitly).

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/1922443002

Cr-Commit-Position: refs/heads/master@{#35753}
parent 2bc60707
......@@ -7337,7 +7337,7 @@ class Internals {
1 * kApiPointerSize + kApiIntSize;
static const int kStringResourceOffset = 3 * kApiPointerSize;
static const int kOddballKindOffset = 5 * kApiPointerSize;
static const int kOddballKindOffset = 5 * kApiPointerSize + sizeof(double);
static const int kForeignAddressOffset = kApiPointerSize;
static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
......
......@@ -294,29 +294,8 @@ Reduction ChangeLowering::ChangeTaggedToUI32(Node* value, Node* control,
Node* if_not_smi = graph()->NewNode(common()->IfTrue(), branch);
Node* vnot_smi;
if (NodeProperties::GetType(value)->Maybe(Type::Undefined())) {
Node* check_undefined = graph()->NewNode(machine()->WordEqual(), value,
jsgraph()->UndefinedConstant());
Node* branch_undefined = graph()->NewNode(
common()->Branch(BranchHint::kFalse), check_undefined, if_not_smi);
Node* if_undefined = graph()->NewNode(common()->IfTrue(), branch_undefined);
Node* vundefined = jsgraph()->Int32Constant(0);
Node* if_not_undefined =
graph()->NewNode(common()->IfFalse(), branch_undefined);
Node* vheap_number =
graph()->NewNode(op, LoadHeapNumberValue(value, if_not_undefined));
if_not_smi =
graph()->NewNode(common()->Merge(2), if_undefined, if_not_undefined);
vnot_smi =
graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
vundefined, vheap_number, if_not_smi);
} else {
vnot_smi = graph()->NewNode(op, LoadHeapNumberValue(value, if_not_smi));
}
STATIC_ASSERT(HeapNumber::kValueOffset == Oddball::kToNumberRawOffset);
Node* vnot_smi = graph()->NewNode(op, LoadHeapNumberValue(value, if_not_smi));
Node* if_smi = graph()->NewNode(common()->IfFalse(), branch);
Node* vfrom_smi = ChangeSmiToWord32(value);
......@@ -336,29 +315,8 @@ Reduction ChangeLowering::ChangeTaggedToFloat64(Node* value, Node* control) {
Node* if_not_smi = graph()->NewNode(common()->IfTrue(), branch);
Node* vnot_smi;
if (NodeProperties::GetType(value)->Maybe(Type::Undefined())) {
Node* check_undefined = graph()->NewNode(machine()->WordEqual(), value,
jsgraph()->UndefinedConstant());
Node* branch_undefined = graph()->NewNode(
common()->Branch(BranchHint::kFalse), check_undefined, if_not_smi);
Node* if_undefined = graph()->NewNode(common()->IfTrue(), branch_undefined);
Node* vundefined =
jsgraph()->Float64Constant(std::numeric_limits<double>::quiet_NaN());
Node* if_not_undefined =
graph()->NewNode(common()->IfFalse(), branch_undefined);
Node* vheap_number = LoadHeapNumberValue(value, if_not_undefined);
if_not_smi =
graph()->NewNode(common()->Merge(2), if_undefined, if_not_undefined);
vnot_smi =
graph()->NewNode(common()->Phi(MachineRepresentation::kFloat64, 2),
vundefined, vheap_number, if_not_smi);
} else {
vnot_smi = LoadHeapNumberValue(value, if_not_smi);
}
STATIC_ASSERT(HeapNumber::kValueOffset == Oddball::kToNumberRawOffset);
Node* vnot_smi = LoadHeapNumberValue(value, if_not_smi);
Node* if_smi = graph()->NewNode(common()->IfFalse(), branch);
Node* vfrom_smi = ChangeSmiToFloat64(value);
......@@ -399,31 +357,9 @@ Reduction ChangeLowering::TruncateTaggedToWord32(Node* value, Node* control) {
Node* if_not_smi = graph()->NewNode(common()->IfTrue(), branch);
Node* vnot_smi;
if (NodeProperties::GetType(value)->Maybe(Type::Undefined())) {
Node* check_undefined = graph()->NewNode(machine()->WordEqual(), value,
jsgraph()->UndefinedConstant());
Node* branch_undefined = graph()->NewNode(
common()->Branch(BranchHint::kFalse), check_undefined, if_not_smi);
Node* if_undefined = graph()->NewNode(common()->IfTrue(), branch_undefined);
Node* vundefined = jsgraph()->Int32Constant(0);
Node* if_not_undefined =
graph()->NewNode(common()->IfFalse(), branch_undefined);
Node* vheap_number =
graph()->NewNode(machine()->TruncateFloat64ToWord32(),
LoadHeapNumberValue(value, if_not_undefined));
if_not_smi =
graph()->NewNode(common()->Merge(2), if_undefined, if_not_undefined);
vnot_smi =
graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
vundefined, vheap_number, if_not_smi);
} else {
vnot_smi = graph()->NewNode(machine()->TruncateFloat64ToWord32(),
LoadHeapNumberValue(value, if_not_smi));
}
STATIC_ASSERT(HeapNumber::kValueOffset == Oddball::kToNumberRawOffset);
Node* vnot_smi = graph()->NewNode(machine()->TruncateFloat64ToWord32(),
LoadHeapNumberValue(value, if_not_smi));
Node* if_smi = graph()->NewNode(common()->IfFalse(), branch);
Node* vfrom_smi = ChangeSmiToWord32(value);
......
......@@ -1909,6 +1909,13 @@ InterceptorInfo* Map::GetIndexedInterceptor() {
constructor->shared()->get_api_func_data()->indexed_property_handler());
}
double Oddball::to_number_raw() const {
return READ_DOUBLE_FIELD(this, kToNumberRawOffset);
}
void Oddball::set_to_number_raw(double value) {
WRITE_DOUBLE_FIELD(this, kToNumberRawOffset, value);
}
ACCESSORS(Oddball, to_string, String, kToStringOffset)
ACCESSORS(Oddball, to_number, Object, kToNumberOffset)
......
......@@ -12788,6 +12788,7 @@ void Oddball::Initialize(Isolate* isolate, Handle<Oddball> oddball,
isolate->factory()->InternalizeUtf8String(to_string);
Handle<String> internalized_type_of =
isolate->factory()->InternalizeUtf8String(type_of);
oddball->set_to_number_raw(to_number->Number());
oddball->set_to_boolean(isolate->heap()->ToBoolean(to_boolean));
oddball->set_to_number(*to_number);
oddball->set_to_string(*internalized_to_string);
......
......@@ -9433,6 +9433,10 @@ class VectorIterator {
// The Oddball describes objects null, undefined, true, and false.
class Oddball: public HeapObject {
public:
// [to_number_raw]: Cached raw to_number computed at startup.
inline double to_number_raw() const;
inline void set_to_number_raw(double value);
// [to_string]: Cached to_string computed at startup.
DECL_ACCESSORS(to_string, String)
......@@ -9462,7 +9466,8 @@ class Oddball: public HeapObject {
bool to_boolean, const char* type_of, byte kind);
// Layout description.
static const int kToStringOffset = HeapObject::kHeaderSize;
static const int kToNumberRawOffset = HeapObject::kHeaderSize;
static const int kToStringOffset = kToNumberRawOffset + kDoubleSize;
static const int kToNumberOffset = kToStringOffset + kPointerSize;
static const int kToBooleanOffset = kToNumberOffset + kPointerSize;
static const int kTypeOfOffset = kToBooleanOffset + kPointerSize;
......@@ -9484,6 +9489,7 @@ class Oddball: public HeapObject {
typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize,
kSize> BodyDescriptor;
STATIC_ASSERT(kToNumberRawOffset == HeapNumber::kValueOffset);
STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset);
STATIC_ASSERT(kNull == Internals::kNullOddballKind);
STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment