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) {
// 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
// that it won't change anymore.
HeapObjectType type = maybe_value->AsHeapObjectRef().type(js_heap_broker());
if (type.oddball_type() == HeapObjectType::kAny ||
type.oddball_type() == HeapObjectType::kUndefined ||
type.oddball_type() == HeapObjectType::kHole) {
OddballType oddball_type = maybe_value->oddball_type(js_heap_broker());
if (oddball_type == OddballType::kAny ||
oddball_type == OddballType::kUndefined ||
oddball_type == OddballType::kHole) {
maybe_value.reset();
}
}
......
......@@ -68,20 +68,20 @@ Node* JSGraph::Constant(Handle<Object> value) {
Node* JSGraph::Constant(const JSHeapBroker* broker, const ObjectRef& ref) {
if (ref.IsSmi()) return Constant(ref.AsSmi());
HeapObjectType type = ref.AsHeapObjectRef().type(broker);
OddballType oddball_type = ref.oddball_type(broker);
if (ref.IsHeapNumber()) {
return Constant(ref.AsHeapNumber().value());
} else if (type.oddball_type() == HeapObjectType::kUndefined) {
} else if (oddball_type == OddballType::kUndefined) {
DCHECK(
ref.object<Object>().equals(isolate()->factory()->undefined_value()));
return UndefinedConstant();
} else if (type.oddball_type() == HeapObjectType::kNull) {
} else if (oddball_type == OddballType::kNull) {
DCHECK(ref.object<Object>().equals(isolate()->factory()->null_value()));
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()));
return TheHoleConstant();
} else if (type.oddball_type() == HeapObjectType::kBoolean) {
} else if (oddball_type == OddballType::kBoolean) {
if (ref.object<Object>().equals(isolate()->factory()->true_value())) {
return TrueConstant();
} else {
......
......@@ -41,10 +41,6 @@ bool ObjectRef::IsSmi() const {
int ObjectRef::AsSmi() const { return object<Smi>()->value(); }
HeapObjectRef ObjectRef::AsHeapObjectRef() const {
return HeapObjectRef(object<HeapObject>());
}
base::Optional<ContextRef> ContextRef::previous(
const JSHeapBroker* broker) const {
AllowHandleAllocation handle_allocation;
......@@ -66,18 +62,18 @@ JSHeapBroker::JSHeapBroker(Isolate* isolate) : isolate_(isolate) {}
HeapObjectType JSHeapBroker::HeapObjectTypeFromMap(Map* map) const {
AllowHandleDereference allow_handle_dereference;
Heap* heap = isolate_->heap();
HeapObjectType::OddballType oddball_type = HeapObjectType::kNone;
OddballType oddball_type = OddballType::kNone;
if (map->instance_type() == ODDBALL_TYPE) {
if (map == heap->undefined_map()) {
oddball_type = HeapObjectType::kUndefined;
oddball_type = OddballType::kUndefined;
} else if (map == heap->null_map()) {
oddball_type = HeapObjectType::kNull;
oddball_type = OddballType::kNull;
} else if (map == heap->boolean_map()) {
oddball_type = HeapObjectType::kBoolean;
oddball_type = OddballType::kBoolean;
} else if (map == heap->the_hole_map()) {
oddball_type = HeapObjectType::kHole;
oddball_type = OddballType::kHole;
} else {
oddball_type = HeapObjectType::kOther;
oddball_type = OddballType::kOther;
DCHECK(map == heap->uninitialized_map() ||
map == heap->termination_exception_map() ||
map == heap->arguments_marker_map() ||
......@@ -171,6 +167,11 @@ ScriptContextTableRef NativeContextRef::script_context_table(
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 internal
} // namespace v8
......@@ -14,17 +14,18 @@ namespace v8 {
namespace internal {
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 {
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 };
typedef base::Flags<Flag> Flags;
......@@ -34,7 +35,8 @@ class HeapObjectType {
: instance_type_(instance_type),
oddball_type_(oddball_type),
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_; }
......@@ -81,9 +83,10 @@ class ObjectRef {
return Handle<T>::cast(object_);
}
OddballType oddball_type(const JSHeapBroker* broker) const;
bool IsSmi() const;
int AsSmi() const;
HeapObjectRef AsHeapObjectRef() const;
#define HEAP_IS_METHOD_DECL(Name) bool Is##Name() const;
HEAP_BROKER_KIND_LIST(HEAP_IS_METHOD_DECL)
......@@ -101,9 +104,6 @@ class HeapObjectRef : public ObjectRef {
public:
explicit HeapObjectRef(Handle<Object> object);
HeapObjectType type(const JSHeapBroker* broker) const;
HeapObjectType::OddballType oddball_type(const JSHeapBroker* broker) const {
return type(broker).oddball_type();
}
private:
friend class JSHeapBroker;
......
......@@ -741,9 +741,9 @@ Reduction JSNativeContextSpecialization::ReduceJSLoadGlobal(Node* node) {
native_context().script_context_table(js_heap_broker()).lookup(name);
if (result) {
ObjectRef contents = result->context.get(js_heap_broker(), result->index);
if (contents.IsHeapObject() &&
contents.AsHeapObject().oddball_type(js_heap_broker()) ==
HeapObjectType::kHole) {
OddballType oddball_type = contents.oddball_type(js_heap_broker());
if (oddball_type == OddballType::kHole ||
oddball_type == OddballType::kAny) {
return NoChange();
}
Node* context = jsgraph()->Constant(js_heap_broker(), result->context);
......@@ -771,12 +771,11 @@ Reduction JSNativeContextSpecialization::ReduceJSStoreGlobal(Node* node) {
native_context().script_context_table(js_heap_broker()).lookup(name);
if (result) {
ObjectRef contents = result->context.get(js_heap_broker(), result->index);
if (contents.IsHeapObject() &&
contents.AsHeapObject().oddball_type(js_heap_broker()) ==
HeapObjectType::kHole) {
OddballType oddball_type = contents.oddball_type(js_heap_broker());
if (oddball_type == OddballType::kHole ||
oddball_type == OddballType::kAny || result->immutable) {
return NoChange();
}
if (result->immutable) return NoChange();
Node* context = jsgraph()->Constant(js_heap_broker(), result->context);
effect = graph()->NewNode(javascript()->StoreContext(0, result->index),
value, context, effect, control);
......
......@@ -164,18 +164,18 @@ Type::bitset BitsetType::Lub(HeapObjectType const& type) {
return kBigInt;
case ODDBALL_TYPE:
switch (type.oddball_type()) {
case HeapObjectType::kHole:
case OddballType::kHole:
return kHole;
case HeapObjectType::kBoolean:
case OddballType::kBoolean:
return kBoolean;
case HeapObjectType::kNull:
case OddballType::kNull:
return kNull;
case HeapObjectType::kUndefined:
case OddballType::kUndefined:
return kUndefined;
case HeapObjectType::kOther:
case OddballType::kOther:
// TODO(neis): We should add a kOtherOddball type.
return kOtherInternal;
case HeapObjectType::kAny:
case OddballType::kAny:
return kOddball | kOtherInternal;
default:
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