Commit 8c4a30ac authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Make oddball type checks more convenient.

Also fix an oversight in my previous CL.

R=jarin@chromium.org

Bug: v8:7790
Change-Id: I61c783392b7b7b38ea28dc44dc1e932d15b55bc6
Reviewed-on: https://chromium-review.googlesource.com/1106170Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53862}
parent 70c43402
...@@ -171,10 +171,10 @@ Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) { ...@@ -171,10 +171,10 @@ Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) {
// We must be conservative and check if the value in the slot is currently // We must be conservative and check if the value in the slot is currently
// the hole or undefined. Only if it is neither of these, can we be sure // the hole or undefined. Only if it is neither of these, can we be sure
// that it won't change anymore. // that it won't change anymore.
HeapObjectType type = maybe_value->AsHeapObjectRef().type(js_heap_broker()); OddballType oddball_type = maybe_value->oddball_type(js_heap_broker());
if (type.oddball_type() == HeapObjectType::kAny || if (oddball_type == OddballType::kAny ||
type.oddball_type() == HeapObjectType::kUndefined || oddball_type == OddballType::kUndefined ||
type.oddball_type() == HeapObjectType::kHole) { oddball_type == OddballType::kHole) {
maybe_value.reset(); maybe_value.reset();
} }
} }
......
...@@ -68,20 +68,20 @@ Node* JSGraph::Constant(Handle<Object> value) { ...@@ -68,20 +68,20 @@ Node* JSGraph::Constant(Handle<Object> value) {
Node* JSGraph::Constant(const JSHeapBroker* broker, const ObjectRef& ref) { Node* JSGraph::Constant(const JSHeapBroker* broker, const ObjectRef& ref) {
if (ref.IsSmi()) return Constant(ref.AsSmi()); if (ref.IsSmi()) return Constant(ref.AsSmi());
HeapObjectType type = ref.AsHeapObjectRef().type(broker); OddballType oddball_type = ref.oddball_type(broker);
if (ref.IsHeapNumber()) { if (ref.IsHeapNumber()) {
return Constant(ref.AsHeapNumber().value()); return Constant(ref.AsHeapNumber().value());
} else if (type.oddball_type() == HeapObjectType::kUndefined) { } else if (oddball_type == OddballType::kUndefined) {
DCHECK( DCHECK(
ref.object<Object>().equals(isolate()->factory()->undefined_value())); ref.object<Object>().equals(isolate()->factory()->undefined_value()));
return UndefinedConstant(); return UndefinedConstant();
} else if (type.oddball_type() == HeapObjectType::kNull) { } else if (oddball_type == OddballType::kNull) {
DCHECK(ref.object<Object>().equals(isolate()->factory()->null_value())); DCHECK(ref.object<Object>().equals(isolate()->factory()->null_value()));
return NullConstant(); return NullConstant();
} else if (type.oddball_type() == HeapObjectType::kHole) { } else if (oddball_type == OddballType::kHole) {
DCHECK(ref.object<Object>().equals(isolate()->factory()->the_hole_value())); DCHECK(ref.object<Object>().equals(isolate()->factory()->the_hole_value()));
return TheHoleConstant(); return TheHoleConstant();
} else if (type.oddball_type() == HeapObjectType::kBoolean) { } else if (oddball_type == OddballType::kBoolean) {
if (ref.object<Object>().equals(isolate()->factory()->true_value())) { if (ref.object<Object>().equals(isolate()->factory()->true_value())) {
return TrueConstant(); return TrueConstant();
} else { } else {
......
...@@ -41,10 +41,6 @@ bool ObjectRef::IsSmi() const { ...@@ -41,10 +41,6 @@ bool ObjectRef::IsSmi() const {
int ObjectRef::AsSmi() const { return object<Smi>()->value(); } int ObjectRef::AsSmi() const { return object<Smi>()->value(); }
HeapObjectRef ObjectRef::AsHeapObjectRef() const {
return HeapObjectRef(object<HeapObject>());
}
base::Optional<ContextRef> ContextRef::previous( base::Optional<ContextRef> ContextRef::previous(
const JSHeapBroker* broker) const { const JSHeapBroker* broker) const {
AllowHandleAllocation handle_allocation; AllowHandleAllocation handle_allocation;
...@@ -66,18 +62,18 @@ JSHeapBroker::JSHeapBroker(Isolate* isolate) : isolate_(isolate) {} ...@@ -66,18 +62,18 @@ JSHeapBroker::JSHeapBroker(Isolate* isolate) : isolate_(isolate) {}
HeapObjectType JSHeapBroker::HeapObjectTypeFromMap(Map* map) const { HeapObjectType JSHeapBroker::HeapObjectTypeFromMap(Map* map) const {
AllowHandleDereference allow_handle_dereference; AllowHandleDereference allow_handle_dereference;
Heap* heap = isolate_->heap(); Heap* heap = isolate_->heap();
HeapObjectType::OddballType oddball_type = HeapObjectType::kNone; OddballType oddball_type = OddballType::kNone;
if (map->instance_type() == ODDBALL_TYPE) { if (map->instance_type() == ODDBALL_TYPE) {
if (map == heap->undefined_map()) { if (map == heap->undefined_map()) {
oddball_type = HeapObjectType::kUndefined; oddball_type = OddballType::kUndefined;
} else if (map == heap->null_map()) { } else if (map == heap->null_map()) {
oddball_type = HeapObjectType::kNull; oddball_type = OddballType::kNull;
} else if (map == heap->boolean_map()) { } else if (map == heap->boolean_map()) {
oddball_type = HeapObjectType::kBoolean; oddball_type = OddballType::kBoolean;
} else if (map == heap->the_hole_map()) { } else if (map == heap->the_hole_map()) {
oddball_type = HeapObjectType::kHole; oddball_type = OddballType::kHole;
} else { } else {
oddball_type = HeapObjectType::kOther; oddball_type = OddballType::kOther;
DCHECK(map == heap->uninitialized_map() || DCHECK(map == heap->uninitialized_map() ||
map == heap->termination_exception_map() || map == heap->termination_exception_map() ||
map == heap->arguments_marker_map() || map == heap->arguments_marker_map() ||
...@@ -171,6 +167,11 @@ ScriptContextTableRef NativeContextRef::script_context_table( ...@@ -171,6 +167,11 @@ ScriptContextTableRef NativeContextRef::script_context_table(
handle(object<Context>()->script_context_table(), broker->isolate())); handle(object<Context>()->script_context_table(), broker->isolate()));
} }
OddballType ObjectRef::oddball_type(const JSHeapBroker* broker) const {
return IsSmi() ? OddballType::kNone
: AsHeapObject().type(broker).oddball_type();
}
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -14,17 +14,18 @@ namespace v8 { ...@@ -14,17 +14,18 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
enum class OddballType : uint8_t {
kNone, // Not an Oddball.
kBoolean, // True or False.
kUndefined,
kNull,
kHole,
kOther, // Oddball, but none of the above.
kAny // Any Oddball.
};
class HeapObjectType { class HeapObjectType {
public: public:
enum OddballType : uint8_t {
kNone, // Not an Oddball.
kBoolean, // True or False.
kUndefined,
kNull,
kHole,
kOther, // Oddball, but none of the above.
kAny // Any Oddball.
};
enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 }; enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 };
typedef base::Flags<Flag> Flags; typedef base::Flags<Flag> Flags;
...@@ -34,7 +35,8 @@ class HeapObjectType { ...@@ -34,7 +35,8 @@ class HeapObjectType {
: instance_type_(instance_type), : instance_type_(instance_type),
oddball_type_(oddball_type), oddball_type_(oddball_type),
flags_(flags) { flags_(flags) {
DCHECK_EQ(instance_type == ODDBALL_TYPE, oddball_type != kNone); DCHECK_EQ(instance_type == ODDBALL_TYPE,
oddball_type != OddballType::kNone);
} }
OddballType oddball_type() const { return oddball_type_; } OddballType oddball_type() const { return oddball_type_; }
...@@ -81,9 +83,10 @@ class ObjectRef { ...@@ -81,9 +83,10 @@ class ObjectRef {
return Handle<T>::cast(object_); return Handle<T>::cast(object_);
} }
OddballType oddball_type(const JSHeapBroker* broker) const;
bool IsSmi() const; bool IsSmi() const;
int AsSmi() const; int AsSmi() const;
HeapObjectRef AsHeapObjectRef() const;
#define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const; #define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const;
HEAP_BROKER_KIND_LIST(HEAP_IS_METHOD_DECL) HEAP_BROKER_KIND_LIST(HEAP_IS_METHOD_DECL)
...@@ -101,9 +104,6 @@ class HeapObjectRef : public ObjectRef { ...@@ -101,9 +104,6 @@ class HeapObjectRef : public ObjectRef {
public: public:
explicit HeapObjectRef(Handle<Object> object); explicit HeapObjectRef(Handle<Object> object);
HeapObjectType type(const JSHeapBroker* broker) const; HeapObjectType type(const JSHeapBroker* broker) const;
HeapObjectType::OddballType oddball_type(const JSHeapBroker* broker) const {
return type(broker).oddball_type();
}
private: private:
friend class JSHeapBroker; friend class JSHeapBroker;
......
...@@ -741,9 +741,9 @@ Reduction JSNativeContextSpecialization::ReduceJSLoadGlobal(Node* node) { ...@@ -741,9 +741,9 @@ Reduction JSNativeContextSpecialization::ReduceJSLoadGlobal(Node* node) {
native_context().script_context_table(js_heap_broker()).lookup(name); native_context().script_context_table(js_heap_broker()).lookup(name);
if (result) { if (result) {
ObjectRef contents = result->context.get(js_heap_broker(), result->index); ObjectRef contents = result->context.get(js_heap_broker(), result->index);
if (contents.IsHeapObject() && OddballType oddball_type = contents.oddball_type(js_heap_broker());
contents.AsHeapObject().oddball_type(js_heap_broker()) == if (oddball_type == OddballType::kHole ||
HeapObjectType::kHole) { oddball_type == OddballType::kAny) {
return NoChange(); return NoChange();
} }
Node* context = jsgraph()->Constant(js_heap_broker(), result->context); Node* context = jsgraph()->Constant(js_heap_broker(), result->context);
...@@ -771,12 +771,11 @@ Reduction JSNativeContextSpecialization::ReduceJSStoreGlobal(Node* node) { ...@@ -771,12 +771,11 @@ Reduction JSNativeContextSpecialization::ReduceJSStoreGlobal(Node* node) {
native_context().script_context_table(js_heap_broker()).lookup(name); native_context().script_context_table(js_heap_broker()).lookup(name);
if (result) { if (result) {
ObjectRef contents = result->context.get(js_heap_broker(), result->index); ObjectRef contents = result->context.get(js_heap_broker(), result->index);
if (contents.IsHeapObject() && OddballType oddball_type = contents.oddball_type(js_heap_broker());
contents.AsHeapObject().oddball_type(js_heap_broker()) == if (oddball_type == OddballType::kHole ||
HeapObjectType::kHole) { oddball_type == OddballType::kAny || result->immutable) {
return NoChange(); return NoChange();
} }
if (result->immutable) return NoChange();
Node* context = jsgraph()->Constant(js_heap_broker(), result->context); Node* context = jsgraph()->Constant(js_heap_broker(), result->context);
effect = graph()->NewNode(javascript()->StoreContext(0, result->index), effect = graph()->NewNode(javascript()->StoreContext(0, result->index),
value, context, effect, control); value, context, effect, control);
......
...@@ -164,18 +164,18 @@ Type::bitset BitsetType::Lub(HeapObjectType const& type) { ...@@ -164,18 +164,18 @@ Type::bitset BitsetType::Lub(HeapObjectType const& type) {
return kBigInt; return kBigInt;
case ODDBALL_TYPE: case ODDBALL_TYPE:
switch (type.oddball_type()) { switch (type.oddball_type()) {
case HeapObjectType::kHole: case OddballType::kHole:
return kHole; return kHole;
case HeapObjectType::kBoolean: case OddballType::kBoolean:
return kBoolean; return kBoolean;
case HeapObjectType::kNull: case OddballType::kNull:
return kNull; return kNull;
case HeapObjectType::kUndefined: case OddballType::kUndefined:
return kUndefined; return kUndefined;
case HeapObjectType::kOther: case OddballType::kOther:
// TODO(neis): We should add a kOtherOddball type. // TODO(neis): We should add a kOtherOddball type.
return kOtherInternal; return kOtherInternal;
case HeapObjectType::kAny: case OddballType::kAny:
return kOddball | kOtherInternal; return kOddball | kOtherInternal;
default: default:
UNREACHABLE(); UNREACHABLE();
......
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