}
-LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) {
+LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
LOperand* value = UseRegisterAtStart(instr->value());
- LInstruction* result = new(zone()) LCheckMap(value);
+ LInstruction* result = new(zone()) LCheckMaps(value);
return AssignEnvironment(result);
}
V(CheckFunction) \
V(CheckInstanceType) \
V(CheckNonSmi) \
- V(CheckMap) \
+ V(CheckMaps) \
V(CheckPrototypeMaps) \
V(CheckSmi) \
V(ClampDToUint8) \
};
-class LCheckMap: public LTemplateInstruction<0, 1, 0> {
+class LCheckMaps: public LTemplateInstruction<0, 1, 0> {
public:
- explicit LCheckMap(LOperand* value) {
+ explicit LCheckMaps(LOperand* value) {
inputs_[0] = value;
}
- DECLARE_CONCRETE_INSTRUCTION(CheckMap, "check-map")
- DECLARE_HYDROGEN_ACCESSOR(CheckMap)
+ DECLARE_CONCRETE_INSTRUCTION(CheckMaps, "check-maps")
+ DECLARE_HYDROGEN_ACCESSOR(CheckMaps)
};
}
-void LCodeGen::DoCheckMap(LCheckMap* instr) {
+void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
Register scratch = scratch0();
LOperand* input = instr->InputAt(0);
ASSERT(input->IsRegister());
Register reg = ToRegister(input);
- Handle<Map> map = instr->hydrogen()->map();
- DoCheckMapCommon(reg, scratch, map, instr->hydrogen()->mode(),
- instr->environment());
+
+ Label success;
+ SmallMapList* map_set = instr->hydrogen()->map_set();
+ for (int i = 0; i < map_set->length() - 1; i++) {
+ Handle<Map> map = map_set->at(i);
+ __ CompareMap(reg, scratch, map, &success, REQUIRE_EXACT_MAP);
+ __ b(eq, &success);
+ }
+ Handle<Map> map = map_set->last();
+ DoCheckMapCommon(reg, scratch, map, REQUIRE_EXACT_MAP, instr->environment());
+ __ bind(&success);
}
void Reserve(int capacity) { list_.Reserve(capacity); }
void Clear() { list_.Clear(); }
+ void Sort() { list_.Sort(); }
bool is_empty() const { return list_.is_empty(); }
int length() const { return list_.length(); }
}
-void HCheckMap::PrintDataTo(StringStream* stream) {
+void HCheckMaps::PrintDataTo(StringStream* stream) {
value()->PrintNameTo(stream);
- stream->Add(" %p", *map());
- if (mode() == REQUIRE_EXACT_MAP) {
- stream->Add(" [EXACT]");
- } else if (!has_element_transitions_) {
- stream->Add(" [EXACT*]");
- } else {
- stream->Add(" [MATCH ELEMENTS]");
+ stream->Add(" [%p", *map_set()->first());
+ for (int i = 1; i < map_set()->length(); ++i) {
+ stream->Add(",%p", *map_set()->at(i));
}
+ stream->Add("]");
}
}
-HType HCheckMap::CalculateInferredType() {
+HType HCheckMaps::CalculateInferredType() {
return value()->type();
}
V(Change) \
V(CheckFunction) \
V(CheckInstanceType) \
- V(CheckMap) \
+ V(CheckMaps) \
V(CheckNonSmi) \
V(CheckPrototypeMaps) \
V(CheckSmi) \
};
-class HCheckMap: public HTemplateInstruction<2> {
+class HCheckMaps: public HTemplateInstruction<2> {
public:
- HCheckMap(HValue* value,
- Handle<Map> map,
- HValue* typecheck = NULL,
- CompareMapMode mode = REQUIRE_EXACT_MAP)
- : map_(map),
- mode_(mode) {
+ HCheckMaps(HValue* value, Handle<Map> map, HValue* typecheck = NULL) {
SetOperandAt(0, value);
// If callers don't depend on a typecheck, they can pass in NULL. In that
// case we use a copy of the |value| argument as a dummy value.
set_representation(Representation::Tagged());
SetFlag(kUseGVN);
SetGVNFlag(kDependsOnMaps);
- // If the map to check doesn't have the untransitioned elements, it must not
- // be hoisted above TransitionElements instructions.
- if (mode == REQUIRE_EXACT_MAP || !map->has_fast_smi_only_elements()) {
- SetGVNFlag(kDependsOnElementsKind);
+ SetGVNFlag(kDependsOnElementsKind);
+ map_set()->Add(map);
+ }
+ HCheckMaps(HValue* value, SmallMapList* maps) {
+ SetOperandAt(0, value);
+ SetOperandAt(1, value);
+ set_representation(Representation::Tagged());
+ SetFlag(kUseGVN);
+ SetGVNFlag(kDependsOnMaps);
+ SetGVNFlag(kDependsOnElementsKind);
+ for (int i = 0; i < maps->length(); i++) {
+ map_set()->Add(maps->at(i));
+ }
+ map_set()->Sort();
+ }
+
+ static HCheckMaps* NewWithTransitions(HValue* object, Handle<Map> map) {
+ HCheckMaps* check_map = new HCheckMaps(object, map);
+ SmallMapList* map_set = check_map->map_set();
+
+ // If the map to check has the untransitioned elements, it can be hoisted
+ // above TransitionElements instructions.
+ if (map->has_fast_smi_only_elements()) {
+ check_map->ClearGVNFlag(kDependsOnElementsKind);
+ }
+
+ Map* transitioned_fast_element_map =
+ map->LookupElementsTransitionMap(FAST_ELEMENTS, NULL);
+ ASSERT(transitioned_fast_element_map == NULL ||
+ map->elements_kind() != FAST_ELEMENTS);
+ if (transitioned_fast_element_map != NULL) {
+ map_set->Add(Handle<Map>(transitioned_fast_element_map));
+ }
+ Map* transitioned_double_map =
+ map->LookupElementsTransitionMap(FAST_DOUBLE_ELEMENTS, NULL);
+ ASSERT(transitioned_double_map == NULL ||
+ map->elements_kind() == FAST_SMI_ONLY_ELEMENTS);
+ if (transitioned_double_map != NULL) {
+ map_set->Add(Handle<Map>(transitioned_double_map));
}
- has_element_transitions_ =
- map->LookupElementsTransitionMap(FAST_DOUBLE_ELEMENTS, NULL) != NULL ||
- map->LookupElementsTransitionMap(FAST_ELEMENTS, NULL) != NULL;
+ map_set->Sort();
+
+ return check_map;
}
virtual Representation RequiredInputRepresentation(int index) {
virtual HType CalculateInferredType();
HValue* value() { return OperandAt(0); }
- Handle<Map> map() const { return map_; }
- CompareMapMode mode() const { return mode_; }
+ SmallMapList* map_set() { return &map_set_; }
- DECLARE_CONCRETE_INSTRUCTION(CheckMap)
+ DECLARE_CONCRETE_INSTRUCTION(CheckMaps)
protected:
virtual bool DataEquals(HValue* other) {
- HCheckMap* b = HCheckMap::cast(other);
- // Two CheckMaps instructions are DataEqual if their maps are identical and
- // they have the same mode. The mode comparison can be ignored if the map
- // has no elements transitions.
- return map_.is_identical_to(b->map()) &&
- (b->mode() == mode() || !has_element_transitions_);
+ HCheckMaps* b = HCheckMaps::cast(other);
+ // Relies on the fact that map_set has been sorted before.
+ if (map_set()->length() != b->map_set()->length()) return false;
+ for (int i = 0; i < map_set()->length(); i++) {
+ if (!map_set()->at(i).is_identical_to(b->map_set()->at(i))) return false;
+ }
+ return true;
}
private:
- bool has_element_transitions_;
- Handle<Map> map_;
- CompareMapMode mode_;
+ SmallMapList map_set_;
};
}
-// Sets the lookup result and returns true if the store can be inlined.
-static bool ComputeStoredField(Handle<Map> type,
- Handle<String> name,
- LookupResult* lookup) {
+// Sets the lookup result and returns true if the load/store can be inlined.
+static bool ComputeLoadStoreField(Handle<Map> type,
+ Handle<String> name,
+ LookupResult* lookup,
+ bool is_store) {
type->LookupInDescriptors(NULL, *name, lookup);
if (!lookup->IsFound()) return false;
if (lookup->type() == FIELD) return true;
- return (lookup->type() == MAP_TRANSITION) &&
+ return is_store && (lookup->type() == MAP_TRANSITION) &&
(type->unused_property_fields() > 0);
}
-static int ComputeStoredFieldIndex(Handle<Map> type,
- Handle<String> name,
- LookupResult* lookup) {
+static int ComputeLoadStoreFieldIndex(Handle<Map> type,
+ Handle<String> name,
+ LookupResult* lookup) {
ASSERT(lookup->type() == FIELD || lookup->type() == MAP_TRANSITION);
if (lookup->type() == FIELD) {
return lookup->GetLocalFieldIndexFromMap(*type);
bool smi_and_map_check) {
if (smi_and_map_check) {
AddInstruction(new(zone()) HCheckNonSmi(object));
- AddInstruction(new(zone()) HCheckMap(object, type, NULL,
- ALLOW_ELEMENT_TRANSITION_MAPS));
+ AddInstruction(HCheckMaps::NewWithTransitions(object, type));
}
- int index = ComputeStoredFieldIndex(type, name, lookup);
+ int index = ComputeLoadStoreFieldIndex(type, name, lookup);
bool is_in_object = index < 0;
int offset = index * kPointerSize;
if (index < 0) {
LookupResult lookup(isolate());
Handle<Map> type = prop->GetReceiverType();
bool is_monomorphic = prop->IsMonomorphic() &&
- ComputeStoredField(type, name, &lookup);
+ ComputeLoadStoreField(type, name, &lookup, true);
return is_monomorphic
? BuildStoreNamedField(object, name, value, type, &lookup,
LookupResult lookup(isolate());
SmallMapList* types = expr->GetReceiverTypes();
bool is_monomorphic = expr->IsMonomorphic() &&
- ComputeStoredField(types->first(), name, &lookup);
+ ComputeLoadStoreField(types->first(), name, &lookup, true);
return is_monomorphic
? BuildStoreNamedField(object, name, value, types->first(), &lookup,
}
+void HGraphBuilder::HandlePolymorphicLoadNamedField(Property* expr,
+ HValue* object,
+ SmallMapList* types,
+ Handle<String> name) {
+ int count = 0;
+ int previous_field_index = 0;
+ bool is_monomorphic_field = true;
+ Handle<Map> map;
+ LookupResult lookup(isolate());
+ for (int i = 0; i < types->length() && count < kMaxLoadPolymorphism; ++i) {
+ map = types->at(i);
+ if (ComputeLoadStoreField(map, name, &lookup, false)) {
+ int index = ComputeLoadStoreFieldIndex(map, name, &lookup);
+ if (count == 0) {
+ previous_field_index = index;
+ } else if (is_monomorphic_field) {
+ is_monomorphic_field = (index == previous_field_index);
+ }
+ ++count;
+ }
+ }
+
+ // Use monomorphic load if property lookup results in the same field index
+ // for all maps. Requires special map check on the set of all handled maps.
+ HInstruction* instr;
+ if (count == types->length() && is_monomorphic_field) {
+ AddInstruction(new(zone()) HCheckMaps(object, types));
+ instr = BuildLoadNamedField(object, expr, map, &lookup, false);
+ } else {
+ HValue* context = environment()->LookupContext();
+ instr = new(zone()) HLoadNamedFieldPolymorphic(context,
+ object,
+ types,
+ name);
+ }
+
+ instr->set_position(expr->position());
+ return ast_context()->ReturnInstruction(instr, expr->id());
+}
+
+
void HGraphBuilder::HandlePolymorphicStoreNamedField(Assignment* expr,
HValue* object,
HValue* value,
for (int i = 0; i < types->length() && count < kMaxStorePolymorphism; ++i) {
Handle<Map> map = types->at(i);
LookupResult lookup(isolate());
- if (ComputeStoredField(map, name, &lookup)) {
+ if (ComputeLoadStoreField(map, name, &lookup, true)) {
if (count == 0) {
AddInstruction(new(zone()) HCheckNonSmi(object)); // Only needed once.
join = graph()->CreateBasicBlock();
bool smi_and_map_check) {
if (smi_and_map_check) {
AddInstruction(new(zone()) HCheckNonSmi(object));
- AddInstruction(new(zone()) HCheckMap(object, type, NULL,
- ALLOW_ELEMENT_TRANSITION_MAPS));
+ AddInstruction(HCheckMaps::NewWithTransitions(object, type));
}
int index = lookup->GetLocalFieldIndexFromMap(*type);
true);
} else if (lookup.IsFound() && lookup.type() == CONSTANT_FUNCTION) {
AddInstruction(new(zone()) HCheckNonSmi(obj));
- AddInstruction(new(zone()) HCheckMap(obj, map, NULL,
- ALLOW_ELEMENT_TRANSITION_MAPS));
+ AddInstruction(HCheckMaps::NewWithTransitions(obj, map));
Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*map));
return new(zone()) HConstant(function, Representation::Tagged());
} else {
HValue* val,
Handle<Map> map,
bool is_store) {
- HInstruction* mapcheck = AddInstruction(new(zone()) HCheckMap(object, map));
+ HInstruction* mapcheck = AddInstruction(new(zone()) HCheckMaps(object, map));
bool fast_smi_only_elements = map->has_fast_smi_only_elements();
bool fast_elements = map->has_fast_elements();
HInstruction* elements = AddInstruction(new(zone()) HLoadElements(object));
if (is_store && (fast_elements || fast_smi_only_elements)) {
- AddInstruction(new(zone()) HCheckMap(
+ AddInstruction(new(zone()) HCheckMaps(
elements, isolate()->factory()->fixed_array_map()));
}
HInstruction* length = NULL;
elements_kind == FAST_ELEMENTS ||
elements_kind == FAST_DOUBLE_ELEMENTS) {
if (is_store && elements_kind != FAST_DOUBLE_ELEMENTS) {
- AddInstruction(new(zone()) HCheckMap(
+ AddInstruction(new(zone()) HCheckMaps(
elements, isolate()->factory()->fixed_array_map(),
elements_kind_branch));
}
instr = BuildLoadNamed(obj, expr, types->first(), name);
} else if (types != NULL && types->length() > 1) {
AddInstruction(new(zone()) HCheckNonSmi(obj));
- HValue* context = environment()->LookupContext();
- instr = new(zone()) HLoadNamedFieldPolymorphic(context, obj, types, name);
+ HandlePolymorphicLoadNamedField(expr, obj, types, name);
+ return;
} else {
instr = BuildLoadNamedGeneric(obj, expr);
}
// its prototypes.
if (smi_and_map_check) {
AddInstruction(new(zone()) HCheckNonSmi(receiver));
- AddInstruction(new(zone()) HCheckMap(receiver, receiver_map, NULL,
- ALLOW_ELEMENT_TRANSITION_MAPS));
+ AddInstruction(HCheckMaps::NewWithTransitions(receiver, receiver_map));
}
if (!expr->holder().is_null()) {
AddInstruction(new(zone()) HCheckPrototypeMaps(
Handle<Map> map = oracle()->GetCompareMap(expr);
if (!map.is_null()) {
AddInstruction(new(zone()) HCheckNonSmi(left));
- AddInstruction(new(zone()) HCheckMap(left, map, NULL,
- ALLOW_ELEMENT_TRANSITION_MAPS));
+ AddInstruction(HCheckMaps::NewWithTransitions(left, map));
AddInstruction(new(zone()) HCheckNonSmi(right));
- AddInstruction(new(zone()) HCheckMap(right, map, NULL,
- ALLOW_ELEMENT_TRANSITION_MAPS));
+ AddInstruction(HCheckMaps::NewWithTransitions(right, map));
HCompareObjectEqAndBranch* result =
new(zone()) HCompareObjectEqAndBranch(left, right);
result->set_position(expr->position());
void HandlePropertyAssignment(Assignment* expr);
void HandleCompoundAssignment(Assignment* expr);
+ void HandlePolymorphicLoadNamedField(Property* expr,
+ HValue* object,
+ SmallMapList* types,
+ Handle<String> name);
void HandlePolymorphicStoreNamedField(Assignment* expr,
HValue* object,
HValue* value,
}
-void LCodeGen::DoCheckMap(LCheckMap* instr) {
+void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
LOperand* input = instr->InputAt(0);
ASSERT(input->IsRegister());
Register reg = ToRegister(input);
- Handle<Map> map = instr->hydrogen()->map();
- DoCheckMapCommon(reg, map, instr->hydrogen()->mode(), instr->environment());
+
+ Label success;
+ SmallMapList* map_set = instr->hydrogen()->map_set();
+ for (int i = 0; i < map_set->length() - 1; i++) {
+ Handle<Map> map = map_set->at(i);
+ __ CompareMap(reg, map, &success, REQUIRE_EXACT_MAP);
+ __ j(equal, &success);
+ }
+ Handle<Map> map = map_set->last();
+ DoCheckMapCommon(reg, map, REQUIRE_EXACT_MAP, instr->environment());
+ __ bind(&success);
}
}
-LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) {
+LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
LOperand* value = UseRegisterAtStart(instr->value());
- LCheckMap* result = new(zone()) LCheckMap(value);
+ LCheckMaps* result = new(zone()) LCheckMaps(value);
return AssignEnvironment(result);
}
V(CallStub) \
V(CheckFunction) \
V(CheckInstanceType) \
- V(CheckMap) \
+ V(CheckMaps) \
V(CheckNonSmi) \
V(CheckPrototypeMaps) \
V(CheckSmi) \
};
-class LCheckMap: public LTemplateInstruction<0, 1, 0> {
+class LCheckMaps: public LTemplateInstruction<0, 1, 0> {
public:
- explicit LCheckMap(LOperand* value) {
+ explicit LCheckMaps(LOperand* value) {
inputs_[0] = value;
}
- DECLARE_CONCRETE_INSTRUCTION(CheckMap, "check-map")
- DECLARE_HYDROGEN_ACCESSOR(CheckMap)
+ DECLARE_CONCRETE_INSTRUCTION(CheckMaps, "check-maps")
+ DECLARE_HYDROGEN_ACCESSOR(CheckMaps)
};
}
-void LCodeGen::DoCheckMap(LCheckMap* instr) {
+void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
Register scratch = scratch0();
LOperand* input = instr->InputAt(0);
ASSERT(input->IsRegister());
}
-LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) {
+LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
LOperand* value = UseRegisterAtStart(instr->value());
- LInstruction* result = new(zone()) LCheckMap(value);
+ LInstruction* result = new(zone()) LCheckMaps(value);
return AssignEnvironment(result);
}
V(CallStub) \
V(CheckFunction) \
V(CheckInstanceType) \
- V(CheckMap) \
+ V(CheckMaps) \
V(CheckNonSmi) \
V(CheckPrototypeMaps) \
V(CheckSmi) \
};
-class LCheckMap: public LTemplateInstruction<0, 1, 0> {
+class LCheckMaps: public LTemplateInstruction<0, 1, 0> {
public:
- explicit LCheckMap(LOperand* value) {
+ explicit LCheckMaps(LOperand* value) {
inputs_[0] = value;
}
- DECLARE_CONCRETE_INSTRUCTION(CheckMap, "check-map")
- DECLARE_HYDROGEN_ACCESSOR(CheckMap)
+ DECLARE_CONCRETE_INSTRUCTION(CheckMaps, "check-maps")
+ DECLARE_HYDROGEN_ACCESSOR(CheckMaps)
};
data_ = kEmptyTag;
}
+ void Sort() {
+ if ((data_ & kTagMask) == kListTag) {
+ list()->Sort(compare_value);
+ }
+ }
+
bool is_empty() const { return length() == 0; }
int length() const {
private:
typedef ZoneList<T*> PointerList;
+ static int compare_value(T* const* a, T* const* b) {
+ return Compare<T>(**a, **b);
+ }
+
static const intptr_t kEmptyTag = 1;
static const intptr_t kSingletonTag = 0;
static const intptr_t kListTag = 2;
}
-void LCodeGen::DoCheckMap(LCheckMap* instr) {
+void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
LOperand* input = instr->InputAt(0);
ASSERT(input->IsRegister());
Register reg = ToRegister(input);
- Handle<Map> map = instr->hydrogen()->map();
- DoCheckMapCommon(reg, map, instr->hydrogen()->mode(), instr->environment());
+
+ Label success;
+ SmallMapList* map_set = instr->hydrogen()->map_set();
+ for (int i = 0; i < map_set->length() - 1; i++) {
+ Handle<Map> map = map_set->at(i);
+ __ CompareMap(reg, map, &success, REQUIRE_EXACT_MAP);
+ __ j(equal, &success);
+ }
+ Handle<Map> map = map_set->last();
+ DoCheckMapCommon(reg, map, REQUIRE_EXACT_MAP, instr->environment());
+ __ bind(&success);
}
}
-LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) {
+LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) {
LOperand* value = UseRegisterAtStart(instr->value());
- LCheckMap* result = new(zone()) LCheckMap(value);
+ LCheckMaps* result = new(zone()) LCheckMaps(value);
return AssignEnvironment(result);
}
V(CallStub) \
V(CheckFunction) \
V(CheckInstanceType) \
- V(CheckMap) \
+ V(CheckMaps) \
V(CheckNonSmi) \
V(CheckPrototypeMaps) \
V(CheckSmi) \
};
-class LCheckMap: public LTemplateInstruction<0, 1, 0> {
+class LCheckMaps: public LTemplateInstruction<0, 1, 0> {
public:
- explicit LCheckMap(LOperand* value) {
+ explicit LCheckMaps(LOperand* value) {
inputs_[0] = value;
}
- DECLARE_CONCRETE_INSTRUCTION(CheckMap, "check-map")
- DECLARE_HYDROGEN_ACCESSOR(CheckMap)
+ DECLARE_CONCRETE_INSTRUCTION(CheckMaps, "check-maps")
+ DECLARE_HYDROGEN_ACCESSOR(CheckMaps)
};