void LCodeGen::DoConstantT(LConstantT* instr) {
- Handle<Object> value = instr->value(isolate());
+ Handle<Object> object = instr->value(isolate());
AllowDeferredHandleDereference smi_check;
- __ Move(ToRegister(instr->result()), value);
+ if (instr->hydrogen()->HasObjectMap()) {
+ Handle<Map> object_map = instr->hydrogen()->ObjectMap().handle();
+ CHECK(object->IsHeapObject());
+ CHECK(!object_map->is_stable() ||
+ *object_map == Handle<HeapObject>::cast(object)->map());
+ }
+ __ Move(ToRegister(instr->result()), object);
}
void LCodeGen::DoConstantT(LConstantT* instr) {
- Handle<Object> value = instr->value(isolate());
+ Handle<Object> object = instr->value(isolate());
AllowDeferredHandleDereference smi_check;
- __ LoadObject(ToRegister(instr->result()), value);
+ if (instr->hydrogen()->HasObjectMap()) {
+ Handle<Map> object_map = instr->hydrogen()->ObjectMap().handle();
+ CHECK(object->IsHeapObject());
+ CHECK(!object_map->is_stable() ||
+ *object_map == Handle<HeapObject>::cast(object)->map());
+ }
+ __ LoadObject(ToRegister(instr->result()), object);
}
HTransitionElementsKind::cast(instr));
break;
}
- case HValue::kCheckMapValue: {
- ReduceCheckMapValue(HCheckMapValue::cast(instr));
- break;
- }
case HValue::kCheckHeapObject: {
ReduceCheckHeapObject(HCheckHeapObject::cast(instr));
break;
INC_STAT(loads_);
}
- void ReduceCheckMapValue(HCheckMapValue* instr) {
- if (!instr->map()->IsConstant()) return; // Nothing to learn.
-
- HValue* object = instr->value()->ActualValue();
- // Match a HCheckMapValue(object, HConstant(map))
- Unique<Map> map = MapConstant(instr->map());
-
- HCheckTableEntry* entry = Find(object);
- if (entry != NULL) {
- if (entry->maps_->Contains(map)) {
- if (entry->maps_->size() == 1) {
- // Object is known to have exactly this map.
- if (entry->check_ != NULL) {
- instr->DeleteAndReplaceWith(entry->check_);
- } else {
- // Mark check as dead but leave it in the graph as a checkpoint for
- // subsequent checks.
- instr->SetFlag(HValue::kIsDead);
- entry->check_ = instr;
- }
- INC_STAT(removed_);
- } else {
- // Only one map survives the check.
- entry->maps_ = new(zone()) UniqueSet<Map>(map, zone());
- entry->check_ = instr;
- }
- }
- } else {
- // No prior information.
- Insert(object, instr, map);
- }
- }
-
void ReduceCheckHeapObject(HCheckHeapObject* instr) {
if (FindMaps(instr->value()->ActualValue()) != NULL) {
// If the object has known maps, it's definitely a heap object.
if (instr->has_transition()) {
// This store transitions the object to a new map.
Kill(object);
- Insert(object, NULL, MapConstant(instr->transition()));
+ Insert(object, NULL, HConstant::cast(instr->transition())->MapValue());
} else if (instr->access().IsMap()) {
// This is a store directly to the map field of the object.
Kill(object);
if (!instr->value()->IsConstant()) return;
- Insert(object, NULL, MapConstant(instr->value()));
+ Insert(object, NULL, HConstant::cast(instr->value())->MapValue());
} else {
// If the instruction changes maps, it should be handled above.
CHECK(!instr->CheckChangesFlag(kMaps));
if (size_ < kMaxTrackedObjects) size_++;
}
- Unique<Map> MapConstant(HValue* value) {
- return Unique<Map>::cast(HConstant::cast(value)->GetUnique());
- }
-
Zone* zone() const { return phase_->zone(); }
friend class HCheckMapsEffects;
}
+HValue* HCheckMapValue::Canonicalize() {
+ if (map()->IsConstant()) {
+ HConstant* c_map = HConstant::cast(map());
+ return HCheckMaps::CreateAndInsertAfter(
+ block()->graph()->zone(), value(), c_map->MapValue(),
+ c_map->HasStableMapValue(), this);
+ }
+ return this;
+}
+
+
void HForInPrepareMap::PrintDataTo(StringStream* stream) {
enumerable()->PrintNameTo(stream);
}
HValue* HCheckMaps::Canonicalize() {
if (!IsStabilityCheck() && maps_are_stable() && value()->IsConstant()) {
HConstant* c_value = HConstant::cast(value());
- if (c_value->HasObjectMap() && c_value->ObjectMapIsStable()) {
+ if (c_value->HasObjectMap()) {
for (int i = 0; i < maps()->size(); ++i) {
if (c_value->ObjectMap() == maps()->at(i)) {
if (maps()->size() > 1) {
: HTemplateInstruction<0>(HType::TypeFromValue(object)),
object_(Unique<Object>::CreateUninitialized(object)),
object_map_(Handle<Map>::null()),
- object_map_is_stable_(false),
+ has_stable_map_value_(false),
has_smi_value_(false),
has_int32_value_(false),
has_double_value_(false),
is_undetectable_(false),
instance_type_(kUnknownInstanceType) {
if (object->IsHeapObject()) {
- Isolate* isolate = Handle<HeapObject>::cast(object)->GetIsolate();
- Handle<Map> map(Handle<HeapObject>::cast(object)->map(), isolate);
+ Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object);
+ Isolate* isolate = heap_object->GetIsolate();
+ Handle<Map> map(heap_object->map(), isolate);
is_not_in_new_space_ = !isolate->heap()->InNewSpace(*object);
instance_type_ = map->instance_type();
is_undetectable_ = map->is_undetectable();
- object_map_ = Unique<Map>::CreateImmovable(map);
- object_map_is_stable_ = map->is_stable();
+ if (map->is_stable()) object_map_ = Unique<Map>::CreateImmovable(map);
+ has_stable_map_value_ = (instance_type_ == MAP_TYPE &&
+ Handle<Map>::cast(heap_object)->is_stable());
}
if (object->IsNumber()) {
double n = object->Number();
}
-HConstant::HConstant(Unique<Object> unique,
+HConstant::HConstant(Unique<Object> object,
+ Unique<Map> object_map,
+ bool has_stable_map_value,
Representation r,
HType type,
bool is_not_in_new_space,
bool is_undetectable,
InstanceType instance_type)
: HTemplateInstruction<0>(type),
- object_(unique),
- object_map_(Handle<Map>::null()),
- object_map_is_stable_(false),
+ object_(object),
+ object_map_(object_map),
+ has_stable_map_value_(has_stable_map_value),
has_smi_value_(false),
has_int32_value_(false),
has_double_value_(false),
boolean_value_(boolean_value),
is_undetectable_(is_undetectable),
instance_type_(instance_type) {
- ASSERT(!unique.handle().is_null());
+ ASSERT(!object.handle().is_null());
ASSERT(!type.IsTaggedNumber());
Initialize(r);
}
Unique<Object> object)
: object_(object),
object_map_(Handle<Map>::null()),
- object_map_is_stable_(false),
+ has_stable_map_value_(false),
has_smi_value_(Smi::IsValid(integer_value)),
has_int32_value_(true),
has_double_value_(true),
Unique<Object> object)
: object_(object),
object_map_(Handle<Map>::null()),
- object_map_is_stable_(false),
+ has_stable_map_value_(false),
has_int32_value_(IsInteger32(double_value)),
has_double_value_(true),
has_external_reference_value_(false),
: HTemplateInstruction<0>(HType::None()),
object_(Unique<Object>(Handle<Object>::null())),
object_map_(Handle<Map>::null()),
- object_map_is_stable_(false),
+ has_stable_map_value_(false),
has_smi_value_(false),
has_int32_value_(false),
has_double_value_(false),
}
ASSERT(!object_.handle().is_null());
return new(zone) HConstant(object_,
+ object_map_,
+ has_stable_map_value_,
r,
type_,
is_not_in_new_space_,
external_reference_value_.address()));
} else {
handle(Isolate::Current())->ShortPrint(stream);
+ stream->Add(" ");
+ if (HasStableMapValue()) {
+ stream->Add("[stable-map] ");
+ }
+ if (HasObjectMap()) {
+ stream->Add("[map %p] ", *ObjectMap().handle());
+ }
}
if (!is_not_in_new_space_) {
stream->Add("[new space] ");
virtual HValue* Canonicalize() V8_OVERRIDE;
+ static HCheckMaps* CreateAndInsertAfter(Zone* zone,
+ HValue* value,
+ Unique<Map> map,
+ bool map_is_stable,
+ HInstruction* instr) {
+ return CreateAndInsertAfter(zone, value, new(zone) UniqueSet<Map>(
+ map, zone), map_is_stable, instr);
+ }
+
+ static HCheckMaps* CreateAndInsertAfter(Zone* zone,
+ HValue* value,
+ const UniqueSet<Map>* maps,
+ bool maps_are_stable,
+ HInstruction* instr) {
+ return instr->Append(new(zone) HCheckMaps(value, maps, maps_are_stable));
+ }
+
DECLARE_CONCRETE_INSTRUCTION(CheckMaps)
protected:
virtual int RedefinedOperandIndex() { return 0; }
private:
- // Clients should use one of the static New* methods above.
+ HCheckMaps(HValue* value, const UniqueSet<Map>* maps, bool maps_are_stable)
+ : HTemplateInstruction<2>(value->type()), maps_(maps),
+ has_migration_target_(false), is_stability_check_(false),
+ maps_are_stable_(maps_are_stable) {
+ ASSERT_NE(0, maps->size());
+ SetOperandAt(0, value);
+ // Use the object value for the dependency.
+ SetOperandAt(1, value);
+ set_representation(Representation::Tagged());
+ SetFlag(kUseGVN);
+ SetDependsOnFlag(kMaps);
+ SetDependsOnFlag(kElementsKind);
+ }
+
HCheckMaps(HValue* value, const UniqueSet<Map>* maps, HValue* typecheck)
: HTemplateInstruction<2>(value->type()), maps_(maps),
has_migration_target_(false), is_stability_check_(false),
}
static HConstant* CreateAndInsertBefore(Zone* zone,
- Unique<Object> unique,
+ Unique<Object> object,
bool is_not_in_new_space,
HInstruction* instruction) {
return instruction->Prepend(new(zone) HConstant(
- unique, Representation::Tagged(), HType::Tagged(),
- is_not_in_new_space, false, false, kUnknownInstanceType));
+ object, Unique<Map>(Handle<Map>::null()), false,
+ Representation::Tagged(), HType::Tagged(), is_not_in_new_space,
+ false, false, kUnknownInstanceType));
}
static HConstant* CreateAndInsertAfter(Zone* zone,
- Unique<Map> unique,
+ Unique<Map> map,
HInstruction* instruction) {
return instruction->Append(new(zone) HConstant(
- unique, Representation::Tagged(), HType::Tagged(),
- true, false, false, MAP_TYPE));
+ map, Unique<Map>(Handle<Map>::null()), false,
+ Representation::Tagged(), HType::Tagged(), true,
+ false, false, MAP_TYPE));
}
Handle<Object> handle(Isolate* isolate) {
bool IsUndetectable() const { return is_undetectable_; }
InstanceType GetInstanceType() const { return instance_type_; }
+ bool HasMapValue() const { return instance_type_ == MAP_TYPE; }
+ Unique<Map> MapValue() const {
+ ASSERT(HasMapValue());
+ return Unique<Map>::cast(GetUnique());
+ }
+ bool HasStableMapValue() const {
+ ASSERT(HasMapValue());
+ return has_stable_map_value_;
+ }
+
bool HasObjectMap() const { return !object_map_.IsNull(); }
Unique<Map> ObjectMap() const {
ASSERT(HasObjectMap());
return object_map_;
}
- bool ObjectMapIsStable() const {
- ASSERT(HasObjectMap());
- return object_map_is_stable_;
- }
virtual intptr_t Hashcode() V8_OVERRIDE {
if (has_int32_value_) {
Representation r = Representation::None(),
bool is_not_in_new_space = true,
Unique<Object> optional = Unique<Object>(Handle<Object>::null()));
- HConstant(Unique<Object> unique,
+ HConstant(Unique<Object> object,
+ Unique<Map> object_map,
+ bool has_stable_map_value,
Representation r,
HType type,
bool is_not_in_new_space,
// constant HeapObject.
Unique<Object> object_;
- // If this is a heap object, this points to the Map of the object.
+ // If object_ is a heap object, this points to the stable map of the object.
Unique<Map> object_map_;
- bool object_map_is_stable_ : 1;
+
+ // If object_ is a map, this indicates whether the map is stable.
+ bool has_stable_map_value_ : 1;
// We store the HConstant in the most specific form safely possible.
// The two flags, has_int32_value_ and has_double_value_ tell us if
HValue* value() { return OperandAt(0); }
HValue* map() { return OperandAt(1); }
+ virtual HValue* Canonicalize() V8_OVERRIDE;
+
DECLARE_CONCRETE_INSTRUCTION(CheckMapValue)
protected:
}
-#define DEFINE_GET_CONSTANT(Name, name, htype, boolean_value) \
+#define DEFINE_GET_CONSTANT(Name, name, type, htype, boolean_value) \
HConstant* HGraph::GetConstant##Name() { \
if (!constant_##name##_.is_set()) { \
HConstant* constant = new(zone()) HConstant( \
Unique<Object>::CreateImmovable(isolate()->factory()->name##_value()), \
+ Unique<Map>::CreateImmovable(isolate()->factory()->type##_map()), \
+ false, \
Representation::Tagged(), \
htype, \
true, \
}
-DEFINE_GET_CONSTANT(Undefined, undefined, HType::Tagged(), false)
-DEFINE_GET_CONSTANT(True, true, HType::Boolean(), true)
-DEFINE_GET_CONSTANT(False, false, HType::Boolean(), false)
-DEFINE_GET_CONSTANT(Hole, the_hole, HType::Tagged(), false)
-DEFINE_GET_CONSTANT(Null, null, HType::Tagged(), false)
+DEFINE_GET_CONSTANT(Undefined, undefined, undefined, HType::Tagged(), false)
+DEFINE_GET_CONSTANT(True, true, boolean, HType::Boolean(), true)
+DEFINE_GET_CONSTANT(False, false, boolean, HType::Boolean(), false)
+DEFINE_GET_CONSTANT(Hole, the_hole, the_hole, HType::Tagged(), false)
+DEFINE_GET_CONSTANT(Null, null, null, HType::Tagged(), false)
#undef DEFINE_GET_CONSTANT
void LCodeGen::DoConstantT(LConstantT* instr) {
Register reg = ToRegister(instr->result());
- Handle<Object> handle = instr->value(isolate());
+ Handle<Object> object = instr->value(isolate());
AllowDeferredHandleDereference smi_check;
- __ LoadObject(reg, handle);
+ if (instr->hydrogen()->HasObjectMap()) {
+ Handle<Map> object_map = instr->hydrogen()->ObjectMap().handle();
+ CHECK(object->IsHeapObject());
+ CHECK(!object_map->is_stable() ||
+ *object_map == Handle<HeapObject>::cast(object)->map());
+ }
+ __ LoadObject(reg, object);
}
void LCodeGen::DoConstantT(LConstantT* instr) {
- Handle<Object> value = instr->value(isolate());
+ Handle<Object> object = instr->value(isolate());
AllowDeferredHandleDereference smi_check;
- __ li(ToRegister(instr->result()), value);
+ if (instr->hydrogen()->HasObjectMap()) {
+ Handle<Map> object_map = instr->hydrogen()->ObjectMap().handle();
+ CHECK(object->IsHeapObject());
+ CHECK(!object_map->is_stable() ||
+ *object_map == Handle<HeapObject>::cast(object)->map());
+ }
+ __ li(ToRegister(instr->result()), object);
}
void LCodeGen::DoConstantT(LConstantT* instr) {
- Handle<Object> value = instr->value(isolate());
- __ Move(ToRegister(instr->result()), value);
+ Handle<Object> object = instr->value(isolate());
+ if (instr->hydrogen()->HasObjectMap()) {
+ Handle<Map> object_map = instr->hydrogen()->ObjectMap().handle();
+ CHECK(object->IsHeapObject());
+ CHECK(!object_map->is_stable() ||
+ *object_map == Handle<HeapObject>::cast(object)->map());
+ }
+ __ Move(ToRegister(instr->result()), object);
}