class HCheckMaps: public HTemplateInstruction<2> {
public:
- HCheckMaps(HValue* value, Handle<Map> map, Zone* zone,
- HValue* typecheck = NULL)
- : map_unique_ids_(0, zone) {
- 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.
- SetOperandAt(1, typecheck != NULL ? typecheck : value);
- set_representation(Representation::Tagged());
- SetFlag(kUseGVN);
- SetFlag(kTrackSideEffectDominators);
- SetGVNFlag(kDependsOnMaps);
- SetGVNFlag(kDependsOnElementsKind);
- map_set()->Add(map, zone);
+ static HCheckMaps* New(HValue* value, Handle<Map> map, Zone* zone,
+ HValue *typecheck = NULL) {
+ HCheckMaps* check_map = new(zone) HCheckMaps(value, zone, typecheck);
+ check_map->map_set_.Add(map, zone);
+ return check_map;
}
- HCheckMaps(HValue* value, SmallMapList* maps, Zone* zone)
- : map_unique_ids_(0, zone) {
- SetOperandAt(0, value);
- SetOperandAt(1, value);
- set_representation(Representation::Tagged());
- SetFlag(kUseGVN);
- SetFlag(kTrackSideEffectDominators);
- SetGVNFlag(kDependsOnMaps);
- SetGVNFlag(kDependsOnElementsKind);
+
+ static HCheckMaps* New(HValue* value, SmallMapList* maps, Zone* zone,
+ HValue *typecheck = NULL) {
+ HCheckMaps* check_map = new(zone) HCheckMaps(value, zone, typecheck);
for (int i = 0; i < maps->length(); i++) {
- map_set()->Add(maps->at(i), zone);
+ check_map->map_set_.Add(maps->at(i), zone);
}
- map_set()->Sort();
+ check_map->map_set_.Sort();
+ return check_map;
}
- static HCheckMaps* NewWithTransitions(HValue* object, Handle<Map> map,
+ static HCheckMaps* NewWithTransitions(HValue* value, Handle<Map> map,
Zone* zone) {
- HCheckMaps* check_map = new(zone) HCheckMaps(object, map, zone);
- SmallMapList* map_set = check_map->map_set();
+ HCheckMaps* check_map = new(zone) HCheckMaps(value, zone, value);
+ check_map->map_set_.Add(map, zone);
// Since transitioned elements maps of the initial map don't fail the map
// check, the CheckMaps instruction doesn't need to depend on ElementsKinds.
Map* transitioned_map =
map->LookupElementsTransitionMap(kind);
if (transitioned_map) {
- map_set->Add(Handle<Map>(transitioned_map), zone);
+ check_map->map_set_.Add(Handle<Map>(transitioned_map), zone);
}
};
- map_set->Sort();
+ check_map->map_set_.Sort();
return check_map;
}
}
private:
+ // Clients should use one of the static New* methods above.
+ HCheckMaps(HValue* value, Zone *zone, HValue* typecheck)
+ : map_unique_ids_(0, zone) {
+ SetOperandAt(0, value);
+ // Use the object value for the dependency if NULL is passed.
+ // TODO(titzer): do GVN flags already express this dependency?
+ SetOperandAt(1, typecheck != NULL ? typecheck : value);
+ set_representation(Representation::Tagged());
+ SetFlag(kUseGVN);
+ SetFlag(kTrackSideEffectDominators);
+ SetGVNFlag(kDependsOnMaps);
+ SetGVNFlag(kDependsOnElementsKind);
+ }
+
SmallMapList map_set_;
ZoneList<UniqueValueId> map_unique_ids_;
};
HValue* HGraphBuilder::BuildCheckMap(HValue* obj,
Handle<Map> map) {
- HCheckMaps* check = new(zone()) HCheckMaps(obj, map, zone());
+ HCheckMaps* check = HCheckMaps::New(obj, map, zone());
AddInstruction(check);
return check;
}
AddInstruction(new(zone) HLoadElements(object, mapcheck));
if (is_store && (fast_elements || fast_smi_only_elements) &&
store_mode != STORE_NO_TRANSITION_HANDLE_COW) {
- HCheckMaps* check_cow_map = new(zone) HCheckMaps(
+ HCheckMaps* check_cow_map = HCheckMaps::New(
elements, isolate()->factory()->fixed_array_map(), zone);
check_cow_map->ClearGVNFlag(kDependsOnElementsKind);
AddInstruction(check_cow_map);
elements = BuildCopyElementsOnWrite(object, elements, elements_kind,
length);
} else {
- HCheckMaps* check_cow_map = new(zone) HCheckMaps(
+ HCheckMaps* check_cow_map = HCheckMaps::New(
elements, isolate()->factory()->fixed_array_map(), zone);
check_cow_map->ClearGVNFlag(kDependsOnElementsKind);
AddInstruction(check_cow_map);
void HOptimizedGraphBuilder::AddCheckMap(HValue* object, Handle<Map> map) {
AddInstruction(new(zone()) HCheckNonSmi(object));
- AddInstruction(new(zone()) HCheckMaps(object, map, zone()));
+ AddInstruction(HCheckMaps::New(object, map, zone()));
}
AddInstruction(new(zone()) HCheckNonSmi(object));
HInstruction* typecheck =
- AddInstruction(new(zone()) HCheckMaps(object, types, zone()));
+ AddInstruction(HCheckMaps::New(object, types, zone()));
HInstruction* instr =
HLoadNamedField::NewArrayLength(zone(), object, typecheck);
instr->set_position(expr->position());
AddInstruction(new(zone()) HCheckNonSmi(object));
HInstruction* instr;
if (count == types->length() && is_monomorphic_field) {
- AddInstruction(new(zone()) HCheckMaps(object, types, zone()));
+ AddInstruction(HCheckMaps::New(object, types, zone()));
instr = BuildLoadNamedField(object, map, &lookup);
} else {
HValue* context = environment()->LookupContext();
Handle<Map> map,
bool is_store,
KeyedAccessStoreMode store_mode) {
- HCheckMaps* mapcheck = new(zone()) HCheckMaps(object, map,
- zone(), dependency);
+ HCheckMaps* mapcheck = HCheckMaps::New(object, map, zone(), dependency);
AddInstruction(mapcheck);
if (dependency) {
mapcheck->ClearGVNFlag(kDependsOnElementsKind);
}
if (!has_double_maps && !has_smi_or_object_maps) return NULL;
- HCheckMaps* check_maps = new(zone()) HCheckMaps(object, maps, zone());
+ HCheckMaps* check_maps = HCheckMaps::New(object, maps, zone());
AddInstruction(check_maps);
HInstruction* instr = BuildUncheckedMonomorphicElementAccess(
object, key, val, check_maps,
HInstruction* access;
if (IsFastElementsKind(elements_kind)) {
if (is_store && !IsFastDoubleElementsKind(elements_kind)) {
- AddInstruction(new(zone()) HCheckMaps(
+ AddInstruction(HCheckMaps::New(
elements, isolate()->factory()->fixed_array_map(),
zone(), elements_kind_branch));
}